use of org.springframework.core.task.SyncTaskExecutor in project spring-integration by spring-projects.
the class ExecutorChannelTests method interceptorWithException.
@Test
public void interceptorWithException() {
ExecutorChannel channel = new ExecutorChannel(new SyncTaskExecutor());
channel.setBeanFactory(mock(BeanFactory.class));
channel.afterPropertiesSet();
Message<Object> message = new GenericMessage<Object>("foo");
MessageHandler handler = mock(MessageHandler.class);
IllegalStateException expected = new IllegalStateException("Fake exception");
willThrow(expected).given(handler).handleMessage(message);
BeforeHandleInterceptor interceptor = new BeforeHandleInterceptor();
channel.addInterceptor(interceptor);
channel.subscribe(handler);
try {
channel.send(message);
} catch (MessageDeliveryException actual) {
assertSame(expected, actual.getCause());
}
verify(handler).handleMessage(message);
assertEquals(1, interceptor.getCounter().get());
assertTrue(interceptor.wasAfterHandledInvoked());
}
use of org.springframework.core.task.SyncTaskExecutor 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.SyncTaskExecutor in project cloudbreak by hortonworks.
the class AbstractFlowConfiguration method getStateMachineConfiguration.
protected MachineConfiguration<S, E> getStateMachineConfiguration() {
StateMachineConfigurationBuilder<S, E> configurationBuilder = new StateMachineConfigurationBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
StateMachineStateBuilder<S, E> stateBuilder = new StateMachineStateBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
StateMachineTransitionBuilder<S, E> transitionBuilder = new StateMachineTransitionBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
StateMachineListener<S, E> listener = new StateMachineListenerAdapter<S, E>() {
@Override
public void stateChanged(State<S, E> from, State<S, E> to) {
LOGGER.debug("state changed from {} to {}", from, to);
}
@Override
public void eventNotAccepted(Message<E> event) {
LOGGER.error("{} not accepted event: {}", getClass().getSimpleName(), event);
}
};
return new MachineConfiguration<>(configurationBuilder, stateBuilder, transitionBuilder, listener, new SyncTaskExecutor());
}
use of org.springframework.core.task.SyncTaskExecutor in project spring-framework by spring-projects.
the class ReactiveTypeHandlerTests method setup.
@BeforeEach
public void setup() throws Exception {
ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean();
factoryBean.afterPropertiesSet();
ContentNegotiationManager manager = factoryBean.getObject();
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
this.handler = new ReactiveTypeHandler(adapterRegistry, new SyncTaskExecutor(), manager);
resetRequest();
}
use of org.springframework.core.task.SyncTaskExecutor in project spring-framework by spring-projects.
the class RestTemplateXhrTransportTests method connect.
private ListenableFuture<WebSocketSession> connect(RestOperations restTemplate, ClientHttpResponse... responses) throws Exception {
RestTemplateXhrTransport transport = new RestTemplateXhrTransport(restTemplate);
transport.setTaskExecutor(new SyncTaskExecutor());
SockJsUrlInfo urlInfo = new SockJsUrlInfo(new URI("https://example.com"));
HttpHeaders headers = new HttpHeaders();
headers.add("h-foo", "h-bar");
TransportRequest request = new DefaultTransportRequest(urlInfo, headers, headers, transport, TransportType.XHR, CODEC);
return transport.connect(request, this.webSocketHandler);
}
Aggregations