Skip to content

Commit

Permalink
stick PortAuthority in it's own Maven module so it can be reused
Browse files Browse the repository at this point in the history
  • Loading branch information
lassewesth committed Jul 25, 2017
1 parent 76ea04c commit c22fbe9
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 32 deletions.
7 changes: 7 additions & 0 deletions enterprise/causal-clustering/pom.xml
Expand Up @@ -202,6 +202,13 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>


<dependency>
<groupId>org.neo4j.build</groupId>
<artifactId>port-authority</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -46,6 +46,7 @@
<module>stresstests</module> <module>stresstests</module>
<module>tools</module> <module>tools</module>
<module>packaging</module> <module>packaging</module>
<module>portauthority</module>
</modules> </modules>


<build> <build>
Expand Down
4 changes: 4 additions & 0 deletions portauthority/LICENSES.txt
@@ -0,0 +1,4 @@
This file contains the full license text of the included third party
libraries. For an overview of the licenses see the NOTICE.txt file.


26 changes: 26 additions & 0 deletions portauthority/NOTICE.txt
@@ -0,0 +1,26 @@
Neo4j
Copyright © 2002-2017 Network Engine for Objects in Lund AB (referred to
in this notice as "Neo Technology")
[http://neotechnology.com]

This product includes software ("Software") developed by Neo Technology.

The software ("Software") is developed and owned by Network Engine
for Objects in Lund AB (referred to in this notice as "Neo Technology").
If you have executed an End User Software License and Services Agreement,
an OEM Software License and Support Services Agreement, or another
commercial license agreement (including an Evaluation Agreement) with
Neo Technology or one of its affiliates (each, a "Commercial Agreement"),
you may use the Software solely pursuant to the terms of the relevant
Commercial Agreement.

If you have not executed a Commercial Agreement with Neo Technology, the
Software is subject to the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
Version 3 (http://www.fsf.org/licensing/licenses/agpl-3.0.html), included
in the LICENSE.txt file.

Full license texts are found in LICENSES.txt.

Third-party licenses
--------------------

47 changes: 47 additions & 0 deletions portauthority/pom.xml
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parent</artifactId>
<groupId>org.neo4j</groupId>
<version>3.3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>org.neo4j.build</groupId>
<artifactId>port-authority</artifactId>

<licenses>
<license>
<name>GNU General Public License, Version 3</name>
<url>http://www.gnu.org/licenses/gpl-3.0-standalone.html</url>
<comments>The software ("Software") developed and owned by Network Engine for
Objects in Lund AB (referred to in this notice as "Neo Technology") is
licensed under the GNU GENERAL PUBLIC LICENSE Version 3 to all third
parties and that license is included below.

However, if you have executed an End User Software License and Services
Agreement or an OEM Software License and Support Services Agreement, or
another commercial license agreement with Neo Technology or one of its
affiliates (each, a "Commercial Agreement"), the terms of the license in
such Commercial Agreement will supersede the GNU GENERAL PUBLIC LICENSE
Version 3 and you may use the Software solely pursuant to the terms of
the relevant Commercial Agreement.
</comments>
</license>
</licenses>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.neo4j.causalclustering; package org.neo4j.build.portauthority;


/** /**
* Port provider that relies on state on disk, so that it can coordinate with other {@link CoordinatingPortProvider}s in * Port provider that relies on state on disk, so that it can coordinate with other {@link CoordinatingPortProvider}s in
Expand Down
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.neo4j.causalclustering; package org.neo4j.build.portauthority;


import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
Expand Down
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.neo4j.causalclustering; package org.neo4j.build.portauthority;


import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
Expand Down
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.neo4j.causalclustering; package org.neo4j.build.portauthority;


public class PortConstants public class PortConstants
{ {
Expand Down
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.neo4j.causalclustering; package org.neo4j.build.portauthority;


public interface PortProbe public interface PortProbe
{ {
Expand Down
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.neo4j.causalclustering; package org.neo4j.build.portauthority;


public interface PortProvider public interface PortProvider
{ {
Expand Down
Expand Up @@ -17,9 +17,9 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.neo4j.causalclustering; package org.neo4j.build.portauthority;


import static org.neo4j.causalclustering.PortConstants.EphemeralPortMaximum; import static org.neo4j.build.portauthority.PortConstants.EphemeralPortMaximum;


import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
Expand Down
Expand Up @@ -17,9 +17,9 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.neo4j.causalclustering; package org.neo4j.build.portauthority;


import static org.neo4j.causalclustering.PortConstants.EphemeralPortMaximum; import static org.neo4j.build.portauthority.PortConstants.EphemeralPortMaximum;


/** /**
* Port provider that relies on state in a single JVM. Not suitable for parallel test execution (as in, several JVM * Port provider that relies on state in a single JVM. Not suitable for parallel test execution (as in, several JVM
Expand Down
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.neo4j.causalclustering; package org.neo4j.build.portauthority;


import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
Expand Down
Expand Up @@ -17,45 +17,50 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.neo4j.causalclustering; package org.neo4j.build.portauthority;


import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.neo4j.causalclustering.PortConstants.EphemeralPortMinimum; import static org.neo4j.build.portauthority.PortConstants.EphemeralPortMinimum;
import static org.neo4j.helpers.collection.Iterators.asSet;


import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;


import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.neo4j.test.rule.TestDirectory; import org.junit.rules.TemporaryFolder;


public class PortRepositoryIT public class PortRepositoryIT
{ {
@Rule @Rule
public TestDirectory testDirectory = TestDirectory.testDirectory(); public TemporaryFolder temporaryFolder = new TemporaryFolder();


@Test @Test
public void shouldReservePorts() throws Exception public void shouldReservePorts() throws Exception
{ {
Path directory = testDirectory.cleanDirectory( "port-repository" ).toPath(); PortRepository portRepository1 = new PortRepository( temporaryDirectory(), EphemeralPortMinimum );
PortRepository portRepository1 = new PortRepository( directory, EphemeralPortMinimum );


int port1 = portRepository1.reserveNextPort( "foo" ); int port1 = portRepository1.reserveNextPort( "foo" );
int port2 = portRepository1.reserveNextPort( "foo" ); int port2 = portRepository1.reserveNextPort( "foo" );
int port3 = portRepository1.reserveNextPort( "foo" ); int port3 = portRepository1.reserveNextPort( "foo" );


assertThat( asSet( port1, port2, port3 ).size(), is( 3 ) ); assertThat( new HashSet<>( asList( port1, port2, port3) ).size(), is( 3 ) );
} }


@Test @Test
public void shouldCoordinateUsingFileSystem() throws Exception public void shouldCoordinateUsingFileSystem() throws Exception
{ {
Path directory = testDirectory.cleanDirectory( "port-repository" ).toPath(); Path temporaryDirectory = temporaryDirectory();
PortRepository portRepository1 = new PortRepository( directory, EphemeralPortMinimum ); PortRepository portRepository1 = new PortRepository( temporaryDirectory, EphemeralPortMinimum );
PortRepository portRepository2 = new PortRepository( directory, EphemeralPortMinimum ); PortRepository portRepository2 = new PortRepository( temporaryDirectory, EphemeralPortMinimum );


int port1 = portRepository1.reserveNextPort( "foo" ); int port1 = portRepository1.reserveNextPort( "foo" );
int port2 = portRepository1.reserveNextPort( "foo" ); int port2 = portRepository1.reserveNextPort( "foo" );
Expand All @@ -64,18 +69,15 @@ public void shouldCoordinateUsingFileSystem() throws Exception
int port5 = portRepository2.reserveNextPort( "foo" ); int port5 = portRepository2.reserveNextPort( "foo" );
int port6 = portRepository1.reserveNextPort( "foo" ); int port6 = portRepository1.reserveNextPort( "foo" );


assertThat( asSet( port1, port2, port3, port4, port5, port6 ).size(), is( 6 ) ); assertThat( new HashSet<>( asList( port1, port2, port3, port4, port5, port6 ) ).size(), is( 6 ) );
} }


@Test @Test
@Ignore @Ignore
public void shouldNotInterfereWithOtherRepositories() throws Exception public void shouldNotInterfereWithOtherRepositories() throws Exception
{ {
Path directory1 = testDirectory.cleanDirectory( "port-repository-1" ).toPath(); PortRepository portRepository1 = new PortRepository( temporaryDirectory(), EphemeralPortMinimum );
Path directory2 = testDirectory.cleanDirectory( "port-repository-2" ).toPath(); PortRepository portRepository2 = new PortRepository( temporaryDirectory(), EphemeralPortMinimum );

PortRepository portRepository1 = new PortRepository( directory1, EphemeralPortMinimum );
PortRepository portRepository2 = new PortRepository( directory2, EphemeralPortMinimum );


int port1 = portRepository1.reserveNextPort( "foo" ); int port1 = portRepository1.reserveNextPort( "foo" );
int port2 = portRepository1.reserveNextPort( "foo" ); int port2 = portRepository1.reserveNextPort( "foo" );
Expand All @@ -84,14 +86,13 @@ public void shouldNotInterfereWithOtherRepositories() throws Exception
int port5 = portRepository2.reserveNextPort( "foo" ); int port5 = portRepository2.reserveNextPort( "foo" );
int port6 = portRepository1.reserveNextPort( "foo" ); int port6 = portRepository1.reserveNextPort( "foo" );


assertThat( asSet( port1, port2, port3, port4, port5, port6 ).size(), is( 4 ) ); assertThat( new HashSet<>( asList( port1, port2, port3, port4, port5, port6 ) ).size(), is( 4 ) );
} }


@Test @Test
public void shouldNotOverrun() throws Exception public void shouldNotOverrun() throws Exception
{ {
Path directory = testDirectory.cleanDirectory( "port-repository" ).toPath(); PortRepository portRepository1 = new PortRepository( temporaryDirectory(), 65534 );
PortRepository portRepository1 = new PortRepository( directory, 65534 );


portRepository1.reserveNextPort( "foo" ); portRepository1.reserveNextPort( "foo" );
portRepository1.reserveNextPort( "foo" ); portRepository1.reserveNextPort( "foo" );
Expand All @@ -107,4 +108,9 @@ public void shouldNotOverrun() throws Exception
assertThat( e.getMessage(), is( "There are no more ports available" ) ); assertThat( e.getMessage(), is( "There are no more ports available" ) );
} }
} }

private Path temporaryDirectory() throws IOException
{
return temporaryFolder.newFolder("port-repository").toPath();
}
} }
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.neo4j.causalclustering; package org.neo4j.build.portauthority;


import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
Expand Down

0 comments on commit c22fbe9

Please sign in to comment.