Skip to content

Commit

Permalink
Fork integration tests in enterprise-kernel, harness, enterprise-server.
Browse files Browse the repository at this point in the history
Start servers on random ports to allow forked tests executions.
Move ha test to integration tests module.
  • Loading branch information
MishaDemianenko committed Jul 7, 2017
1 parent 7038b68 commit 10ee188
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 81 deletions.
11 changes: 0 additions & 11 deletions community/neo4j-harness/pom.xml
Expand Up @@ -54,17 +54,6 @@
</license> </license>
</licenses> </licenses>


<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
</configuration>
</plugin>
</plugins>
</build>

<dependencies> <dependencies>


<dependency> <dependency>
Expand Down
Expand Up @@ -97,16 +97,16 @@ private void init( File workingDir )
withConfig( http1.type, "HTTP" ); withConfig( http1.type, "HTTP" );
withConfig( http1.encryption, Encryption.NONE.name() ); withConfig( http1.encryption, Encryption.NONE.name() );
withConfig( http1.enabled, "true" ); withConfig( http1.enabled, "true" );
withConfig( http1.address, "localhost:" + Integer.toString( freePort( 1001, 3000 ) ) ); withConfig( http1.address, "localhost:0" );


withConfig( http2.type, "HTTP" ); withConfig( http2.type, "HTTP" );
withConfig( http2.encryption, Encryption.TLS.name() ); withConfig( http2.encryption, Encryption.TLS.name() );
withConfig( http2.enabled, "false" ); withConfig( http2.enabled, "false" );
withConfig( http2.address, "localhost:" + Integer.toString( freePort( 3001, 5000 ) ) ); withConfig( http2.address, "localhost:0" );


withConfig( bolt0.type, "BOLT" ); withConfig( bolt0.type, "BOLT" );
withConfig( bolt0.enabled, "true" ); withConfig( bolt0.enabled, "true" );
withConfig( bolt0.address, "localhost:" + Integer.toString( freePort( 5001, 9000 ) ) ); withConfig( bolt0.address, "localhost:0" );
} }


@Override @Override
Expand Down Expand Up @@ -250,18 +250,6 @@ private String randomFolderName()
return DigestUtils.md5Hex( Long.toString( ThreadLocalRandom.current().nextLong() ) ); return DigestUtils.md5Hex( Long.toString( ThreadLocalRandom.current().nextLong() ) );
} }


private int freePort( int startRange, int endRange )
{
try
{
return Ports.findFreePort( Ports.INADDR_LOCALHOST, new int[]{startRange, endRange} ).getPort();
}
catch ( IOException e )
{
throw new RuntimeException( "Unable to find an available port: " + e.getMessage(), e );
}
}

