use of mockit.Invocation in project drill by apache.
the class FunctionInitializerTest method testConcurrentFunctionBodyLoad.
@Test
public void testConcurrentFunctionBodyLoad() throws Exception {
final FunctionInitializer functionInitializer = new FunctionInitializer(CLASS_NAME, classLoader);
final AtomicInteger counter = new AtomicInteger();
new MockUp<FunctionInitializer>() {
@Mock
Java.CompilationUnit convertToCompilationUnit(Invocation inv, Class<?> clazz) {
counter.incrementAndGet();
return inv.proceed();
}
};
int threadsNumber = 5;
ExecutorService executor = Executors.newFixedThreadPool(threadsNumber);
try {
List<Future<String>> results = executor.invokeAll(Collections.nCopies(threadsNumber, new Callable<String>() {
@Override
public String call() throws Exception {
return functionInitializer.getMethod("eval");
}
}));
final Set<String> uniqueResults = new HashSet<>();
for (Future<String> result : results) {
uniqueResults.add(result.get());
}
assertEquals("All threads should have received the same result", 1, uniqueResults.size());
assertEquals("Number of function body loads should match", 1, counter.intValue());
} finally {
executor.shutdownNow();
}
}
Aggregations