From c22fbe93146aba3c42e63349790cff8e75d28e85 Mon Sep 17 00:00:00 2001 From: Lasse Westh-Nielsen Date: Wed, 5 Jul 2017 14:56:07 +0200 Subject: [PATCH] stick PortAuthority in it's own Maven module so it can be reused --- enterprise/causal-clustering/pom.xml | 7 +++ pom.xml | 1 + portauthority/LICENSES.txt | 4 ++ portauthority/NOTICE.txt | 26 ++++++++++ portauthority/pom.xml | 47 +++++++++++++++++++ .../CoordinatingPortProvider.java | 2 +- .../portauthority}/DefaultPortProbe.java | 2 +- .../build/portauthority}/PortAuthority.java | 2 +- .../build/portauthority}/PortConstants.java | 2 +- .../neo4j/build/portauthority}/PortProbe.java | 2 +- .../build/portauthority}/PortProvider.java | 2 +- .../build/portauthority}/PortRepository.java | 4 +- .../portauthority}/SimplePortProvider.java | 4 +- .../CoordinatingPortProviderTest.java | 2 +- .../portauthority}/PortRepositoryIT.java | 46 ++++++++++-------- .../SimplePortProviderTest.java | 2 +- 16 files changed, 123 insertions(+), 32 deletions(-) create mode 100644 portauthority/LICENSES.txt create mode 100644 portauthority/NOTICE.txt create mode 100644 portauthority/pom.xml rename {enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering => portauthority/src/main/java/org/neo4j/build/portauthority}/CoordinatingPortProvider.java (97%) rename {enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering => portauthority/src/main/java/org/neo4j/build/portauthority}/DefaultPortProbe.java (96%) rename {enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering => portauthority/src/main/java/org/neo4j/build/portauthority}/PortAuthority.java (98%) rename {enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering => portauthority/src/main/java/org/neo4j/build/portauthority}/PortConstants.java (96%) rename {enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering => portauthority/src/main/java/org/neo4j/build/portauthority}/PortProbe.java (95%) rename {enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering => portauthority/src/main/java/org/neo4j/build/portauthority}/PortProvider.java (95%) rename {enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering => portauthority/src/main/java/org/neo4j/build/portauthority}/PortRepository.java (95%) rename {enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering => portauthority/src/main/java/org/neo4j/build/portauthority}/SimplePortProvider.java (93%) rename {enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering => portauthority/src/test/java/org/neo4j/build/portauthority}/CoordinatingPortProviderTest.java (98%) rename {enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering => portauthority/src/test/java/org/neo4j/build/portauthority}/PortRepositoryIT.java (63%) rename {enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering => portauthority/src/test/java/org/neo4j/build/portauthority}/SimplePortProviderTest.java (98%) diff --git a/enterprise/causal-clustering/pom.xml b/enterprise/causal-clustering/pom.xml index b23d5945e84c..72090ee13c65 100644 --- a/enterprise/causal-clustering/pom.xml +++ b/enterprise/causal-clustering/pom.xml @@ -202,6 +202,13 @@ test + + org.neo4j.build + port-authority + ${project.version} + test + + org.mockito mockito-core diff --git a/pom.xml b/pom.xml index 10ccfabe647e..171dd455fb42 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,7 @@ stresstests tools packaging + portauthority diff --git a/portauthority/LICENSES.txt b/portauthority/LICENSES.txt new file mode 100644 index 000000000000..e62824d7096a --- /dev/null +++ b/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. + + diff --git a/portauthority/NOTICE.txt b/portauthority/NOTICE.txt new file mode 100644 index 000000000000..5519ed4ba3c2 --- /dev/null +++ b/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 +-------------------- + diff --git a/portauthority/pom.xml b/portauthority/pom.xml new file mode 100644 index 000000000000..4bbf77417075 --- /dev/null +++ b/portauthority/pom.xml @@ -0,0 +1,47 @@ + + + + parent + org.neo4j + 3.3.0-SNAPSHOT + + 4.0.0 + + org.neo4j.build + port-authority + + + + GNU General Public License, Version 3 + http://www.gnu.org/licenses/gpl-3.0-standalone.html + 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. + + + + + + + junit + junit + test + + + org.mockito + mockito-core + test + + + diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/CoordinatingPortProvider.java b/portauthority/src/main/java/org/neo4j/build/portauthority/CoordinatingPortProvider.java similarity index 97% rename from enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/CoordinatingPortProvider.java rename to portauthority/src/main/java/org/neo4j/build/portauthority/CoordinatingPortProvider.java index c004862032e9..511eaa8a4cf6 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/CoordinatingPortProvider.java +++ b/portauthority/src/main/java/org/neo4j/build/portauthority/CoordinatingPortProvider.java @@ -17,7 +17,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -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 diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/DefaultPortProbe.java b/portauthority/src/main/java/org/neo4j/build/portauthority/DefaultPortProbe.java similarity index 96% rename from enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/DefaultPortProbe.java rename to portauthority/src/main/java/org/neo4j/build/portauthority/DefaultPortProbe.java index 90ccc2f2d760..70f3604f0c27 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/DefaultPortProbe.java +++ b/portauthority/src/main/java/org/neo4j/build/portauthority/DefaultPortProbe.java @@ -17,7 +17,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.neo4j.causalclustering; +package org.neo4j.build.portauthority; import java.io.IOException; import java.net.ServerSocket; diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortAuthority.java b/portauthority/src/main/java/org/neo4j/build/portauthority/PortAuthority.java similarity index 98% rename from enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortAuthority.java rename to portauthority/src/main/java/org/neo4j/build/portauthority/PortAuthority.java index 8a4fa83bee72..81abf812b650 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortAuthority.java +++ b/portauthority/src/main/java/org/neo4j/build/portauthority/PortAuthority.java @@ -17,7 +17,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.neo4j.causalclustering; +package org.neo4j.build.portauthority; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortConstants.java b/portauthority/src/main/java/org/neo4j/build/portauthority/PortConstants.java similarity index 96% rename from enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortConstants.java rename to portauthority/src/main/java/org/neo4j/build/portauthority/PortConstants.java index d784c53ce0e2..2f9e03a8b4bd 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortConstants.java +++ b/portauthority/src/main/java/org/neo4j/build/portauthority/PortConstants.java @@ -17,7 +17,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.neo4j.causalclustering; +package org.neo4j.build.portauthority; public class PortConstants { diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortProbe.java b/portauthority/src/main/java/org/neo4j/build/portauthority/PortProbe.java similarity index 95% rename from enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortProbe.java rename to portauthority/src/main/java/org/neo4j/build/portauthority/PortProbe.java index 9066b5e3f5e7..f80879f93bb0 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortProbe.java +++ b/portauthority/src/main/java/org/neo4j/build/portauthority/PortProbe.java @@ -17,7 +17,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.neo4j.causalclustering; +package org.neo4j.build.portauthority; public interface PortProbe { diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortProvider.java b/portauthority/src/main/java/org/neo4j/build/portauthority/PortProvider.java similarity index 95% rename from enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortProvider.java rename to portauthority/src/main/java/org/neo4j/build/portauthority/PortProvider.java index 1835f2cf7fe7..810372935e66 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortProvider.java +++ b/portauthority/src/main/java/org/neo4j/build/portauthority/PortProvider.java @@ -17,7 +17,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.neo4j.causalclustering; +package org.neo4j.build.portauthority; public interface PortProvider { diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortRepository.java b/portauthority/src/main/java/org/neo4j/build/portauthority/PortRepository.java similarity index 95% rename from enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortRepository.java rename to portauthority/src/main/java/org/neo4j/build/portauthority/PortRepository.java index f6770d6fddca..428f148418fc 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortRepository.java +++ b/portauthority/src/main/java/org/neo4j/build/portauthority/PortRepository.java @@ -17,9 +17,9 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -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.IOException; diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/SimplePortProvider.java b/portauthority/src/main/java/org/neo4j/build/portauthority/SimplePortProvider.java similarity index 93% rename from enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/SimplePortProvider.java rename to portauthority/src/main/java/org/neo4j/build/portauthority/SimplePortProvider.java index 38559b8c08a6..f4d57bca0b11 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/SimplePortProvider.java +++ b/portauthority/src/main/java/org/neo4j/build/portauthority/SimplePortProvider.java @@ -17,9 +17,9 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -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 diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/CoordinatingPortProviderTest.java b/portauthority/src/test/java/org/neo4j/build/portauthority/CoordinatingPortProviderTest.java similarity index 98% rename from enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/CoordinatingPortProviderTest.java rename to portauthority/src/test/java/org/neo4j/build/portauthority/CoordinatingPortProviderTest.java index d95ae08e0c92..8058e53be530 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/CoordinatingPortProviderTest.java +++ b/portauthority/src/test/java/org/neo4j/build/portauthority/CoordinatingPortProviderTest.java @@ -17,7 +17,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.neo4j.causalclustering; +package org.neo4j.build.portauthority; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortRepositoryIT.java b/portauthority/src/test/java/org/neo4j/build/portauthority/PortRepositoryIT.java similarity index 63% rename from enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortRepositoryIT.java rename to portauthority/src/test/java/org/neo4j/build/portauthority/PortRepositoryIT.java index a9858b93510a..921c5619d067 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/PortRepositoryIT.java +++ b/portauthority/src/test/java/org/neo4j/build/portauthority/PortRepositoryIT.java @@ -17,45 +17,50 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.neo4j.causalclustering; +package org.neo4j.build.portauthority; +import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import static org.neo4j.causalclustering.PortConstants.EphemeralPortMinimum; -import static org.neo4j.helpers.collection.Iterators.asSet; +import static org.neo4j.build.portauthority.PortConstants.EphemeralPortMinimum; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; 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.Rule; import org.junit.Test; -import org.neo4j.test.rule.TestDirectory; +import org.junit.rules.TemporaryFolder; public class PortRepositoryIT { @Rule - public TestDirectory testDirectory = TestDirectory.testDirectory(); + public TemporaryFolder temporaryFolder = new TemporaryFolder(); @Test public void shouldReservePorts() throws Exception { - Path directory = testDirectory.cleanDirectory( "port-repository" ).toPath(); - PortRepository portRepository1 = new PortRepository( directory, EphemeralPortMinimum ); + PortRepository portRepository1 = new PortRepository( temporaryDirectory(), EphemeralPortMinimum ); int port1 = portRepository1.reserveNextPort( "foo" ); int port2 = 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 public void shouldCoordinateUsingFileSystem() throws Exception { - Path directory = testDirectory.cleanDirectory( "port-repository" ).toPath(); - PortRepository portRepository1 = new PortRepository( directory, EphemeralPortMinimum ); - PortRepository portRepository2 = new PortRepository( directory, EphemeralPortMinimum ); + Path temporaryDirectory = temporaryDirectory(); + PortRepository portRepository1 = new PortRepository( temporaryDirectory, EphemeralPortMinimum ); + PortRepository portRepository2 = new PortRepository( temporaryDirectory, EphemeralPortMinimum ); int port1 = portRepository1.reserveNextPort( "foo" ); int port2 = portRepository1.reserveNextPort( "foo" ); @@ -64,18 +69,15 @@ public void shouldCoordinateUsingFileSystem() throws Exception int port5 = portRepository2.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 @Ignore public void shouldNotInterfereWithOtherRepositories() throws Exception { - Path directory1 = testDirectory.cleanDirectory( "port-repository-1" ).toPath(); - Path directory2 = testDirectory.cleanDirectory( "port-repository-2" ).toPath(); - - PortRepository portRepository1 = new PortRepository( directory1, EphemeralPortMinimum ); - PortRepository portRepository2 = new PortRepository( directory2, EphemeralPortMinimum ); + PortRepository portRepository1 = new PortRepository( temporaryDirectory(), EphemeralPortMinimum ); + PortRepository portRepository2 = new PortRepository( temporaryDirectory(), EphemeralPortMinimum ); int port1 = portRepository1.reserveNextPort( "foo" ); int port2 = portRepository1.reserveNextPort( "foo" ); @@ -84,14 +86,13 @@ public void shouldNotInterfereWithOtherRepositories() throws Exception int port5 = portRepository2.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 public void shouldNotOverrun() throws Exception { - Path directory = testDirectory.cleanDirectory( "port-repository" ).toPath(); - PortRepository portRepository1 = new PortRepository( directory, 65534 ); + PortRepository portRepository1 = new PortRepository( temporaryDirectory(), 65534 ); portRepository1.reserveNextPort( "foo" ); portRepository1.reserveNextPort( "foo" ); @@ -107,4 +108,9 @@ public void shouldNotOverrun() throws Exception assertThat( e.getMessage(), is( "There are no more ports available" ) ); } } + + private Path temporaryDirectory() throws IOException + { + return temporaryFolder.newFolder("port-repository").toPath(); + } } diff --git a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/SimplePortProviderTest.java b/portauthority/src/test/java/org/neo4j/build/portauthority/SimplePortProviderTest.java similarity index 98% rename from enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/SimplePortProviderTest.java rename to portauthority/src/test/java/org/neo4j/build/portauthority/SimplePortProviderTest.java index 7d1c1398ba88..3b30c376b9ef 100644 --- a/enterprise/causal-clustering/src/test/java/org/neo4j/causalclustering/SimplePortProviderTest.java +++ b/portauthority/src/test/java/org/neo4j/build/portauthority/SimplePortProviderTest.java @@ -17,7 +17,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.neo4j.causalclustering; +package org.neo4j.build.portauthority; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is;