Search in sources :

Example 91 with AtomicInteger

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());
}
Also used : IndexerZkConfig(io.druid.server.initialization.IndexerZkConfig) SimpleWorkerResourceManagementConfig(io.druid.indexing.overlord.autoscaling.SimpleWorkerResourceManagementConfig) WorkerBehaviorConfig(io.druid.indexing.overlord.setup.WorkerBehaviorConfig) ScheduledExecutorFactory(io.druid.java.util.common.concurrent.ScheduledExecutorFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ZkPathsConfig(io.druid.server.initialization.ZkPathsConfig) HttpClient(com.metamx.http.client.HttpClient) SimpleWorkerResourceManagementStrategy(io.druid.indexing.overlord.autoscaling.SimpleWorkerResourceManagementStrategy) RemoteTaskRunnerConfig(io.druid.indexing.overlord.config.RemoteTaskRunnerConfig) ResourceManagementSchedulerConfig(io.druid.indexing.overlord.autoscaling.ResourceManagementSchedulerConfig) Test(org.junit.Test)

Example 92 with AtomicInteger

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 93 with AtomicInteger

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 94 with AtomicInteger

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 95 with AtomicInteger

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));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Closeable(java.io.Closeable) Test(org.junit.Test)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7986 Test (org.junit.Test)3775 CountDownLatch (java.util.concurrent.CountDownLatch)1072 ArrayList (java.util.ArrayList)1018 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)849 List (java.util.List)740 IOException (java.io.IOException)719 AtomicReference (java.util.concurrent.atomic.AtomicReference)574 HashMap (java.util.HashMap)499 Map (java.util.Map)460 Test (org.testng.annotations.Test)419 File (java.io.File)337 ExecutorService (java.util.concurrent.ExecutorService)337 Test (org.junit.jupiter.api.Test)334 AtomicLong (java.util.concurrent.atomic.AtomicLong)329 TimeUnit (java.util.concurrent.TimeUnit)323 HashSet (java.util.HashSet)315 Arrays (java.util.Arrays)308 Set (java.util.Set)284 Collections (java.util.Collections)266