Skip to content

Commit

Permalink
Enable and update execution guard tests for driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Sep 9, 2016
1 parent 71c9933 commit 80f090a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
Expand Up @@ -20,17 +20,17 @@


package org.neo4j.bolt.v1.messaging; package org.neo4j.bolt.v1.messaging;


import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.neo4j.bolt.v1.runtime.BoltResponseHandler; import org.neo4j.bolt.v1.runtime.BoltResponseHandler;
import org.neo4j.bolt.v1.runtime.BoltWorker; import org.neo4j.bolt.v1.runtime.BoltWorker;
import org.neo4j.bolt.v1.runtime.Neo4jError; import org.neo4j.bolt.v1.runtime.Neo4jError;
import org.neo4j.bolt.v1.runtime.spi.Record;
import org.neo4j.bolt.v1.runtime.spi.BoltResult; import org.neo4j.bolt.v1.runtime.spi.BoltResult;
import org.neo4j.bolt.v1.runtime.spi.Record;
import org.neo4j.logging.Log; import org.neo4j.logging.Log;


import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/** /**
* This class is responsible for routing incoming request messages to a worker * This class is responsible for routing incoming request messages to a worker
* as well as handling outgoing response messages via appropriate handlers. * as well as handling outgoing response messages via appropriate handlers.
Expand Down Expand Up @@ -141,9 +141,6 @@ public void onStart()
@Override @Override
public void onRecords( BoltResult result, boolean pull ) throws Exception public void onRecords( BoltResult result, boolean pull ) throws Exception
{ {
// Overridden if records are returned, therefore
// should fail if called but not overridden.
assert false;
} }


@Override @Override
Expand Down
Expand Up @@ -42,6 +42,7 @@
import org.neo4j.graphdb.config.Setting; import org.neo4j.graphdb.config.Setting;
import org.neo4j.graphdb.factory.GraphDatabaseBuilder; import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.harness.internal.Ports;
import org.neo4j.helpers.collection.MapUtil; import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.io.fs.FileUtils; import org.neo4j.io.fs.FileUtils;
import org.neo4j.kernel.GraphDatabaseDependencies; import org.neo4j.kernel.GraphDatabaseDependencies;
Expand Down Expand Up @@ -103,6 +104,8 @@ public class TransactionGuardIntegrationTest
private static GraphDatabaseAPI databaseWithTimeoutAndGuard; private static GraphDatabaseAPI databaseWithTimeoutAndGuard;
private static GraphDatabaseAPI databaseWithoutTimeout; private static GraphDatabaseAPI databaseWithoutTimeout;
private static CommunityNeoServer neoServer; private static CommunityNeoServer neoServer;
private static int boltPortCustomGuard;
private static int boltPortDatabaseWithTimeout;


@Test @Test
public void terminateLongRunningTransaction() public void terminateLongRunningTransaction()
Expand Down Expand Up @@ -304,15 +307,15 @@ public void terminateLongRunningRestTransactionalEndpointWithCustomTimeoutQuery(
assertDatabaseDoesNotHaveNodes( database ); assertDatabaseDoesNotHaveNodes( database );
} }


// @Test @Test
public void terminateLongRunningDriverQuery() throws Exception public void terminateLongRunningDriverQuery() throws Exception
{ {
GraphDatabaseAPI database = startDatabaseWithTimeout(); GraphDatabaseAPI database = startDatabaseWithTimeout();
CommunityNeoServer neoServer = startNeoServer( (GraphDatabaseFacade) database ); CommunityNeoServer neoServer = startNeoServer( (GraphDatabaseFacade) database );


org.neo4j.driver.v1.Config driverConfig = getDriverConfig(); org.neo4j.driver.v1.Config driverConfig = getDriverConfig();


try ( Driver driver = GraphDatabase.driver( "bolt://localhost", driverConfig ); try ( Driver driver = GraphDatabase.driver( "bolt://localhost:" + boltPortDatabaseWithTimeout, driverConfig );
Session session = driver.session() ) Session session = driver.session() )
{ {
org.neo4j.driver.v1.Transaction transaction = session.beginTransaction(); org.neo4j.driver.v1.Transaction transaction = session.beginTransaction();
Expand All @@ -332,12 +335,35 @@ public void terminateLongRunningDriverQuery() throws Exception
assertDatabaseDoesNotHaveNodes( database ); assertDatabaseDoesNotHaveNodes( database );
} }


@Test
public void terminateLongRunningDriverPeriodicCommitQuery() throws Exception
{
GraphDatabaseAPI database = startDatabaseWithTimeoutCustomGuard();
CommunityNeoServer neoServer = startNeoServer( (GraphDatabaseFacade) database );

org.neo4j.driver.v1.Config driverConfig = getDriverConfig();

try ( Driver driver = GraphDatabase.driver( "bolt://localhost:" + boltPortCustomGuard, driverConfig );
Session session = driver.session() )
{
URL url = prepareTestImportFile( 8 );
session.run( "USING PERIODIC COMMIT 5 LOAD CSV FROM '" + url + "' AS line CREATE ();" ).consume();
fail("Transaction should be already terminated by execution guard.");
}
catch ( Exception expected )
{
//
}
assertDatabaseDoesNotHaveNodes( database );
}

private GraphDatabaseAPI startDatabaseWithTimeoutCustomGuard() private GraphDatabaseAPI startDatabaseWithTimeoutCustomGuard()
{ {
if ( databaseWithTimeoutAndGuard == null ) if ( databaseWithTimeoutAndGuard == null )
{ {
Map<Setting<?>,String> configMap = getSettingsWithTransactionTimeout(); boltPortCustomGuard = findFreePort();
databaseWithTimeoutAndGuard = startCustomGuardedDatabase( testDirectory.directory( "dbWithoutTimeoutAndguard" ), configMap ); Map<Setting<?>,String> configMap = getSettingsWithTimeoutAndBolt( boltPortCustomGuard );
databaseWithTimeoutAndGuard = startCustomGuardedDatabase( testDirectory.directory( "dbWithoutTimeoutAndGuard" ), configMap );
} }
return databaseWithTimeoutAndGuard; return databaseWithTimeoutAndGuard;
} }
Expand All @@ -346,9 +372,9 @@ private GraphDatabaseAPI startDatabaseWithTimeout()
{ {
if ( databaseWithTimeout == null ) if ( databaseWithTimeout == null )
{ {
Map<Setting<?>,String> configMap = getSettingsWithTimeoutAndBolt(); boltPortDatabaseWithTimeout = findFreePort();
databaseWithTimeout = startCustomDatabase( testDirectory.directory( "dbWithTimeout" ), Map<Setting<?>,String> configMap = getSettingsWithTimeoutAndBolt( boltPortDatabaseWithTimeout );
configMap ); databaseWithTimeout = startCustomDatabase( testDirectory.directory( "dbWithTimeout" ), configMap );
} }
return databaseWithTimeout; return databaseWithTimeout;
} }
Expand Down Expand Up @@ -389,21 +415,16 @@ private CommunityNeoServer startNeoServer( GraphDatabaseFacade database ) throws
return neoServer; return neoServer;
} }


private Map<Setting<?>,String> getSettingsWithTimeoutAndBolt() private Map<Setting<?>,String> getSettingsWithTimeoutAndBolt( int boltPort )
{ {
Map<Setting<?>,String> configMap = getSettingsWithTransactionTimeout();
GraphDatabaseSettings.BoltConnector boltConnector = boltConnector( "0" ); GraphDatabaseSettings.BoltConnector boltConnector = boltConnector( "0" );
MapUtil.genericMap(configMap, return MapUtil.genericMap(
GraphDatabaseSettings.transaction_timeout, "2s",
boltConnector.address, "localhost:" + boltPort,
boltConnector.type, "BOLT", boltConnector.type, "BOLT",
boltConnector.enabled, "true", boltConnector.enabled, "true",
boltConnector.encryption_level, GraphDatabaseSettings.BoltConnector.EncryptionLevel.DISABLED.name(), boltConnector.encryption_level, GraphDatabaseSettings.BoltConnector.EncryptionLevel.DISABLED.name(),
GraphDatabaseSettings.auth_enabled, "false" ); GraphDatabaseSettings.auth_enabled, "false" );
return configMap;
}

private Map<Setting<?>,String> getSettingsWithTransactionTimeout()
{
return MapUtil.genericMap( GraphDatabaseSettings.transaction_timeout, "2s" );
} }


private Map<Setting<?>,String> getSettingsWithoutTransactionTimeout() private Map<Setting<?>,String> getSettingsWithoutTransactionTimeout()
Expand All @@ -429,6 +450,23 @@ private URL prepareTestImportFile( int lines ) throws IOException
return tempFile.toURI().toURL(); return tempFile.toURI().toURL();
} }


private int findFreePort()
{
return freePort( 8000, 8100 );
}

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 Response execute( GraphDatabaseShellServer shellServer, private Response execute( GraphDatabaseShellServer shellServer,
CollectingOutput output, Serializable clientId, String command ) throws ShellException CollectingOutput output, Serializable clientId, String command ) throws ShellException
{ {
Expand Down

0 comments on commit 80f090a

Please sign in to comment.