Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@
import org.neo4j.driver.v1.exceptions.ClientException;

import static java.util.Collections.unmodifiableMap;

import static org.neo4j.driver.internal.ParameterSupport.NO_PARAMETERS;

public class ResultBuilder implements StreamCollector
{
private final static List<String> NO_KEYS = new ArrayList<>();

private final SummaryBuilder summaryBuilder;

private List<Record> body = new ArrayList<>();
private List<String> keys = null;
private Map<String, Integer> keyIndexLookup = null;
private List<String> keys = NO_KEYS;
private Map<String,Integer> keyIndexLookup = null;

public ResultBuilder( String statement, Map<String, Value> parameters )
{
Expand All @@ -60,7 +61,7 @@ public ResultBuilder( String statement, Map<String, Value> parameters )
@Override
public void keys( String[] names )
{
if ( keys == null )
if ( keys == NO_KEYS )
{
int numFields = names.length;
if ( numFields == 0 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,34 @@ public void shouldBeAbleToOpenTxAfterPreviousIsClosed() throws Throwable
// Then we should've gotten a transaction object back
assertNotNull( tx );
}

@Test
public void shouldNotBeAbleToUseSessionWhileOngoingTransaction() throws Throwable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two tests has nothing to do with the fix, I just thought they were missing.

{
// Given
Connection mock = mock( Connection.class );
InternalSession sess = new InternalSession( mock );
sess.beginTransaction();

// Expect
exception.expect( ClientException.class );

// When
sess.run( "whatever" );
}

@Test
public void shouldBeAbleToUseSessionAgainWhenTransactionIsClosed() throws Throwable
{
// Given
Connection mock = mock( Connection.class );
InternalSession sess = new InternalSession( mock );
sess.beginTransaction().close();

// When
sess.run( "whatever" );

// Then
verify( mock ).sync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import org.neo4j.driver.v1.util.TestNeo4jSession;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import static org.neo4j.driver.v1.Values.parameters;

public class ResultStreamIT
Expand Down Expand Up @@ -109,4 +109,14 @@ public void shouldGiveHelpfulFailureMessageWhenAccessNonExistingPropertyOnNode()
// Then
assertTrue( rs.value( "n" ).value( "age" ).isNull() );
}

@Test
public void shouldNotReturnNullKeysOnEmptyResult()
{
// Given
ResultCursor rs = session.run( "CREATE (n:Person {name:{name}})", parameters( "name", "Tom Hanks" ) );

// THEN
assertNotNull( rs.keys() );
}
}