Skip to content

Commit

Permalink
Fixing the test failure due to wait for bookmark change in V3 to TxSt…
Browse files Browse the repository at this point in the history
…ateMachine.

Removed bookmark meta data in response to Pull_All after Begin in V1
  • Loading branch information
Zhen Li authored and zhenlineo committed Jul 20, 2018
1 parent 5a262c5 commit 3e5308b
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,11 @@ public String[] fieldNames()
public void accept( Visitor visitor )
{
}

@Override
public String toString()
{
return "EmptyBoltResult{}";
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.time.Clock;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.neo4j.bolt.runtime.BoltResult;
Expand Down Expand Up @@ -97,6 +98,12 @@ public void accept( final Visitor visitor ) throws Exception
}
}

@Override
public String toString()
{
return "CypherAdapterStream{" + "delegate=" + delegate + ", fieldNames=" + Arrays.toString( fieldNames ) + '}';
}

private MapValue queryStats( QueryStatistics queryStatistics )
{
MapValueBuilder builder = new MapValueBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ enum State
State beginTransaction( MutableTransactionState ctx, TransactionStateMachineSPI spi, Bookmark bookmark ) throws KernelException
{
waitForBookmark( ctx, spi, bookmark );
ctx.currentResult = BoltResult.EMPTY;
ctx.currentTransaction = spi.beginTransaction( ctx.loginContext );
return EXPLICIT_TRANSACTION;
}
Expand All @@ -259,11 +260,6 @@ private void waitForBookmark( MutableTransactionState ctx, TransactionStateMachi
if ( bookmark != null )
{
spi.awaitUpToDate( bookmark.txId() );
ctx.currentResult = new BookmarkResult( bookmark );
}
else
{
ctx.currentResult = BoltResult.EMPTY;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ public void accept( Visitor visitor )
public void close()
{
}

@Override
public String toString()
{
return "BookmarkResult{" + "bookmark=" + bookmark + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,10 @@ public QueryResult.Record[] records()
QueryResult.Record[] recordArray = new QueryResult.Record[records.size()];
return records.toArray( recordArray );
}

@Override
public String toString()
{
return "RecordedBoltResponse{" + "records=" + records + ", response=" + response + ", metadata=" + metadata + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

import org.neo4j.bolt.messaging.ResponseMessage;
Expand Down Expand Up @@ -106,5 +107,11 @@ public void accept( Visitor visitor ) throws Exception
public void close()
{
}

@Override
public String toString()
{
return "TestBoltResult{" + "records=" + Arrays.toString( records ) + '}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@
import org.neo4j.kernel.impl.util.ValueUtils;
import org.neo4j.values.AnyValue;
import org.neo4j.values.storable.LongValue;
import org.neo4j.values.storable.TextValue;
import org.neo4j.values.virtual.MapValue;
import org.neo4j.values.virtual.VirtualValues;

import static java.util.Collections.emptyMap;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.neo4j.bolt.testing.BoltMatchers.failedWithStatus;
Expand Down Expand Up @@ -233,6 +236,36 @@ public void shouldSucceedOn__run_BEGIN__pullAll__run_COMMIT__pullALL__run_COMMIT
assertThat( recorder.nextResponse(), succeeded() );
}

@Test
public void shouldNotSendBookmarkInPullAllResponse() throws Throwable
{
// Given
BoltStateMachine machine = env.newMachine( boltChannel );
machine.process( new InitMessage( USER_AGENT, emptyMap() ), nullResponseHandler() );

// And Given that I've ran and pulled one stream
BoltResponseRecorder recorder = new BoltResponseRecorder();
machine.process( new RunMessage( "BEGIN", EMPTY_PARAMS ), nullResponseHandler() );
machine.process( PullAllMessage.INSTANCE, nullResponseHandler() );
machine.process( new RunMessage( "RETURN 1", EMPTY_PARAMS ), nullResponseHandler() );
machine.process( PullAllMessage.INSTANCE, nullResponseHandler() );
machine.process( new RunMessage( "COMMIT", EMPTY_PARAMS ), nullResponseHandler() );
machine.process( PullAllMessage.INSTANCE, recorder );
AnyValue bookmark = recorder.nextResponse().metadata( "bookmark" );
assertNotNull( bookmark );
String bookmarkStr = ((TextValue) bookmark).stringValue();

// When I run a new statement
recorder.reset();
machine.process( new RunMessage( "BEGIN", map( "bookmark", bookmarkStr ) ), nullResponseHandler() );
machine.process( PullAllMessage.INSTANCE, recorder );

// Then
RecordedBoltResponse response = recorder.nextResponse();
assertThat( response, succeeded() );
assertThat( response.hasMetadata( "bookmark" ), is( false ) );
}

@Test
public void shouldFailOn__run__run() throws Throwable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void shouldReadYourOwnWrites() throws Exception
machine.process( new RunMessage( "COMMIT", EMPTY_MAP ), nullResponseHandler() );
machine.process( PullAllMessage.INSTANCE, recorder );

assertThat( recorder.nextResponse(), succeededWithMetadata( "bookmark", BOOKMARK_PATTERN ) );
assertThat( recorder.nextResponse(), succeeded() );
assertThat( recorder.nextResponse(), succeededWithRecord( "two" ) );
assertThat( recorder.nextResponse(), succeededWithMetadata( "bookmark", BOOKMARK_PATTERN ) );
}
Expand Down

0 comments on commit 3e5308b

Please sign in to comment.