Search in sources :

Example 26 with BoltStateMachine

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

the class BoltMatchers method hasNoTransaction.

public static Matcher<BoltStateMachine> hasNoTransaction() {
    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 27 with BoltStateMachine

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

the class MonitoredBoltWorkerFactoryTest method shouldSignalReceivedStartAndComplete.

@Test
public void shouldSignalReceivedStartAndComplete() throws Throwable {
    // given
    FakeClock clock = Clocks.fakeClock();
    WorkerFactory delegate = mock(WorkerFactory.class);
    BoltStateMachine machine = mock(BoltStateMachine.class);
    when(delegate.newWorker(anyObject(), anyObject())).thenReturn(new BoltWorker() {

        @Override
        public void enqueue(Job job) {
            clock.forward(1337, TimeUnit.MILLISECONDS);
            try {
                job.perform(machine);
            } catch (BoltConnectionFatality connectionFatality) {
                throw new RuntimeException(connectionFatality);
            }
        }

        @Override
        public void interrupt() {
            throw new RuntimeException();
        }

        @Override
        public void halt() {
            throw new RuntimeException();
        }
    });
    Monitors monitors = new Monitors();
    CountingSessionMonitor monitor = new CountingSessionMonitor();
    monitors.addMonitorListener(monitor);
    MonitoredWorkerFactory workerFactory = new MonitoredWorkerFactory(monitors, delegate, clock);
    BoltWorker worker = workerFactory.newWorker(CONNECTION_DESCRIPTOR);
    // when
    worker.enqueue((stateMachine) -> {
        stateMachine.run("hello", null, nullResponseHandler());
        clock.forward(1338, TimeUnit.MILLISECONDS);
    });
    // then
    assertEquals(1, monitor.messagesReceived);
    assertEquals(1337, monitor.queueTime);
    assertEquals(1338, monitor.processingTime);
}
Also used : FakeClock(org.neo4j.time.FakeClock) MonitoredBoltWorker(org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory.MonitoredBoltWorker) Monitors(org.neo4j.kernel.monitoring.Monitors) Test(org.junit.Test)

Example 28 with BoltStateMachine

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

the class BoltConnectionAuthIT method shouldGiveKernelVersionOnInit.

@Test
public void shouldGiveKernelVersionOnInit() throws Throwable {
    // Given it is important for client applications to programmatically
    // identify expired credentials as the cause of not being authenticated
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    String version = "Neo4j/" + Version.getNeo4jVersion();
    // When
    machine.init(USER_AGENT, map("scheme", "basic", "principal", "neo4j", "credentials", "neo4j"), recorder);
    machine.run("CREATE ()", map(), recorder);
    // Then
    assertThat(recorder.nextResponse(), succeededWithMetadata("server", version));
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 29 with BoltStateMachine

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

the class BoltConnectionAuthIT method shouldBeAbleToActOnSessionWhenUpdatingCredentials.

@Test
public void shouldBeAbleToActOnSessionWhenUpdatingCredentials() throws Throwable {
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    // when
    machine.init(USER_AGENT, map("scheme", "basic", "principal", "neo4j", "credentials", "neo4j", "new_credentials", "secret"), recorder);
    machine.run("CREATE ()", map(), recorder);
    // then
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 30 with BoltStateMachine

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

the class BoltConnectionAuthIT method shouldGiveCredentialsExpiredStatusOnExpiredCredentials.

@Test
public void shouldGiveCredentialsExpiredStatusOnExpiredCredentials() throws Throwable {
    // Given it is important for client applications to programmatically
    // identify expired credentials as the cause of not being authenticated
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    // When
    machine.init(USER_AGENT, map("scheme", "basic", "principal", "neo4j", "credentials", "neo4j"), recorder);
    machine.run("CREATE ()", map(), recorder);
    // Then
    assertThat(recorder.nextResponse(), succeededWithMetadata("credentials_expired", true));
    assertThat(recorder.nextResponse(), failedWithStatus(Status.Security.CredentialsExpired));
}
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