You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2016/03/29 18:13:06 UTC

aries-rsa git commit: Fix repo and add tests

Repository: aries-rsa
Updated Branches:
  refs/heads/master 55809ab28 -> d8162e405


Fix repo and add tests


Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/d8162e40
Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/d8162e40
Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/d8162e40

Branch: refs/heads/master
Commit: d8162e405b3724442d031a52713d40f65af5f239
Parents: 55809ab
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Tue Mar 29 18:12:51 2016 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Tue Mar 29 18:12:51 2016 +0200

----------------------------------------------------------------------
 discovery/zookeeper/pom.xml                     | 35 +++++++++++++-
 .../aries/rsa/provider/tcp/TcpEndpoint.java     | 22 ++++++---
 .../aries/rsa/provider/tcp/ActivatorTest.java   | 50 ++++++++++++++++++++
 .../aries/rsa/provider/tcp/TcpEndpointTest.java | 42 ++++++++++++++++
 repository/pom.xml                              |  8 ++--
 5 files changed, 144 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d8162e40/discovery/zookeeper/pom.xml
----------------------------------------------------------------------
diff --git a/discovery/zookeeper/pom.xml b/discovery/zookeeper/pom.xml
index 389704c..b2f718b 100644
--- a/discovery/zookeeper/pom.xml
+++ b/discovery/zookeeper/pom.xml
@@ -17,7 +17,8 @@
   specific language governing permissions and limitations
   under the License.
 -->
-<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/maven-v4_0_0.xsd">
+<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/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
 
     <parent>
@@ -26,7 +27,7 @@
         <version>1.8-SNAPSHOT</version>
         <relativePath>../../parent/pom.xml</relativePath>
     </parent>
-    
+
     <groupId>org.apache.aries.rsa.discovery</groupId>
     <artifactId>org.apache.aries.rsa.discovery.zookeeper</artifactId>
     <packaging>bundle</packaging>
@@ -45,6 +46,36 @@
         <dependency>
             <groupId>org.apache.zookeeper</groupId>
             <artifactId>zookeeper</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.sun.jdmk</groupId>
+                    <artifactId>jmxtools</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>com.sun.jmx</groupId>
+                    <artifactId>jmxri</artifactId>
+                </exclusion>
+                <exclusion>
+                    <artifactId>slf4j-log4j12</artifactId>
+                    <groupId>org.slf4j</groupId>
+                </exclusion>
+                <exclusion>
+                    <artifactId>jline</artifactId>
+                    <groupId>jline</groupId>
+                </exclusion>
+                <exclusion>
+                    <artifactId>netty</artifactId>
+                    <groupId>io.netty</groupId>
+                </exclusion>
+                <exclusion>
+                    <artifactId>log4j</artifactId>
+                    <groupId>log4j</groupId>
+                </exclusion>
+                <exclusion>
+                    <groupId>io.netty</groupId>
+                    <artifactId>netty</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <dependency>

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d8162e40/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpEndpoint.java
----------------------------------------------------------------------
diff --git a/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpEndpoint.java b/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpEndpoint.java
index 8f61e3c..0dfc9de 100644
--- a/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpEndpoint.java
+++ b/provider/tcp/src/main/java/org/apache/aries/rsa/provider/tcp/TcpEndpoint.java
@@ -30,19 +30,27 @@ public class TcpEndpoint implements Endpoint {
     private TCPServer tcpServer;
     
     public TcpEndpoint(Object service, Map<String, Object> effectiveProperties) {
-        Integer port = getInt(effectiveProperties, "port", 0);
-        String localip = LocalHostUtil.getLocalIp();
-        int numThreads = getInt(effectiveProperties, "numThreads", 10);
-        tcpServer = new TCPServer(service, localip, port, numThreads);
-        effectiveProperties.put(RemoteConstants.ENDPOINT_ID, "tcp://" + localip + ":" + tcpServer.getPort());
+        Integer port = getInt(effectiveProperties, "port", "0");
+        String hostName = getString(effectiveProperties, "hostname", System.getProperty("aries.rsa.hostname"));
+        if (hostName == null) {
+            hostName = LocalHostUtil.getLocalIp();
+        }
+        int numThreads = getInt(effectiveProperties, "numThreads", "10");
+        tcpServer = new TCPServer(service, hostName, port, numThreads);
+        String endpointId = String.format("tcp://%s:%s",hostName, tcpServer.getPort());
+        effectiveProperties.put(RemoteConstants.ENDPOINT_ID, endpointId);
         effectiveProperties.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, "");
         this.epd = new EndpointDescription(effectiveProperties);
     }
     
 
