Search in sources :

Example 1 with DefaultExecutorServiceHandler

use of com.dangdang.ddframe.job.executor.handler.impl.DefaultExecutorServiceHandler in project elastic-job by dangdangdotcom.

the class ExecutorServiceHandlerRegistryTest method assertGetExecutorServiceHandlerForConcurrent.

@Test
public void assertGetExecutorServiceHandlerForConcurrent() throws InterruptedException {
    int threadCount = 100;
    CyclicBarrier barrier = new CyclicBarrier(threadCount);
    ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
    CountDownLatch latch = new CountDownLatch(threadCount);
    Set<ExecutorService> set = new CopyOnWriteArraySet<>();
    for (int i = 0; i < threadCount; i++) {
        executorService.submit(new GetExecutorServiceHandlerTask(barrier, latch, set));
    }
    latch.await();
    assertThat(set.size(), is(1));
    assertThat(ExecutorServiceHandlerRegistry.getExecutorServiceHandler("test_job", new DefaultExecutorServiceHandler()), is(set.iterator().next()));
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) DefaultExecutorServiceHandler(com.dangdang.ddframe.job.executor.handler.impl.DefaultExecutorServiceHandler) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) CountDownLatch(java.util.concurrent.CountDownLatch) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test)

Example 2 with DefaultExecutorServiceHandler

use of com.dangdang.ddframe.job.executor.handler.impl.DefaultExecutorServiceHandler in project elastic-job by dangdangdotcom.

the class SimpleJobExecutorTest method assertNewExecutorWithDefaultHandlers.

@Test
public void assertNewExecutorWithDefaultHandlers() throws NoSuchFieldException {
    when(jobFacade.loadJobRootConfiguration(true)).thenReturn(new TestSimpleJobConfiguration("ErrorHandler", Object.class.getName()));
    SimpleJobExecutor simpleJobExecutor = new SimpleJobExecutor(new TestSimpleJob(jobCaller), jobFacade);
    assertThat(ReflectionUtils.getFieldValue(simpleJobExecutor, AbstractElasticJobExecutor.class.getDeclaredField("executorService")), instanceOf(new DefaultExecutorServiceHandler().createExecutorService("test_job").getClass()));
    assertThat(ReflectionUtils.getFieldValue(simpleJobExecutor, AbstractElasticJobExecutor.class.getDeclaredField("jobExceptionHandler")), instanceOf(DefaultJobExceptionHandler.class));
}
Also used : TestSimpleJobConfiguration(com.dangdang.ddframe.job.fixture.config.TestSimpleJobConfiguration) TestSimpleJob(com.dangdang.ddframe.job.fixture.job.TestSimpleJob) DefaultJobExceptionHandler(com.dangdang.ddframe.job.executor.handler.impl.DefaultJobExceptionHandler) DefaultExecutorServiceHandler(com.dangdang.ddframe.job.executor.handler.impl.DefaultExecutorServiceHandler) Test(org.junit.Test)

Example 3 with DefaultExecutorServiceHandler

use of com.dangdang.ddframe.job.executor.handler.impl.DefaultExecutorServiceHandler in project elastic-job by dangdangdotcom.

the class ExecutorServiceHandlerRegistryTest method assertRemove.

@Test
public void assertRemove() {
    ExecutorService actual = ExecutorServiceHandlerRegistry.getExecutorServiceHandler("test_job", new DefaultExecutorServiceHandler());
    ExecutorServiceHandlerRegistry.remove("test_job");
    assertThat(actual, not(ExecutorServiceHandlerRegistry.getExecutorServiceHandler("test_job", new DefaultExecutorServiceHandler())));
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) DefaultExecutorServiceHandler(com.dangdang.ddframe.job.executor.handler.impl.DefaultExecutorServiceHandler) Test(org.junit.Test)

Aggregations

DefaultExecutorServiceHandler (com.dangdang.ddframe.job.executor.handler.impl.DefaultExecutorServiceHandler)3 Test (org.junit.Test)3 ExecutorService (java.util.concurrent.ExecutorService)2 DefaultJobExceptionHandler (com.dangdang.ddframe.job.executor.handler.impl.DefaultJobExceptionHandler)1 TestSimpleJobConfiguration (com.dangdang.ddframe.job.fixture.config.TestSimpleJobConfiguration)1 TestSimpleJob (com.dangdang.ddframe.job.fixture.job.TestSimpleJob)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1