org.springframework.core.task.SyncTaskExecutor Java Examples

The following examples show how to use org.springframework.core.task.SyncTaskExecutor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractFlowConfigurationTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Override
protected MachineConfiguration<State, Event> getStateMachineConfiguration() {
    StateMachineConfigurationBuilder<State, Event> configurationBuilder =
            new StateMachineConfigurationBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    StateMachineStateBuilder<State, Event> stateBuilder =
            new StateMachineStateBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    StateMachineTransitionBuilder<State, Event> transitionBuilder =
            new StateMachineTransitionBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    StateMachineListener<State, Event> listener =
            new StateMachineListenerAdapter<State, Event>() {
                @Override
                public void eventNotAccepted(Message<Event> event) {
                    throw new NotAcceptedException();
                }
            };
    return new MachineConfiguration<>(configurationBuilder, stateBuilder, transitionBuilder, listener,
            new SyncTaskExecutor());
}
 
Example #2
Source File: AbstractActionTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    underTest = spy(new TestAction());
    underTest.setFailureEvent(Event.FAILURE);
    MockitoAnnotations.initMocks(this);
    BDDMockito.given(flow.getFlowId()).willReturn(FLOW_ID);
    BDDMockito.given(runningFlows.get(anyString())).willReturn(flow);
    StateMachineConfigurationBuilder<State, Event> configurationBuilder =
            new StateMachineConfigurationBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    configurationBuilder.setTaskExecutor(new SyncTaskExecutor());
    StateMachineStateBuilder<State, Event> stateBuilder =
            new StateMachineStateBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    stateBuilder.withStates().initial(State.INIT).state(State.DOING, underTest, null);
    StateMachineTransitionBuilder<State, Event> transitionBuilder =
            new StateMachineTransitionBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    transitionBuilder.withExternal().source(State.INIT).target(State.DOING).event(Event.DOIT);
    stateMachine = new ObjectStateMachineFactory<>(configurationBuilder.build(), transitionBuilder.build(), stateBuilder.build()).getStateMachine();
    stateMachine.start();

    when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);
    when(spanBuilder.addReference(anyString(), any())).thenReturn(spanBuilder);
    when(spanBuilder.ignoreActiveSpan()).thenReturn(spanBuilder);
    when(spanBuilder.start()).thenReturn(span);
    when(tracer.activateSpan(span)).thenReturn(scope);
    when(span.context()).thenReturn(spanContext);
}
 
Example #3
Source File: WebAsyncManager.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
private void logExecutorWarning() {
	if (taskExecutorWarning && logger.isWarnEnabled()) {
		synchronized (DEFAULT_TASK_EXECUTOR) {
			AsyncTaskExecutor executor = this.taskExecutor;
			if (taskExecutorWarning &&
					(executor instanceof SimpleAsyncTaskExecutor || executor instanceof SyncTaskExecutor)) {
				String executorTypeName = executor.getClass().getSimpleName();
				logger.warn("\n!!!\n" +
						"An Executor is required to handle java.util.concurrent.Callable return values.\n" +
						"Please, configure a TaskExecutor in the MVC config under \"async support\".\n" +
						"The " + executorTypeName + " currently in use is not suitable under load.\n" +
						"-------------------------------\n" +
						"Request URI: '" + formatRequestUri() + "'\n" +
						"!!!");
				taskExecutorWarning = false;
			}
		}
	}
}
 
Example #4
Source File: AbstractFlowConfiguration.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
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<>() {
                @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());
}
 
Example #5
Source File: ContextResourceLoaderAutoConfigurationTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void createResourceLoader_withoutExecutorSettings_executorConfigured() {

	// Arrange
	this.context = new AnnotationConfigApplicationContext();
	this.context.register(ContextResourceLoaderAutoConfiguration.class);

	// Act
	this.context.refresh();

	// Assert
	SimpleStorageProtocolResolver simpleStorageProtocolResolver = (SimpleStorageProtocolResolver) this.context
			.getProtocolResolvers().iterator().next();
	SyncTaskExecutor taskExecutor = (SyncTaskExecutor) ReflectionTestUtils
			.getField(simpleStorageProtocolResolver, "taskExecutor");
	assertThat(taskExecutor).isNotNull();
}
 
Example #6
Source File: WebAsyncManager.java    From java-technology-stack with MIT License 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
private void logExecutorWarning() {
	if (taskExecutorWarning && logger.isWarnEnabled()) {
		synchronized (DEFAULT_TASK_EXECUTOR) {
			AsyncTaskExecutor executor = this.taskExecutor;
			if (taskExecutorWarning &&
					(executor instanceof SimpleAsyncTaskExecutor || executor instanceof SyncTaskExecutor)) {
				String executorTypeName = executor.getClass().getSimpleName();
				logger.warn("\n!!!\n" +
						"An Executor is required to handle java.util.concurrent.Callable return values.\n" +
						"Please, configure a TaskExecutor in the MVC config under \"async support\".\n" +
						"The " + executorTypeName + " currently in use is not suitable under load.\n" +
						"-------------------------------\n" +
						"Request URI: '" + formatRequestUri() + "'\n" +
						"!!!");
				taskExecutorWarning = false;
			}
		}
	}
}
 
