use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.
the class BoltConnectionIT method shouldCloseConnectionAckFailureBeforeInit.
@Test
public void shouldCloseConnectionAckFailureBeforeInit() throws Throwable {
// Given
BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
// when
BoltResponseRecorder recorder = new BoltResponseRecorder();
verifyKillsConnection(() -> machine.ackFailure(recorder));
// then
assertThat(recorder.nextResponse(), failedWithStatus(Status.Request.Invalid));
}
use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.
the class FragmentedMessageDeliveryTest method testPermutation.
private void testPermutation(byte[] unfragmented, ByteBuf[] fragments) throws Exception {
// Given
BoltStateMachine machine = mock(BoltStateMachine.class);
Channel ch = mock(Channel.class);
when(ch.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
when(ctx.channel()).thenReturn(ch);
BoltProtocolV1 protocol = new BoltProtocolV1(new SynchronousBoltWorker(machine), ch, NullLogService.getInstance());
// When data arrives split up according to the current permutation
for (ByteBuf fragment : fragments) {
fragment.readerIndex(0).retain();
protocol.handle(ctx, fragment);
}
// Then the session should've received the specified messages, and the protocol should be in a nice clean state
try {
verify(machine).run(eq("Mjölnir"), anyMapOf(String.class, Object.class), any(BoltResponseHandler.class));
} catch (AssertionError e) {
throw new AssertionError("Failed to handle fragmented delivery.\n" + "Messages: " + Arrays.toString(messages) + "\n" + "Chunk size: " + chunkSize + "\n" + "Serialized data delivered in fragments: " + describeFragments(fragments) + "\n" + "Unfragmented data: " + HexPrinter.hex(unfragmented) + "\n", e);
} finally {
// To avoid buffer leak errors
protocol.close();
}
}
use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.
the class SocketTransportHandlerTest method shouldInitializeProtocolOnFirstMessage.
@Test
public void shouldInitializeProtocolOnFirstMessage() throws Exception {
BoltStateMachine machine = mock(BoltStateMachine.class);
ProtocolChooser chooser = protocolChooser(machine);
ChannelHandlerContext context = channelHandlerContextMock();
SocketTransportHandler handler = new SocketTransportHandler(chooser, NullLogProvider.getInstance());
handler.channelRead(context, handshake());
BoltProtocol protocol1 = chooser.chosenProtocol();
handler.channelRead(context, handshake());
BoltProtocol protocol2 = chooser.chosenProtocol();
assertSame(protocol1, protocol2);
}
use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.
the class BoltConnectionIT method shouldSupportUsingPeriodicCommitInSession.
@Test
public void shouldSupportUsingPeriodicCommitInSession() throws Exception {
// Given
BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
machine.init(USER_AGENT, emptyMap(), null);
Map<String, Object> params = new HashMap<>();
params.put("csvFileUrl", createLocalIrisData(machine));
long txIdBeforeQuery = env.lastClosedTxId();
long batch = 40;
// When
Object[] result = runAndPull(machine, "USING PERIODIC COMMIT " + batch + "\n" + "LOAD CSV WITH HEADERS FROM {csvFileUrl} AS l\n" + "MATCH (c:Class {name: l.class_name})\n" + "CREATE (s:Sample {sepal_length: l.sepal_length, sepal_width: l.sepal_width, petal_length: l.petal_length, petal_width: l.petal_width})\n" + "CREATE (c)<-[:HAS_CLASS]-(s)\n" + "RETURN count(*) AS c", params);
// Then
assertThat(result.length, equalTo(1));
Record record = (Record) result[0];
Object[] fields = record.fields();
assertThat(fields.length, equalTo(1));
assertThat(fields[0], equalTo(150L));
/*
* 7 tokens have been created for
* 'Sample' label
* 'HAS_CLASS' relationship type
* 'name', 'sepal_length', 'sepal_width', 'petal_length', and 'petal_width' property keys
*
* Note that the token id for the label 'Class' has been created in `createLocalIrisData(...)` so it shouldn't1
* be counted again here
*/
long tokensCommits = 7;
long commits = (IRIS_DATA.split("\n").length - 1) / batch;
long txId = env.lastClosedTxId();
assertEquals(tokensCommits + commits + txIdBeforeQuery, txId);
}
use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.
the class BoltConnectionIT method shouldHandleImplicitCommitFailure.
@Test
public void shouldHandleImplicitCommitFailure() throws Throwable {
// Given
BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
machine.init(USER_AGENT, emptyMap(), null);
machine.run("CREATE (n:Victim)-[:REL]->()", EMPTY_PARAMS, nullResponseHandler());
machine.discardAll(nullResponseHandler());
// When I perform an action that will fail on commit
BoltResponseRecorder recorder = new BoltResponseRecorder();
machine.run("MATCH (n:Victim) DELETE n", EMPTY_PARAMS, recorder);
// Then the statement running should have succeeded
assertThat(recorder.nextResponse(), succeeded());
recorder.reset();
machine.discardAll(recorder);
// But the stop should have failed, since it implicitly triggers commit and thus triggers a failure
assertThat(recorder.nextResponse(), failedWithStatus(Status.Schema.ConstraintValidationFailed));
//assertThat( discarding.next(), failedWith( Status.Schema.ConstraintValidationFailed ) );
}
Aggregations