Skip to content

Commit

Permalink
Backport NeoServerPortConflictIT flaky test fixes to 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Nov 7, 2018
1 parent 7efda73 commit fa9fa29
Showing 1 changed file with 8 additions and 13 deletions.
Expand Up @@ -27,7 +27,6 @@


import org.neo4j.helpers.ListenSocketAddress; import org.neo4j.helpers.ListenSocketAddress;
import org.neo4j.logging.AssertableLogProvider; import org.neo4j.logging.AssertableLogProvider;
import org.neo4j.ports.allocation.PortAuthority;
import org.neo4j.server.helpers.CommunityServerBuilder; import org.neo4j.server.helpers.CommunityServerBuilder;
import org.neo4j.test.server.ExclusiveServerTestBase; import org.neo4j.test.server.ExclusiveServerTestBase;


Expand All @@ -38,14 +37,13 @@


public class NeoServerPortConflictIT extends ExclusiveServerTestBase public class NeoServerPortConflictIT extends ExclusiveServerTestBase
{ {

@Test @Test
public void shouldComplainIfServerPortIsAlreadyTaken() throws IOException public void shouldComplainIfServerPortIsAlreadyTaken() throws IOException
{ {
int serverPort = PortAuthority.allocatePort(); try ( ServerSocket socket = new ServerSocket( 0, 0, InetAddress.getLocalHost() ) )
ListenSocketAddress contestedAddress = new ListenSocketAddress( "localhost", serverPort );
try ( ServerSocket ignored = new ServerSocket(
contestedAddress.getPort(), 0, InetAddress.getByName( contestedAddress.getHostname() ) ) )
{ {
ListenSocketAddress contestedAddress = new ListenSocketAddress( socket.getInetAddress().getHostName(), socket.getLocalPort() );
AssertableLogProvider logProvider = new AssertableLogProvider(); AssertableLogProvider logProvider = new AssertableLogProvider();
CommunityNeoServer server = CommunityServerBuilder.server( logProvider ) CommunityNeoServer server = CommunityServerBuilder.server( logProvider )
.onAddress( contestedAddress ) .onAddress( contestedAddress )
Expand Down Expand Up @@ -76,17 +74,14 @@ public void shouldComplainIfServerPortIsAlreadyTaken() throws IOException
@Test @Test
public void shouldComplainIfServerHTTPSPortIsAlreadyTaken() throws IOException public void shouldComplainIfServerHTTPSPortIsAlreadyTaken() throws IOException
{ {
int serverPort = PortAuthority.allocatePort(); try ( ServerSocket httpsSocket = new ServerSocket( 0, 0, InetAddress.getLocalHost() ) )
int httpsPort = PortAuthority.allocatePort();
ListenSocketAddress unContestedAddress = new ListenSocketAddress( "localhost", serverPort );
ListenSocketAddress contestedAddress = new ListenSocketAddress( "localhost", httpsPort );
try ( ServerSocket ignored = new ServerSocket(
contestedAddress.getPort(), 0, InetAddress.getByName( contestedAddress.getHostname() ) ) )
{ {
ListenSocketAddress unContestedAddress = new ListenSocketAddress( httpsSocket.getInetAddress().getHostName(), 0 );
ListenSocketAddress httpsAddress = new ListenSocketAddress( httpsSocket.getInetAddress().getHostName(), httpsSocket.getLocalPort() );
AssertableLogProvider logProvider = new AssertableLogProvider(); AssertableLogProvider logProvider = new AssertableLogProvider();
CommunityNeoServer server = CommunityServerBuilder.server( logProvider ) CommunityNeoServer server = CommunityServerBuilder.server( logProvider )
.onAddress( unContestedAddress ) .onAddress( unContestedAddress )
.onHttpsAddress( contestedAddress ) .onHttpsAddress( httpsAddress )
.withHttpsEnabled() .withHttpsEnabled()
.usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() ) .usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() )
.build(); .build();
Expand All @@ -106,7 +101,7 @@ public void shouldComplainIfServerHTTPSPortIsAlreadyTaken() throws IOException
"Failed to start Neo4j on %s: %s", "Failed to start Neo4j on %s: %s",
unContestedAddress, unContestedAddress,
format( "At least one of the addresses %s or %s is already in use, cannot bind to it.", format( "At least one of the addresses %s or %s is already in use, cannot bind to it.",
unContestedAddress, contestedAddress ) unContestedAddress, httpsAddress )
) )
); );
server.stop(); server.stop();
Expand Down

0 comments on commit fa9fa29

Please sign in to comment.