Skip to content

Commit

Permalink
Better error message for out-of-order rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Feb 26, 2016
1 parent ed2940b commit c71fc2d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Expand Up @@ -134,6 +134,12 @@ public State reset( SessionStateMachine ctx )
return IDLE; return IDLE;
} }


@Override
public State rollbackTransaction( SessionStateMachine ctx )
{
return error( ctx, new Neo4jError( Status.Request.Invalid,
"rollback cannot be done when there is no open transaction in the session." ) );
}
}, },


/** /**
Expand Down
Expand Up @@ -90,7 +90,6 @@ public static Matcher<? super RecordingCallback.Call> failedWith( final Status e
protected boolean matchesSafely( RecordingCallback.Call item ) protected boolean matchesSafely( RecordingCallback.Call item )
{ {
return expected == item.error().status(); return expected == item.error().status();

} }


@Override @Override
Expand All @@ -101,6 +100,24 @@ public void describeTo( Description description )
}; };
} }


public static Matcher<? super RecordingCallback.Call> failedWith( final String expected )
{
return new TypeSafeMatcher<RecordingCallback.Call>()
{
@Override
protected boolean matchesSafely( RecordingCallback.Call item )
{
return expected.equals( item.error().message() );
}

@Override
public void describeTo( Description description )
{
description.appendText( expected );
}
};
}

public static Matcher<? super RecordingCallback.Call> ignored() public static Matcher<? super RecordingCallback.Call> ignored()
{ {
return new TypeSafeMatcher<RecordingCallback.Call>() return new TypeSafeMatcher<RecordingCallback.Call>()
Expand Down
Expand Up @@ -89,15 +89,18 @@ public void shouldHandleBeginRollback() throws Throwable
public void shouldFailNicelyWhenOutOfOrderRollback() throws Throwable public void shouldFailNicelyWhenOutOfOrderRollback() throws Throwable
{ {
// Given // Given
RecordingCallback<RecordStream, Object> responses = new RecordingCallback<>(); RecordingCallback<StatementMetadata, ?> runResponse = new RecordingCallback<>();
RecordingCallback<RecordStream, Object> pullResponse = new RecordingCallback<>();
Session session = env.newSession(); Session session = env.newSession();
session.init( "TestClient", Collections.<String, Object>emptyMap(), null, null ); session.init( "TestClient", Collections.<String, Object>emptyMap(), null, null );


// When // When
session.run( "ROLLBACK", EMPTY_PARAMS, null, Session.Callbacks.<StatementMetadata,Object>noop()); session.run( "ROLLBACK", EMPTY_PARAMS, null, runResponse );
session.pullAll( null, responses ); session.pullAll( null, pullResponse );


// Then // Then
MatcherAssert.assertThat( responses.next(), SessionMatchers.ignored()); MatcherAssert.assertThat( runResponse.next(),
SessionMatchers.failedWith( "rollback cannot be done when there is no open transaction in the session."));
MatcherAssert.assertThat( pullResponse.next(), SessionMatchers.ignored());
} }
} }

0 comments on commit c71fc2d

Please sign in to comment.