diff --git a/community/shell/src/main/java/org/neo4j/shell/impl/RemoteClient.java b/community/shell/src/main/java/org/neo4j/shell/impl/RemoteClient.java index 76886395be4b0..dedfa0b206192 100644 --- a/community/shell/src/main/java/org/neo4j/shell/impl/RemoteClient.java +++ b/community/shell/src/main/java/org/neo4j/shell/impl/RemoteClient.java @@ -36,102 +36,104 @@ */ public class RemoteClient extends AbstractClient { - private ShellServer server; - private final RmiLocation serverLocation; - private final Output out; + private ShellServer server; + private final RmiLocation serverLocation; + private final Output out; - public RemoteClient( Map initialSession, RmiLocation serverLocation, CtrlCHandler ctrlcHandler ) throws ShellException + public RemoteClient( Map initialSession, RmiLocation serverLocation, + CtrlCHandler ctrlcHandler ) throws ShellException { this( initialSession, serverLocation, RemoteOutput.newOutput(), ctrlcHandler ); } - public RemoteClient( Map initialSession, RmiLocation serverLocation, Output output ) throws ShellException + public RemoteClient( Map initialSession, RmiLocation serverLocation, Output output ) + throws ShellException { this( initialSession, serverLocation, output, InterruptSignalHandler.getHandler() ); } - /** - * @param serverLocation the RMI location of the server to connect to. - * @throws ShellException if no server was found at the RMI location. - */ - public RemoteClient( Map initialSession, RmiLocation serverLocation, Output out, CtrlCHandler ctrlcHandler ) throws ShellException - { - super( initialSession, ctrlcHandler ); - this.serverLocation = serverLocation; - this.out = out; - this.server = findRemoteServer(); - } + /** + * @param serverLocation the RMI location of the server to connect to. + * @throws ShellException if no server was found at the RMI location. + */ + public RemoteClient( Map initialSession, RmiLocation serverLocation, Output out, + CtrlCHandler ctrlcHandler ) throws ShellException + { + super( initialSession, ctrlcHandler ); + this.serverLocation = serverLocation; + this.out = out; + this.server = findRemoteServer(); + } - private ShellServer findRemoteServer() throws ShellException - { - try - { - ShellServer result = ( ShellServer ) this.serverLocation.getBoundObject(); - sayHi( result ); - updateTimeForMostRecentConnection(); - return result; - } - catch ( RemoteException e ) - { - throw ShellException.wrapCause( e ); - } - } + private ShellServer findRemoteServer() throws ShellException + { + try + { + ShellServer result = (ShellServer) this.serverLocation.getBoundObject(); + sayHi( result ); + updateTimeForMostRecentConnection(); + return result; + } + catch ( RemoteException e ) + { + throw ShellException.wrapCause( e ); + } + } - public Output getOutput() - { - return this.out; - } + public Output getOutput() + { + return this.out; + } - public ShellServer getServer() - { - // Poke the server by calling a method, f.ex. the welcome() method. - // If the connection is lost then try to reconnect, using the last - // server lookup address. - boolean hadServer = this.server != null; - boolean shouldTryToReconnect = this.server == null; - try - { - if ( !shouldTryToReconnect ) - { - server.welcome( initialSession ); - } - } - catch ( RemoteException | ShellException ignored ) - { - shouldTryToReconnect = true; - } + public ShellServer getServer() + { + // Poke the server by calling a method, f.ex. the welcome() method. + // If the connection is lost then try to reconnect, using the last + // server lookup address. + boolean hadServer = this.server != null; + boolean shouldTryToReconnect = this.server == null; + try + { + if ( !shouldTryToReconnect ) + { + server.welcome( initialSession ); + } + } + catch ( RemoteException | ShellException ignored ) + { + shouldTryToReconnect = true; + } + + Exception originException = null; + if ( shouldTryToReconnect ) + { + this.server = null; + try + { + this.server = findRemoteServer(); + if ( hadServer ) + { + getOutput().println( "[Reconnected to server]" ); + } + } + catch ( ShellException | RemoteException ee ) + { + // Ok + originException = ee; + } + } - Exception originException = null; - if ( shouldTryToReconnect ) - { - this.server = null; - try - { - this.server = findRemoteServer(); - if ( hadServer ) - { - getOutput().println( "[Reconnected to server]" ); - } - } - catch ( ShellException | RemoteException ee ) - { - // Ok - originException = ee; - } - } + if ( this.server == null ) + { + throw new RuntimeException( "Server closed or cannot be reached anymore: " + originException.getMessage(), + originException ); + } + return this.server; + } - if ( this.server == null ) - { - throw new RuntimeException( - "Server closed or cannot be reached anymore: " + - originException.getMessage(), originException ); - } - return this.server; - } - - public void shutdown() - { - super.shutdown(); - tryUnexport( this.out ); - } + public void shutdown() + { + super.shutdown(); + tryUnexport( this.out ); + } } diff --git a/community/shell/src/main/java/org/neo4j/shell/impl/RmiLocation.java b/community/shell/src/main/java/org/neo4j/shell/impl/RmiLocation.java index eca5109d9f69e..9dfe46dee91ec 100644 --- a/community/shell/src/main/java/org/neo4j/shell/impl/RmiLocation.java +++ b/community/shell/src/main/java/org/neo4j/shell/impl/RmiLocation.java @@ -22,6 +22,7 @@ import java.net.MalformedURLException; import java.net.UnknownHostException; import java.rmi.Naming; +import java.rmi.NoSuchObjectException; import java.rmi.NotBoundException; import java.rmi.Remote; import java.rmi.RemoteException; @@ -35,165 +36,167 @@ */ public class RmiLocation { - private final String host; - private final int port; - private final String name; - private Registry registry; + private final String host; + private final int port; + private final String name; + private Registry registry; - private RmiLocation( String host, int port, String name ) - { - this.host = host; - this.port = port; - this.name = name; - } + private RmiLocation( String host, int port, String name ) + { + this.host = host; + this.port = port; + this.name = name; + } - /** - * Creates a new RMI location instance. - * @param host the RMI host, f.ex. "localhost". - * @param port the RMI port. - * @param name the RMI name, f.ex. "shell". - * @return a new {@link RmiLocation} instance. - */ - public static RmiLocation location( String host, int port, String name ) - { - return new RmiLocation( host, port, name ); - } + /** + * Creates a new RMI location instance. + * + * @param host the RMI host, f.ex. "localhost". + * @param port the RMI port. + * @param name the RMI name, f.ex. "shell". + * @return a new {@link RmiLocation} instance. + */ + public static RmiLocation location( String host, int port, String name ) + { + return new RmiLocation( host, port, name ); + } - /** - * @return the host of this RMI location. - */ - public String getHost() - { - return this.host; - } + /** + * @return the host of this RMI location. + */ + public String getHost() + { + return this.host; + } - /** - * @return the port of this RMI location. - */ - public int getPort() - { - return this.port; - } + /** + * @return the port of this RMI location. + */ + public int getPort() + { + return this.port; + } - /** - * @return the name of this RMI location. - */ - public String getName() - { - return this.name; - } + /** + * @return the name of this RMI location. + */ + public String getName() + { + return this.name; + } - private static String getProtocol() - { - return "rmi://"; - } + private static String getProtocol() + { + return "rmi://"; + } - /** - * @return "short" URL, consisting of protocol, host and port, f.ex. - * "rmi://localhost:8080". - */ - public String toShortUrl() - { - return getProtocol() + getHost() + ":" + getPort(); - } + /** + * @return "short" URL, consisting of protocol, host and port, f.ex. + * "rmi://localhost:8080". + */ + public String toShortUrl() + { + return getProtocol() + getHost() + ":" + getPort(); + } - /** - * @return the full RMI URL, f.ex. - * "rmi://localhost:8080/the/shellname". - */ - public String toUrl() - { - return getProtocol() + getHost() + ":" + getPort() + "/" + getName(); - } + /** + * @return the full RMI URL, f.ex. + * "rmi://localhost:8080/the/shellname". + */ + public String toUrl() + { + return getProtocol() + getHost() + ":" + getPort() + "/" + getName(); + } - /** - * Ensures that the RMI registry is created for this JVM instance and port, - * see {@link #getPort()}. - * @return the registry for the port. - * @throws RemoteException RMI error. - */ - public Registry ensureRegistryCreated() - throws RemoteException - { - try - { - Naming.list( toShortUrl() ); - return LocateRegistry.getRegistry( getHost(), getPort() ); - } - catch ( RemoteException e ) - { + /** + * Ensures that the RMI registry is created for this JVM instance and port, + * see {@link #getPort()}. + * + * @return the registry for the port. + * @throws RemoteException RMI error. + */ + public Registry ensureRegistryCreated() throws RemoteException + { + try + { + Naming.list( toShortUrl() ); + return LocateRegistry.getRegistry( getHost(), getPort() ); + } + catch ( RemoteException e ) + { try { return LocateRegistry.createRegistry( getPort(), null, new HostBoundSocketFactory( host ) ); } catch ( UnknownHostException hostException ) { - throw new RemoteException( "Unable to bind to '"+host+"', unknown hostname.", hostException ); + throw new RemoteException( "Unable to bind to '" + host + "', unknown hostname.", hostException ); } } - catch ( java.net.MalformedURLException e ) - { - throw new RemoteException( "Malformed URL", e ); - } - } + catch ( java.net.MalformedURLException e ) + { + throw new RemoteException( "Malformed URL", e ); + } + } - /** - * Binds an object to the RMI location defined by this instance. - * @param object the object to bind. - * @throws RemoteException RMI error. - */ - public void bind( Remote object ) throws RemoteException - { - this.registry = ensureRegistryCreated(); - try - { - Naming.rebind( toUrl(), object ); - } - catch ( MalformedURLException e ) - { - throw new RemoteException( "Malformed URL", e ); - } - } + /** + * Binds an object to the RMI location defined by this instance. + * + * @param object the object to bind. + * @throws RemoteException RMI error. + */ + public void bind( Remote object ) throws RemoteException + { + this.registry = ensureRegistryCreated(); + try + { + Naming.rebind( toUrl(), object ); + } + catch ( MalformedURLException e ) + { + throw new RemoteException( "Malformed URL", e ); + } + } - public void unbind() throws RemoteException - { - UnicastRemoteObject.unexportObject( this.registry, true ); - } + public void unbind() throws RemoteException + { + UnicastRemoteObject.unexportObject( this.registry, true ); + } - /** - * @return whether or not there's an object bound to the RMI location - * defined by this instance. - */ - public boolean isBound() - { - try - { - getBoundObject(); - return true; - } - catch ( RemoteException e ) - { - return false; - } - } + /** + * @return whether or not there's an object bound to the RMI location + * defined by this instance. + */ + public boolean isBound() + { + try + { + getBoundObject(); + return true; + } + catch ( RemoteException e ) + { + return false; + } + } - /** - * @return the bound object for the RMI location defined by this instance. - * @throws RemoteException if there's no object bound for the RMI location. - */ - public Remote getBoundObject() throws RemoteException - { - try - { - return Naming.lookup( toUrl() ); - } - catch ( NotBoundException e ) - { - throw new RemoteException( "Not bound", e ); - } - catch ( MalformedURLException e ) - { - throw new RemoteException( "Malformed URL", e ); - } - } + /** + * @return the bound object for the RMI location defined by this instance. + * @throws RemoteException if there's no object bound for the RMI location. + */ + public Remote getBoundObject() throws RemoteException + { + try + { + return Naming.lookup( toUrl() ); + } + catch ( NoSuchObjectException | NotBoundException e ) + { + throw new RemoteException( "Not bound", e ); + } + catch ( MalformedURLException e ) + { + throw new RemoteException( "Malformed URL", e ); + } + } } diff --git a/community/shell/src/test/java/org/neo4j/shell/AbstractShellTest.java b/community/shell/src/test/java/org/neo4j/shell/AbstractShellIT.java similarity index 93% rename from community/shell/src/test/java/org/neo4j/shell/AbstractShellTest.java rename to community/shell/src/test/java/org/neo4j/shell/AbstractShellIT.java index 51464f9ac41ce..a8b767dcdd1b1 100644 --- a/community/shell/src/test/java/org/neo4j/shell/AbstractShellTest.java +++ b/community/shell/src/test/java/org/neo4j/shell/AbstractShellIT.java @@ -52,7 +52,7 @@ import static org.neo4j.shell.ShellLobby.NO_INITIAL_SESSION; import static org.neo4j.shell.ShellLobby.remoteLocation; -public abstract class AbstractShellTest +public abstract class AbstractShellIT { protected GraphDatabaseAPI db; protected ShellServer shellServer; @@ -75,10 +75,10 @@ public void doBefore() throws Exception protected SameJvmClient newShellClient( ShellServer server ) throws ShellException, RemoteException { - return newShellClient( server, Collections.singletonMap( "quiet", true ) ); + return newShellClient( server, Collections.singletonMap( "quiet", true ) ); } - protected SameJvmClient newShellClient( ShellServer server, Map session ) + protected SameJvmClient newShellClient( ShellServer server, Map session ) throws ShellException, RemoteException { return new SameJvmClient( session, server, new CollectingOutput(), InterruptSignalHandler.getHandler() ); @@ -122,10 +122,10 @@ protected ShellClient newRemoteClient() throws Exception return newRemoteClient( NO_INITIAL_SESSION ); } - protected ShellClient newRemoteClient( Map initialSession ) throws Exception + protected ShellClient newRemoteClient( Map initialSession ) throws Exception { - return new RemoteClient( initialSession, remoteLocation( remotelyAvailableOnPort ), - new CollectingOutput(), InterruptSignalHandler.getHandler() ); + return new RemoteClient( initialSession, remoteLocation( remotelyAvailableOnPort ), new CollectingOutput(), + InterruptSignalHandler.getHandler() ); } protected void makeServerRemotelyAvailable() throws RemoteException @@ -187,8 +187,8 @@ public void executeCommand( String command, String... theseLinesMustExistRegEx ) executeCommand( shellClient, command, theseLinesMustExistRegEx ); } - public void executeCommand( ShellClient client, String command, - String... theseLinesMustExistRegEx ) throws Exception + public void executeCommand( ShellClient client, String command, String... theseLinesMustExistRegEx ) + throws Exception { CollectingOutput output = new CollectingOutput(); client.evaluate( command, output ); @@ -208,7 +208,7 @@ public void executeCommand( ShellClient client, String command, } } assertTrue( "Was expecting a line matching '" + lineThatMustExist + "', but didn't find any from out of " + - Iterables.asCollection( output ), found != negative ); + Iterables.asCollection( output ), found != negative ); } } @@ -225,7 +225,8 @@ public void executeCommandExpectingException( String command, String errorMessag String errorMessage = e.getMessage(); if ( !errorMessage.toLowerCase().contains( errorMessageShouldContain.toLowerCase() ) ) { - fail( "Error message '" + errorMessage + "' should have contained '" + errorMessageShouldContain + "'" ); + fail( "Error message '" + errorMessage + "' should have contained '" + errorMessageShouldContain + + "'" ); } } } @@ -290,7 +291,7 @@ protected Relationship[] createRelationshipChain( int length ) protected Relationship[] createRelationshipChain( RelationshipType type, int length ) { - try( Transaction transaction = db.beginTx() ) + try ( Transaction transaction = db.beginTx() ) { Relationship[] relationshipChain = createRelationshipChain( db.createNode(), type, length ); transaction.success(); @@ -298,8 +299,7 @@ protected Relationship[] createRelationshipChain( RelationshipType type, int len } } - protected Relationship[] createRelationshipChain( Node startingFromNode, RelationshipType type, - int length ) + protected Relationship[] createRelationshipChain( Node startingFromNode, RelationshipType type, int length ) { try ( Transaction tx = db.beginTx() ) { diff --git a/community/shell/src/test/java/org/neo4j/shell/TestApps.java b/community/shell/src/test/java/org/neo4j/shell/AppsIT.java similarity index 99% rename from community/shell/src/test/java/org/neo4j/shell/TestApps.java rename to community/shell/src/test/java/org/neo4j/shell/AppsIT.java index 4870145f620cb..7581743c9b4a5 100644 --- a/community/shell/src/test/java/org/neo4j/shell/TestApps.java +++ b/community/shell/src/test/java/org/neo4j/shell/AppsIT.java @@ -68,7 +68,7 @@ import static org.neo4j.graphdb.RelationshipType.withName; import static org.neo4j.helpers.collection.MapUtil.genericMap; -public class TestApps extends AbstractShellTest +public class AppsIT extends AbstractShellIT { @Rule public SuppressOutput suppressOutput = SuppressOutput.suppressAll(); diff --git a/community/shell/src/test/java/org/neo4j/shell/TestClientReconnect.java b/community/shell/src/test/java/org/neo4j/shell/ClientReconnectIT.java similarity index 88% rename from community/shell/src/test/java/org/neo4j/shell/TestClientReconnect.java rename to community/shell/src/test/java/org/neo4j/shell/ClientReconnectIT.java index 00cc9e02ddb66..14bd97bf7a181 100644 --- a/community/shell/src/test/java/org/neo4j/shell/TestClientReconnect.java +++ b/community/shell/src/test/java/org/neo4j/shell/ClientReconnectIT.java @@ -19,15 +19,16 @@ */ package org.neo4j.shell; +import org.junit.Test; + import java.io.Serializable; import java.util.Map; -import org.junit.Test; import org.neo4j.helpers.collection.MapUtil; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; -public class TestClientReconnect extends AbstractShellTest +public class ClientReconnectIT extends AbstractShellIT { @Test public void remoteClientAbleToReconnectAndContinue() throws Exception @@ -40,14 +41,13 @@ public void remoteClientAbleToReconnectAndContinue() throws Exception executeCommand( client, "help", "Available commands" ); client.shutdown(); } - + @Test public void initialSessionValuesSurvivesReconnect() throws Exception { createRelationshipChain( 2 ); makeServerRemotelyAvailable(); - Map initialSession = MapUtil.genericMap( - "TITLE_KEYS", "test" ); + Map initialSession = MapUtil.genericMap( "TITLE_KEYS", "test" ); ShellClient client = newRemoteClient( initialSession ); String name = "MyTest"; client.evaluate( "mknode --cd" ); diff --git a/community/shell/src/test/java/org/neo4j/shell/TestConfiguration.java b/community/shell/src/test/java/org/neo4j/shell/ConfigurationIT.java similarity index 98% rename from community/shell/src/test/java/org/neo4j/shell/TestConfiguration.java rename to community/shell/src/test/java/org/neo4j/shell/ConfigurationIT.java index 36574c08501f1..adfa88bc1fb99 100644 --- a/community/shell/src/test/java/org/neo4j/shell/TestConfiguration.java +++ b/community/shell/src/test/java/org/neo4j/shell/ConfigurationIT.java @@ -30,7 +30,7 @@ import static org.junit.Assert.assertTrue; -public class TestConfiguration +public class ConfigurationIT { private GraphDatabaseAPI db; private ShellServer server; diff --git a/community/shell/src/test/java/org/neo4j/shell/DontShutdownClient.java b/community/shell/src/test/java/org/neo4j/shell/DontShutdownClient.java index adef218b98e6d..b4d0c0e5a7ec9 100644 --- a/community/shell/src/test/java/org/neo4j/shell/DontShutdownClient.java +++ b/community/shell/src/test/java/org/neo4j/shell/DontShutdownClient.java @@ -26,7 +26,7 @@ import org.neo4j.shell.impl.SystemOutput; import org.neo4j.shell.kernel.GraphDatabaseShellServer; -import static org.neo4j.shell.TestRmiPublication.createDefaultConfigFile; +import static org.neo4j.shell.RmiPublicationIT.createDefaultConfigFile; public class DontShutdownClient { diff --git a/community/shell/src/test/java/org/neo4j/shell/DontShutdownLocalServer.java b/community/shell/src/test/java/org/neo4j/shell/DontShutdownLocalServer.java index 61f67e7bb4fa5..dd8090b41ef89 100644 --- a/community/shell/src/test/java/org/neo4j/shell/DontShutdownLocalServer.java +++ b/community/shell/src/test/java/org/neo4j/shell/DontShutdownLocalServer.java @@ -23,7 +23,7 @@ import org.neo4j.shell.kernel.GraphDatabaseShellServer; -import static org.neo4j.shell.TestRmiPublication.createDefaultConfigFile; +import static org.neo4j.shell.RmiPublicationIT.createDefaultConfigFile; public class DontShutdownLocalServer { diff --git a/community/shell/src/test/java/org/neo4j/shell/ErrorsAndWarningsTest.java b/community/shell/src/test/java/org/neo4j/shell/ErrorsAndWarningsIT.java similarity index 63% rename from community/shell/src/test/java/org/neo4j/shell/ErrorsAndWarningsTest.java rename to community/shell/src/test/java/org/neo4j/shell/ErrorsAndWarningsIT.java index cd4e0e831c2f0..0cfbf70778979 100644 --- a/community/shell/src/test/java/org/neo4j/shell/ErrorsAndWarningsTest.java +++ b/community/shell/src/test/java/org/neo4j/shell/ErrorsAndWarningsIT.java @@ -19,7 +19,7 @@ */ package org.neo4j.shell; -import org.junit.Rule; +import org.junit.Before; import org.junit.Test; import java.io.ByteArrayInputStream; @@ -28,58 +28,21 @@ import java.io.InputStream; import java.io.PrintStream; -import org.neo4j.graphdb.factory.GraphDatabaseBuilder; -import org.neo4j.graphdb.factory.GraphDatabaseSettings; -import org.neo4j.kernel.configuration.Settings; -import org.neo4j.kernel.internal.GraphDatabaseAPI; -import org.neo4j.test.ImpermanentDatabaseRule; - import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertThat; -public class ErrorsAndWarningsTest +public class ErrorsAndWarningsIT extends AbstractShellIT { - @Rule - public ImpermanentDatabaseRule db = null; - - public void startDatabase( final Boolean presentError ) + @Before + public void setup() throws Exception { - db = new ImpermanentDatabaseRule() - { - @Override - protected void configure( GraphDatabaseBuilder builder ) - { - builder.setConfig( ShellSettings.remote_shell_enabled, Settings.TRUE ); - builder.setConfig( GraphDatabaseSettings.cypher_hints_error, presentError.toString() ); - } - - @Override - public GraphDatabaseAPI getGraphDatabaseAPI() - { - try - { - before(); - } - catch ( Throwable throwable ) - { - throwable.printStackTrace(); - } - return super.getGraphDatabaseAPI(); - } - }; - - db.getGraphDatabaseAPI(); + makeServerRemotelyAvailable(); } @Test public void unsupportedQueryShouldBeSilent() throws IOException { - // Given - // an empty database - - startDatabase( false ); - // When InputStream realStdin = System.in; try diff --git a/community/shell/src/test/java/org/neo4j/shell/TestReadOnlyServer.java b/community/shell/src/test/java/org/neo4j/shell/ReadOnlyServerIT.java similarity index 97% rename from community/shell/src/test/java/org/neo4j/shell/TestReadOnlyServer.java rename to community/shell/src/test/java/org/neo4j/shell/ReadOnlyServerIT.java index 2769591834510..0dbb53de17b95 100644 --- a/community/shell/src/test/java/org/neo4j/shell/TestReadOnlyServer.java +++ b/community/shell/src/test/java/org/neo4j/shell/ReadOnlyServerIT.java @@ -29,7 +29,7 @@ import org.neo4j.shell.kernel.GraphDatabaseShellServer; import org.neo4j.shell.kernel.ReadOnlyGraphDatabaseProxy; -public class TestReadOnlyServer extends AbstractShellTest +public class ReadOnlyServerIT extends AbstractShellIT { @Override protected ShellServer newServer( GraphDatabaseAPI db ) throws ShellException, RemoteException diff --git a/community/shell/src/test/java/org/neo4j/shell/TestRmiPublication.java b/community/shell/src/test/java/org/neo4j/shell/RmiPublicationIT.java similarity index 90% rename from community/shell/src/test/java/org/neo4j/shell/TestRmiPublication.java rename to community/shell/src/test/java/org/neo4j/shell/RmiPublicationIT.java index 8c40d3e424f40..981d62ad66427 100644 --- a/community/shell/src/test/java/org/neo4j/shell/TestRmiPublication.java +++ b/community/shell/src/test/java/org/neo4j/shell/RmiPublicationIT.java @@ -37,7 +37,7 @@ import static java.lang.System.getProperty; import static org.junit.Assert.assertEquals; -public class TestRmiPublication +public class RmiPublicationIT { public static File createDefaultConfigFile( File path ) throws IOException { @@ -69,15 +69,16 @@ public void jvmShouldDieEvenIfLocalServerIsLeftHanging() throws Exception private int spawnJvm( Class mainClass, String name ) throws Exception { String dir = testDirectory.directory( name ).getAbsolutePath(); - return waitForExit( getRuntime().exec( new String[] { "java", "-cp", getProperty( "java.class.path" ), - "-Djava.awt.headless=true", mainClass.getName(), dir } ), 20 ); + return waitForExit( getRuntime() + .exec( new String[]{"java", "-cp", getProperty( "java.class.path" ), "-Djava.awt.headless=true", + mainClass.getName(), dir} ), 20 ); } private int waitForExit( Process process, int maxSeconds ) throws InterruptedException { try { - long endTime = System.currentTimeMillis() + maxSeconds*1000; + long endTime = System.currentTimeMillis() + maxSeconds * 1000; ProcessStreamHandler streamHandler = new ProcessStreamHandler( process, false ); streamHandler.launch(); try @@ -94,7 +95,7 @@ private int waitForExit( Process process, int maxSeconds ) throws InterruptedExc } } - tempHackToGetThreadDump(process); + tempHackToGetThreadDump( process ); throw new RuntimeException( "Process didn't exit on its own." ); } @@ -115,12 +116,12 @@ private void tempHackToGetThreadDump( Process process ) { Field pidField = process.getClass().getDeclaredField( "pid" ); pidField.setAccessible( true ); - int pid = (int)pidField.get( process ); + int pid = (int) pidField.get( process ); ProcessBuilder processBuilder = new ProcessBuilder( "/bin/sh", "-c", "kill -3 " + pid ); processBuilder.redirectErrorStream( true ); Process dumpProc = processBuilder.start(); - ProcessStreamHandler streamHandler = new ProcessStreamHandler(dumpProc, false); + ProcessStreamHandler streamHandler = new ProcessStreamHandler( dumpProc, false ); streamHandler.launch(); try { @@ -131,7 +132,7 @@ private void tempHackToGetThreadDump( Process process ) streamHandler.cancel(); } } - catch( Throwable e ) + catch ( Throwable e ) { e.printStackTrace(); } diff --git a/community/shell/src/test/java/org/neo4j/shell/ServerClientInteractionTest.java b/community/shell/src/test/java/org/neo4j/shell/ServerClientInteractionIT.java similarity index 57% rename from community/shell/src/test/java/org/neo4j/shell/ServerClientInteractionTest.java rename to community/shell/src/test/java/org/neo4j/shell/ServerClientInteractionIT.java index 61920ea1fafee..fab3230c94daa 100644 --- a/community/shell/src/test/java/org/neo4j/shell/ServerClientInteractionTest.java +++ b/community/shell/src/test/java/org/neo4j/shell/ServerClientInteractionIT.java @@ -19,36 +19,31 @@ */ package org.neo4j.shell; -import java.io.Serializable; - -import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.neo4j.helpers.collection.MapUtil; -import org.neo4j.kernel.internal.GraphDatabaseAPI; -import org.neo4j.shell.impl.SameJvmClient; -import org.neo4j.shell.impl.SimpleAppServer; -import org.neo4j.shell.kernel.GraphDatabaseShellServer; -import org.neo4j.test.ImpermanentGraphDatabase; import static java.util.regex.Pattern.compile; - import static org.junit.Assert.assertTrue; import static org.neo4j.shell.Variables.PROMPT_KEY; -public class ServerClientInteractionTest +public class ServerClientInteractionIT extends AbstractShellIT { + private SilentLocalOutput out = new SilentLocalOutput(); - private GraphDatabaseAPI db; + @Before + public void setup() throws Exception + { + makeServerRemotelyAvailable(); + } @Test public void shouldConsiderAndInterpretCustomClientPrompt() throws Exception { // GIVEN - client.setSessionVariable( PROMPT_KEY, "MyPrompt \\d \\t$ " ); + shellClient.setSessionVariable( PROMPT_KEY, "MyPrompt \\d \\t$ " ); // WHEN - Response response = server.interpretLine( client.getId(), "", out ); + Response response = shellServer.interpretLine( shellClient.getId(), "", out ); // THEN String regexPattern = "MyPrompt .{1,3} .{1,3} \\d{1,2} \\d{2}:\\d{2}:\\d{2}\\$"; @@ -56,23 +51,4 @@ public void shouldConsiderAndInterpretCustomClientPrompt() throws Exception compile( regexPattern ).matcher( response.getPrompt() ).find() ); } - private SimpleAppServer server; - private ShellClient client; - private SilentLocalOutput out; - - @Before - public void before() throws Exception - { - db = new ImpermanentGraphDatabase( ); - server = new GraphDatabaseShellServer( db ); - out = new SilentLocalOutput(); - client = new SameJvmClient( MapUtil.genericMap(), server, out, InterruptSignalHandler.getHandler() ); - } - - @After - public void after() throws Exception - { - server.shutdown(); - db.shutdown(); - } } diff --git a/community/shell/src/test/java/org/neo4j/shell/StartClientTest.java b/community/shell/src/test/java/org/neo4j/shell/StartClientIT.java similarity index 73% rename from community/shell/src/test/java/org/neo4j/shell/StartClientTest.java rename to community/shell/src/test/java/org/neo4j/shell/StartClientIT.java index d49c580b7774a..57ab13144ae27 100644 --- a/community/shell/src/test/java/org/neo4j/shell/StartClientTest.java +++ b/community/shell/src/test/java/org/neo4j/shell/StartClientIT.java @@ -35,12 +35,9 @@ import org.neo4j.bolt.v1.runtime.Sessions; import org.neo4j.graphdb.Transaction; -import org.neo4j.graphdb.factory.GraphDatabaseBuilder; -import org.neo4j.kernel.configuration.Settings; import org.neo4j.logging.AssertableLogProvider; import org.neo4j.shell.impl.AbstractClient; import org.neo4j.shell.kernel.GraphDatabaseShellServer; -import org.neo4j.test.ImpermanentDatabaseRule; import org.neo4j.test.SuppressOutput; import org.neo4j.test.TestGraphDatabaseFactory; @@ -58,25 +55,15 @@ import static org.neo4j.logging.AssertableLogProvider.inLog; import static org.neo4j.test.SuppressOutput.suppressAll; -public class StartClientTest +public class StartClientIT extends AbstractShellIT { @Rule public SuppressOutput mute = suppressAll(); - @Rule - public ImpermanentDatabaseRule db = new ImpermanentDatabaseRule() - { - @Override - protected void configure( GraphDatabaseBuilder builder ) - { - builder.setConfig( ShellSettings.remote_shell_enabled, Settings.TRUE ); - } - }; - @Before - public void startDatabase() + public void startDatabase() throws Exception { - db.getGraphDatabaseAPI(); + makeServerRemotelyAvailable(); } @Test @@ -86,13 +73,12 @@ public void givenShellClientWhenOpenFileThenExecuteFileCommands() // an empty database // When - StartClient.main(new String[]{"-file", getClass().getResource( "/testshell.txt" ).getFile()}); + StartClient.main( new String[]{"-file", getClass().getResource( "/testshell.txt" ).getFile()} ); // Then - try ( Transaction tx = db.getGraphDatabaseAPI().beginTx() ) + try ( Transaction tx = db.beginTx() ) { - assertThat( (String) db.getGraphDatabaseAPI().getNodeById( 0 ).getProperty( "foo" ), - equalTo( "bar" ) ); + assertThat( db.getNodeById( 0 ).getProperty( "foo" ), equalTo( "bar" ) ); tx.success(); } } @@ -108,7 +94,7 @@ public void givenShellClientWhenReadFromStdinThenExecutePipedCommands() throws I try { System.setIn( new ByteArrayInputStream( "CREATE (n {foo:'bar'});".getBytes() ) ); - StartClient.main( new String[] { "-file", "-" } ); + StartClient.main( new String[]{"-file", "-"} ); } finally { @@ -116,10 +102,9 @@ public void givenShellClientWhenReadFromStdinThenExecutePipedCommands() throws I } // Then - try ( Transaction tx = db.getGraphDatabaseAPI().beginTx() ) + try ( Transaction tx = db.beginTx() ) { - assertThat( (String) db.getGraphDatabaseAPI().getNodeById( 0 ).getProperty( "foo" ), - equalTo( "bar" ) ); + assertThat( db.getNodeById( 0 ).getProperty( "foo" ), equalTo( "bar" ) ); tx.success(); } } @@ -131,7 +116,7 @@ public void mustWarnWhenRunningScriptWithUnterminatedMultilineCommands() String script = getClass().getResource( "/unterminated-cypher-query.txt" ).getFile(); // When running the script with -file - String output = runAndCaptureOutput( new String[]{ "-file", script } ); + String output = runAndCaptureOutput( new String[]{"-file", script} ); // Then we should get a warning assertThat( output, containsString( AbstractClient.WARN_UNTERMINATED_INPUT ) ); @@ -144,7 +129,7 @@ public void mustNotAboutExitingWithUnterminatedCommandWhenItIsNothingButComments String script = getClass().getResource( "/unterminated-comment.txt" ).getFile(); // When running the script with -file - String output = runAndCaptureOutput( new String[]{ "-file", script } ); + String output = runAndCaptureOutput( new String[]{"-file", script} ); // Then we should get a warning assertThat( output, not( containsString( AbstractClient.WARN_UNTERMINATED_INPUT ) ) ); @@ -164,15 +149,15 @@ public void testShellCloseAfterCommandExecution() throws Exception StartClient startClient = new StartClient( out, err ) { @Override - protected GraphDatabaseShellServer getGraphDatabaseShellServer( File path, boolean readOnly, String configFile ) throws RemoteException + protected GraphDatabaseShellServer getGraphDatabaseShellServer( File path, boolean readOnly, + String configFile ) throws RemoteException { return databaseShellServer; } }; // when - startClient.start( new String[]{"-path", db.getGraphDatabaseAPI().getStoreDir(), - "-c", "CREATE (n {foo:'bar'});"}, ctrlCHandler ); + startClient.start( new String[]{"-path", db.getStoreDir(), "-c", "CREATE (n {foo:'bar'});"}, ctrlCHandler ); // verify verify( databaseShellServer ).shutdown(); @@ -185,12 +170,11 @@ public void shouldReportEditionThroughDbInfoApp() throws Exception ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); CtrlCHandler ctrlCHandler = mock( CtrlCHandler.class ); - StartClient client = new StartClient( - new PrintStream( out ), new PrintStream( err ) ); + StartClient client = new StartClient( new PrintStream( out ), new PrintStream( err ) ); // when - client.start( new String[]{"-path", db.getGraphDatabaseAPI().getStoreDir(), - "-c", "dbinfo -g Configuration unsupported.dbms.edition"}, ctrlCHandler ); + client.start( new String[]{"-path", db.getStoreDir(), "-c", "dbinfo -g Configuration unsupported.dbms.edition"}, + ctrlCHandler ); // then assertEquals( 0, err.size() ); @@ -204,8 +188,7 @@ public void shouldPrintVersionAndExit() throws Exception ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); CtrlCHandler ctrlCHandler = mock( CtrlCHandler.class ); - StartClient client = new StartClient( - new PrintStream( out ), new PrintStream( err ) ); + StartClient client = new StartClient( new PrintStream( out ), new PrintStream( err ) ); // when client.start( new String[]{"-version"}, ctrlCHandler ); @@ -226,17 +209,14 @@ public void shouldNotStartBolt() throws IOException new StartClient( System.out, System.err ) { @Override - protected GraphDatabaseShellServer getGraphDatabaseShellServer( File path, boolean readOnly, String - configFile ) throws RemoteException + protected GraphDatabaseShellServer getGraphDatabaseShellServer( File path, boolean readOnly, + String configFile ) throws RemoteException { - return new GraphDatabaseShellServer( - new TestGraphDatabaseFactory().setUserLogProvider( log ), path, readOnly, configFile ); + return new GraphDatabaseShellServer( new TestGraphDatabaseFactory().setUserLogProvider( log ), path, + readOnly, configFile ); } - }.start( new String[]{ - "-c", "RETURN 1;", - "-path", db.getGraphDatabaseAPI().getStoreDir(), - "-config", getClass().getResource( "/config-with-bolt-connector.conf" ).getFile()}, - mock( CtrlCHandler.class ) ); + }.start( new String[]{"-c", "RETURN 1;", "-path", db.getStoreDir(), "-config", + getClass().getResource( "/config-with-bolt-connector.conf" ).getFile()}, mock( CtrlCHandler.class ) ); // Then log.assertNone( inLog( startsWith( Sessions.class.getPackage().getName() ) ).any() ); diff --git a/community/shell/src/test/java/org/neo4j/shell/impl/AbstractClientTest.java b/community/shell/src/test/java/org/neo4j/shell/impl/ClientIT.java similarity index 99% rename from community/shell/src/test/java/org/neo4j/shell/impl/AbstractClientTest.java rename to community/shell/src/test/java/org/neo4j/shell/impl/ClientIT.java index 14168e608b84f..e0f0d77ecf879 100644 --- a/community/shell/src/test/java/org/neo4j/shell/impl/AbstractClientTest.java +++ b/community/shell/src/test/java/org/neo4j/shell/impl/ClientIT.java @@ -37,9 +37,8 @@ import static org.hamcrest.Matchers.contains; import static org.junit.Assert.assertThat; -public class AbstractClientTest +public class ClientIT { - @Test public void shouldHandleNormalInput() throws ShellException, RemoteException { @@ -152,4 +151,4 @@ public Output getOutput() assertThat( messages, contains( message ) ); assertThat( client.getPrompt(), equalTo( prompt ) ); } -} \ No newline at end of file +} diff --git a/enterprise/kernel/src/test/java/org/neo4j/shell/TestPECListing.java b/enterprise/kernel/src/test/java/org/neo4j/shell/PECListingIT.java similarity index 99% rename from enterprise/kernel/src/test/java/org/neo4j/shell/TestPECListing.java rename to enterprise/kernel/src/test/java/org/neo4j/shell/PECListingIT.java index ec89e0eb7d4f4..8d22b796a10b9 100644 --- a/enterprise/kernel/src/test/java/org/neo4j/shell/TestPECListing.java +++ b/enterprise/kernel/src/test/java/org/neo4j/shell/PECListingIT.java @@ -29,7 +29,7 @@ import static org.neo4j.graphdb.Label.label; -public class TestPECListing extends AbstractShellTest +public class PECListingIT extends AbstractShellIT { @Override protected GraphDatabaseAPI newDb()