Search in sources :

Example 1 with SingularityManagedThreadPoolFactory

use of com.hubspot.singularity.SingularityManagedThreadPoolFactory in project Singularity by HubSpot.

the class SingularityMesosSchedulerClientTest method setup.

@BeforeEach
public void setup() {
    executorService = Mockito.mock(ExecutorService.class);
    SingularityManagedThreadPoolFactory executorServiceFactory = Mockito.mock(SingularityManagedThreadPoolFactory.class);
    Mockito.when(executorServiceFactory.get("singularity-mesos-scheduler-client", 1)).thenReturn(executorService);
    client = new SingularityMesosSchedulerClient(Mockito.mock(SingularityConfiguration.class), "test", Mockito.mock(AtomicLong.class), executorServiceFactory);
    scheduler = Mockito.mock(SingularityMesosScheduler.class);
    try {
        Field schedulerField = SingularityMesosSchedulerClient.class.getDeclaredField("scheduler");
        schedulerField.setAccessible(true);
        schedulerField.set(client, scheduler);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SingularityManagedThreadPoolFactory(com.hubspot.singularity.SingularityManagedThreadPoolFactory) Field(java.lang.reflect.Field) ExecutorService(java.util.concurrent.ExecutorService) Mesos4xxException(com.hubspot.mesos.rx.java.Mesos4xxException) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with SingularityManagedThreadPoolFactory

use of com.hubspot.singularity.SingularityManagedThreadPoolFactory in project Singularity by HubSpot.

the class SingularityBlockingThreadPoolTest method testBoundedQueueBlocksWhenFullForCompletableFutures.

@Test
public void testBoundedQueueBlocksWhenFullForCompletableFutures() {
    SingularityManagedThreadPoolFactory threadPoolFactory = new SingularityManagedThreadPoolFactory(new SingularityConfiguration());
    Assertions.assertThrows(RejectedExecutionException.class, () -> {
        ExecutorAndQueue executorAndQueue = threadPoolFactory.get("test", 2, 5, false);
        IntStream.range(0, 10).forEach(i -> CompletableFuture.runAsync(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException ie) {
            // didn't see that...
            }
        }, executorAndQueue.getExecutorService()));
    });
    Assertions.assertDoesNotThrow(() -> {
        ExecutorAndQueue executorAndQueue = threadPoolFactory.get("test", 2, 5, true);
        IntStream.range(0, 10).forEach(i -> CompletableFuture.runAsync(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException ie) {
            // didn't see that...
            }
        }, executorAndQueue.getExecutorService()));
    });
}
Also used : SingularityManagedThreadPoolFactory(com.hubspot.singularity.SingularityManagedThreadPoolFactory) ExecutorAndQueue(com.hubspot.singularity.async.ExecutorAndQueue) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration) Test(org.junit.jupiter.api.Test)

Example 3 with SingularityManagedThreadPoolFactory

use of com.hubspot.singularity.SingularityManagedThreadPoolFactory in project Singularity by HubSpot.

the class SingularityBlockingThreadPoolTest method testBoundedQueueBlocksWhenFull.

@Test
public void testBoundedQueueBlocksWhenFull() {
    SingularityManagedThreadPoolFactory threadPoolFactory = new SingularityManagedThreadPoolFactory(new SingularityConfiguration());
    Assertions.assertThrows(RejectedExecutionException.class, () -> {
        ExecutorAndQueue executorAndQueue = threadPoolFactory.get("test", 2, 5, false);
        IntStream.range(0, 10).forEach(i -> executorAndQueue.getExecutorService().submit(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException ie) {
            // didn't see that...
            }
        }));
    });
    Assertions.assertDoesNotThrow(() -> {
        ExecutorAndQueue executorAndQueue = threadPoolFactory.get("test", 2, 5, true);
        IntStream.range(0, 10).forEach(i -> executorAndQueue.getExecutorService().submit(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException ie) {
            // didn't see that...
            }
        }));
    });
}
Also used : SingularityManagedThreadPoolFactory(com.hubspot.singularity.SingularityManagedThreadPoolFactory) ExecutorAndQueue(com.hubspot.singularity.async.ExecutorAndQueue) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

SingularityManagedThreadPoolFactory (com.hubspot.singularity.SingularityManagedThreadPoolFactory)3 ExecutorAndQueue (com.hubspot.singularity.async.ExecutorAndQueue)2 SingularityConfiguration (com.hubspot.singularity.config.SingularityConfiguration)2 Test (org.junit.jupiter.api.Test)2 Mesos4xxException (com.hubspot.mesos.rx.java.Mesos4xxException)1 Field (java.lang.reflect.Field)1 ExecutorService (java.util.concurrent.ExecutorService)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1