diff --git a/community/bolt/src/test/java/org/neo4j/bolt/AbstractBoltTransportsTest.java b/community/bolt/src/test/java/org/neo4j/bolt/AbstractBoltTransportsTest.java
new file mode 100644
index 0000000000000..e932357941808
--- /dev/null
+++ b/community/bolt/src/test/java/org/neo4j/bolt/AbstractBoltTransportsTest.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2002-2018 "Neo Technology,"
+ * Network Engine for Objects in Lund AB [http://neotechnology.com]
+ *
+ * This file is part of Neo4j.
+ *
+ * Neo4j is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.neo4j.bolt;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.neo4j.bolt.v1.messaging.Neo4jPack;
+import org.neo4j.bolt.v1.messaging.Neo4jPackV1;
+import org.neo4j.bolt.v1.transport.integration.TransportTestUtil;
+import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection;
+import org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection;
+import org.neo4j.bolt.v1.transport.socket.client.SocketConnection;
+import org.neo4j.bolt.v1.transport.socket.client.TransportConnection;
+import org.neo4j.bolt.v1.transport.socket.client.WebSocketConnection;
+import org.neo4j.bolt.v2.messaging.Neo4jPackV2;
+import org.neo4j.helpers.HostnamePort;
+
+import static org.junit.runners.Parameterized.Parameter;
+import static org.junit.runners.Parameterized.Parameters;
+
+@RunWith( Parameterized.class )
+public abstract class AbstractBoltTransportsTest
+{
+ private static final List> CONNECTION_CLASSES = Arrays.asList(
+ SocketConnection.class,
+ WebSocketConnection.class,
+ SecureSocketConnection.class,
+ SecureWebSocketConnection.class );
+
+ private static final List NEO4J_PACK_VERSIONS = Arrays.asList(
+ new Neo4jPackV1(),
+ new Neo4jPackV2() );
+
+ @Parameter( 0 )
+ public Class extends TransportConnection> connectionClass;
+
+ @Parameter( 1 )
+ public Neo4jPack neo4jPack;
+
+ @Parameter( 2 )
+ public String name;
+
+ protected HostnamePort address;
+ protected TransportConnection connection;
+ protected TransportTestUtil util;
+
+ @Before
+ public void initializeConnectionAndUtil() throws Exception
+ {
+ connection = connectionClass.newInstance();
+ util = new TransportTestUtil( neo4jPack );
+ }
+
+ @After
+ public void disconnectFromDatabase() throws Exception
+ {
+ if ( connection != null )
+ {
+ connection.disconnect();
+ }
+ }
+
+ @Parameters( name = "{2}" )
+ public static List parameters()
+ {
+ List result = new ArrayList<>();
+ for ( Class extends TransportConnection> connectionClass : CONNECTION_CLASSES )
+ {
+ for ( Neo4jPack neo4jPack : NEO4J_PACK_VERSIONS )
+ {
+ result.add( new Object[]{connectionClass, neo4jPack, newName( connectionClass, neo4jPack )} );
+ }
+ }
+ return result;
+ }
+
+ protected TransportConnection newConnection() throws Exception
+ {
+ return connectionClass.newInstance();
+ }
+
+ protected void reconnect() throws Exception
+ {
+ if ( connection != null )
+ {
+ connection.disconnect();
+ }
+ connection = newConnection();
+ }
+
+ private static String newName( Class extends TransportConnection> connectionClass, Neo4jPack neo4jPack )
+ {
+ return connectionClass.getSimpleName() + " & " + neo4jPack.getClass().getSimpleName();
+ }
+}
diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConfigIT.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConfigIT.java
index fcb4538ef8048..8864bc0a0ff49 100644
--- a/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConfigIT.java
+++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/integration/BoltConfigIT.java
@@ -22,15 +22,10 @@
import org.junit.Rule;
import org.junit.Test;
-import org.neo4j.bolt.v1.messaging.Neo4jPackV1;
+import org.neo4j.bolt.AbstractBoltTransportsTest;
import org.neo4j.bolt.v1.messaging.message.InitMessage;
import org.neo4j.bolt.v1.transport.integration.Neo4jWithSocket;
-import org.neo4j.bolt.v1.transport.integration.TransportTestUtil;
-import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.SocketConnection;
import org.neo4j.bolt.v1.transport.socket.client.TransportConnection;
-import org.neo4j.bolt.v1.transport.socket.client.WebSocketConnection;
import org.neo4j.helpers.HostnamePort;
import org.neo4j.kernel.configuration.BoltConnector;
import org.neo4j.test.rule.SuppressOutput;
@@ -42,7 +37,7 @@
import static org.neo4j.bolt.v1.transport.integration.TransportTestUtil.eventuallyReceives;
import static org.neo4j.kernel.configuration.BoltConnector.EncryptionLevel.REQUIRED;
-public class BoltConfigIT
+public class BoltConfigIT extends AbstractBoltTransportsTest
{
private static final String ANOTHER_CONNECTOR_KEY = "1";
@@ -61,27 +56,14 @@ public class BoltConfigIT
@Rule
public SuppressOutput suppressOutput = SuppressOutput.suppressAll();
- private final TransportTestUtil util = new TransportTestUtil( new Neo4jPackV1() );
-
@Test
public void shouldSupportMultipleConnectors() throws Throwable
{
- // Given
- // When
-
- // Then
HostnamePort address0 = server.lookupConnector( DEFAULT_CONNECTOR_KEY );
- assertConnectionAccepted( address0, new WebSocketConnection() );
- assertConnectionAccepted( address0, new SecureWebSocketConnection() );
- assertConnectionAccepted( address0, new SocketConnection() );
- assertConnectionAccepted( address0, new SecureSocketConnection() );
+ assertConnectionAccepted( address0, newConnection() );
HostnamePort address1 = server.lookupConnector( ANOTHER_CONNECTOR_KEY );
- assertConnectionRejected( address1, new WebSocketConnection() );
- assertConnectionAccepted( address1, new SecureWebSocketConnection() );
- assertConnectionRejected( address1, new SocketConnection() );
- assertConnectionAccepted( address1, new SecureSocketConnection() );
-
+ assertConnectionRejected( address1, newConnection() );
}
private void assertConnectionRejected( HostnamePort address, TransportConnection client ) throws Exception
diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/AuthenticationIT.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/AuthenticationIT.java
index e9e18adb55135..985dc6e2719f5 100644
--- a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/AuthenticationIT.java
+++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/AuthenticationIT.java
@@ -21,22 +21,18 @@
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
-import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
import java.io.IOException;
-import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.function.Consumer;
-import org.neo4j.bolt.v1.messaging.Neo4jPackV1;
+import org.neo4j.bolt.AbstractBoltTransportsTest;
import org.neo4j.bolt.v1.messaging.message.AckFailureMessage;
import org.neo4j.bolt.v1.messaging.message.FailureMessage;
import org.neo4j.bolt.v1.messaging.message.InitMessage;
@@ -44,12 +40,6 @@
import org.neo4j.bolt.v1.messaging.message.ResetMessage;
import org.neo4j.bolt.v1.messaging.message.ResponseMessage;
import org.neo4j.bolt.v1.messaging.message.RunMessage;
-import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.SocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.TransportConnection;
-import org.neo4j.bolt.v1.transport.socket.client.WebSocketConnection;
-import org.neo4j.function.Factory;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.HostnamePort;
import org.neo4j.kernel.api.exceptions.Status;
@@ -60,7 +50,6 @@
import org.neo4j.values.virtual.MapValue;
import org.neo4j.values.virtual.VirtualValues;
-import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
@@ -73,8 +62,7 @@
import static org.neo4j.bolt.v1.transport.integration.TransportTestUtil.eventuallyReceives;
import static org.neo4j.helpers.collection.MapUtil.map;
-@RunWith( Parameterized.class )
-public class AuthenticationIT
+public class AuthenticationIT extends AbstractBoltTransportsTest
{
protected EphemeralFileSystemRule fsRule = new EphemeralFileSystemRule();
protected Neo4jWithSocket server =
@@ -93,124 +81,102 @@ protected Consumer> getSettingsFunction()
return settings -> settings.put( GraphDatabaseSettings.auth_enabled.name(), "true" );
}
- @Parameterized.Parameter
- public Factory cf;
-
private HostnamePort address;
- private TransportConnection client;
private final String version = "Neo4j/" + Version.getNeo4jVersion();
- private final TransportTestUtil util = new TransportTestUtil( new Neo4jPackV1() );
-
- @Parameterized.Parameters
- public static Collection> transports()
- {
- return asList( SocketConnection::new, WebSocketConnection::new, SecureSocketConnection::new,
- SecureWebSocketConnection::new );
- }
@Before
public void setup()
{
- this.client = cf.newInstance();
- this.address = server.lookupDefaultConnector();
- }
-
- @After
- public void teardown() throws Exception
- {
- if ( client != null )
- {
- client.disconnect();
- }
+ address = server.lookupDefaultConnector();
}
@Test
public void shouldRespondWithCredentialsExpiredOnFirstUse() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgSuccess( map( "credentials_expired", true, "server", version ) ) ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess( map( "credentials_expired", true, "server", version ) ) ) );
verifyConnectionOpen();
}
private void verifyConnectionOpen() throws IOException
{
- client.send( util.chunk( ResetMessage.reset() ) );
- assertThat( client, util.eventuallyReceives( msgSuccess() ) );
+ connection.send( util.chunk( ResetMessage.reset() ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess() ) );
}
@Test
public void shouldFailIfWrongCredentials() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "wrong", "scheme", "basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
"The client is unauthorized due to authentication failure." ) ) );
- assertThat( client, eventuallyDisconnects() );
+ assertThat( connection, eventuallyDisconnects() );
}
@Test
public void shouldFailIfWrongCredentialsFollowingSuccessfulLogin() throws Throwable
{
// When change password
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1", map( "principal", "neo4j",
"credentials", "neo4j", "new_credentials", "secret", "scheme", "basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgSuccess() ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess() ) );
// When login again with the new password
reconnect();
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "secret", "scheme", "basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgSuccess() ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess() ) );
// When login again with the wrong password
reconnect();
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "wrong", "scheme", "basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
"The client is unauthorized due to authentication failure." ) ) );
- assertThat( client, eventuallyDisconnects() );
+ assertThat( connection, eventuallyDisconnects() );
}
@Test
public void shouldFailIfMalformedAuthTokenWrongType() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
@@ -218,19 +184,19 @@ public void shouldFailIfMalformedAuthTokenWrongType() throws Throwable
"basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
"Unsupported authentication token, the value associated with the key `principal` " +
"must be a String but was: ArrayList" ) ) );
- assertThat( client, eventuallyDisconnects() );
+ assertThat( connection, eventuallyDisconnects() );
}
@Test
public void shouldFailIfMalformedAuthTokenMissingKey() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
@@ -238,36 +204,36 @@ public void shouldFailIfMalformedAuthTokenMissingKey() throws Throwable
"basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
"Unsupported authentication token, missing key `credentials`" ) ) );
- assertThat( client, eventuallyDisconnects() );
+ assertThat( connection, eventuallyDisconnects() );
}
@Test
public void shouldFailIfMalformedAuthTokenMissingScheme() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "neo4j" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
"Unsupported authentication token, missing key `scheme`" ) ) );
- assertThat( client, eventuallyDisconnects() );
+ assertThat( connection, eventuallyDisconnects() );
}
@Test
public void shouldFailIfMalformedAuthTokenUnknownScheme() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
@@ -275,11 +241,11 @@ public void shouldFailIfMalformedAuthTokenUnknownScheme() throws Throwable
"scheme", "unknown" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
"Unsupported authentication token, scheme 'unknown' is not supported." ) ) );
- assertThat( client, eventuallyDisconnects() );
+ assertThat( connection, eventuallyDisconnects() );
}
@Test
@@ -293,17 +259,17 @@ public void shouldFailDifferentlyIfTooManyFailedAuthAttempts() throws Exception
while ( System.currentTimeMillis() < timeout && !failureMatcher.gotSpecialMessage() )
{
// Done in a loop because we're racing with the clock to get enough failed requests in 5 seconds
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "WHAT_WAS_THE_PASSWORD_AGAIN",
"scheme", "basic" ) ) ) );
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( failureMatcher ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( failureMatcher ) );
- assertThat( client, eventuallyDisconnects() );
+ assertThat( connection, eventuallyDisconnects() );
reconnect();
}
@@ -317,231 +283,222 @@ public void shouldFailDifferentlyIfTooManyFailedAuthAttempts() throws Exception
public void shouldBeAbleToUpdateCredentials() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1", map( "principal", "neo4j",
"credentials", "neo4j", "new_credentials", "secret", "scheme", "basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgSuccess() ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess() ) );
// If I reconnect I cannot use the old password
reconnect();
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) );
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
"The client is unauthorized due to authentication failure." ) ) );
// But the new password works fine
reconnect();
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "secret", "scheme", "basic" ) ) ) );
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgSuccess() ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess() ) );
}
@Test
public void shouldBeAuthenticatedAfterUpdatingCredentials() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1", map( "principal", "neo4j",
"credentials", "neo4j", "new_credentials", "secret", "scheme", "basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgSuccess() ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess() ) );
// When
- client.send( util.chunk(
+ connection.send( util.chunk(
RunMessage.run( "MATCH (n) RETURN n" ),
PullAllMessage.pullAll() ) );
// Then
- assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess(), msgSuccess() ) );
}
@Test
public void shouldBeAbleToChangePasswordUsingBuiltInProcedure() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgSuccess( map( "credentials_expired", true, "server", version ) ) ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess( map( "credentials_expired", true, "server", version ) ) ) );
// When
- client.send( util.chunk(
+ connection.send( util.chunk(
RunMessage.run( "CALL dbms.security.changePassword", singletonMap( "password", "secret" ) ),
PullAllMessage.pullAll() ) );
// Then
- assertThat( client, util.eventuallyReceives( msgSuccess() ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess() ) );
// If I reconnect I cannot use the old password
reconnect();
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) );
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.Unauthorized,
"The client is unauthorized due to authentication failure." ) ) );
// But the new password works fine
reconnect();
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "secret", "scheme", "basic" ) ) ) );
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgSuccess() ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess() ) );
}
@Test
public void shouldBeAuthenticatedAfterChangePasswordUsingBuiltInProcedure() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgSuccess( map( "credentials_expired", true, "server", version ) ) ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess( map( "credentials_expired", true, "server", version ) ) ) );
// When
- client.send( util.chunk(
+ connection.send( util.chunk(
RunMessage.run( "CALL dbms.security.changePassword", singletonMap( "password", "secret" ) ),
PullAllMessage.pullAll() ) );
// Then
- assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess(), msgSuccess() ) );
// When
- client.send( util.chunk(
+ connection.send( util.chunk(
RunMessage.run( "MATCH (n) RETURN n" ),
PullAllMessage.pullAll() ) );
// Then
- assertThat( client, util.eventuallyReceives( msgSuccess(), msgSuccess() ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess(), msgSuccess() ) );
}
@Test
public void shouldFailWhenReusingTheSamePassword() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgSuccess( map( "credentials_expired", true, "server", version ) ) ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess( map( "credentials_expired", true, "server", version ) ) ) );
// When
- client.send( util.chunk(
+ connection.send( util.chunk(
RunMessage.run( "CALL dbms.security.changePassword", singletonMap( "password", "neo4j" ) ),
PullAllMessage.pullAll() ) );
// Then
- assertThat( client, util.eventuallyReceives( msgFailure( Status.General.InvalidArguments,
+ assertThat( connection, util.eventuallyReceives( msgFailure( Status.General.InvalidArguments,
"Old password and new password cannot be the same." ) ) );
// However you should also be able to recover
- client.send( util.chunk(
+ connection.send( util.chunk(
AckFailureMessage.ackFailure(),
RunMessage.run( "CALL dbms.security.changePassword", singletonMap( "password", "abc" ) ),
PullAllMessage.pullAll() ) );
- assertThat( client, util.eventuallyReceives( msgIgnored(), msgSuccess(), msgSuccess(), msgSuccess() ) );
+ assertThat( connection, util.eventuallyReceives( msgIgnored(), msgSuccess(), msgSuccess(), msgSuccess() ) );
}
@Test
public void shouldFailWhenSubmittingEmptyPassword() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgSuccess( map( "credentials_expired", true, "server", version ) ) ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess( map( "credentials_expired", true, "server", version ) ) ) );
// When
- client.send( util.chunk(
+ connection.send( util.chunk(
RunMessage.run( "CALL dbms.security.changePassword", singletonMap( "password", "" ) ),
PullAllMessage.pullAll() ) );
// Then
- assertThat( client, util.eventuallyReceives( msgFailure( Status.General.InvalidArguments,
+ assertThat( connection, util.eventuallyReceives( msgFailure( Status.General.InvalidArguments,
"A password cannot be empty." ) ) );
// However you should also be able to recover
- client.send( util.chunk(
+ connection.send( util.chunk(
AckFailureMessage.ackFailure(),
RunMessage.run( "CALL dbms.security.changePassword", singletonMap( "password", "abc" ) ),
PullAllMessage.pullAll() ) );
- assertThat( client, util.eventuallyReceives( msgIgnored(), msgSuccess(), msgSuccess(), msgSuccess() ) );
+ assertThat( connection, util.eventuallyReceives( msgIgnored(), msgSuccess(), msgSuccess(), msgSuccess() ) );
}
@Test
public void shouldNotBeAbleToReadWhenPasswordChangeRequired() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
InitMessage.init( "TestClient/1.1",
map( "principal", "neo4j", "credentials", "neo4j", "scheme", "basic" ) ) ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives( msgSuccess( map( "credentials_expired", true, "server", version ) ) ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess( map( "credentials_expired", true, "server", version ) ) ) );
// When
- client.send( util.chunk(
+ connection.send( util.chunk(
RunMessage.run( "MATCH (n) RETURN n" ),
PullAllMessage.pullAll() ) );
// Then
- assertThat( client, util.eventuallyReceives( msgFailure( Status.Security.CredentialsExpired,
+ assertThat( connection, util.eventuallyReceives( msgFailure( Status.Security.CredentialsExpired,
"The credentials you provided were valid, but must be changed before you can use this instance." ) ) );
- assertThat( client, eventuallyDisconnects() );
- }
-
- private void reconnect() throws Exception
- {
- if ( client != null )
- {
- client.disconnect();
- }
- this.client = cf.newInstance();
+ assertThat( connection, eventuallyDisconnects() );
}
class FailureMsgMatcher extends TypeSafeMatcher
diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/BoltChannelAutoReadLimiterIT.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/BoltChannelAutoReadLimiterIT.java
index cdf62cbde587d..f63a441bda6b5 100644
--- a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/BoltChannelAutoReadLimiterIT.java
+++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/BoltChannelAutoReadLimiterIT.java
@@ -21,25 +21,16 @@
import org.apache.commons.lang3.StringUtils;
import org.hamcrest.CoreMatchers;
-import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import java.util.Collection;
import java.util.Map;
import java.util.function.Consumer;
-import org.neo4j.bolt.v1.messaging.Neo4jPackV1;
+import org.neo4j.bolt.AbstractBoltTransportsTest;
import org.neo4j.bolt.v1.runtime.BoltChannelAutoReadLimiter;
-import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.SocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.TransportConnection;
-import org.neo4j.bolt.v1.transport.socket.client.WebSocketConnection;
import org.neo4j.collection.RawIterator;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
@@ -58,7 +49,6 @@
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.fs.EphemeralFileSystemRule;
-import static java.util.Arrays.asList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -69,8 +59,7 @@
import static org.neo4j.bolt.v1.transport.integration.TransportTestUtil.eventuallyReceives;
import static org.neo4j.kernel.api.proc.ProcedureSignature.procedureSignature;
-@RunWith( Parameterized.class )
-public class BoltChannelAutoReadLimiterIT
+public class BoltChannelAutoReadLimiterIT extends AbstractBoltTransportsTest
{
private AssertableLogProvider logProvider;
private EphemeralFileSystemRule fsRule = new EphemeralFileSystemRule();
@@ -79,18 +68,7 @@ public class BoltChannelAutoReadLimiterIT
@Rule
public RuleChain ruleChain = RuleChain.outerRule( fsRule ).around( server );
- @Parameterized.Parameter
- public TransportConnection connection;
-
private HostnamePort address;
- private TransportTestUtil util;
-
- @Parameterized.Parameters
- public static Collection transports()
- {
- return asList( new SecureSocketConnection(), new SocketConnection(), new SecureWebSocketConnection(),
- new WebSocketConnection() );
- }
protected TestGraphDatabaseFactory getTestGraphDatabaseFactory()
{
@@ -104,7 +82,7 @@ protected TestGraphDatabaseFactory getTestGraphDatabaseFactory()
}
- protected Consumer> getSettingsFunction()
+ protected Consumer> getSettingsFunction()
{
return settings -> settings.put( GraphDatabaseSettings.auth_enabled.name(), "false" );
}
@@ -115,23 +93,13 @@ public void setup() throws Exception
installSleepProcedure( server.graphDatabaseService() );
address = server.lookupDefaultConnector();
- util = new TransportTestUtil( new Neo4jPackV1() );
- }
-
- @After
- public void after() throws Exception
- {
- if ( connection != null )
- {
- connection.disconnect();
- }
}
@Test
public void largeNumberOfSlowRunningJobsShouldChangeAutoReadState() throws Exception
{
int numberOfRunDiscardPairs = 1000;
- String largeString = StringUtils.repeat( " ", 8 * 1024 );
+ String largeString = StringUtils.repeat( " ", 8 * 1024 );
connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
@@ -170,7 +138,7 @@ private static void installSleepProcedure( GraphDatabaseService db ) throws Proc
dbApi.getDependencyResolver().resolveDependency( Procedures.class ).register(
new CallableProcedure.BasicProcedure(
- procedureSignature("boltissue", "sleep")
+ procedureSignature( "boltissue", "sleep" )
.in( "data", Neo4jTypes.NTString )
.out( ProcedureSignature.VOID )
.build() )
diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/ConcurrentAccessIT.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/ConcurrentAccessIT.java
index 32a1590d44f20..257793076faf1 100644
--- a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/ConcurrentAccessIT.java
+++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/ConcurrentAccessIT.java
@@ -22,10 +22,7 @@
import org.hamcrest.CoreMatchers;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
@@ -34,17 +31,11 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-import org.neo4j.bolt.v1.messaging.Neo4jPackV1;
+import org.neo4j.bolt.AbstractBoltTransportsTest;
import org.neo4j.bolt.v1.messaging.message.InitMessage;
-import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.SocketConnection;
import org.neo4j.bolt.v1.transport.socket.client.TransportConnection;
-import org.neo4j.bolt.v1.transport.socket.client.WebSocketConnection;
-import org.neo4j.function.Factory;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
-import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
@@ -62,25 +53,12 @@
* Multiple concurrent users should be able to connect simultaneously. We test this with multiple users running
* load that they roll back, asserting they don't see each others changes.
*/
-@RunWith( Parameterized.class )
-public class ConcurrentAccessIT
+public class ConcurrentAccessIT extends AbstractBoltTransportsTest
{
@Rule
public Neo4jWithSocket server = new Neo4jWithSocket( getClass(), settings ->
settings.put( GraphDatabaseSettings.auth_enabled.name(), "false" ) );
- @Parameterized.Parameter
- public Factory cf;
-
- private final TransportTestUtil util = new TransportTestUtil( new Neo4jPackV1() );
-
- @Parameterized.Parameters
- public static Collection> transports()
- {
- return asList( SocketConnection::new, WebSocketConnection::new, SecureSocketConnection::new,
- SecureWebSocketConnection::new );
- }
-
@Test
public void shouldRunSimpleStatement() throws Throwable
{
@@ -133,7 +111,7 @@ private Callable newWorker( final int iterationsToRun ) throws Exception
public Void call() throws Exception
{
// Connect
- TransportConnection client = cf.newInstance();
+ TransportConnection client = newConnection();
client.connect( server.lookupDefaultConnector() ).send( util.acceptedVersions( 1, 0, 0, 0 ) );
assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportErrorIT.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportErrorIT.java
index 99f8c7cb1c0bb..fb85fc676580d 100644
--- a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportErrorIT.java
+++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportErrorIT.java
@@ -19,29 +19,17 @@
*/
package org.neo4j.bolt.v1.transport.integration;
-import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
import java.util.Arrays;
-import java.util.Collection;
-import org.neo4j.bolt.v1.messaging.Neo4jPackV1;
+import org.neo4j.bolt.AbstractBoltTransportsTest;
import org.neo4j.bolt.v1.messaging.RecordingByteChannel;
import org.neo4j.bolt.v1.packstream.BufferedChannelOutput;
import org.neo4j.bolt.v1.packstream.PackStream;
-import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.SocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.TransportConnection;
-import org.neo4j.bolt.v1.transport.socket.client.WebSocketConnection;
-import org.neo4j.function.Factory;
-import org.neo4j.helpers.HostnamePort;
-
-import static java.util.Arrays.asList;
+
import static org.hamcrest.MatcherAssert.assertThat;
import static org.neo4j.bolt.v1.messaging.BoltRequestMessage.RUN;
import static org.neo4j.bolt.v1.messaging.message.RunMessage.run;
@@ -49,41 +37,15 @@
import static org.neo4j.bolt.v1.transport.integration.TransportTestUtil.eventuallyDisconnects;
import static org.neo4j.bolt.v1.transport.integration.TransportTestUtil.eventuallyReceives;
-@RunWith( Parameterized.class )
-public class TransportErrorIT
+public class TransportErrorIT extends AbstractBoltTransportsTest
{
@Rule
public Neo4jWithSocket server = new Neo4jWithSocket( getClass() );
- @Parameterized.Parameter
- public Factory cf;
-
- private HostnamePort address;
- private TransportConnection client;
- private TransportTestUtil util;
-
- @Parameterized.Parameters
- public static Collection> transports()
- {
- return asList( SocketConnection::new, WebSocketConnection::new, SecureSocketConnection::new,
- SecureWebSocketConnection::new );
- }
-
@Before
public void setup()
{
- this.client = cf.newInstance();
- this.address = server.lookupDefaultConnector();
- this.util = new TransportTestUtil( new Neo4jPackV1() );
- }
-
- @After
- public void tearDown() throws Exception
- {
- if ( client != null )
- {
- client.disconnect();
- }
+ address = server.lookupDefaultConnector();
}
@Test
@@ -94,13 +56,13 @@ public void shouldHandleIncorrectFraming() throws Throwable
truncated = Arrays.copyOf(truncated, truncated.length - 12);
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk( 32, truncated ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, eventuallyDisconnects() );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, eventuallyDisconnects() );
}
@Test
@@ -118,13 +80,13 @@ public void shouldHandleMessagesWithIncorrectFields() throws Throwable
byte[] invalidMessage = rawData.getBytes();
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk( 32, invalidMessage ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, eventuallyDisconnects() );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, eventuallyDisconnects() );
}
@Test
@@ -141,13 +103,13 @@ public void shouldHandleUnknownMessages() throws Throwable
byte[] invalidMessage = rawData.getBytes();
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk( 32, invalidMessage ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, eventuallyDisconnects() );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, eventuallyDisconnects() );
}
@Test
@@ -165,12 +127,12 @@ public void shouldHandleUnknownMarkerBytes() throws Throwable
byte[] invalidMessage = rawData.getBytes();
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk( 32, invalidMessage ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, eventuallyDisconnects() );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, eventuallyDisconnects() );
}
}
diff --git a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportSessionIT.java b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportSessionIT.java
index 5b0e44831ecf7..8bebaf58c112b 100644
--- a/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportSessionIT.java
+++ b/community/bolt/src/test/java/org/neo4j/bolt/v1/transport/integration/TransportSessionIT.java
@@ -21,23 +21,13 @@
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
-import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import java.util.Collection;
import java.util.HashMap;
-import org.neo4j.bolt.v1.messaging.Neo4jPackV1;
-import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.SocketConnection;
-import org.neo4j.bolt.v1.transport.socket.client.TransportConnection;
-import org.neo4j.bolt.v1.transport.socket.client.WebSocketConnection;
-import org.neo4j.function.Factory;
+import org.neo4j.bolt.AbstractBoltTransportsTest;
import org.neo4j.graphdb.InputPosition;
import org.neo4j.graphdb.SeverityLevel;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
@@ -69,72 +59,47 @@
import static org.neo4j.values.storable.Values.longValue;
import static org.neo4j.values.storable.Values.stringValue;
-@SuppressWarnings( "unchecked" )
-@RunWith( Parameterized.class )
-public class TransportSessionIT
+public class TransportSessionIT extends AbstractBoltTransportsTest
{
@Rule
public Neo4jWithSocket server = new Neo4jWithSocket( getClass(), settings ->
settings.put( GraphDatabaseSettings.auth_enabled.name(), "false" ) );
- @Parameterized.Parameter( 0 )
- public Factory cf;
-
private HostnamePort address;
- private TransportConnection client;
- private TransportTestUtil util;
-
- @Parameterized.Parameters
- public static Collection> transports()
- {
- return asList( SocketConnection::new, WebSocketConnection::new, SecureSocketConnection::new,
- SecureWebSocketConnection::new );
- }
@Before
public void setup()
{
- this.client = cf.newInstance();
- this.address = server.lookupDefaultConnector();
- this.util = new TransportTestUtil( new Neo4jPackV1() );
- }
-
- @After
- public void tearDown() throws Exception
- {
- if ( client != null )
- {
- client.disconnect();
- }
+ address = server.lookupDefaultConnector();
}
@Test
public void shouldNegotiateProtocolVersion() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
}
@Test
public void shouldReturnNilOnNoApplicableVersion() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1337, 0, 0, 0 ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 0} ) );
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 0} ) );
}
@Test
public void shouldRunSimpleStatement() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
init( "TestClient/1.1", emptyMap() ),
@@ -142,8 +107,8 @@ public void shouldRunSimpleStatement() throws Throwable
pullAll() ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgSuccess( CoreMatchers.allOf( hasEntry( is( "fields" ),
equalTo( asList( "a", "a_squared" ) ) ), hasKey( "result_available_after" ) ) ),
@@ -158,7 +123,7 @@ public void shouldRunSimpleStatement() throws Throwable
public void shouldRespondWithMetadataToDiscardAll() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
init( "TestClient/1.1", emptyMap() ),
@@ -166,8 +131,8 @@ public void shouldRespondWithMetadataToDiscardAll() throws Throwable
discardAll() ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgSuccess(
CoreMatchers.allOf( hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ),
@@ -180,15 +145,15 @@ public void shouldRespondWithMetadataToDiscardAll() throws Throwable
public void shouldBeAbleToRunQueryAfterAckFailure() throws Throwable
{
// Given
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
init( "TestClient/1.1", emptyMap() ),
run( "QINVALID" ),
pullAll() ) );
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgFailure( Status.Statement.SyntaxError,
String.format( "Invalid input 'Q': expected (line 1, column 1 (offset: 0))%n" +
@@ -196,10 +161,10 @@ public void shouldBeAbleToRunQueryAfterAckFailure() throws Throwable
" ^" ) ), msgIgnored() ) );
// When
- client.send( util.chunk( ackFailure(), run( "RETURN 1" ), pullAll() ) );
+ connection.send( util.chunk( ackFailure(), run( "RETURN 1" ), pullAll() ) );
// Then
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgSuccess(),
msgRecord( eqRecord( equalTo( longValue( 1L ) ) ) ),
@@ -210,15 +175,15 @@ public void shouldBeAbleToRunQueryAfterAckFailure() throws Throwable
public void shouldRunProcedure() throws Throwable
{
// Given
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
init( "TestClient/1.1", emptyMap() ),
run( "CREATE (n:Test {age: 2}) RETURN n.age AS age" ),
pullAll() ) );
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgSuccess( CoreMatchers.allOf( hasEntry( is( "fields" ), equalTo( singletonList( "age" ) ) ),
hasKey( "result_available_after" ) ) ),
@@ -226,12 +191,12 @@ public void shouldRunProcedure() throws Throwable
msgSuccess() ) );
// When
- client.send( util.chunk(
+ connection.send( util.chunk(
run( "CALL db.labels() YIELD label" ),
pullAll() ) );
// Then
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, util.eventuallyReceives(
msgSuccess( CoreMatchers.allOf( hasEntry( is( "fields" ), equalTo( singletonList( "label" ) ) ),
hasKey( "result_available_after" ) ) ),
msgRecord( eqRecord( Matchers.equalTo( stringValue( "Test" ) ) ) ),
@@ -243,7 +208,7 @@ public void shouldRunProcedure() throws Throwable
public void shouldHandleDeletedNodes() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
init( "TestClient/1.1", emptyMap() ),
@@ -251,8 +216,8 @@ public void shouldHandleDeletedNodes() throws Throwable
pullAll() ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgSuccess( CoreMatchers.allOf( hasEntry( is( "fields" ), equalTo( singletonList( "n" ) ) ),
hasKey( "result_available_after" ) ) ) ) );
@@ -264,17 +229,17 @@ public void shouldHandleDeletedNodes() throws Throwable
// labels: [] (90)
// props: {} (A)]
//}
- assertThat( client,
+ assertThat( connection,
eventuallyReceives( bytes( 0x00, 0x08, 0xB1, 0x71, 0x91,
0xB3, 0x4E, 0x00, 0x90, 0xA0, 0x00, 0x00 ) ) );
- assertThat( client, util.eventuallyReceives( msgSuccess() ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess() ) );
}
@Test
public void shouldHandleDeletedRelationships() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
init( "TestClient/1.1", emptyMap() ),
@@ -282,8 +247,8 @@ public void shouldHandleDeletedRelationships() throws Throwable
pullAll() ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgSuccess( CoreMatchers.allOf( hasEntry( is( "fields" ), equalTo( singletonList( "r" ) ) ),
hasKey( "result_available_after" ) ) ) ) );
@@ -297,36 +262,36 @@ public void shouldHandleDeletedRelationships() throws Throwable
// type: "T" (81 54)
// props: {} (A0)]
//}
- assertThat( client,
+ assertThat( connection,
eventuallyReceives( bytes( 0x00, 0x0B, 0xB1, 0x71, 0x91,
0xB5, 0x52, 0x00, 0x00, 0x01, 0x81, 0x54, 0xA0, 0x00, 0x00 ) ) );
- assertThat( client, util.eventuallyReceives( msgSuccess() ) );
+ assertThat( connection, util.eventuallyReceives( msgSuccess() ) );
}
@Test
public void shouldNotLeakStatsToNextStatement() throws Throwable
{
// Given
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
init( "TestClient/1.1", emptyMap() ),
run( "CREATE (n)" ),
pullAll() ) );
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgSuccess(),
msgSuccess() ) );
// When
- client.send(
+ connection.send(
util.chunk(
run( "RETURN 1" ),
pullAll() ) );
// Then
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgRecord( eqRecord( equalTo( longValue( 1L ) ) ) ),
msgSuccess( CoreMatchers.allOf( hasEntry( is( "type" ), equalTo( "r" ) ),
@@ -337,7 +302,7 @@ public void shouldNotLeakStatsToNextStatement() throws Throwable
public void shouldSendNotifications() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
init( "TestClient/1.1", emptyMap() ),
@@ -345,8 +310,8 @@ public void shouldSendNotifications() throws Throwable
pullAll() ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgSuccess(),
hasNotification(
@@ -364,7 +329,7 @@ public void shouldSendNotifications() throws Throwable
public void shouldFailNicelyOnPoints() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
init( "TestClient/1.1", emptyMap() ),
@@ -372,8 +337,8 @@ public void shouldFailNicelyOnPoints() throws Throwable
pullAll() ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgSuccess( CoreMatchers.allOf( hasEntry( is( "fields" ), equalTo( singletonList( "p" ) ) ),
hasKey( "result_available_after" ) ) ),
@@ -402,7 +367,7 @@ public void shouldFailNicelyOnNullKeysInMap() throws Throwable
params.put( "p", inner );
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
init( "TestClient/1.1", emptyMap() ),
@@ -410,17 +375,17 @@ public void shouldFailNicelyOnNullKeysInMap() throws Throwable
pullAll() ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgFailure( Status.Request.Invalid,
"Value `null` is not supported as key in maps, must be a non-nullable string." ),
msgIgnored() ) );
- client.send( util.chunk( ackFailure(), run( "RETURN 1" ), pullAll() ) );
+ connection.send( util.chunk( ackFailure(), run( "RETURN 1" ), pullAll() ) );
// Then
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgSuccess(),
msgRecord( eqRecord( equalTo( longValue( 1L ) ) ) ),
@@ -431,7 +396,7 @@ public void shouldFailNicelyOnNullKeysInMap() throws Throwable
public void shouldFailNicelyWhenDroppingUnknownIndex() throws Throwable
{
// When
- client.connect( address )
+ connection.connect( address )
.send( util.acceptedVersions( 1, 0, 0, 0 ) )
.send( util.chunk(
init( "TestClient/1.1", emptyMap() ),
@@ -439,8 +404,8 @@ public void shouldFailNicelyWhenDroppingUnknownIndex() throws Throwable
pullAll() ) );
// Then
- assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
- assertThat( client, util.eventuallyReceives(
+ assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
+ assertThat( connection, util.eventuallyReceives(
msgSuccess(),
msgFailure( Status.Schema.IndexDropFailed,
"Unable to drop index on :Movie12345(id): No such INDEX ON :Movie12345(id)." ),