use of org.springframework.scheduling.concurrent.ConcurrentTaskScheduler in project spring-integration by spring-projects.
the class StompSessionManagerTests method testDoConnectFailure.
@Test
public void testDoConnectFailure() throws Exception {
StompClientSupport stompClient = mock(StompClientSupport.class);
stompClient.setTaskScheduler(new ConcurrentTaskScheduler());
AbstractStompSessionManager sessionManager = new AbstractStompSessionManager(stompClient) {
private final AtomicBoolean thrown = new AtomicBoolean();
@Override
protected ListenableFuture<StompSession> doConnect(StompSessionHandler handler) {
if (!this.thrown.getAndSet(true)) {
throw new RuntimeException("intentional");
} else {
SettableListenableFuture<StompSession> future = new SettableListenableFuture<StompSession>();
StompSession stompSession = mock(StompSession.class);
future.set(stompSession);
handler.afterConnected(stompSession, getConnectHeaders());
return future;
}
}
};
sessionManager.start();
final SettableListenableFuture<StompSession> stompSessionFuture = new SettableListenableFuture<StompSession>();
sessionManager.connect(new StompSessionHandlerAdapter() {
@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
stompSessionFuture.set(session);
}
});
assertNotNull(stompSessionFuture.get(10, TimeUnit.SECONDS));
sessionManager.stop();
}
use of org.springframework.scheduling.concurrent.ConcurrentTaskScheduler in project spring-security by spring-projects.
the class DelegatingSecurityContextTaskSchedulerTests method scheduleWhenSecurityContextThenSecurityContextPropagated.
@Test
public void scheduleWhenSecurityContextThenSecurityContextPropagated() throws Exception {
willAnswer((invocation) -> {
assertThat(SecurityContextHolder.getContext()).isEqualTo(this.securityContext);
return null;
}).given(this.runnable).run();
TaskScheduler delegateTaskScheduler = new ConcurrentTaskScheduler();
this.delegatingSecurityContextTaskScheduler = new DelegatingSecurityContextTaskScheduler(delegateTaskScheduler, this.securityContext);
assertWrapped(this.runnable);
}
use of org.springframework.scheduling.concurrent.ConcurrentTaskScheduler in project CVE-2018-1270 by CaledoniaProject.
the class ServiceClient method main.
public static void main(String... argv) {
WebSocketClient webSocketClient = new StandardWebSocketClient();
WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
stompClient.setTaskScheduler(new ConcurrentTaskScheduler());
String url = "ws://127.0.0.1:8080/hello";
StompSessionHandler sessionHandler = new MySessionHandler();
stompClient.connect(url, sessionHandler);
// Don't close immediately.
new Scanner(System.in).nextLine();
}
use of org.springframework.scheduling.concurrent.ConcurrentTaskScheduler in project spring-security by spring-projects.
the class DelegatingSecurityContextTaskSchedulerTests method scheduleWhenDefaultThenCurrentSecurityContextPropagated.
@Test
public void scheduleWhenDefaultThenCurrentSecurityContextPropagated() throws Exception {
willAnswer((invocation) -> {
assertThat(SecurityContextHolder.getContext()).isEqualTo(this.originalSecurityContext);
return null;
}).given(this.runnable).run();
TaskScheduler delegateTaskScheduler = new ConcurrentTaskScheduler();
this.delegatingSecurityContextTaskScheduler = new DelegatingSecurityContextTaskScheduler(delegateTaskScheduler);
assertWrapped(this.runnable);
}
use of org.springframework.scheduling.concurrent.ConcurrentTaskScheduler in project spring-framework by spring-projects.
the class ScheduledTaskRegistrar method scheduleTasks.
/**
* Schedule all registered tasks against the underlying
* {@linkplain #setTaskScheduler(TaskScheduler) task scheduler}.
*/
@SuppressWarnings("deprecation")
protected void scheduleTasks() {
if (this.taskScheduler == null) {
this.localExecutor = Executors.newSingleThreadScheduledExecutor();
this.taskScheduler = new ConcurrentTaskScheduler(this.localExecutor);
}
if (this.triggerTasks != null) {
for (TriggerTask task : this.triggerTasks) {
addScheduledTask(scheduleTriggerTask(task));
}
}
if (this.cronTasks != null) {
for (CronTask task : this.cronTasks) {
addScheduledTask(scheduleCronTask(task));
}
}
if (this.fixedRateTasks != null) {
for (IntervalTask task : this.fixedRateTasks) {
addScheduledTask(scheduleFixedRateTask(task));
}
}
if (this.fixedDelayTasks != null) {
for (IntervalTask task : this.fixedDelayTasks) {
addScheduledTask(scheduleFixedDelayTask(task));
}
}
}
Aggregations