Skip to content

Commit

Permalink
Merge pull request #9724 from MishaDemianenko/3.3-reconnect-same-port
Browse files Browse the repository at this point in the history
Export remote shell server on the same port as before restart for reconnect
  • Loading branch information
MishaDemianenko committed Jul 27, 2017
2 parents 921a1e1 + 32efefc commit f9f24f4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public abstract class AbstractShellIT
protected GraphDatabaseAPI db;
protected ShellServer shellServer;
protected ShellClient shellClient;
private Integer remotelyAvailableOnPort;
protected Integer remotelyAvailableOnPort;
protected static final RelationshipType RELATIONSHIP_TYPE = withName( "TYPE" );

@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,35 @@
*/
package org.neo4j.shell;

import org.junit.Before;
import org.junit.Test;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.shell.impl.SimpleAppServer;

import static org.junit.Assert.assertTrue;

public class ClientReconnectIT extends AbstractShellIT
{
@Before
public void setUp() throws RemoteException
{
makeServerRemotelyAvailable();
}

@Test
public void remoteClientAbleToReconnectAndContinue() throws Exception
{
makeServerRemotelyAvailable();
ShellClient client = newRemoteClient();
executeCommand( client, "help", "Available commands" );
int serverPort = this.remotelyAvailableOnPort;
restartServer();
makeServerRemotelyAvailable();
makeRemoveAvailableOnPort( serverPort );
executeCommand( client, "help", "Available commands" );
client.shutdown();
}
Expand All @@ -46,7 +56,6 @@ public void remoteClientAbleToReconnectAndContinue() throws Exception
public void initialSessionValuesSurvivesReconnect() throws Exception
{
createRelationshipChain( 2 );
makeServerRemotelyAvailable();
Map<String,Serializable> initialSession = MapUtil.genericMap( "TITLE_KEYS", "test" );
ShellClient client = newRemoteClient( initialSession );
String name = "MyTest";
Expand All @@ -55,4 +64,23 @@ public void initialSessionValuesSurvivesReconnect() throws Exception
assertTrue( client.getPrompt().contains( name ) );
client.shutdown();
}

private void makeRemoveAvailableOnPort( int serverPort ) throws RemoteException
{
long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis( 30 );
do
{
try
{
shellServer.makeRemotelyAvailable( serverPort, SimpleAppServer.DEFAULT_NAME );
return;
}
catch ( Throwable t )
{
//ignore
}
}
while ( System.currentTimeMillis() < deadline );
throw new RuntimeException( "Not able to start shell server on desired port for more then 30 seconds." );
}
}

0 comments on commit f9f24f4

Please sign in to comment.