use of org.springframework.core.task.support.ExecutorServiceAdapter in project spring-integration by spring-projects.
the class LockRegistryLeaderInitiatorTests method testGracefulLeaderSelectorExit.
@Test
public void testGracefulLeaderSelectorExit() throws Exception {
AtomicReference<Throwable> throwableAtomicReference = new AtomicReference<>();
LockRegistry registry = mock(LockRegistry.class);
Lock lock = spy(new ReentrantLock());
willAnswer(invocation -> {
try {
return invocation.callRealMethod();
} catch (Throwable e) {
throwableAtomicReference.set(e);
throw e;
}
}).given(lock).unlock();
given(registry.obtain(anyString())).willReturn(lock);
LockRegistryLeaderInitiator another = new LockRegistryLeaderInitiator(registry);
willAnswer(invocation -> {
another.stop();
return false;
}).given(lock).tryLock(anyLong(), eq(TimeUnit.MILLISECONDS));
new DirectFieldAccessor(another).setPropertyValue("executorService", new ExecutorServiceAdapter(new SyncTaskExecutor()));
another.start();
Throwable throwable = throwableAtomicReference.get();
assertNull(throwable);
}
use of org.springframework.core.task.support.ExecutorServiceAdapter in project plugin-prov-azure by ligoj.
the class ProvAzurePluginResourceTest method checkStatusShudownFailed.
/**
* Authority is valid, but the token cannot be acquired
*/
@Test
public void checkStatusShudownFailed() throws Exception {
prepareMockAuth();
httpServer.start();
final TaskExecutor taskExecutor = Mockito.mock(TaskExecutor.class);
final ProvAzurePluginResource resource = newResource(new ExecutorServiceAdapter(taskExecutor) {
@Override
public void shutdown() {
throw new IllegalStateException();
}
});
Assertions.assertThrows(IllegalStateException.class, () -> {
resource.checkStatus(subscriptionResource.getParametersNoCheck(subscription));
});
}
Aggregations