Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CD683200B13 for ; Wed, 15 Jun 2016 19:21:12 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CBDD3160A4D; Wed, 15 Jun 2016 17:21:12 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id EC8AF160A19 for ; Wed, 15 Jun 2016 19:21:11 +0200 (CEST) Received: (qmail 97395 invoked by uid 500); 15 Jun 2016 17:21:11 -0000 Mailing-List: contact commits-help@zest.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zest.apache.org Delivered-To: mailing list commits@zest.apache.org Received: (qmail 97386 invoked by uid 99); 15 Jun 2016 17:21:11 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Jun 2016 17:21:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 11302DFB38; Wed, 15 Jun 2016 17:21:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: paulmerlin@apache.org To: commits@zest.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer 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 +0000 (UTC) archived-at: Wed, 15 Jun 2016 17:21:13 -0000 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 Authored: Wed Jun 15 19:19:41 2016 +0200 Committer: Paul Merlin 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 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 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 parameters = new ArrayList<>(); for( Map.Entry 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 ) ) {