use of java.util.concurrent.atomic.AtomicReference in project druid by druid-io.
the class LookupCoordinatorManagerTest method testUpdateAllOnHostFailsWithFailedThings.
@Test
public void testUpdateAllOnHostFailsWithFailedThings() throws Exception {
final HttpResponseHandler<InputStream, InputStream> responseHandler = EasyMock.createStrictMock(HttpResponseHandler.class);
final String failedLookup = "failedLookup";
final URL url = LookupCoordinatorManager.getLookupsURL(HostAndPort.fromString("localhost"));
final SettableFuture<InputStream> future = SettableFuture.create();
future.set(new ByteArrayInputStream(StringUtils.toUtf8(mapper.writeValueAsString(ImmutableMap.of("status", "accepted", LookupModule.FAILED_UPDATES_KEY, ImmutableMap.of(failedLookup, ImmutableMap.of()))))));
EasyMock.expect(client.go(EasyMock.<Request>anyObject(), EasyMock.<SequenceInputStreamResponseHandler>anyObject(), EasyMock.<Duration>anyObject())).andReturn(future).once();
EasyMock.replay(client, responseHandler);
final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {
@Override
HttpResponseHandler<InputStream, InputStream> makeResponseHandler(final AtomicInteger returnCode, final AtomicReference<String> reasonString) {
returnCode.set(200);
reasonString.set("");
return responseHandler;
}
};
expectedException.expectMessage("Lookups failed to update: [\"" + failedLookup + "\"]");
try {
manager.updateAllOnHost(url, SINGLE_LOOKUP_MAP);
} finally {
EasyMock.verify(client, responseHandler);
}
}
use of java.util.concurrent.atomic.AtomicReference in project druid by druid-io.
the class LookupCoordinatorManagerTest method testDeleteAllTierMissing.
@Test
public void testDeleteAllTierMissing() throws Exception {
final HttpResponseHandler<InputStream, InputStream> responseHandler = EasyMock.createStrictMock(HttpResponseHandler.class);
final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {
@Override
HttpResponseHandler<InputStream, InputStream> makeResponseHandler(final AtomicInteger returnCode, final AtomicReference<String> reasonString) {
returnCode.set(404);
reasonString.set("");
return responseHandler;
}
};
final HostAndPort hostAndPort = HostAndPort.fromParts("someHost", 8080);
final Collection<String> drop = ImmutableList.of("lookup1");
EasyMock.expect(discoverer.getNodes(LookupModule.getTierListenerPath(LOOKUP_TIER))).andReturn(ImmutableList.of(hostAndPort)).once();
final SettableFuture<InputStream> future = SettableFuture.create();
future.set(new ByteArrayInputStream(new byte[0]));
EasyMock.expect(client.go(EasyMock.<Request>anyObject(), EasyMock.<SequenceInputStreamResponseHandler>anyObject(), EasyMock.<Duration>anyObject())).andReturn(future).once();
EasyMock.replay(client, discoverer, responseHandler);
manager.deleteAllOnTier(LOOKUP_TIER, drop);
EasyMock.verify(client, discoverer, responseHandler);
}
use of java.util.concurrent.atomic.AtomicReference in project druid by druid-io.
the class LookupCoordinatorManagerTest method testDeleteAllTierContinuesOnMissing.
@Test
public void testDeleteAllTierContinuesOnMissing() throws Exception {
final HttpResponseHandler<InputStream, InputStream> responseHandler = EasyMock.createStrictMock(HttpResponseHandler.class);
final AtomicInteger responseHandlerCalls = new AtomicInteger(0);
final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {
@Override
HttpResponseHandler<InputStream, InputStream> makeResponseHandler(final AtomicInteger returnCode, final AtomicReference<String> reasonString) {
if (responseHandlerCalls.getAndIncrement() == 0) {
returnCode.set(404);
reasonString.set("Not Found");
} else {
returnCode.set(202);
reasonString.set("");
}
return responseHandler;
}
};
final HostAndPort hostAndPort = HostAndPort.fromParts("someHost", 8080);
final Collection<String> drop = ImmutableList.of("lookup1");
EasyMock.expect(discoverer.getNodes(LookupModule.getTierListenerPath(LOOKUP_TIER))).andReturn(ImmutableList.of(hostAndPort, hostAndPort)).once();
final SettableFuture<InputStream> future = SettableFuture.create();
future.set(new ByteArrayInputStream(new byte[0]));
EasyMock.expect(client.go(EasyMock.<Request>anyObject(), EasyMock.<SequenceInputStreamResponseHandler>anyObject(), EasyMock.<Duration>anyObject())).andReturn(future).times(2);
EasyMock.replay(client, discoverer, responseHandler);
manager.deleteAllOnTier(LOOKUP_TIER, drop);
EasyMock.verify(client, discoverer, responseHandler);
Assert.assertEquals(2, responseHandlerCalls.get());
}
use of java.util.concurrent.atomic.AtomicReference in project druid by druid-io.
the class RemoteTaskRunnerTestUtils method makeRemoteTaskRunner.
RemoteTaskRunner makeRemoteTaskRunner(RemoteTaskRunnerConfig config) throws Exception {
RemoteTaskRunner remoteTaskRunner = new RemoteTaskRunner(jsonMapper, config, new IndexerZkConfig(new ZkPathsConfig() {
@Override
public String getBase() {
return basePath;
}
}, null, null, null, null, null), cf, new PathChildrenCacheFactory.Builder(), null, DSuppliers.of(new AtomicReference<>(WorkerBehaviorConfig.defaultConfig())), ScheduledExecutors.fixed(1, "Remote-Task-Runner-Cleanup--%d"), new NoopResourceManagementStrategy<WorkerTaskRunner>());
remoteTaskRunner.start();
return remoteTaskRunner;
}
use of java.util.concurrent.atomic.AtomicReference in project druid by druid-io.
the class CompressedLongsSerdeTest method testConcurrentThreadReads.
// This test attempts to cause a race condition with the DirectByteBuffers, it's non-deterministic in causing it,
// which sucks but I can't think of a way to deterministically cause it...
private void testConcurrentThreadReads(final Supplier<IndexedLongs> supplier, final IndexedLongs indexed, final long[] vals) throws Exception {
final AtomicReference<String> reason = new AtomicReference<String>("none");
final int numRuns = 1000;
final CountDownLatch startLatch = new CountDownLatch(1);
final CountDownLatch stopLatch = new CountDownLatch(2);
final AtomicBoolean failureHappened = new AtomicBoolean(false);
new Thread(new Runnable() {
@Override
public void run() {
try {
startLatch.await();
} catch (InterruptedException e) {
failureHappened.set(true);
reason.set("interrupt.");
stopLatch.countDown();
return;
}
try {
for (int i = 0; i < numRuns; ++i) {
for (int j = 0; j < indexed.size(); ++j) {
final long val = vals[j];
final long indexedVal = indexed.get(j);
if (Longs.compare(val, indexedVal) != 0) {
failureHappened.set(true);
reason.set(String.format("Thread1[%d]: %d != %d", j, val, indexedVal));
stopLatch.countDown();
return;
}
}
}
} catch (Exception e) {
e.printStackTrace();
failureHappened.set(true);
reason.set(e.getMessage());
}
stopLatch.countDown();
}
}).start();
final IndexedLongs indexed2 = supplier.get();
try {
new Thread(new Runnable() {
@Override
public void run() {
try {
startLatch.await();
} catch (InterruptedException e) {
stopLatch.countDown();
return;
}
try {
for (int i = 0; i < numRuns; ++i) {
for (int j = indexed2.size() - 1; j >= 0; --j) {
final long val = vals[j];
final long indexedVal = indexed2.get(j);
if (Longs.compare(val, indexedVal) != 0) {
failureHappened.set(true);
reason.set(String.format("Thread2[%d]: %d != %d", j, val, indexedVal));
stopLatch.countDown();
return;
}
}
}
} catch (Exception e) {
e.printStackTrace();
reason.set(e.getMessage());
failureHappened.set(true);
}
stopLatch.countDown();
}
}).start();
startLatch.countDown();
stopLatch.await();
} finally {
CloseQuietly.close(indexed2);
}
if (failureHappened.get()) {
Assert.fail("Failure happened. Reason: " + reason.get());
}
}
Aggregations