use of org.apache.cxf.jaxrs.ext.search.SearchBean in project cxf by apache.
the class LuceneQueryVisitorFiqlTest method testThatMultipleQueriesForTheSameFieldAreThreadSafe.
@Test
public void testThatMultipleQueriesForTheSameFieldAreThreadSafe() throws InterruptedException, ExecutionException {
final LuceneQueryVisitor<SearchBean> visitor = new LuceneQueryVisitor<>();
final ExecutorService executorService = Executors.newFixedThreadPool(5);
final Collection<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < 5; ++i) {
final int index = i;
futures.add(executorService.submit(new Runnable() {
@Override
public void run() {
final SearchCondition<SearchBean> filter = getParser().parse("name==text" + index);
visitor.reset();
visitor.visit(filter);
assertNotNull("Query should not be null", visitor.getQuery());
assertThat(visitor.getQuery().toString(), equalTo("name:text" + index));
}
}));
}
executorService.shutdown();
assertTrue("All threads should be terminated", executorService.awaitTermination(5, TimeUnit.SECONDS));
for (final Future<?> future : futures) {
// The exception will be raised if queries are messed up
future.get();
}
}
Aggregations