Skip to content

Commit

Permalink
Correct transcation commiting lifecycle
Browse files Browse the repository at this point in the history
Committing the transaction on RESP_FILTERS_START event
instead of RESOURCE_METHOD_FINISHED.

Fixes #850, closes #915
  • Loading branch information
phxql authored and Artem Prigoda committed Mar 6, 2015
1 parent 20938de commit 58c2ec5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Expand Up @@ -78,7 +78,7 @@ public void onEvent(RequestEvent event) {
} }
} }
} }
else if (event.getType() == RequestEvent.Type.RESOURCE_METHOD_FINISHED) { else if (event.getType() == RequestEvent.Type.RESP_FILTERS_START) {
if (this.session != null) { if (this.session != null) {
try { try {
commitTransaction(); commitTransaction();
Expand Down
Expand Up @@ -39,7 +39,7 @@ public class UnitOfWorkApplicationListenerTest {


private final RequestEvent requestStartEvent = mock(RequestEvent.class); private final RequestEvent requestStartEvent = mock(RequestEvent.class);
private final RequestEvent requestMethodStartEvent = mock(RequestEvent.class); private final RequestEvent requestMethodStartEvent = mock(RequestEvent.class);
private final RequestEvent requestMethodFinishEvent = mock(RequestEvent.class); private final RequestEvent responseFiltersStartEvent = mock(RequestEvent.class);
private final RequestEvent requestMethodExceptionEvent = mock(RequestEvent.class); private final RequestEvent requestMethodExceptionEvent = mock(RequestEvent.class);
private final Session session = mock(Session.class); private final Session session = mock(Session.class);
private final Transaction transaction = mock(Transaction.class); private final Transaction transaction = mock(Transaction.class);
Expand All @@ -56,10 +56,10 @@ public void setUp() throws Exception {


when(appEvent.getType()).thenReturn(ApplicationEvent.Type.INITIALIZATION_APP_FINISHED); when(appEvent.getType()).thenReturn(ApplicationEvent.Type.INITIALIZATION_APP_FINISHED);
when(requestMethodStartEvent.getType()).thenReturn(RequestEvent.Type.RESOURCE_METHOD_START); when(requestMethodStartEvent.getType()).thenReturn(RequestEvent.Type.RESOURCE_METHOD_START);
when(requestMethodFinishEvent.getType()).thenReturn(RequestEvent.Type.RESOURCE_METHOD_FINISHED); when(responseFiltersStartEvent.getType()).thenReturn(RequestEvent.Type.RESP_FILTERS_START);
when(requestMethodExceptionEvent.getType()).thenReturn(RequestEvent.Type.ON_EXCEPTION); when(requestMethodExceptionEvent.getType()).thenReturn(RequestEvent.Type.ON_EXCEPTION);
when(requestMethodStartEvent.getUriInfo()).thenReturn(uriInfo); when(requestMethodStartEvent.getUriInfo()).thenReturn(uriInfo);
when(requestMethodFinishEvent.getUriInfo()).thenReturn(uriInfo); when(responseFiltersStartEvent.getUriInfo()).thenReturn(uriInfo);
when(requestMethodExceptionEvent.getUriInfo()).thenReturn(uriInfo); when(requestMethodExceptionEvent.getUriInfo()).thenReturn(uriInfo);


prepareAppEvent("methodWithDefaultAnnotation"); prepareAppEvent("methodWithDefaultAnnotation");
Expand Down Expand Up @@ -204,7 +204,7 @@ private void execute() {
listener.onEvent(appEvent); listener.onEvent(appEvent);
RequestEventListener requestListener = listener.onRequest(requestStartEvent); RequestEventListener requestListener = listener.onRequest(requestStartEvent);
requestListener.onEvent(requestMethodStartEvent); requestListener.onEvent(requestMethodStartEvent);
requestListener.onEvent(requestMethodFinishEvent); requestListener.onEvent(responseFiltersStartEvent);
} }


private void executeWithException() { private void executeWithException() {
Expand Down

0 comments on commit 58c2ec5

Please sign in to comment.