Search in sources :

Example 1 with TransportConnection

use of org.neo4j.bolt.testing.client.TransportConnection in project neo4j by neo4j.

the class ConnectionTrackingIT method killConnectionViaBolt.

private void killConnectionViaBolt(TrackedNetworkConnection trackedConnection) throws Exception {
    String id = trackedConnection.id();
    String user = trackedConnection.username();
    TransportConnection connection = connectSocketTo(neo4j.boltURI());
    try {
        connection.send(util.defaultAcceptedVersions()).send(auth("neo4j", NEO4J_USER_PWD)).send(util.defaultRunAutoCommitTx("CALL dbms.killConnection('" + id + "')"));
        assertThat(connection).satisfies(util.eventuallyReceivesSelectedProtocolVersion());
        assertThat(connection).satisfies(util.eventuallyReceives(msgSuccess(), msgSuccess(), msgRecord(eqRecord(new Condition<>(anyValue -> true, "any value"), new Condition<>(v -> v.equals(stringOrNoValue(user)), "user value"), new Condition<>(v -> v.equals(stringValue("Connection found")), "connection"))), msgSuccess()));
    } finally {
        connection.disconnect();
    }
}
Also used : HamcrestCondition(org.assertj.core.api.HamcrestCondition) Condition(org.assertj.core.api.Condition) TransportConnection(org.neo4j.bolt.testing.client.TransportConnection)

Example 2 with TransportConnection

use of org.neo4j.bolt.testing.client.TransportConnection in project neo4j by neo4j.

the class ConnectionTrackingIT method testKillingOfConnections.

private void testKillingOfConnections(URI uri, TestConnector connector, int count) throws Exception {
    List<TransportConnection> socketConnections = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        socketConnections.add(connectSocketTo(uri));
    }
    awaitNumberOfAcceptedConnectionsToBe(count);
    verifyConnectionCount(connector, null, count);
    killAcceptedConnectionViaBolt();
    verifyConnectionCount(connector, null, 0);
    for (TransportConnection socketConnection : socketConnections) {
        assertConnectionBreaks(socketConnection);
    }
}
Also used : TransportConnection(org.neo4j.bolt.testing.client.TransportConnection) ArrayList(java.util.ArrayList)

Example 3 with TransportConnection

use of org.neo4j.bolt.testing.client.TransportConnection in project neo4j by neo4j.

the class ConnectionTrackingIT method afterEach.

@AfterEach
void afterEach() {
    for (TransportConnection connection : connections) {
        try {
            connection.disconnect();
        } catch (Exception ignore) {
        }
    }
    httpClients.clear();
    IOUtils.closeAllSilently(acceptedConnectionsFromConnectionTracker());
    terminateAllTransactions();
    awaitNumberOfAcceptedConnectionsToBe(0);
}
Also used : TransportConnection(org.neo4j.bolt.testing.client.TransportConnection) TimeoutException(java.util.concurrent.TimeoutException) SocketException(java.net.SocketException) IOException(java.io.IOException) AfterEach(org.junit.jupiter.api.AfterEach)

Example 4 with TransportConnection

use of org.neo4j.bolt.testing.client.TransportConnection in project neo4j by neo4j.

the class BoltSchedulerBusyIT method enterStreaming.

private TransportConnection enterStreaming() throws Throwable {
    TransportConnection connection = null;
    Throwable error = null;
    // retry couple times because worker threads might seem busy
    for (int i = 1; i <= 7; i++) {
        try {
            connection = newConnection();
            enterStreaming(connection, i);
            error = null;
            return connection;
        } catch (Throwable t) {
            // failed to enter the streaming state, record the error and retry
            if (error == null) {
                error = t;
            } else {
                error.addSuppressed(t);
            }
            close(connection);
            SECONDS.sleep(i);
        }
    }
    if (error != null) {
        throw error;
    }
    throw new IllegalStateException("Unable to enter the streaming state");
}
Also used : TransportConnection(org.neo4j.bolt.testing.client.TransportConnection)

Example 5 with TransportConnection

use of org.neo4j.bolt.testing.client.TransportConnection in project neo4j by neo4j.

the class AuthenticationIT method collectAuthFailureOnFailedAuth.

private FailureMessage collectAuthFailureOnFailedAuth() {
    FailureMsgMatcher failureRecorder = new FailureMsgMatcher();
    TransportConnection connection = null;
    try {
        connection = newConnection();
        connection.connect(address).send(util.defaultAcceptedVersions()).send(util.defaultAuth(map("principal", "neo4j", "credentials", "WHAT_WAS_THE_PASSWORD_AGAIN", "scheme", "basic")));
        assertThat(connection).satisfies(util.eventuallyReceivesSelectedProtocolVersion());
        assertThat(connection).satisfies(util.eventuallyReceives(failureRecorder));
        assertThat(connection).satisfies(eventuallyDisconnects());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        if (connection != null) {
            try {
                connection.disconnect();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }
    }
    return failureRecorder.specialMessage;
}
Also used : TransportConnection(org.neo4j.bolt.testing.client.TransportConnection) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException)

Aggregations

TransportConnection (org.neo4j.bolt.testing.client.TransportConnection)6 IOException (java.io.IOException)2 TimeoutException (java.util.concurrent.TimeoutException)2 SocketException (java.net.SocketException)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 Condition (org.assertj.core.api.Condition)1 HamcrestCondition (org.assertj.core.api.HamcrestCondition)1 AfterEach (org.junit.jupiter.api.AfterEach)1