incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1600654 - in /sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology: Connector.java LargeTopologyWithHubTest.java TopologyTest.java TopologyTestHelper.java
Date Thu, 05 Jun 2014 13:36:09 GMT
Author: bdelacretaz
Date: Thu Jun  5 13:36:08 2014
New Revision: 1600654

URL: http://svn.apache.org/r1600654
Log:
SLING-3495 - separate LargeTopologyWithHubTest to prepare for adding retries to it

Added:
    sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/Connector.java
    sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/LargeTopologyWithHubTest.java
Modified:
    sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/TopologyTest.java
    sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/TopologyTestHelper.java

Added: sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/Connector.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/Connector.java?rev=1600654&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/Connector.java
(added)
+++ sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/Connector.java
Thu Jun  5 13:36:08 2014
@@ -0,0 +1,40 @@
+/*
+ * 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.sling.discovery.impl.topology;
+
+import org.apache.sling.discovery.impl.setup.Instance;
+import org.apache.sling.discovery.impl.topology.connector.TopologyConnectorClientInformation;
+
+class Connector {
+    @SuppressWarnings("unused")
+    private final Instance from;
+    @SuppressWarnings("unused")
+    private final Instance to;
+    private final int jettyPort;
+    @SuppressWarnings("unused")
+    private final TopologyConnectorClientInformation connectorInfo;
+
+    Connector(Instance from, Instance to) throws Throwable {
+        this.from = from;
+        this.to = to;
+        to.startJetty();
+        this.jettyPort = to.getJettyPort();
+        this.connectorInfo = from.connectTo("http://localhost:"+jettyPort+"/system/console/topology/connector");
+    }
+}
\ No newline at end of file

Added: sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/LargeTopologyWithHubTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/LargeTopologyWithHubTest.java?rev=1600654&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/LargeTopologyWithHubTest.java
(added)
+++ sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/LargeTopologyWithHubTest.java
Thu Jun  5 13:36:08 2014
@@ -0,0 +1,65 @@
+/*
+ * 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.sling.discovery.impl.topology;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.sling.discovery.impl.setup.Instance;
+import org.junit.After;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LargeTopologyWithHubTest {
+
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+    private final List<Instance> instances = new LinkedList<Instance>();
+    
+    @After
+    public void tearDown() throws Exception {
+        for (Iterator<Instance> it = instances.iterator(); it.hasNext();) {
+            final Instance instance = it.next();
+            instance.stop();
+        }
+    }
+    
+    @Test
+    public void testLargeTopologyWithHub() throws Throwable {
+        logger.info("testLargeTopologyWithHub: start");
+        final int TEST_SIZE = 100;
+        Instance hub = TopologyTestHelper.createInstance(instances, "hub");
+        
+        List<String> slingIds = new LinkedList<String>();
+        slingIds.add(hub.getSlingId());
+        for(int i=0; i<TEST_SIZE; i++) {
+//            logger.info("testLargeTopologyWithHub: adding instance "+i);
+            Instance instance = TopologyTestHelper.createInstance(instances, "instance"+i);
+//            logger.info("testLargeTopologyWithHub: adding connector "+i);
+            new Connector(instance, hub);
+            slingIds.add(instance.getSlingId());
+        }
+        logger.info("testLargeTopologyWithHub: checking if all connectors are registered");
+        TopologyTestHelper.assertTopologyConsistsOf(hub.getDiscoveryService().getTopology(),
slingIds.toArray(new String[slingIds.size()]));
+        logger.info("testLargeTopologyWithHub: end");
+    }
+
+}

Modified: sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/TopologyTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/TopologyTest.java?rev=1600654&r1=1600653&r2=1600654&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/TopologyTest.java
(original)
+++ sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/TopologyTest.java
Thu Jun  5 13:36:08 2014
@@ -19,8 +19,6 @@
 package org.apache.sling.discovery.impl.topology;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 import java.util.Collection;
 import java.util.Iterator;
@@ -29,35 +27,13 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.sling.discovery.InstanceDescription;
-import org.apache.sling.discovery.TopologyView;
 import org.apache.sling.discovery.impl.setup.Instance;
 import org.apache.sling.discovery.impl.topology.announcement.Announcement;
-import org.apache.sling.discovery.impl.topology.connector.TopologyConnectorClientInformation;
 import org.junit.After;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class TopologyTest {
 
-    private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
-    class Connector {
-        
-        private final Instance from;
-        private final Instance to;
-        private final int jettyPort;
-        private final TopologyConnectorClientInformation connectorInfo;
-
-        Connector(Instance from, Instance to) throws Throwable {
-            this.from = from;
-            this.to = to;
-            to.startJetty();
-            this.jettyPort = to.getJettyPort();
-            this.connectorInfo = from.connectTo("http://localhost:"+jettyPort+"/system/console/topology/connector");
-        }
-    }
-    
     private final List<Instance> instances = new LinkedList<Instance>();
     
     @After
@@ -68,20 +44,10 @@ public class TopologyTest {
         }
     }
     
-    private Instance createInstance(String debugName) throws Exception {
-        final Instance instance = Instance.newStandaloneInstance(debugName, true);
-        instances.add(instance);
-        return instance;
-    }
-
-    private Connector createConnector(Instance instance1, Instance instance2) throws Throwable
{
-        return new Connector(instance1, instance2);
-    }
-    
     @Test
     public void testTwoNodes() throws Throwable {
-        Instance instance1 = createInstance("instance1");
-        Instance instance2 = createInstance("instance2");
+        Instance instance1 = TopologyTestHelper.createInstance(instances, "instance1");
+        Instance instance2 = TopologyTestHelper.createInstance(instances, "instance2");
         instance1.getConfig().setHeartbeatTimeout(2);
         instance1.getConfig().setHeartbeatInterval(1);
         instance2.getConfig().setHeartbeatTimeout(1);
@@ -95,7 +61,7 @@ public class TopologyTest {
         assertEquals(instance1.getSlingId(), instances1.iterator().next().getSlingId());
         assertEquals(instance2.getSlingId(), instances2.iterator().next().getSlingId());
         
-        Connector connector = createConnector(instance1, instance2);
+        new Connector(instance1, instance2);
         
         // check instance 1's announcements
         Collection<Announcement> instance1LocalAnnouncements = 
@@ -114,8 +80,8 @@ public class TopologyTest {
         assertEquals(false, instance2LocalAnnouncement.isInherited());
         
         // check topology
-        assertTopologyConsistsOf(instance1.getDiscoveryService().getTopology(), instance1.getSlingId(),
instance2.getSlingId());
-        assertTopologyConsistsOf(instance2.getDiscoveryService().getTopology(), instance1.getSlingId(),
instance2.getSlingId());
+        TopologyTestHelper.assertTopologyConsistsOf(instance1.getDiscoveryService().getTopology(),
instance1.getSlingId(), instance2.getSlingId());
+        TopologyTestHelper.assertTopologyConsistsOf(instance2.getDiscoveryService().getTopology(),
instance1.getSlingId(), instance2.getSlingId());
 
         instance1LocalAnnouncements = 
                 instance1.getAnnouncementRegistry().listLocalAnnouncements();
@@ -133,8 +99,8 @@ public class TopologyTest {
                 instance2.getAnnouncementRegistry().listLocalAnnouncements();
         assertEquals(0, instance2LocalAnnouncements.size());
 
-        assertTopologyConsistsOf(instance1.getDiscoveryService().getTopology(), instance1.getSlingId(),
instance2.getSlingId());
-        assertTopologyConsistsOf(instance2.getDiscoveryService().getTopology(), instance2.getSlingId());
+        TopologyTestHelper.assertTopologyConsistsOf(instance1.getDiscoveryService().getTopology(),
instance1.getSlingId(), instance2.getSlingId());
+        TopologyTestHelper.assertTopologyConsistsOf(instance2.getDiscoveryService().getTopology(),
instance2.getSlingId());
         
         Thread.sleep(1000);
         instance1LocalAnnouncements = 
@@ -144,47 +110,7 @@ public class TopologyTest {
                 instance2.getAnnouncementRegistry().listLocalAnnouncements();
         assertEquals(0, instance2LocalAnnouncements.size());
 
-        assertTopologyConsistsOf(instance1.getDiscoveryService().getTopology(), instance1.getSlingId());
-        assertTopologyConsistsOf(instance2.getDiscoveryService().getTopology(), instance2.getSlingId());
+        TopologyTestHelper.assertTopologyConsistsOf(instance1.getDiscoveryService().getTopology(),
instance1.getSlingId());
+        TopologyTestHelper.assertTopologyConsistsOf(instance2.getDiscoveryService().getTopology(),
instance2.getSlingId());
     }
-
-    private void assertTopologyConsistsOf(TopologyView topology,
-            String... slingIds) {
-        assertNotNull(topology);
-        assertEquals(topology.getInstances().size(), slingIds.length);
-        for(int i=0; i<slingIds.length; i++) {
-            final String aSlingId = slingIds[i];
-            final Set instances = topology.getInstances();
-            boolean found = false;
-            for (Iterator it = instances.iterator(); it.hasNext();) {
-                InstanceDescription anInstance = (InstanceDescription) it.next();
-                if (anInstance.getSlingId().equals(aSlingId)) {
-                    found = true;
-                    break;
-                }
-            }
-            assertTrue(found);
-        }
-    }
-    
-    @Test
-    public void testLargeTopologyWithHub() throws Throwable {
-        logger.info("testLargeTopologyWithHub: start");
-        final int TEST_SIZE = 100;
-        Instance hub = createInstance("hub");
-        
-        List<String> slingIds = new LinkedList<String>();
-        slingIds.add(hub.getSlingId());
-        for(int i=0; i<TEST_SIZE; i++) {
-//            logger.info("testLargeTopologyWithHub: adding instance "+i);
-            Instance instance = createInstance("instance"+i);
-//            logger.info("testLargeTopologyWithHub: adding connector "+i);
-            Connector connector = createConnector(instance, hub);
-            slingIds.add(instance.getSlingId());
-        }
-        logger.info("testLargeTopologyWithHub: checking if all connectors are registered");
-        assertTopologyConsistsOf(hub.getDiscoveryService().getTopology(), slingIds.toArray(new
String[slingIds.size()]));
-        logger.info("testLargeTopologyWithHub: end");
-    }
-
 }

Modified: sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/TopologyTestHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/TopologyTestHelper.java?rev=1600654&r1=1600653&r2=1600654&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/TopologyTestHelper.java
(original)
+++ sling/trunk/bundles/extensions/discovery/impl/src/test/java/org/apache/sling/discovery/impl/topology/TopologyTestHelper.java
Thu Jun  5 13:36:08 2014
@@ -18,19 +18,26 @@
  */
 package org.apache.sling.discovery.impl.topology;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Map;