private static String toStringForThirdPartyPackageProperty( List<ThirdPartyJaxRsPackage> extensions ) private static String toStringForThirdPartyPackageProperty( List<ThirdPartyJaxRsPackage> extensions )
{ {
String propertyString = ""; String propertyString = "";
Expand Down
Expand Up @@ -28,17 +28,18 @@
import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.config.Configuration; import org.neo4j.graphdb.config.Configuration;
import org.neo4j.harness.ServerControls; import org.neo4j.harness.ServerControls;
import org.neo4j.helpers.AdvertisedSocketAddress;
import org.neo4j.helpers.Exceptions; import org.neo4j.helpers.Exceptions;
import org.neo4j.helpers.HostnamePort;
import org.neo4j.io.fs.FileUtils; import org.neo4j.io.fs.FileUtils;
import org.neo4j.kernel.configuration.BoltConnector; import org.neo4j.kernel.configuration.ConnectorPortRegister;
import org.neo4j.server.AbstractNeoServer; import org.neo4j.server.AbstractNeoServer;


public class InProcessServerControls implements ServerControls public class InProcessServerControls implements ServerControls
{ {
private final File serverFolder; private final File serverFolder;
private final AbstractNeoServer server; private final AbstractNeoServer server;
private final Closeable additionalClosable; private final Closeable additionalClosable;
private ConnectorPortRegister connectorPortRegister;


public InProcessServerControls( File serverFolder, AbstractNeoServer server, Closeable additionalClosable ) public InProcessServerControls( File serverFolder, AbstractNeoServer server, Closeable additionalClosable )
{ {
Expand All @@ -50,8 +51,8 @@ public InProcessServerControls( File serverFolder, AbstractNeoServer server, Clo
@Override @Override
public URI boltURI() public URI boltURI()
{ {
AdvertisedSocketAddress address = server.getConfig().get( new BoltConnector( "bolt" ).advertised_address ); HostnamePort boltHostNamePort = connectorPortRegister.getLocalAddress( "bolt" );
return URI.create( "bolt://" + address.getHostname() + ":" + address.getPort() ); return URI.create( "bolt://" + boltHostNamePort.getHost() + ":" + boltHostNamePort.getPort() );
} }


@Override @Override
Expand All @@ -69,12 +70,14 @@ public Optional<URI> httpsURI()
public void start() public void start()
{ {
this.server.start(); this.server.start();
this.connectorPortRegister = server.getDependencyResolver().resolveDependency( ConnectorPortRegister.class );
} }


@Override @Override
public void close() public void close()
{ {
server.stop(); server.stop();
this.connectorPortRegister = null;
try try
{ {
additionalClosable.close(); additionalClosable.close();
Expand Down
Expand Up @@ -83,8 +83,7 @@ public class InProcessBuilderTestIT
public void shouldLaunchAServerInSpecifiedDirectory() throws Exception public void shouldLaunchAServerInSpecifiedDirectory() throws Exception
{ {
// Given // Given
File workDir = new File( testDir.directory(), "specific" ); File workDir = testDir.directory( "specific" );
workDir.mkdir();


// When // When
try ( ServerControls server = getTestServerBuilder( workDir ).newServer() ) try ( ServerControls server = getTestServerBuilder( workDir ).newServer() )
Expand Down
Expand Up @@ -61,7 +61,7 @@


public class CommunityServerBuilder public class CommunityServerBuilder
{ {
private static final ListenSocketAddress ANY_ADDRESS = new ListenSocketAddress( "localhost", 0 ); protected static final ListenSocketAddress ANY_ADDRESS = new ListenSocketAddress( "localhost", 0 );


protected final LogProvider logProvider; protected final LogProvider logProvider;
private ListenSocketAddress address = new ListenSocketAddress( "localhost", 7474 ); private ListenSocketAddress address = new ListenSocketAddress( "localhost", 7474 );
Expand Down
6 changes: 0 additions & 6 deletions enterprise/kernel/pom.xml
Expand Up @@ -47,12 +47,6 @@


<build> <build>
<plugins> <plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>net.alchim31.maven</groupId> <groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId> <artifactId>scala-maven-plugin</artifactId>
Expand Down
7 changes: 0 additions & 7 deletions enterprise/server-enterprise/pom.xml
Expand Up @@ -285,13 +285,6 @@
<useManifestOnlyJar>false</useManifestOnlyJar> <useManifestOnlyJar>false</useManifestOnlyJar>
</configuration> </configuration>
</plugin> </plugin>

<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>


Expand Down
Expand Up @@ -31,7 +31,7 @@ public class NeoServerRestartTestEnterpriseIT extends NeoServerRestartTestIT
{ {
protected NeoServer getNeoServer( String customPageSwapperName ) throws IOException protected NeoServer getNeoServer( String customPageSwapperName ) throws IOException
{ {
CommunityServerBuilder builder = EnterpriseServerBuilder.server() CommunityServerBuilder builder = EnterpriseServerBuilder.serverOnRandomPorts()
.withProperty( GraphDatabaseSettings.pagecache_swapper.name(), customPageSwapperName ); .withProperty( GraphDatabaseSettings.pagecache_swapper.name(), customPageSwapperName );
return builder.build(); return builder.build();
} }
Expand Down
Expand Up @@ -53,7 +53,7 @@ public class EnterpriseServerIT
public void shouldBeAbleToStartInHAMode() throws Throwable public void shouldBeAbleToStartInHAMode() throws Throwable
{ {
// Given // Given
NeoServer server = EnterpriseServerBuilder.server() NeoServer server = EnterpriseServerBuilder.serverOnRandomPorts()
.usingDataDir( folder.getRoot().getAbsolutePath() ) .usingDataDir( folder.getRoot().getAbsolutePath() )
.withProperty( mode.name(), "HA" ) .withProperty( mode.name(), "HA" )
.withProperty( server_id.name(), "1" ) .withProperty( server_id.name(), "1" )
Expand All @@ -69,7 +69,7 @@ public void shouldBeAbleToStartInHAMode() throws Throwable
assertThat( server.getDatabase().getGraph(), is( instanceOf(HighlyAvailableGraphDatabase.class) ) ); assertThat( server.getDatabase().getGraph(), is( instanceOf(HighlyAvailableGraphDatabase.class) ) );


Client client = Client.create(); Client client = Client.create();
ClientResponse r = client.resource( "http://localhost:7474/db/manage/server/ha" ) ClientResponse r = client.resource( getHaEndpoint( server ) )
.accept( APPLICATION_JSON ).get( ClientResponse.class ); .accept( APPLICATION_JSON ).get( ClientResponse.class );
assertEquals( 200, r.getStatus() ); assertEquals( 200, r.getStatus() );
assertThat( r.getEntity( String.class ), containsString( "master" ) ); assertThat( r.getEntity( String.class ), containsString( "master" ) );
Expand All @@ -84,7 +84,7 @@ public void shouldBeAbleToStartInHAMode() throws Throwable
public void shouldRequireAuthorizationForHAStatusEndpoints() throws Exception public void shouldRequireAuthorizationForHAStatusEndpoints() throws Exception
{ {
// Given // Given
NeoServer server = EnterpriseServerBuilder.server() NeoServer server = EnterpriseServerBuilder.serverOnRandomPorts()
.withProperty( GraphDatabaseSettings.auth_enabled.name(), "true" ) .withProperty( GraphDatabaseSettings.auth_enabled.name(), "true" )
.usingDataDir( folder.getRoot().getAbsolutePath() ) .usingDataDir( folder.getRoot().getAbsolutePath() )
.withProperty( mode.name(), "HA" ) .withProperty( mode.name(), "HA" )
Expand All @@ -101,7 +101,7 @@ public void shouldRequireAuthorizationForHAStatusEndpoints() throws Exception
assertThat( server.getDatabase().getGraph(), is( instanceOf(HighlyAvailableGraphDatabase.class) ) ); assertThat( server.getDatabase().getGraph(), is( instanceOf(HighlyAvailableGraphDatabase.class) ) );


Client client = Client.create(); Client client = Client.create();
ClientResponse r = client.resource( "http://localhost:7474/db/manage/server/ha" ) ClientResponse r = client.resource( getHaEndpoint( server ) )
.accept( APPLICATION_JSON ).get( ClientResponse.class ); .accept( APPLICATION_JSON ).get( ClientResponse.class );
assertEquals( 401, r.getStatus() ); assertEquals( 401, r.getStatus() );
} }
Expand All @@ -115,7 +115,7 @@ public void shouldRequireAuthorizationForHAStatusEndpoints() throws Exception
public void shouldAllowDisablingAuthorizationOnHAStatusEndpoints() throws Exception public void shouldAllowDisablingAuthorizationOnHAStatusEndpoints() throws Exception
{ {
// Given // Given
NeoServer server = EnterpriseServerBuilder.server() NeoServer server = EnterpriseServerBuilder.serverOnRandomPorts()
.withProperty( GraphDatabaseSettings.auth_enabled.name(), "true" ) .withProperty( GraphDatabaseSettings.auth_enabled.name(), "true" )
.withProperty( HaSettings.ha_status_auth_enabled.name(), "false" ) .withProperty( HaSettings.ha_status_auth_enabled.name(), "false" )
.usingDataDir( folder.getRoot().getAbsolutePath() ) .usingDataDir( folder.getRoot().getAbsolutePath() )
Expand All @@ -133,7 +133,7 @@ public void shouldAllowDisablingAuthorizationOnHAStatusEndpoints() throws Except
assertThat( server.getDatabase().getGraph(), is( instanceOf(HighlyAvailableGraphDatabase.class) ) ); assertThat( server.getDatabase().getGraph(), is( instanceOf(HighlyAvailableGraphDatabase.class) ) );


Client client = Client.create(); Client client = Client.create();
ClientResponse r = client.resource( "http://localhost:7474/db/manage/server/ha" ) ClientResponse r = client.resource( getHaEndpoint( server ) )
.accept( APPLICATION_JSON ).get( ClientResponse.class ); .accept( APPLICATION_JSON ).get( ClientResponse.class );
assertEquals( 200, r.getStatus() ); assertEquals( 200, r.getStatus() );
assertThat( r.getEntity( String.class ), containsString( "master" ) ); assertThat( r.getEntity( String.class ), containsString( "master" ) );
Expand All @@ -144,6 +144,11 @@ public void shouldAllowDisablingAuthorizationOnHAStatusEndpoints() throws Except
} }
} }


private String getHaEndpoint( NeoServer server )
{
return server.baseUri().toString() + "db/manage/server/ha";
}

@After @After
public void whoListensOn5001() public void whoListensOn5001()
{ {
Expand Down
Expand Up @@ -19,27 +19,25 @@
*/ */
package org.neo4j.server.enterprise.functional; package org.neo4j.server.enterprise.functional;


import java.io.File;
import java.io.IOException;

import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;


import java.io.File;
import java.io.IOException;

import org.neo4j.metrics.MetricsSettings; import org.neo4j.metrics.MetricsSettings;
import org.neo4j.metrics.source.server.ServerMetrics; import org.neo4j.metrics.source.server.ServerMetrics;
import org.neo4j.server.NeoServer; import org.neo4j.server.NeoServer;
import org.neo4j.server.configuration.ServerSettings; import org.neo4j.server.configuration.ServerSettings;
import org.neo4j.server.enterprise.helpers.EnterpriseServerBuilder; import org.neo4j.server.enterprise.helpers.EnterpriseServerBuilder;


import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static javax.ws.rs.core.MediaType.APPLICATION_JSON;

import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;

import static org.neo4j.metrics.MetricsTestHelper.metricsCsv; import static org.neo4j.metrics.MetricsTestHelper.metricsCsv;
import static org.neo4j.metrics.MetricsTestHelper.readLongValue; import static org.neo4j.metrics.MetricsTestHelper.readLongValue;


Expand All @@ -54,7 +52,7 @@ public void shouldShowServerMetrics() throws Throwable
// Given // Given
String path = folder.getRoot().getAbsolutePath(); String path = folder.getRoot().getAbsolutePath();
File metricsPath = new File( path + "/metrics" ); File metricsPath = new File( path + "/metrics" );
NeoServer server = EnterpriseServerBuilder.server() NeoServer server = EnterpriseServerBuilder.serverOnRandomPorts()
.usingDataDir( path ) .usingDataDir( path )
.withProperty( MetricsSettings.metricsEnabled.name(), "true" ) .withProperty( MetricsSettings.metricsEnabled.name(), "true" )
.withProperty( MetricsSettings.csvEnabled.name(), "true" ) .withProperty( MetricsSettings.csvEnabled.name(), "true" )
Expand All @@ -67,7 +65,7 @@ public void shouldShowServerMetrics() throws Throwable
// when // when
server.start(); server.start();


String host = "http://localhost:7474" + String host = "http://localhost:" + server.baseUri().getPort() +
ServerSettings.rest_api_path.getDefaultValue() + "/transaction/commit"; ServerSettings.rest_api_path.getDefaultValue() + "/transaction/commit";


for ( int i = 0; i < 5; i++ ) for ( int i = 0; i < 5; i++ )
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException; import java.io.IOException;
import java.util.Optional; import java.util.Optional;


import org.neo4j.kernel.configuration.BoltConnector;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory; import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory;
import org.neo4j.logging.LogProvider; import org.neo4j.logging.LogProvider;
Expand All @@ -44,6 +45,14 @@ public static EnterpriseServerBuilder server()
return server( NullLogProvider.getInstance() ); return server( NullLogProvider.getInstance() );
} }


public static EnterpriseServerBuilder serverOnRandomPorts()
{
EnterpriseServerBuilder server = server();
server.onRandomPorts();
server.withProperty( new BoltConnector( "bolt" ).listen_address.name(), "localhost:0" );
return server;
}

public static EnterpriseServerBuilder server( LogProvider logProvider ) public static EnterpriseServerBuilder server( LogProvider logProvider )
{ {
return new EnterpriseServerBuilder( logProvider ); return new EnterpriseServerBuilder( logProvider );
Expand Down
Expand Up @@ -62,7 +62,7 @@ public void shouldBeAbleToRestartServer() throws Exception
Config config = ConfigLoader.loadConfig( Config config = ConfigLoader.loadConfig(
Optional.of( baseDir.directory() ), Optional.of( baseDir.directory() ),
EnterpriseServerBuilder EnterpriseServerBuilder
.server() .serverOnRandomPorts()
.withDefaultDatabaseTuning() .withDefaultDatabaseTuning()
.usingDataDir( dataDirectory1 ) .usingDataDir( dataDirectory1 )
.createConfigFiles(), .createConfigFiles(),
Expand Down
Expand Up @@ -47,7 +47,7 @@ public abstract class EnterpriseVersionIT extends ExclusiveServerTestBase
public static void setupServer() throws Exception public static void setupServer() throws Exception
{ {
FakeClock clock = Clocks.fakeClock(); FakeClock clock = Clocks.fakeClock();
server = EnterpriseServerBuilder.server() server = EnterpriseServerBuilder.serverOnRandomPorts()
.usingDataDir( staticFolder.getRoot().getAbsolutePath() ) .usingDataDir( staticFolder.getRoot().getAbsolutePath() )
.withClock(clock) .withClock(clock)
.build(); .build();
Expand Down
Expand Up @@ -36,7 +36,6 @@
import org.neo4j.graphdb.schema.ConstraintDefinition; import org.neo4j.graphdb.schema.ConstraintDefinition;
import org.neo4j.graphdb.schema.ConstraintType; import org.neo4j.graphdb.schema.ConstraintType;
import org.neo4j.kernel.impl.annotations.Documented; import org.neo4j.kernel.impl.annotations.Documented;
import org.neo4j.logging.NullLogProvider;
import org.neo4j.server.NeoServer; import org.neo4j.server.NeoServer;
import org.neo4j.server.enterprise.helpers.EnterpriseServerBuilder; import org.neo4j.server.enterprise.helpers.EnterpriseServerBuilder;
import org.neo4j.server.helpers.CommunityServerBuilder; import org.neo4j.server.helpers.CommunityServerBuilder;
Expand Down Expand Up @@ -80,7 +79,7 @@ public static void initServer() throws Exception
{ {
suppressAll().call( (Callable<Void>) () -> suppressAll().call( (Callable<Void>) () ->
{ {
CommunityServerBuilder serverBuilder = EnterpriseServerBuilder.server( NullLogProvider.getInstance() ); CommunityServerBuilder serverBuilder = EnterpriseServerBuilder.serverOnRandomPorts();


PropertyExistenceConstraintsIT.server = ServerHelper.createNonPersistentServer( serverBuilder ); PropertyExistenceConstraintsIT.server = ServerHelper.createNonPersistentServer( serverBuilder );
return null; return null;
Expand Down
Expand Up @@ -42,6 +42,7 @@
import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.security.SecurityContext; import org.neo4j.kernel.api.security.SecurityContext;
import org.neo4j.kernel.configuration.BoltConnector; import org.neo4j.kernel.configuration.BoltConnector;
import org.neo4j.kernel.configuration.ConnectorPortRegister;
import org.neo4j.kernel.configuration.ssl.LegacySslPolicyConfig; import org.neo4j.kernel.configuration.ssl.LegacySslPolicyConfig;
import org.neo4j.kernel.enterprise.api.security.EnterpriseAuthManager; import org.neo4j.kernel.enterprise.api.security.EnterpriseAuthManager;
import org.neo4j.kernel.impl.coreapi.InternalTransaction; import org.neo4j.kernel.impl.coreapi.InternalTransaction;
Expand All @@ -65,6 +66,9 @@


abstract class AbstractRESTInteraction extends CommunityServerTestBase implements NeoInteractionLevel<RESTSubject> abstract class AbstractRESTInteraction extends CommunityServerTestBase implements NeoInteractionLevel<RESTSubject>
{ {

private ConnectorPortRegister connectorPortRegister;

abstract String commitPath(); abstract String commitPath();


abstract void consume( Consumer<ResourceIterator<Map<String,Object>>> resultConsumer, JsonNode data ); abstract void consume( Consumer<ResourceIterator<Map<String,Object>>> resultConsumer, JsonNode data );
Expand All @@ -79,7 +83,7 @@ abstract class AbstractRESTInteraction extends CommunityServerTestBase implement


AbstractRESTInteraction( Map<String,String> config ) throws IOException AbstractRESTInteraction( Map<String,String> config ) throws IOException
{ {
CommunityServerBuilder builder = EnterpriseServerBuilder.server(); CommunityServerBuilder builder = EnterpriseServerBuilder.serverOnRandomPorts();
builder = builder builder = builder
.withProperty( new BoltConnector( "bolt" ).type.name(), "BOLT" ) .withProperty( new BoltConnector( "bolt" ).type.name(), "BOLT" )
.withProperty( new BoltConnector( "bolt" ).enabled.name(), "true" ) .withProperty( new BoltConnector( "bolt" ).enabled.name(), "true" )
Expand All @@ -97,6 +101,7 @@ abstract class AbstractRESTInteraction extends CommunityServerTestBase implement
this.server = builder.build(); this.server = builder.build();
this.server.start(); this.server.start();
authManager = this.server.getDependencyResolver().resolveDependency( EnterpriseAuthManager.class ); authManager = this.server.getDependencyResolver().resolveDependency( EnterpriseAuthManager.class );
connectorPortRegister = server.getDependencyResolver().resolveDependency( ConnectorPortRegister.class );
} }


@Override @Override
Expand Down Expand Up @@ -223,7 +228,7 @@ public String getConnectionProtocol()
@Override @Override
public HostnamePort lookupConnector( String connectorKey ) public HostnamePort lookupConnector( String connectorKey )
{ {
return new HostnamePort( "localhost", 7687 ); return connectorPortRegister.getLocalAddress( connectorKey );
} }


private String parseErrorMessage( HTTP.Response response ) private String parseErrorMessage( HTTP.Response response )
Expand Down

0 comments on commit 10ee188

Please sign in to comment.