Example #7
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void createRelative_existingObject_returnsRelativeCreatedFile() throws IOException {

	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(new ObjectMetadata());
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Act
	SimpleStorageResource subObject = simpleStorageResource
			.createRelative("subObject");

	// Assert
	assertThat(subObject.getFilename()).isEqualTo("object/subObject");
}
 
Example #8
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void contentLength_withExistingResource_returnsContentLengthOfObjectMetaData()
		throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	ObjectMetadata objectMetadata = new ObjectMetadata();
	objectMetadata.setContentLength(1234L);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(objectMetadata);

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThat(simpleStorageResource.contentLength()).isEqualTo(1234L);
}
 
Example #9
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void getDescription_withoutObjectMetaData_returnsDescriptiveDescription()
		throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"1", "2", new SyncTaskExecutor());
	String description = simpleStorageResource.getDescription();

	// Assert
	assertThat(description.contains("bucket")).isTrue();
	assertThat(description.contains("object")).isTrue();
	assertThat(description.contains("1")).isTrue();
	assertThat(description.contains("2")).isTrue();
}
 
Example #10
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void getInputStream_existingObject_returnsInputStreamWithContent() throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	ObjectMetadata objectMetadata = mock(ObjectMetadata.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(objectMetadata);

	S3Object s3Object = new S3Object();
	s3Object.setObjectMetadata(objectMetadata);
	s3Object.setObjectContent(new ByteArrayInputStream(new byte[] { 42 }));
	when(amazonS3.getObject(any(GetObjectRequest.class))).thenReturn(s3Object);

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThat(simpleStorageResource.exists()).isTrue();
	assertThat(simpleStorageResource.getInputStream().read()).isEqualTo(42);
}
 
Example #11
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void lastModified_withExistingResource_returnsLastModifiedDateOfResource()
		throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	ObjectMetadata objectMetadata = new ObjectMetadata();
	Date lastModified = new Date();
	objectMetadata.setLastModified(lastModified);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(objectMetadata);

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThat(simpleStorageResource.lastModified())
			.isEqualTo(lastModified.getTime());
}
 
Example #12
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void getUrl_existingObject_returnsUrlWithS3Scheme() throws Exception {

	AmazonS3Client amazonS3 = mock(AmazonS3Client.class);

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThat(simpleStorageResource.getS3Uri())
			.isEqualTo(new URI("s3://bucket/object"));

}
 
Example #13
Source File: ThreadedPerformanceTest.java    From batchers with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleThreaded() throws Exception {
    respondSuccess(NUMBER_OF_EMPLOYEES);

    setExecutor(new SyncTaskExecutor());
    jobExecution = jobLauncher.run(job, jobParams);
    printExecutionTime("SingleThreaded", jobExecution);
}
 
Example #14
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void exists_withExistingObjectMetadata_returnsTrue() throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(new ObjectMetadata());

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThat(simpleStorageResource.exists()).isTrue();
}
 
Example #15
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void exists_withoutExistingObjectMetadata_returnsFalse() throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(null);

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Act
	assertThat(simpleStorageResource.exists()).isFalse();
}
 
Example #16
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void contentLength_fileDoesNotExists_reportsError() throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(null);
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThatThrownBy(simpleStorageResource::contentLength)
			.isInstanceOf(FileNotFoundException.class)
			.hasMessageContaining("not found");

}
 
Example #17
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void lastModified_fileDoestNotExist_reportsError() throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(null);

	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThatThrownBy(simpleStorageResource::lastModified)
			.isInstanceOf(FileNotFoundException.class)
			.hasMessageContaining("not found");
}
 
Example #18
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void getFileName_existingObject_returnsFileNameWithoutBucketNameFromParameterWithoutActuallyFetchingTheFile()
		throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	when(amazonS3.getObjectMetadata(any(GetObjectMetadataRequest.class)))
			.thenReturn(null);

	// Act
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucket", "object", new SyncTaskExecutor());

	// Assert
	assertThat(simpleStorageResource.getFilename()).isEqualTo("object");
}
 
Example #19
Source File: ReactiveTypeHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
ReactiveTypeHandler(ReactiveAdapterRegistry registry, TaskExecutor executor, ContentNegotiationManager manager) {
	Assert.notNull(registry, "ReactiveAdapterRegistry is required");
	Assert.notNull(executor, "TaskExecutor is required");
	Assert.notNull(manager, "ContentNegotiationManager is required");
	this.adapterRegistry = registry;
	this.taskExecutor = executor;
	this.contentNegotiationManager = manager;

	this.taskExecutorWarning =
			(executor instanceof SimpleAsyncTaskExecutor || executor instanceof SyncTaskExecutor);
}
 
