forked from ronmamo/reflections
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ronmamo#206 from andreabertagnolli/issue81
Fix issue ronmamo#81 by disabling cache's use on url connection
- Loading branch information
Showing
2 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/org/reflections/ReflectionsThreadSafenessTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.reflections; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.junit.Test; | ||
import org.reflections.scanners.SubTypesScanner; | ||
import org.reflections.util.ClasspathHelper; | ||
import org.reflections.util.ConfigurationBuilder; | ||
|
||
import java.util.Set; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class ReflectionsThreadSafenessTest { | ||
|
||
/** | ||
* https://github.com/ronmamo/reflections/issues/81 | ||
*/ | ||
@Test | ||
public void reflections_scan_is_thread_safe() throws Exception { | ||
|
||
Callable<Set<Class<? extends ImmutableMap>>> callable = new Callable<Set<Class<? extends ImmutableMap>>>() { | ||
@Override | ||
public Set<Class<? extends ImmutableMap>> call() throws Exception { | ||
final Reflections reflections = new Reflections(new ConfigurationBuilder() | ||
.setUrls(singletonList(ClasspathHelper.forClass(ImmutableMap.class))) | ||
.setScanners(new SubTypesScanner(false))); | ||
|
||
return reflections.getSubTypesOf(ImmutableMap.class); | ||
} | ||
}; | ||
|
||
final ExecutorService pool = Executors.newFixedThreadPool(2); | ||
|
||
final Future<?> first = pool.submit(callable); | ||
final Future<?> second = pool.submit(callable); | ||
|
||
assertEquals(first.get(5, SECONDS), second.get(5, SECONDS)); | ||
} | ||
} |