Java Code Examples for org.springframework.web.context.request.async.WebAsyncManager#clearConcurrentResult()
The following examples show how to use
org.springframework.web.context.request.async.WebAsyncManager#clearConcurrentResult() .
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: OpenEntityManagerInViewTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void testOpenEntityManagerInViewInterceptorAsyncScenario() throws Exception { // Initial request thread OpenEntityManagerInViewInterceptor interceptor = new OpenEntityManagerInViewInterceptor(); interceptor.setEntityManagerFactory(factory); given(factory.createEntityManager()).willReturn(this.manager); interceptor.preHandle(this.webRequest); assertTrue(TransactionSynchronizationManager.hasResource(factory)); AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response); WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.webRequest); asyncManager.setTaskExecutor(new SyncTaskExecutor()); asyncManager.setAsyncWebRequest(asyncWebRequest); asyncManager.startCallableProcessing(new Callable<String>() { @Override public String call() throws Exception { return "anything"; } }); interceptor.afterConcurrentHandlingStarted(this.webRequest); assertFalse(TransactionSynchronizationManager.hasResource(factory)); // Async dispatch thread interceptor.preHandle(this.webRequest); assertTrue(TransactionSynchronizationManager.hasResource(factory)); asyncManager.clearConcurrentResult(); // check that further invocations simply participate interceptor.preHandle(new ServletWebRequest(request)); interceptor.preHandle(new ServletWebRequest(request)); interceptor.postHandle(new ServletWebRequest(request), null); interceptor.afterCompletion(new ServletWebRequest(request), null); interceptor.postHandle(new ServletWebRequest(request), null); interceptor.afterCompletion(new ServletWebRequest(request), null); interceptor.preHandle(new ServletWebRequest(request)); interceptor.postHandle(new ServletWebRequest(request), null); interceptor.afterCompletion(new ServletWebRequest(request), null); interceptor.postHandle(this.webRequest, null); assertTrue(TransactionSynchronizationManager.hasResource(factory)); given(this.manager.isOpen()).willReturn(true); interceptor.afterCompletion(this.webRequest, null); assertFalse(TransactionSynchronizationManager.hasResource(factory)); verify(this.manager).close(); }
Example 2
Source File: OpenEntityManagerInViewTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void testOpenEntityManagerInViewInterceptorAsyncScenario() throws Exception { // Initial request thread OpenEntityManagerInViewInterceptor interceptor = new OpenEntityManagerInViewInterceptor(); interceptor.setEntityManagerFactory(factory); given(factory.createEntityManager()).willReturn(this.manager); interceptor.preHandle(this.webRequest); assertTrue(TransactionSynchronizationManager.hasResource(factory)); AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response); WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.webRequest); asyncManager.setTaskExecutor(new SyncTaskExecutor()); asyncManager.setAsyncWebRequest(asyncWebRequest); asyncManager.startCallableProcessing(new Callable<String>() { @Override public String call() throws Exception { return "anything"; } }); interceptor.afterConcurrentHandlingStarted(this.webRequest); assertFalse(TransactionSynchronizationManager.hasResource(factory)); // Async dispatch thread interceptor.preHandle(this.webRequest); assertTrue(TransactionSynchronizationManager.hasResource(factory)); asyncManager.clearConcurrentResult(); // check that further invocations simply participate interceptor.preHandle(new ServletWebRequest(request)); interceptor.preHandle(new ServletWebRequest(request)); interceptor.postHandle(new ServletWebRequest(request), null); interceptor.afterCompletion(new ServletWebRequest(request), null); interceptor.postHandle(new ServletWebRequest(request), null); interceptor.afterCompletion(new ServletWebRequest(request), null); interceptor.preHandle(new ServletWebRequest(request)); interceptor.postHandle(new ServletWebRequest(request), null); interceptor.afterCompletion(new ServletWebRequest(request), null); interceptor.postHandle(this.webRequest, null); assertTrue(TransactionSynchronizationManager.hasResource(factory)); given(this.manager.isOpen()).willReturn(true); interceptor.afterCompletion(this.webRequest, null); assertFalse(TransactionSynchronizationManager.hasResource(factory)); verify(this.manager).close(); }
Example 3
Source File: OpenEntityManagerInViewTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void testOpenEntityManagerInViewInterceptorAsyncScenario() throws Exception { // Initial request thread OpenEntityManagerInViewInterceptor interceptor = new OpenEntityManagerInViewInterceptor(); interceptor.setEntityManagerFactory(factory); given(factory.createEntityManager()).willReturn(this.manager); interceptor.preHandle(this.webRequest); assertTrue(TransactionSynchronizationManager.hasResource(factory)); AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response); WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.webRequest); asyncManager.setTaskExecutor(new SyncTaskExecutor()); asyncManager.setAsyncWebRequest(asyncWebRequest); asyncManager.startCallableProcessing(new Callable<String>() { @Override public String call() throws Exception { return "anything"; } }); interceptor.afterConcurrentHandlingStarted(this.webRequest); assertFalse(TransactionSynchronizationManager.hasResource(factory)); // Async dispatch thread interceptor.preHandle(this.webRequest); assertTrue(TransactionSynchronizationManager.hasResource(factory)); asyncManager.clearConcurrentResult(); // check that further invocations simply participate interceptor.preHandle(new ServletWebRequest(request)); interceptor.preHandle(new ServletWebRequest(request)); interceptor.postHandle(new ServletWebRequest(request), null); interceptor.afterCompletion(new ServletWebRequest(request), null); interceptor.postHandle(new ServletWebRequest(request), null); interceptor.afterCompletion(new ServletWebRequest(request), null); interceptor.preHandle(new ServletWebRequest(request)); interceptor.postHandle(new ServletWebRequest(request), null); interceptor.afterCompletion(new ServletWebRequest(request), null); interceptor.postHandle(this.webRequest, null); assertTrue(TransactionSynchronizationManager.hasResource(factory)); given(this.manager.isOpen()).willReturn(true); interceptor.afterCompletion(this.webRequest, null); assertFalse(TransactionSynchronizationManager.hasResource(factory)); verify(this.manager).close(); }