Search in sources :

Example 1 with BoltStateMachine

use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.

the class ThreadedWorkerFactory method newWorker.

@Override
public BoltWorker newWorker(BoltConnectionDescriptor connectionDescriptor, Runnable onClose) {
    BoltStateMachine machine = connector.newMachine(connectionDescriptor, onClose, clock);
    RunnableBoltWorker worker = new RunnableBoltWorker(machine, logging);
    scheduler.schedule(sessionWorker, worker, stringMap(THREAD_ID, machine.key()));
    return worker;
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine)

Example 2 with BoltStateMachine

use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.

the class BoltMatchers method hasTransaction.

public static Matcher<BoltStateMachine> hasTransaction() {
    return new BaseMatcher<BoltStateMachine>() {

        @Override
        public boolean matches(final Object item) {
            final BoltStateMachine machine = (BoltStateMachine) item;
            final StatementProcessor statementProcessor = machine.statementProcessor();
            return statementProcessor != null && statementProcessor.hasTransaction();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("no transaction");
        }
    };
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) StatementProcessor(org.neo4j.bolt.v1.runtime.StatementProcessor)

Example 3 with BoltStateMachine

use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.

the class BoltMatchers method verifyOneResponse.

public static void verifyOneResponse(BoltStateMachine.State initialState, ThrowingBiConsumer<BoltStateMachine, BoltResponseRecorder, BoltConnectionFatality> transition) throws AuthenticationException, BoltConnectionFatality {
    BoltStateMachine machine = newMachine(initialState);
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    try {
        transition.accept(machine, recorder);
    } catch (BoltConnectionFatality connectionFatality) {
    // acceptable for invalid transitions
    }
    assertEquals(1, recorder.responseCount());
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltConnectionFatality(org.neo4j.bolt.v1.runtime.BoltConnectionFatality)

Example 4 with BoltStateMachine

use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.

the class BoltConnectionAuthIT method shouldCloseConnectionAfterAuthenticationFailure.

@Test
public void shouldCloseConnectionAfterAuthenticationFailure() throws Throwable {
    // Given
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    // When... then
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    verifyKillsConnection(() -> machine.init(USER_AGENT, map("scheme", "basic", "principal", "neo4j", "credentials", "j4oen"), recorder));
    // ...and
    assertThat(recorder.nextResponse(), failedWithStatus(Status.Security.Unauthorized));
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 5 with BoltStateMachine

use of org.neo4j.bolt.v1.runtime.BoltStateMachine in project neo4j by neo4j.

the class BoltConnectionIT method shouldSucceedOn__run__pullAll__run.

@Test
public void shouldSucceedOn__run__pullAll__run() throws Throwable {
    // Given
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    machine.init(USER_AGENT, emptyMap(), null);
    // And Given that I've ran and pulled one stream
    machine.run("RETURN 1", EMPTY_PARAMS, nullResponseHandler());
    machine.pullAll(nullResponseHandler());
    // When I run a new statement
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.run("RETURN 1", EMPTY_PARAMS, recorder);
    // Then
    assertThat(recorder.nextResponse(), succeeded());
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Aggregations

BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)49 Test (org.junit.Test)43 BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)31 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 HashMap (java.util.HashMap)4 SocketTransportHandler (org.neo4j.bolt.transport.SocketTransportHandler)4 BoltConnectionFatality (org.neo4j.bolt.v1.runtime.BoltConnectionFatality)4 SynchronousBoltWorker (org.neo4j.bolt.v1.runtime.SynchronousBoltWorker)4 ByteBuf (io.netty.buffer.ByteBuf)3 Channel (io.netty.channel.Channel)3 InetSocketAddress (java.net.InetSocketAddress)3 BaseMatcher (org.hamcrest.BaseMatcher)3 Description (org.hamcrest.Description)3 BoltConnectionDescriptor (org.neo4j.bolt.v1.runtime.BoltConnectionDescriptor)3 Record (org.neo4j.bolt.v1.runtime.spi.Record)3 ProtocolChooser (org.neo4j.bolt.transport.ProtocolChooser)2 BoltResponseHandler (org.neo4j.bolt.v1.runtime.BoltResponseHandler)2 StatementProcessor (org.neo4j.bolt.v1.runtime.StatementProcessor)2 BoltResult (org.neo4j.bolt.v1.runtime.spi.BoltResult)2 BoltProtocolV1 (org.neo4j.bolt.v1.transport.BoltProtocolV1)2