polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject zest-java git commit: Library Rest admin server now has a Configuration to set a port
Date Wed, 15 Jun 2016 17:21:11 GMT
Repository: zest-java
Updated Branches:
  refs/heads/develop 9bd8a764b -> 17543d30a


Library Rest admin server now has a Configuration to set a port

And the tests use a dynamic port to address environmental flakiness on
builds.apache.org


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/17543d30
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/17543d30
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/17543d30

Branch: refs/heads/develop
Commit: 17543d30a3fe8a6bdc54ee0f88588cf298f1facf
Parents: 9bd8a76
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Wed Jun 15 19:19:41 2016 +0200
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Wed Jun 15 19:20:59 2016 +0200

----------------------------------------------------------------------
 .../rest/admin/RestServerConfiguration.java     | 32 ++++++++++++++++++
 .../library/rest/admin/RestServerMixin.java     |  9 ++++-
 .../zest/library/rest/admin/RestTest.java       | 35 +++++++++++++++-----
 3 files changed, 67 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/17543d30/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestServerConfiguration.java
----------------------------------------------------------------------
diff --git a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestServerConfiguration.java
b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestServerConfiguration.java
new file mode 100644
index 0000000..fb26c0d
--- /dev/null
+++ b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestServerConfiguration.java
@@ -0,0 +1,32 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *
+ */
+package org.apache.zest.library.rest.admin;
+
+import org.apache.zest.api.common.UseDefaults;
+import org.apache.zest.api.property.Property;
+
+/**
+ * RestServer Configuration.
+ */
+public interface RestServerConfiguration
+{
+    @UseDefaults( "8192" )
+    Property<Integer> port();
+}

http://git-wip-us.apache.org/repos/asf/zest-java/blob/17543d30/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestServerMixin.java
----------------------------------------------------------------------
diff --git a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestServerMixin.java
b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestServerMixin.java
index 13f63ea..a58596c 100644
--- a/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestServerMixin.java
+++ b/libraries/rest/src/main/java/org/apache/zest/library/rest/admin/RestServerMixin.java
@@ -20,7 +20,9 @@
 
 package org.apache.zest.library.rest.admin;
 
+import org.apache.zest.api.configuration.Configuration;
 import org.apache.zest.api.injection.scope.Structure;
+import org.apache.zest.api.injection.scope.This;
 import org.apache.zest.api.structure.Module;
 import org.restlet.Component;
 import org.restlet.data.Protocol;
@@ -31,14 +33,19 @@ public abstract class RestServerMixin
     @Structure
     private Module module;
 
