Skip to content

Commit

Permalink
Merge pull request #374 from lutovich/1.1-tx-isOpen
Browse files Browse the repository at this point in the history
Fix `Transaction#isOpen()`
  • Loading branch information
zhenlineo authored May 18, 2017
2 parents e953d34 + 682c8d0 commit 85760c8
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public synchronized StatementResult run( Statement statement )
@Override
public boolean isOpen()
{
return state == State.ACTIVE;
return state != State.SUCCEEDED && state != State.ROLLED_BACK;
}

private void ensureNotFailed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@

import org.neo4j.driver.internal.spi.Collector;
import org.neo4j.driver.internal.spi.Connection;
import org.neo4j.driver.v1.Transaction;
import org.neo4j.driver.v1.Value;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -143,4 +146,71 @@ public void shouldSyncWhenBookmarkGiven()
inOrder.verify( connection ).pullAll( Collector.NO_OP );
inOrder.verify( connection ).sync();
}

@Test
public void shouldBeOpenAfterConstruction()
{
Transaction tx = new ExplicitTransaction( openConnectionMock(), mock( Runnable.class ) );

assertTrue( tx.isOpen() );
}

@Test
public void shouldBeOpenWhenMarkedForSuccess()
{
Transaction tx = new ExplicitTransaction( openConnectionMock(), mock( Runnable.class ) );

tx.success();

assertTrue( tx.isOpen() );
}

@Test
public void shouldBeOpenWhenMarkedForFailure()
{
Transaction tx = new ExplicitTransaction( openConnectionMock(), mock( Runnable.class ) );

tx.failure();

assertTrue( tx.isOpen() );
}

@Test
public void shouldBeOpenWhenMarkedToClose()
{
ExplicitTransaction tx = new ExplicitTransaction( openConnectionMock(), mock( Runnable.class ) );

tx.markToClose();

assertTrue( tx.isOpen() );
}

@Test
public void shouldBeClosedAfterCommit()
{
Transaction tx = new ExplicitTransaction( openConnectionMock(), mock( Runnable.class ) );

tx.success();
tx.close();

assertFalse( tx.isOpen() );
}

@Test
public void shouldBeClosedAfterRollback()
{
Transaction tx = new ExplicitTransaction( openConnectionMock(), mock( Runnable.class ) );

tx.failure();
tx.close();

assertFalse( tx.isOpen() );
}

private static Connection openConnectionMock()
{
Connection connection = mock( Connection.class );
when( connection.isOpen() ).thenReturn( true );
return connection;
}
}

0 comments on commit 85760c8

Please sign in to comment.