-    private Integer getInt(Map<String, Object> effectiveProperties, String key, int defaultValue) {
+    private Integer getInt(Map<String, Object> effectiveProperties, String key, String defaultValue) {
+        return Integer.parseInt(getString(effectiveProperties, key, defaultValue));
+    }
+    
+    private String getString(Map<String, Object> effectiveProperties, String key, String defaultValue) {
         String value = (String)effectiveProperties.get(key);
-        return value != null ? Integer.parseInt(value) : defaultValue;
+        return value != null ? value : defaultValue;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d8162e40/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/ActivatorTest.java
----------------------------------------------------------------------
diff --git a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/ActivatorTest.java b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/ActivatorTest.java
new file mode 100644
index 0000000..029424f
--- /dev/null
+++ b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/ActivatorTest.java
@@ -0,0 +1,50 @@
+/**
+ * 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.aries.rsa.provider.tcp;
+
+import static org.easymock.EasyMock.expect;
+
+import java.util.Dictionary;
+
+import org.apache.aries.rsa.spi.DistributionProvider;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class ActivatorTest {
+
+    @SuppressWarnings({
+     "rawtypes", "unchecked"
+    })
+    @Test
+    public void testStartStop() throws Exception {
+        IMocksControl c = EasyMock.createControl();
+        BundleContext context = c.createMock(BundleContext.class);
+        ServiceRegistration sreg = c.createMock(ServiceRegistration.class);
+        expect(context.registerService(EasyMock.eq(DistributionProvider.class), EasyMock.anyObject(DistributionProvider.class), EasyMock.anyObject(Dictionary.class))).andReturn(sreg );
+        
+        c.replay();
+        Activator activator = new Activator();
+        activator.start(context);
+        activator.stop(context);
+        c.verify();
+    }
+}

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d8162e40/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpEndpointTest.java
----------------------------------------------------------------------
diff --git a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpEndpointTest.java b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpEndpointTest.java
new file mode 100644
index 0000000..cf4c291
--- /dev/null
+++ b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpEndpointTest.java
@@ -0,0 +1,42 @@
+package org.apache.aries.rsa.provider.tcp;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.aries.rsa.provider.tcp.myservice.MyService;
+import org.apache.aries.rsa.provider.tcp.myservice.MyServiceImpl;
+import org.junit.Assert;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+import org.osgi.service.remoteserviceadmin.RemoteConstants;
+
+public class TcpEndpointTest {
+
+    @Test
+    public void testEndpointProperties() throws IOException {
+        Object service = new MyServiceImpl();
+        Map<String, Object> props = new HashMap<>();
+        props.put(Constants.OBJECTCLASS, new String[]{MyService.class.getName()});
+        props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "");
+        props.put("port", "45346");
+        props.put("hostname", "myhost");
+        TcpEndpoint tcpEndpoint = new TcpEndpoint(service, props);
+        EndpointDescription epd = tcpEndpoint.description();
+        Assert.assertEquals("tcp://myhost:45346", epd.getId());
+        tcpEndpoint.close();
+    }
+    
+    @Test
+    public void testEndpointPropertiesDefault() throws IOException {
+        Object service = new MyServiceImpl();
+        Map<String, Object> props = new HashMap<>();
+        props.put(Constants.OBJECTCLASS, new String[]{MyService.class.getName()});
+        props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "");
+        TcpEndpoint tcpEndpoint = new TcpEndpoint(service, props);
+        EndpointDescription epd = tcpEndpoint.description();
+        Assert.assertNotNull(epd.getId());
+        tcpEndpoint.close();
+    }
+}

http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d8162e40/repository/pom.xml
----------------------------------------------------------------------
diff --git a/repository/pom.xml b/repository/pom.xml
index e6f5cd7..e8732e6 100644
--- a/repository/pom.xml
+++ b/repository/pom.xml
@@ -85,10 +85,10 @@
             <groupId>org.apache.zookeeper</groupId>
             <artifactId>zookeeper</artifactId>
             <exclusions>
-            	<exclusion>
-            		<artifactId>slf4j-api</artifactId>
-            		<groupId>org.slf4j</groupId>
-            	</exclusion>
+                <exclusion>
+                    <artifactId>slf4j-api</artifactId>
+                    <groupId>org.slf4j</groupId>
+                </exclusion>
             </exclusions>
         </dependency>
         <dependency>