Add onError callback to DeferredResult
Issue: SPR-15614
This commit is contained in:
committed by
Rossen Stoyanchev
parent
140542e8b1
commit
e0678ba583
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -228,6 +228,48 @@ public class OpenEntityManagerInViewTests {
|
||||
verify(this.manager).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOpenEntityManagerInViewInterceptorAsyncErrorScenario() throws Exception {
|
||||
|
||||
// Initial request thread
|
||||
|
||||
OpenEntityManagerInViewInterceptor interceptor = new OpenEntityManagerInViewInterceptor();
|
||||
interceptor.setEntityManagerFactory(factory);
|
||||
|
||||
given(this.factory.createEntityManager()).willReturn(this.manager);
|
||||
|
||||
interceptor.preHandle(this.webRequest);
|
||||
assertTrue(TransactionSynchronizationManager.hasResource(this.factory));
|
||||
|
||||
AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response);
|
||||
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(this.request);
|
||||
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(this.factory));
|
||||
|
||||
// Async request timeout
|
||||
|
||||
given(this.manager.isOpen()).willReturn(true);
|
||||
|
||||
MockAsyncContext asyncContext = (MockAsyncContext) this.request.getAsyncContext();
|
||||
for (AsyncListener listener : asyncContext.getListeners()) {
|
||||
listener.onError(new AsyncEvent(asyncContext, new Exception()));
|
||||
}
|
||||
for (AsyncListener listener : asyncContext.getListeners()) {
|
||||
listener.onComplete(new AsyncEvent(asyncContext));
|
||||
}
|
||||
|
||||
verify(this.manager).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOpenEntityManagerInViewFilter() throws Exception {
|
||||
given(manager.isOpen()).willReturn(true);
|
||||
|
||||
Reference in New Issue
Block a user