+import java.util.Set;
 import java.util.UUID;
 
 import junitx.util.PrivateAccessor;
 
 import org.apache.sling.discovery.ClusterView;
 import org.apache.sling.discovery.InstanceDescription;
+import org.apache.sling.discovery.TopologyView;
 import org.apache.sling.discovery.impl.common.DefaultClusterViewImpl;
 import org.apache.sling.discovery.impl.common.DefaultInstanceDescriptionImpl;
+import org.apache.sling.discovery.impl.setup.Instance;
 
 public class TopologyTestHelper {
 
@@ -114,4 +121,29 @@ public class TopologyTestHelper {
         return (Map<String, String>) PrivateAccessor.getField(
                 instanceDescription, "properties");
     }
+    
+    public static void assertTopologyConsistsOf(TopologyView topology, String... slingIds)
{
+        assertNotNull(topology);
+        assertEquals(topology.getInstances().size(), slingIds.length);
+        for(int i=0; i<slingIds.length; i++) {
+            final String aSlingId = slingIds[i];
+            final Set<?> instances = topology.getInstances();
+            boolean found = false;
+            for (Iterator<?> it = instances.iterator(); it.hasNext();) {
+                InstanceDescription anInstance = (InstanceDescription) it.next();
+                if (anInstance.getSlingId().equals(aSlingId)) {
+                    found = true;
+                    break;
+                }
+            }
+            assertTrue(found);
+        }
+    }
+    
+    public static Instance createInstance(Collection<Instance> instances, String debugName)
throws Exception {
+        final Instance instance = Instance.newStandaloneInstance(debugName, true);
+        instances.add(instance);
+        return instance;
+    }
+
 }



Mime
View raw message