use of java.util.concurrent.Future in project druid by druid-io.
the class ServerManagerTest method testDelete2.
@Test
public void testDelete2() throws Exception {
loadQueryable("test", "3", new Interval("2011-04-04/2011-04-05"));
Future future = assertQueryable(Granularities.DAY, "test", new Interval("2011-04-04/2011-04-06"), ImmutableList.<Pair<String, Interval>>of(new Pair<String, Interval>("3", new Interval("2011-04-04/2011-04-05"))));
waitForTestVerificationAndCleanup(future);
dropQueryable("test", "3", new Interval("2011-04-04/2011-04-05"));
dropQueryable("test", "1", new Interval("2011-04-04/2011-04-05"));
future = assertQueryable(Granularities.HOUR, "test", new Interval("2011-04-04/2011-04-04T06"), ImmutableList.<Pair<String, Interval>>of(new Pair<String, Interval>("2", new Interval("2011-04-04T00/2011-04-04T01")), new Pair<String, Interval>("2", new Interval("2011-04-04T01/2011-04-04T02")), new Pair<String, Interval>("2", new Interval("2011-04-04T02/2011-04-04T03")), new Pair<String, Interval>("2", new Interval("2011-04-04T04/2011-04-04T05")), new Pair<String, Interval>("2", new Interval("2011-04-04T05/2011-04-04T06"))));
waitForTestVerificationAndCleanup(future);
future = assertQueryable(Granularities.HOUR, "test", new Interval("2011-04-04/2011-04-04T03"), ImmutableList.<Pair<String, Interval>>of(new Pair<String, Interval>("2", new Interval("2011-04-04T00/2011-04-04T01")), new Pair<String, Interval>("2", new Interval("2011-04-04T01/2011-04-04T02")), new Pair<String, Interval>("2", new Interval("2011-04-04T02/2011-04-04T03"))));
waitForTestVerificationAndCleanup(future);
future = assertQueryable(Granularities.HOUR, "test", new Interval("2011-04-04T04/2011-04-04T06"), ImmutableList.<Pair<String, Interval>>of(new Pair<String, Interval>("2", new Interval("2011-04-04T04/2011-04-04T05")), new Pair<String, Interval>("2", new Interval("2011-04-04T05/2011-04-04T06"))));
waitForTestVerificationAndCleanup(future);
}
use of java.util.concurrent.Future in project druid by druid-io.
the class ChainedExecutionQueryRunnerTest method testQueryTimeout.
@Test(timeout = 60000)
public void testQueryTimeout() throws Exception {
ExecutorService exec = PrioritizedExecutorService.create(new Lifecycle(), new DruidProcessingConfig() {
@Override
public String getFormatString() {
return "test";
}
@Override
public int getNumThreads() {
return 2;
}
});
final CountDownLatch queriesStarted = new CountDownLatch(2);
final CountDownLatch queriesInterrupted = new CountDownLatch(2);
final CountDownLatch queryIsRegistered = new CountDownLatch(1);
Capture<ListenableFuture> capturedFuture = new Capture<>();
QueryWatcher watcher = EasyMock.createStrictMock(QueryWatcher.class);
watcher.registerQuery(EasyMock.<Query>anyObject(), EasyMock.and(EasyMock.<ListenableFuture>anyObject(), EasyMock.capture(capturedFuture)));
EasyMock.expectLastCall().andAnswer(new IAnswer<Void>() {
@Override
public Void answer() throws Throwable {
queryIsRegistered.countDown();
return null;
}
}).once();
EasyMock.replay(watcher);
ArrayBlockingQueue<DyingQueryRunner> interrupted = new ArrayBlockingQueue<>(3);
Set<DyingQueryRunner> runners = Sets.newHashSet(new DyingQueryRunner(queriesStarted, queriesInterrupted, interrupted), new DyingQueryRunner(queriesStarted, queriesInterrupted, interrupted), new DyingQueryRunner(queriesStarted, queriesInterrupted, interrupted));
ChainedExecutionQueryRunner chainedRunner = new ChainedExecutionQueryRunner<>(exec, watcher, Lists.<QueryRunner<Integer>>newArrayList(runners));
HashMap<String, Object> context = new HashMap<String, Object>();
final Sequence seq = chainedRunner.run(Druids.newTimeseriesQueryBuilder().dataSource("test").intervals("2014/2015").aggregators(Lists.<AggregatorFactory>newArrayList(new CountAggregatorFactory("count"))).context(ImmutableMap.<String, Object>of(QueryContextKeys.TIMEOUT, 100, "queryId", "test")).build(), context);
Future resultFuture = Executors.newFixedThreadPool(1).submit(new Runnable() {
@Override
public void run() {
Sequences.toList(seq, Lists.newArrayList());
}
});
// wait for query to register and start
queryIsRegistered.await();
queriesStarted.await();
Assert.assertTrue(capturedFuture.hasCaptured());
ListenableFuture future = capturedFuture.getValue();
// wait for query to time out
QueryInterruptedException cause = null;
try {
resultFuture.get();
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof QueryInterruptedException);
Assert.assertEquals("Query timeout", ((QueryInterruptedException) e.getCause()).getErrorCode());
cause = (QueryInterruptedException) e.getCause();
}
queriesInterrupted.await();
Assert.assertNotNull(cause);
Assert.assertTrue(future.isCancelled());
DyingQueryRunner interrupted1 = interrupted.poll();
synchronized (interrupted1) {
Assert.assertTrue("runner 1 started", interrupted1.hasStarted);
Assert.assertTrue("runner 1 interrupted", interrupted1.interrupted);
}
DyingQueryRunner interrupted2 = interrupted.poll();
synchronized (interrupted2) {
Assert.assertTrue("runner 2 started", interrupted2.hasStarted);
Assert.assertTrue("runner 2 interrupted", interrupted2.interrupted);
}
runners.remove(interrupted1);
runners.remove(interrupted2);
DyingQueryRunner remainingRunner = runners.iterator().next();
synchronized (remainingRunner) {
Assert.assertTrue("runner 3 should be interrupted or not have started", !remainingRunner.hasStarted || remainingRunner.interrupted);
}
Assert.assertFalse("runner 1 not completed", interrupted1.hasCompleted);
Assert.assertFalse("runner 2 not completed", interrupted2.hasCompleted);
Assert.assertFalse("runner 3 not completed", remainingRunner.hasCompleted);
EasyMock.verify(watcher);
}
use of java.util.concurrent.Future in project druid by druid-io.
the class BlockingPoolTest method testConcurrentBatchClose.
@Test(timeout = 1000)
public void testConcurrentBatchClose() throws ExecutionException, InterruptedException {
final int batch1 = POOL.maxSize() / 2;
final Callable<ReferenceCountingResourceHolder<List<Integer>>> c1 = new Callable<ReferenceCountingResourceHolder<List<Integer>>>() {
@Override
public ReferenceCountingResourceHolder<List<Integer>> call() throws Exception {
return POOL.takeBatch(batch1, 10);
}
};
final int batch2 = POOL.maxSize() - batch1;
final Callable<ReferenceCountingResourceHolder<List<Integer>>> c2 = new Callable<ReferenceCountingResourceHolder<List<Integer>>>() {
@Override
public ReferenceCountingResourceHolder<List<Integer>> call() throws Exception {
return POOL.takeBatch(batch2, 10);
}
};
final Future<ReferenceCountingResourceHolder<List<Integer>>> f1 = SERVICE.submit(c1);
final Future<ReferenceCountingResourceHolder<List<Integer>>> f2 = SERVICE.submit(c2);
final ReferenceCountingResourceHolder<List<Integer>> r1 = f1.get();
final ReferenceCountingResourceHolder<List<Integer>> r2 = f2.get();
assertNotNull(r1);
assertNotNull(r2);
assertEquals(batch1, r1.get().size());
assertEquals(batch2, r2.get().size());
assertEquals(0, POOL.getPoolSize());
final Future future1 = SERVICE.submit(new Runnable() {
@Override
public void run() {
r1.close();
}
});
final Future future2 = SERVICE.submit(new Runnable() {
@Override
public void run() {
r2.close();
}
});
future1.get();
future2.get();
assertEquals(POOL.maxSize(), POOL.getPoolSize());
}
use of java.util.concurrent.Future in project druid by druid-io.
the class BlockingPoolTest method testConcurrentTakeBatchClose.
@Test(timeout = 1000)
public void testConcurrentTakeBatchClose() throws ExecutionException, InterruptedException {
final ReferenceCountingResourceHolder<List<Integer>> r1 = POOL.takeBatch(1, 10);
final Callable<ReferenceCountingResourceHolder<List<Integer>>> c2 = new Callable<ReferenceCountingResourceHolder<List<Integer>>>() {
@Override
public ReferenceCountingResourceHolder<List<Integer>> call() throws Exception {
return POOL.takeBatch(10, 100);
}
};
final Future<ReferenceCountingResourceHolder<List<Integer>>> f2 = SERVICE.submit(c2);
final Future f1 = SERVICE.submit(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// ignore
}
r1.close();
}
});
final ReferenceCountingResourceHolder<List<Integer>> r2 = f2.get();
f1.get();
assertNotNull(r2);
assertEquals(10, r2.get().size());
assertEquals(0, POOL.getPoolSize());
r2.close();
assertEquals(POOL.maxSize(), POOL.getPoolSize());
}
use of java.util.concurrent.Future in project elasticsearch by elastic.
the class SearchWithRejectionsIT method testOpenContextsAfterRejections.
public void testOpenContextsAfterRejections() throws InterruptedException {
createIndex("test");
ensureGreen("test");
final int docs = scaledRandomIntBetween(20, 50);
for (int i = 0; i < docs; i++) {
client().prepareIndex("test", "type", Integer.toString(i)).setSource("field", "value").execute().actionGet();
}
IndicesStatsResponse indicesStats = client().admin().indices().prepareStats().execute().actionGet();
assertThat(indicesStats.getTotal().getSearch().getOpenContexts(), equalTo(0L));
refresh();
int numSearches = 10;
Future<SearchResponse>[] responses = new Future[numSearches];
SearchType searchType = randomFrom(SearchType.DEFAULT, SearchType.QUERY_THEN_FETCH, SearchType.DFS_QUERY_THEN_FETCH);
logger.info("search type is {}", searchType);
for (int i = 0; i < numSearches; i++) {
responses[i] = client().prepareSearch().setQuery(matchAllQuery()).setSearchType(searchType).execute();
}
for (int i = 0; i < numSearches; i++) {
try {
responses[i].get();
} catch (Exception t) {
}
}
awaitBusy(() -> client().admin().indices().prepareStats().execute().actionGet().getTotal().getSearch().getOpenContexts() == 0, 1, TimeUnit.SECONDS);
indicesStats = client().admin().indices().prepareStats().execute().actionGet();
assertThat(indicesStats.getTotal().getSearch().getOpenContexts(), equalTo(0L));
}
Aggregations