Example #20
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void writeFile_forNewFile_writesFileContent() throws Exception {
	// Arrange
	AmazonS3 amazonS3 = mock(AmazonS3.class);
	SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
			"bucketName", "objectName", new SyncTaskExecutor());
	String messageContext = "myFileContent";
	when(amazonS3.putObject(eq("bucketName"), eq("objectName"),
			any(InputStream.class), any(ObjectMetadata.class)))
					.thenAnswer((Answer<PutObjectResult>) invocation -> {
						assertThat(invocation.getArguments()[0])
								.isEqualTo("bucketName");
						assertThat(invocation.getArguments()[1])
								.isEqualTo("objectName");
						byte[] content = new byte[messageContext.length()];
						assertThat(((InputStream) invocation.getArguments()[2])
								.read(content)).isEqualTo(content.length);
						assertThat(new String(content)).isEqualTo(messageContext);
						return new PutObjectResult();
					});
	OutputStream outputStream = simpleStorageResource.getOutputStream();

	// Act
	outputStream.write(messageContext.getBytes());
	outputStream.flush();
	outputStream.close();

	// Assert
}
 
Example #21
Source File: SimpleStorageResourceTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void getUri_encodes_objectName() throws Exception {
	AmazonS3 s3 = mock(AmazonS3.class);
	when(s3.getRegion()).thenReturn(Region.US_West_2);
	SimpleStorageResource resource = new SimpleStorageResource(s3, "bucketName",
			"some/[objectName]", new SyncTaskExecutor());

	assertThat(resource.getURI()).isEqualTo(new URI(
			"https://s3.us-west-2.amazonaws.com/bucketName/some%2F%5BobjectName%5D"));
}
 
Example #22
Source File: EventsAutoConfiguration.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * A multicast event publisher to replace the default one used by Spring via the ApplicationContext.
 *
 * @param syncTaskExecutor  The synchronous task executor to use
 * @param asyncTaskExecutor The asynchronous task executor to use
 * @return The application event multicaster to use
 */
@Bean
@ConditionalOnMissingBean(GenieEventBus.class)
public GenieEventBusImpl applicationEventMulticaster(
    @Qualifier("genieSyncTaskExecutor") final SyncTaskExecutor syncTaskExecutor,
    @Qualifier("genieAsyncTaskExecutor") final AsyncTaskExecutor asyncTaskExecutor
) {
    final SimpleApplicationEventMulticaster syncMulticaster = new SimpleApplicationEventMulticaster();
    syncMulticaster.setTaskExecutor(syncTaskExecutor);

    final SimpleApplicationEventMulticaster asyncMulticaster = new SimpleApplicationEventMulticaster();
    asyncMulticaster.setTaskExecutor(asyncTaskExecutor);
    return new GenieEventBusImpl(syncMulticaster, asyncMulticaster);
}
 
Example #23
Source File: RestTemplateXhrTransportTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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("http://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);
}
 
Example #24
Source File: ReactiveTypeHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
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();
}
 
Example #25
Source File: RestTemplateXhrTransportTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
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);
}
 
Example #26
Source File: AdHocStarter.java    From spring-batch-rest with Apache License 2.0 5 votes vote down vote up
public AdHocStarter(JobLocator jobLocator, JobRepository jobRepository, JobPropertyResolvers jobPropertyResolvers,
                    @Value("${com.github.chrisgleissner.springbatchrest.addUniqueJobParameter:true}") boolean addUniqueJobParameter,
                    JobRegistry jobRegistry) {
    this.jobLocator = jobLocator;
    asyncJobLauncher = jobLauncher(new SimpleAsyncTaskExecutor(), jobRepository);
    syncJobLauncher = jobLauncher(new SyncTaskExecutor(), jobRepository);
    this.jobPropertyResolvers = jobPropertyResolvers;
    this.addUniqueJobParameter = addUniqueJobParameter;
    this.jobRegistry = jobRegistry;
    log.info("Adding unique job parameter: {}", addUniqueJobParameter);
}
 
Example #27
Source File: ReactiveTypeHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
ReactiveTypeHandler(ReactiveAdapterRegistry registry, TaskExecutor executor, ContentNegotiationManager manager) {
	Assert.notNull(registry, "ReactiveAdapterRegistry is required");
	Assert.notNull(executor, "TaskExecutor is required");
	Assert.notNull(manager, "ContentNegotiationManager is required");
	this.reactiveRegistry = registry;
	this.taskExecutor = executor;
	this.taskExecutorWarning = executor instanceof SimpleAsyncTaskExecutor || executor instanceof SyncTaskExecutor;
	this.contentNegotiationManager = manager;
}
 
Example #28
Source File: ReactiveTypeHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
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();
}
 
Example #29
Source File: RestTemplateXhrTransportTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
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("http://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);
}
 
Example #30
Source File: GracefulShutdownTomcatConnectorCustomizerTest.java    From spring-boot-graceful-shutdown with Apache License 2.0 5 votes vote down vote up
private Connector configureConnectorToReturnDifferentThreadPoolImplementation() {
    Connector mockConnector = mock(Connector.class);
    ProtocolHandler mockProtocolHandler = mock(ProtocolHandler.class);

    when(mockConnector.getProtocolHandler()).thenReturn(mockProtocolHandler);
    when(mockProtocolHandler.getExecutor()).thenReturn(new SyncTaskExecutor());

    return mockConnector;
}