org.springframework.mock.web.test.MockAsyncContext Java Examples

The following examples show how to use org.springframework.mock.web.test.MockAsyncContext. 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: WebAsyncManagerTimeoutTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void startCallableProcessingAfterTimeoutException() throws Exception {

	StubCallable callable = new StubCallable();
	Exception exception = new Exception();

	CallableProcessingInterceptor interceptor = mock(CallableProcessingInterceptor.class);
	given(interceptor.handleTimeout(this.asyncWebRequest, callable)).willThrow(exception);

	this.asyncManager.registerCallableInterceptor("timeoutInterceptor", interceptor);
	this.asyncManager.startCallableProcessing(callable);

	this.asyncWebRequest.onTimeout(ASYNC_EVENT);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(exception, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());

	verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
}
 
Example #2
Source File: WebAsyncManagerErrorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void startCallableProcessingErrorAndComplete() throws Exception {
	StubCallable callable = new StubCallable();

	CallableProcessingInterceptor interceptor = mock(CallableProcessingInterceptor.class);
	Exception e = new Exception();
	given(interceptor.handleError(this.asyncWebRequest, callable, e)).willReturn(RESULT_NONE);

	this.asyncManager.registerCallableInterceptor("interceptor", interceptor);
	this.asyncManager.startCallableProcessing(callable);

	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);
	this.asyncWebRequest.onComplete(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(e, this.asyncManager.getConcurrentResult());

	verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
	verify(interceptor).afterCompletion(this.asyncWebRequest, callable);
}
 
Example #3
Source File: WebAsyncManagerErrorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void startCallableProcessingErrorAndResumeThroughCallback() throws Exception {

	StubCallable callable = new StubCallable();
	WebAsyncTask<Object> webAsyncTask = new WebAsyncTask<>(callable);
	webAsyncTask.onError(new Callable<Object>() {
		@Override
		public Object call() throws Exception {
			return 7;
		}
	});

	this.asyncManager.startCallableProcessing(webAsyncTask);

	Exception e = new Exception();
	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(7, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #4
Source File: WebAsyncManagerErrorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void startCallableProcessingErrorAndResumeThroughInterceptor() throws Exception {

	StubCallable callable = new StubCallable();

	CallableProcessingInterceptor interceptor = mock(CallableProcessingInterceptor.class);
	Exception e = new Exception();
	given(interceptor.handleError(this.asyncWebRequest, callable, e)).willReturn(22);

	this.asyncManager.registerCallableInterceptor("errorInterceptor", interceptor);
	this.asyncManager.startCallableProcessing(callable);

	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(22, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());

	verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
}
 
Example #5
Source File: WebAsyncManagerErrorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void startCallableProcessingAfterException() throws Exception {

	StubCallable callable = new StubCallable();
	Exception exception = new Exception();

	CallableProcessingInterceptor interceptor = mock(CallableProcessingInterceptor.class);
	Exception e = new Exception();
	given(interceptor.handleError(this.asyncWebRequest, callable, e)).willThrow(exception);

	this.asyncManager.registerCallableInterceptor("errorInterceptor", interceptor);
	this.asyncManager.startCallableProcessing(callable);

	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(exception, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());

	verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
}
 
Example #6
Source File: WebAsyncManagerErrorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingErrorAndComplete() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<>();

	DeferredResultProcessingInterceptor interceptor = mock(DeferredResultProcessingInterceptor.class);
	Exception e = new Exception();
	given(interceptor.handleError(this.asyncWebRequest, deferredResult, e)).willReturn(true);

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);
	this.asyncWebRequest.onComplete(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(e, this.asyncManager.getConcurrentResult());

	verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, deferredResult);
	verify(interceptor).preProcess(this.asyncWebRequest, deferredResult);
	verify(interceptor).afterCompletion(this.asyncWebRequest, deferredResult);
}
 