+    @This
+    private Configuration<RestServerConfiguration> configuration;
+
     private Component component;
 
     @Override
     public void startServer()
         throws Exception
     {
+        configuration.refresh();
+
         component = new Component();
-        component.getServers().add( Protocol.HTTP, 8182 );
+        component.getServers().add( Protocol.HTTP, configuration.get().port().get() );
         RestApplication application = module.newObject( RestApplication.class, component.getContext()
);
         component.getDefaultHost().attach( application );
         component.start();

http://git-wip-us.apache.org/repos/asf/zest-java/blob/17543d30/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/RestTest.java
----------------------------------------------------------------------
diff --git a/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/RestTest.java
b/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/RestTest.java
index 184de4a..651495c 100644
--- a/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/RestTest.java
+++ b/libraries/rest/src/test/java/org/apache/zest/library/rest/admin/RestTest.java
@@ -21,6 +21,7 @@
 package org.apache.zest.library.rest.admin;
 
 import java.io.IOException;
+import java.io.UncheckedIOException;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -38,6 +39,7 @@ import org.apache.http.message.BasicNameValuePair;
 import org.apache.http.util.EntityUtils;
 import org.apache.zest.api.association.Association;
 import org.apache.zest.api.common.Optional;
+import org.apache.zest.api.common.Visibility;
 import org.apache.zest.api.entity.EntityBuilder;
 import org.apache.zest.api.entity.EntityComposite;
 import org.apache.zest.api.injection.scope.Service;
@@ -50,10 +52,10 @@ import org.apache.zest.bootstrap.Assembler;
 import org.apache.zest.bootstrap.AssemblyException;
 import org.apache.zest.bootstrap.ModuleAssembly;
 import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler;
-import org.apache.zest.entitystore.memory.MemoryEntityStoreService;
 import org.apache.zest.index.rdf.assembly.RdfMemoryStoreAssembler;
-import org.apache.zest.spi.uuid.UuidIdentityGeneratorService;
 import org.apache.zest.test.AbstractZestTest;
+import org.apache.zest.test.EntityTestAssembler;
+import org.apache.zest.test.util.FreePortFinder;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -65,6 +67,19 @@ import static org.junit.Assert.assertThat;
 
 public class RestTest extends AbstractZestTest
 {
+    private static final int ADMIN_PORT;
+
+    static
+    {
+        try
+        {
+            ADMIN_PORT = FreePortFinder.findFreePortOnLoopback();
+        }
+        catch( IOException ex )
+        {
+            throw new UncheckedIOException( ex );
+        }
+    }
 
     @Override
     protected ApplicationDescriptor newApplication()
@@ -90,11 +105,15 @@ public class RestTest extends AbstractZestTest
     public void assemble( ModuleAssembly module )
         throws AssemblyException
     {
+        ModuleAssembly config = module.layer().module( "config" );
+        new EntityTestAssembler().assemble( config );
+        config.configurations( RestServerConfiguration.class ).visibleIn( Visibility.layer
);
+        config.forMixin( RestServerConfiguration.class ).declareDefaults().port().set( ADMIN_PORT
);
+
         module.objects( RestTest.class, RestTester.class );
         module.entities( PersonEntity.class );
         module.services( RestServerComposite.class ).instantiateOnStartup();
-        module.services( MemoryEntityStoreService.class ).identifiedBy( "store" );
-        module.services( UuidIdentityGeneratorService.class );
+        new EntityTestAssembler().assemble( module );
     }
 
     @Override
@@ -220,7 +239,7 @@ public class RestTest extends AbstractZestTest
             throws IOException
         {
             CloseableHttpClient client = HttpClients.createDefault();
-            HttpGet method = new HttpGet( "http://localhost:8182/entity/" + identity + ".rdf"
);
+            HttpGet method = new HttpGet( "http://localhost:" + ADMIN_PORT + "/entity/" +
identity + ".rdf" );
             method.addHeader( "Accept", "application/rdf+xml" );
             try( CloseableHttpResponse response = client.execute( method ) )
             {
@@ -236,7 +255,7 @@ public class RestTest extends AbstractZestTest
             throws IOException
         {
             CloseableHttpClient client = HttpClients.createDefault();
-            HttpPost method = new HttpPost( "http://localhost:8182/entity/" + identity );
+            HttpPost method = new HttpPost( "http://localhost:" + ADMIN_PORT + "/entity/"
+ identity );
             List<NameValuePair> parameters = new ArrayList<>();
             for( Map.Entry<String, String> entry : params.entrySet() )
             {
@@ -256,7 +275,7 @@ public class RestTest extends AbstractZestTest
             throws IOException
         {
             CloseableHttpClient client = HttpClients.createDefault();
-            HttpDelete method = new HttpDelete( "http://localhost:8182/entity/" + identity
);
+            HttpDelete method = new HttpDelete( "http://localhost:" + ADMIN_PORT + "/entity/"
+ identity );
             try( CloseableHttpResponse response = client.execute( method ) )
             {
                 if( response.getStatusLine().getStatusCode() != 204 )
@@ -270,7 +289,7 @@ public class RestTest extends AbstractZestTest
             throws IOException
         {
             CloseableHttpClient client = HttpClients.createDefault();
-            HttpGet method = new HttpGet( "http://localhost:8182/entity.rdf" );
+            HttpGet method = new HttpGet( "http://localhost:" + ADMIN_PORT + "/entity.rdf"
);
             method.addHeader( "Accept", "application/rdf+xml" );
             try( CloseableHttpResponse response = client.execute( method ) )
             {


Mime
View raw message