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);
}
}
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()));
});
}
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...
}
}));
});
}
Aggregations