use of java.util.concurrent.atomic.AtomicInteger in project druid by druid-io.
the class RemoteTaskRunnerFactoryTest method testExecNotSharedBetweenRunners.
@Test
public void testExecNotSharedBetweenRunners() {
final AtomicInteger executorCount = new AtomicInteger(0);
RemoteTaskRunnerConfig config = new RemoteTaskRunnerConfig();
IndexerZkConfig indexerZkConfig = new IndexerZkConfig(new ZkPathsConfig() {
@Override
public String getBase() {
return basePath;
}
}, null, null, null, null, null);
HttpClient httpClient = EasyMock.createMock(HttpClient.class);
Supplier<WorkerBehaviorConfig> workerBehaviorConfig = EasyMock.createMock(Supplier.class);
ScheduledExecutorFactory executorFactory = new ScheduledExecutorFactory() {
@Override
public ScheduledExecutorService create(int i, String s) {
executorCount.incrementAndGet();
return ScheduledExecutors.fixed(i, s);
}
};
SimpleWorkerResourceManagementConfig resourceManagementConfig = new SimpleWorkerResourceManagementConfig();
ResourceManagementSchedulerConfig resourceManagementSchedulerConfig = new ResourceManagementSchedulerConfig() {
@Override
public boolean isDoAutoscale() {
return true;
}
};
RemoteTaskRunnerFactory factory = new RemoteTaskRunnerFactory(cf, config, indexerZkConfig, jsonMapper, httpClient, workerBehaviorConfig, executorFactory, resourceManagementSchedulerConfig, new SimpleWorkerResourceManagementStrategy(resourceManagementConfig, workerBehaviorConfig, resourceManagementSchedulerConfig, executorFactory));
Assert.assertEquals(1, executorCount.get());
RemoteTaskRunner remoteTaskRunner1 = factory.build();
Assert.assertEquals(2, executorCount.get());
RemoteTaskRunner remoteTaskRunner2 = factory.build();
Assert.assertEquals(3, executorCount.get());
}
use of java.util.concurrent.atomic.AtomicInteger in project druid by druid-io.
the class RetryUtilsTest method testExceptionPredicateNotMatching.
@Test
public void testExceptionPredicateNotMatching() throws Exception {
final AtomicInteger count = new AtomicInteger();
boolean threwExpectedException = false;
try {
RetryUtils.retry(new Callable<String>() {
@Override
public String call() throws Exception {
if (count.incrementAndGet() >= 2) {
return "hey";
} else {
throw new IOException("uhh");
}
}
}, isTransient, 3);
} catch (IOException e) {
threwExpectedException = e.getMessage().equals("uhh");
}
Assert.assertTrue("threw expected exception", threwExpectedException);
Assert.assertEquals("count", 1, count.get());
}
use of java.util.concurrent.atomic.AtomicInteger in project druid by druid-io.
the class RetryUtilsTest method testEventualSuccess.
@Test
public void testEventualSuccess() throws Exception {
final AtomicInteger count = new AtomicInteger();
final String result = RetryUtils.retry(new Callable<String>() {
@Override
public String call() throws Exception {
if (count.incrementAndGet() >= 2) {
return "hey";
} else {
throw new IOException("what");
}
}
}, isTransient, 3);
Assert.assertEquals("result", "hey", result);
Assert.assertEquals("count", 2, count.get());
}
use of java.util.concurrent.atomic.AtomicInteger in project druid by druid-io.
the class RetryUtilsTest method testEventualFailure.
@Test
public void testEventualFailure() throws Exception {
final AtomicInteger count = new AtomicInteger();
boolean threwExpectedException = false;
try {
RetryUtils.retry(new Callable<String>() {
@Override
public String call() throws Exception {
count.incrementAndGet();
throw new IOException("what");
}
}, isTransient, 2);
} catch (IOException e) {
threwExpectedException = e.getMessage().equals("what");
}
Assert.assertTrue("threw expected exception", threwExpectedException);
Assert.assertEquals("count", 2, count.get());
}
use of java.util.concurrent.atomic.AtomicInteger in project druid by druid-io.
the class WrappingSequenceTest method testSanity.
@Test
public void testSanity() throws Exception {
final AtomicInteger closedCounter = new AtomicInteger(0);
Closeable closeable = new Closeable() {
@Override
public void close() throws IOException {
closedCounter.incrementAndGet();
}
};
final List<Integer> nums = Arrays.asList(1, 2, 3, 4, 5);
SequenceTestHelper.testAll(Sequences.withBaggage(Sequences.simple(nums), closeable), nums);
Assert.assertEquals(3, closedCounter.get());
closedCounter.set(0);
SequenceTestHelper.testClosed(closedCounter, Sequences.withBaggage(new UnsupportedSequence(), closeable));
}
Aggregations