Example #7
Source File: WebAsyncManagerErrorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingErrorAndResumeThroughCallback() throws Exception {

	final DeferredResult<Throwable> deferredResult = new DeferredResult<>();
	deferredResult.onError(new Consumer<Throwable>() {
		@Override
		public void accept(Throwable t) {
			deferredResult.setResult(t);
		}
	});

	this.asyncManager.startDeferredResultProcessing(deferredResult);

	Exception e = new Exception();
	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(e, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #8
Source File: WebAsyncManagerErrorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingErrorAndResumeThroughInterceptor() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<>();

	DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptor() {
		@Override
		public <T> boolean handleError(NativeWebRequest request, DeferredResult<T> result, Throwable t)
				throws Exception {
			result.setErrorResult(t);
			return true;
		}
	};

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	Exception e = new Exception();
	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(e, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #9
Source File: WebAsyncManagerErrorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingAfterException() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<>();
	final Exception exception = new Exception();

	DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptor() {
		@Override
		public <T> boolean handleError(NativeWebRequest request, DeferredResult<T> result, Throwable t)
				throws Exception {
			throw exception;
		}
	};

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	Exception e = new Exception();
	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(e, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #10
Source File: WebAsyncManagerTimeoutTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void startCallableProcessingTimeoutAndResumeThroughCallback() throws Exception {

	StubCallable callable = new StubCallable();
	WebAsyncTask<Object> webAsyncTask = new WebAsyncTask<>(callable);
	webAsyncTask.onTimeout(new Callable<Object>() {
		@Override
		public Object call() throws Exception {
			return 7;
		}
	});

	this.asyncManager.startCallableProcessing(webAsyncTask);

	this.asyncWebRequest.onTimeout(ASYNC_EVENT);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(7, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #11
Source File: WebAsyncManagerErrorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void startCallableProcessingErrorAndComplete() throws Exception {
	StubCallable callable = new StubCallable();

	CallableProcessingInterceptor interceptor = mock(CallableProcessingInterceptor.class);
	Exception e = new Exception();
	given(interceptor.handleError(this.asyncWebRequest, callable, e)).willReturn(RESULT_NONE);

	this.asyncManager.registerCallableInterceptor("interceptor", interceptor);
	this.asyncManager.startCallableProcessing(callable);

	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);
	this.asyncWebRequest.onComplete(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(e, this.asyncManager.getConcurrentResult());

	verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
	verify(interceptor).afterCompletion(this.asyncWebRequest, callable);
}
 
Example #12
Source File: WebAsyncManagerTimeoutTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingTimeoutAndResumeThroughCallback() throws Exception {

	final DeferredResult<Integer> deferredResult = new DeferredResult<>();
	deferredResult.onTimeout(new Runnable() {
		@Override
		public void run() {
			deferredResult.setResult(23);
		}
	});

	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = null;
	this.asyncWebRequest.onTimeout(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(23, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #13
Source File: WebAsyncManagerTimeoutTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingTimeoutAndResumeThroughInterceptor() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<>();

	DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptor() {
		@Override
		public <T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> result) throws Exception {
			result.setErrorResult(23);
			return true;
		}
	};

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = null;
	this.asyncWebRequest.onTimeout(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(23, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #14
Source File: WebAsyncManagerTimeoutTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingAfterTimeoutException() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<>();
	final Exception exception = new Exception();

	DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptor() {
		@Override
		public <T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> result) throws Exception {
			throw exception;
		}
	};

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = null;
	this.asyncWebRequest.onTimeout(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(exception, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #15
Source File: WebAsyncManagerTimeoutTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void startCallableProcessingTimeoutAndResumeThroughCallback() throws Exception {

	StubCallable callable = new StubCallable();
	WebAsyncTask<Object> webAsyncTask = new WebAsyncTask<Object>(callable);
	webAsyncTask.onTimeout(new Callable<Object>() {
		@Override
		public Object call() throws Exception {
			return 7;
		}
	});

	this.asyncManager.startCallableProcessing(webAsyncTask);

	this.asyncWebRequest.onTimeout(ASYNC_EVENT);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(7, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #16
Source File: WebAsyncManagerTimeoutTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void startCallableProcessingAfterTimeoutException() throws Exception {

	StubCallable callable = new StubCallable();
	Exception exception = new Exception();

	CallableProcessingInterceptor interceptor = mock(CallableProcessingInterceptor.class);
	given(interceptor.handleTimeout(this.asyncWebRequest, callable)).willThrow(exception);

	this.asyncManager.registerCallableInterceptor("timeoutInterceptor", interceptor);
	this.asyncManager.startCallableProcessing(callable);

	this.asyncWebRequest.onTimeout(ASYNC_EVENT);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(exception, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());

	verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
}
 
Example #17
Source File: WebAsyncManagerTimeoutTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void startDeferredResultProcessingTimeoutAndResumeThroughCallback() throws Exception {

	final DeferredResult<Integer> deferredResult = new DeferredResult<Integer>();
	deferredResult.onTimeout(new Runnable() {
		@Override
		public void run() {
			deferredResult.setResult(23);
		}
	});

	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = null;
	this.asyncWebRequest.onTimeout(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(23, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #18
Source File: WebAsyncManagerTimeoutTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void startDeferredResultProcessingTimeoutAndResumeThroughInterceptor() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<Integer>();

	DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptorAdapter() {
		@Override
		public <T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> result) throws Exception {
			result.setErrorResult(23);
			return true;
		}
	};

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = null;
	this.asyncWebRequest.onTimeout(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(23, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #19
Source File: WebAsyncManagerTimeoutTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void startDeferredResultProcessingAfterTimeoutException() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<Integer>();
	final Exception exception = new Exception();

	DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptorAdapter() {
		@Override
		public <T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> result) throws Exception {
			throw exception;
		}
	};

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = null;
	this.asyncWebRequest.onTimeout(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(exception, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #20
Source File: WebAsyncManagerErrorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingErrorAndResumeThroughCallback() throws Exception {

	final DeferredResult<Throwable> deferredResult = new DeferredResult<>();
	deferredResult.onError(new Consumer<Throwable>() {
		@Override
		public void accept(Throwable t) {
			deferredResult.setResult(t);
		}
	});

	this.asyncManager.startDeferredResultProcessing(deferredResult);

	Exception e = new Exception();
	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(e, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #21
Source File: WebAsyncManagerErrorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingErrorAndResumeThroughInterceptor() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<>();

	DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptor() {
		@Override
		public <T> boolean handleError(NativeWebRequest request, DeferredResult<T> result, Throwable t)
				throws Exception {
			result.setErrorResult(t);
			return true;
		}
	};

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	Exception e = new Exception();
	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(e, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #22
Source File: WebAsyncManagerErrorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void startCallableProcessingErrorAndResumeThroughCallback() throws Exception {

	StubCallable callable = new StubCallable();
	WebAsyncTask<Object> webAsyncTask = new WebAsyncTask<>(callable);
	webAsyncTask.onError(new Callable<Object>() {
		@Override
		public Object call() throws Exception {
			return 7;
		}
	});

	this.asyncManager.startCallableProcessing(webAsyncTask);

	Exception e = new Exception();
	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(7, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #23
Source File: WebAsyncManagerErrorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void startCallableProcessingErrorAndResumeThroughInterceptor() throws Exception {

	StubCallable callable = new StubCallable();

	CallableProcessingInterceptor interceptor = mock(CallableProcessingInterceptor.class);
	Exception e = new Exception();
	given(interceptor.handleError(this.asyncWebRequest, callable, e)).willReturn(22);

	this.asyncManager.registerCallableInterceptor("errorInterceptor", interceptor);
	this.asyncManager.startCallableProcessing(callable);

	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(22, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());

	verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
}
 
Example #24
Source File: WebAsyncManagerErrorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void startCallableProcessingAfterException() throws Exception {

	StubCallable callable = new StubCallable();
	Exception exception = new Exception();

	CallableProcessingInterceptor interceptor = mock(CallableProcessingInterceptor.class);
	Exception e = new Exception();
	given(interceptor.handleError(this.asyncWebRequest, callable, e)).willThrow(exception);

	this.asyncManager.registerCallableInterceptor("errorInterceptor", interceptor);
	this.asyncManager.startCallableProcessing(callable);

	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(exception, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());

	verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
}
 
Example #25
Source File: WebAsyncManagerTimeoutTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingAfterTimeoutException() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<>();
	final Exception exception = new Exception();

	DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptor() {
		@Override
		public <T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> result) throws Exception {
			throw exception;
		}
	};

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = null;
	this.asyncWebRequest.onTimeout(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(exception, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #26
Source File: WebAsyncManagerTimeoutTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingTimeoutAndResumeThroughInterceptor() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<>();

	DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptor() {
		@Override
		public <T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> result) throws Exception {
			result.setErrorResult(23);
			return true;
		}
	};

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = null;
	this.asyncWebRequest.onTimeout(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(23, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #27
Source File: WebAsyncManagerTimeoutTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingTimeoutAndResumeThroughCallback() throws Exception {

	final DeferredResult<Integer> deferredResult = new DeferredResult<>();
	deferredResult.onTimeout(new Runnable() {
		@Override
		public void run() {
			deferredResult.setResult(23);
		}
	});

	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = null;
	this.asyncWebRequest.onTimeout(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(23, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #28
Source File: WebAsyncManagerErrorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingErrorAndComplete() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<>();

	DeferredResultProcessingInterceptor interceptor = mock(DeferredResultProcessingInterceptor.class);
	Exception e = new Exception();
	given(interceptor.handleError(this.asyncWebRequest, deferredResult, e)).willReturn(true);

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);
	this.asyncWebRequest.onComplete(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(e, this.asyncManager.getConcurrentResult());

	verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, deferredResult);
	verify(interceptor).preProcess(this.asyncWebRequest, deferredResult);
	verify(interceptor).afterCompletion(this.asyncWebRequest, deferredResult);
}
 
Example #29
Source File: WebAsyncManagerErrorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void startDeferredResultProcessingAfterException() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<>();
	final Exception exception = new Exception();

	DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptor() {
		@Override
		public <T> boolean handleError(NativeWebRequest request, DeferredResult<T> result, Throwable t)
				throws Exception {
			throw exception;
		}
	};

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	Exception e = new Exception();
	AsyncEvent event = new AsyncEvent(new MockAsyncContext(this.servletRequest, this.servletResponse), e);
	this.asyncWebRequest.onError(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(e, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
Example #30
Source File: WebAsyncManagerTimeoutTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void startCallableProcessingAfterTimeoutException() throws Exception {

	StubCallable callable = new StubCallable();
	Exception exception = new Exception();

	CallableProcessingInterceptor interceptor = mock(CallableProcessingInterceptor.class);
	given(interceptor.handleTimeout(this.asyncWebRequest, callable)).willThrow(exception);

	this.asyncManager.registerCallableInterceptor("timeoutInterceptor", interceptor);
	this.asyncManager.startCallableProcessing(callable);

	this.asyncWebRequest.onTimeout(ASYNC_EVENT);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(exception, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());

	verify(interceptor).beforeConcurrentHandling(this.asyncWebRequest, callable);
}