Search in sources :

Example 11 with SearchBean

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();
    }
}
Also used : SearchBean(org.apache.cxf.jaxrs.ext.search.SearchBean) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Test(org.junit.Test)

Aggregations

SearchBean (org.apache.cxf.jaxrs.ext.search.SearchBean)11 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 ExceptionMapper (javax.ws.rs.ext.ExceptionMapper)2 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)2 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)2 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)2 ResponseExceptionMapper (org.apache.cxf.jaxrs.client.ResponseExceptionMapper)2 ConditionType (org.apache.cxf.jaxrs.ext.search.ConditionType)2 QueryContextProvider (org.apache.cxf.jaxrs.ext.search.QueryContextProvider)2 SearchContextProvider (org.apache.cxf.jaxrs.ext.search.SearchContextProvider)2 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)2 BinaryDataProvider (org.apache.cxf.jaxrs.provider.BinaryDataProvider)2 JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)2 SyncopeFiqlSearchCondition (org.apache.syncope.common.lib.search.SyncopeFiqlSearchCondition)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 Bus (org.apache.cxf.Bus)1