diff --git a/build_no_test.sh b/build.sh similarity index 100% rename from build_no_test.sh rename to build.sh diff --git a/pssim.sh b/pssim.sh new file mode 100755 index 0000000..3f6d3cc --- /dev/null +++ b/pssim.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +JAVA_HOME=~/software/jdk1.7.0_79 +MIN_HEAP=1g +MAX_HEAP=10g +GC_OPTS="+UseConcMarkSweepGC" +PSSIM_JAR_PATH=~/workspace/pssim/target/pssim-0.1-jar-with-dependencies.jar + +if [ -z "$JAVA_HOME" ]; then + JAVA_CMD="java" +else + JAVA_CMD=$JAVA_HOME/bin/java +fi + +$JAVA_CMD -Xms$MIN_HEAP -Xmx$MAX_HEAP -XX:$GC_OPTS -jar $PSSIM_JAR_PATH de.tum.msrg.pubsub.PSSim $@ + +echo finished $@ diff --git a/src/test/java/de/tum/msrg/AllTests.java b/src/test/java/de/tum/msrg/AllTests.java deleted file mode 100644 index 3bf7d7d..0000000 --- a/src/test/java/de/tum/msrg/AllTests.java +++ /dev/null @@ -1,45 +0,0 @@ -package de.tum.msrg; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(Suite.class) -@SuiteClasses({ - de.tum.msrg.pubsub.TestBaseline.class, - de.tum.msrg.pubsub.TestBaselineWithLinkCongestion.class, - de.tum.msrg.pubsub.TestBaselineWithBrokerOverloaded.class, - // test.baseline.TestSim.class, // does not work with JUnit - - de.tum.msrg.config.TestConfig.class, - - de.tum.msrg.lpbcast.TestGossiper.class, - - de.tum.msrg.message.TestMessage.class, - de.tum.msrg.message.TestSubscription.class, - de.tum.msrg.message.TestAdvertisement.class, - de.tum.msrg.message.TestPublication.class, - - de.tum.msrg.overlay.TestOverlayGossipLatency.class, - de.tum.msrg.overlay.TestOverlayLink.class, - de.tum.msrg.overlay.TestPubSubNodeWload.class, - - de.tum.msrg.popsub.TestCommMonitor.class, - de.tum.msrg.popsub.TestCommManager.class, - de.tum.msrg.popsub.TestPopsubOverlay.class, - de.tum.msrg.popsub.TestRateSampler.class, - de.tum.msrg.popsub.TestUtilRatio.class, - - de.tum.msrg.sim.TestWorkloadGenerator.class, - - de.tum.msrg.topology.TestNodeInfo.class, - - de.tum.msrg.underlay.TestEdge.class, - de.tum.msrg.underlay.TestNetwork.class, - de.tum.msrg.underlay.TestNode.class, - de.tum.msrg.underlay.TestTopology.class, -}) - -public class AllTests { - public static double ASSERT_DELTA = 1e-5; -} diff --git a/src/test/java/de/tum/msrg/config/TestConfig.java b/src/test/java/de/tum/msrg/config/TestConfig.java deleted file mode 100644 index 74fc34f..0000000 --- a/src/test/java/de/tum/msrg/config/TestConfig.java +++ /dev/null @@ -1,45 +0,0 @@ -package de.tum.msrg.config; - -import static org.junit.Assert.*; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.collections4.CollectionUtils; -import org.junit.Test; - -import de.tum.msrg.config.Configuration; -import de.tum.msrg.config.ConfigParserException; - -public class TestConfig { - - public enum DistType { - RANDOM, UNIFORM; - } - - private String correctConfig = "[section]\n" - + "name = config \n" - + "size = 70 \n" - + "delay = 2.34 \n" - + "boolean_var = true\n" - + "[work load]\n" - + "distribution = uniform\n" - + "[lists] \n" - + "clients = 4,5,90 \n"; - - @Test - public void testCorrect() throws ConfigParserException, IOException{ - Configuration config = new Configuration(correctConfig); - assertEquals(config.getStringConfig("section.name"), "config"); - assertEquals(config.getIntConfig("section.size"), 70); - assertEquals(config.getFloatConfig("section.delay"), 2.34, 0.001); - assertTrue(config.getBooleanConfig("section.boolean_var")); - assertEquals(config.getEnumConfig(DistType.class, "work load.distribution"), DistType.UNIFORM); - List actualClients = Arrays.asList(4, 90, 5); - assertTrue(CollectionUtils.isEqualCollection(config.getList(int.class, "lists.clients"), actualClients)); - config.addProperty("runtime.verbose", false); - assertFalse(config.getBooleanConfig("runtime.verbose")); - } - -} diff --git a/src/test/java/de/tum/msrg/message/TestAdvertisement.java b/src/test/java/de/tum/msrg/message/TestAdvertisement.java deleted file mode 100644 index 0b68589..0000000 --- a/src/test/java/de/tum/msrg/message/TestAdvertisement.java +++ /dev/null @@ -1,37 +0,0 @@ -package de.tum.msrg.message; - -import de.tum.msrg.message.Advertisement; -import de.tum.msrg.message.Attribute; -import de.tum.msrg.message.Subscription; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * Created by pxsalehi on 09.02.16. - */ -public class TestAdvertisement { - - @Test - public void testIsMatches() { - // a1={0, x > 10, y < 200} a2={1, x < 100, 150 < y < 400} - // s1={0, x > 0} s2={1, 0 < x < 50, y < 500}, s3={1; y < 10}, s4={1} - Attribute.noOfAttributes = 2; - Attribute.lowRange = 0; - Attribute.highRange = 1000; - Subscription.setTotalClasses(2); - Advertisement a1 = new Advertisement(0, new Attribute[]{Attribute.greaterThan(10), Attribute.lessThan(200)}); - Advertisement a2 = new Advertisement(1, new Attribute[]{Attribute.lessThan(100), Attribute.range(150, 400)}); - Subscription s1 = new Subscription(0, new Attribute[]{Attribute.greaterThan(0), Attribute.star()}); - Subscription s2 = new Subscription(1, new Attribute[]{Attribute.range(0, 50), Attribute.lessThan(500)}); - Subscription s3 = new Subscription(1, new Attribute[]{Attribute.star(), Attribute.lessThan(10)}); - Subscription s4 = new Subscription(1, new Attribute[]{Attribute.star(), Attribute.star()}); - assertTrue(a1.isMatches(s1)); - assertFalse(a1.isMatches(s2)); - assertFalse(a1.isMatches(s3)); - assertFalse(a1.isMatches(s4)); - assertFalse(a2.isMatches(s1)); - assertTrue(a2.isMatches(s2)); - assertFalse(a2.isMatches(s3)); - assertTrue(a2.isMatches(s4)); - } -} diff --git a/src/test/java/de/tum/msrg/message/TestMessage.java b/src/test/java/de/tum/msrg/message/TestMessage.java deleted file mode 100644 index 9a95a91..0000000 --- a/src/test/java/de/tum/msrg/message/TestMessage.java +++ /dev/null @@ -1,43 +0,0 @@ -package de.tum.msrg.message; - -import org.junit.Test; -import static org.junit.Assert.*; -import de.tum.msrg.topology.NodeInfo; - -/** - * Created by pxsalehi on 18.12.15. - */ -public class TestMessage { - private NodeInfo b1 = new NodeInfo(1, 1); - private NodeInfo b2 = new NodeInfo(2, 2); - private NodeInfo b3 = new NodeInfo(3, 1); - - @Test - public void testEquals() { - Message m1 = new Message(Message.Type.PUB, b1, b2); - Message m2 = new Message(Message.Type.PUB, b2, b1); - Message m3 = new Message(Message.Type.PUB, b1, b2); - m3.setId(m1.getId()); - Message m4 = new Message(Message.Type.PUB, b1, b2); - assertEquals(m1, m3); - assertEquals(m3, m1); - assertFalse(m1.equals(m2)); - assertFalse(m2.equals(m3)); - assertFalse(m1.equals(m4)); // different message ids - } - - @Test - public void testPubMessageEquals() { - Publication p0 = new Publication(); - Publication p1 = new Publication(); - PubMessage pm1 = new PubMessage(b1, b2, p0); - PubMessage pm2 = new PubMessage(b1, b2, p0); - PubMessage pm3 = new PubMessage(b1, b2, p0); - pm3.setId(pm1.getId()); - PubMessage pm4 = new PubMessage(b2, b1, p0); - pm4.setId(pm2.getId()); - assertEquals(pm1, pm3); - assertFalse(pm1.equals(pm2)); - assertFalse(pm2.equals(pm4)); - } -} diff --git a/src/test/java/de/tum/msrg/message/TestPublication.java b/src/test/java/de/tum/msrg/message/TestPublication.java deleted file mode 100644 index a2d12ae..0000000 --- a/src/test/java/de/tum/msrg/message/TestPublication.java +++ /dev/null @@ -1,26 +0,0 @@ -package de.tum.msrg.message; - -import de.tum.msrg.AllTests; -import de.tum.msrg.topology.NodeInfo; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * Created by pxsalehi on 05.04.16. - */ -public class TestPublication { - - @Test - public void testClone() { - NodeInfo pubBroker = new NodeInfo(0, 2); - Publication p = new Publication(0, new float[]{2.3f, 100f}); - p.setSourceBroker(pubBroker); - Publication pclone = new Publication(p); - assertEquals(pclone.getId(), p.getId() + 1); - assertEquals(pclone.getSourceBroker(), p.getSourceBroker()); - assertEquals(pclone.getPubClass(), p.getPubClass()); - assertEquals(pclone.getAttributes().length, p.getAttributes().length); - for(int i = 0; i < p.getAttributes().length; ++i) - assertEquals(p.getAttributes()[i], pclone.getAttributes()[i], AllTests.ASSERT_DELTA); - } -} diff --git a/src/test/java/de/tum/msrg/message/TestSubscription.java b/src/test/java/de/tum/msrg/message/TestSubscription.java deleted file mode 100644 index cddde9d..0000000 --- a/src/test/java/de/tum/msrg/message/TestSubscription.java +++ /dev/null @@ -1,63 +0,0 @@ -package de.tum.msrg.message; - -import static org.junit.Assert.*; - -import org.junit.Test; - -import de.tum.msrg.message.Attribute; -import de.tum.msrg.message.Publication; -import de.tum.msrg.message.Subscription; -import de.tum.msrg.message.Attribute.Operator; - -public class TestSubscription { - - @Test - public void testIsMatches() { - /** - * p1: { 0, 10 , 421 } matches s1 - * p2: { 0, 1 , 99 } matches s1, s3 - * p3: { 1, 500, 99.8 } matches s2 - * p4: { 2, 89, 900.5 } matches nothing - * - * s1: { 0, x <= 10 , 90 <= y <= 421 } - * s2: { 1, 300 <= x <= 600 , 90 <= y <= 100] } - * s3: { 0, 1 <= x <= 2 , y >= 90] } - * s4: { 3, *, * } - */ - Attribute.lowRange = 0f; - Attribute.highRange = 1000f; - Publication p1 = new Publication(0, new float[]{10f, 421f}); - Publication p2 = new Publication(0, new float[]{1f, 99f}); - Publication p3 = new Publication(1, new float[]{500f, 99.8f}); - Publication p4 = new Publication(2, new float[]{89f, 900.5f}); - Subscription s1 = new Subscription(0, new Attribute[]{ - new Attribute(Operator.LESS_THAN, Attribute.lowRange, 10f), - new Attribute(Operator.RANGE, 90f, 421f)}); - Subscription s2 = new Subscription(1, new Attribute[]{ - new Attribute(Operator.RANGE, 300f, 600f), - new Attribute(Operator.RANGE, 90f, 100f)}); - Subscription s3 = new Subscription(0, new Attribute[]{ - new Attribute(Operator.RANGE, 1f, 2f), - new Attribute(Operator.GREATER_THAN, 90f, Attribute.highRange)}); - Subscription s4 = new Subscription(3, new Attribute[]{ - new Attribute(Operator.RANGE, Attribute.lowRange, Attribute.highRange), - new Attribute(Operator.RANGE, Attribute.lowRange, Attribute.highRange)}); - assertTrue(s1.isMatches(p1)); - assertFalse(s2.isMatches(p1)); - assertFalse(s3.isMatches(p1)); - assertFalse(s4.isMatches(p1)); - assertTrue (s1.isMatches(p2)); - assertFalse(s2.isMatches(p2)); - assertTrue(s3.isMatches(p2)); - assertFalse(s4.isMatches(p2)); - assertFalse(s1.isMatches(p3)); - assertTrue(s2.isMatches(p3)); - assertFalse(s3.isMatches(p3)); - assertFalse(s4.isMatches(p3)); - assertFalse(s1.isMatches(p4)); - assertFalse(s2.isMatches(p4)); - assertFalse(s3.isMatches(p4)); - assertFalse(s4.isMatches(p4)); - } - -} diff --git a/src/test/java/de/tum/msrg/overlay/OverlayLinkMock.java b/src/test/java/de/tum/msrg/overlay/OverlayLinkMock.java deleted file mode 100644 index 2e8fe4b..0000000 --- a/src/test/java/de/tum/msrg/overlay/OverlayLinkMock.java +++ /dev/null @@ -1,44 +0,0 @@ -package de.tum.msrg.overlay; - -/** - * Created by pxsalehi on 22.04.16. - */ -public class OverlayLinkMock extends OverlayLink { - private int latency; - private int fromNode; - private int toNode; - - public OverlayLinkMock(int fromNode, int toNode, int latency) { - this.fromNode = fromNode; - this.latency = latency; - this.toNode = toNode; - } - - @Override - public int getLatency() { - return latency; - } - - @Override - public int hashCode() { - int result = fromNode; - result = 31 * result + toNode; - return result; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - OverlayLinkMock that = (OverlayLinkMock) o; - if (fromNode != that.fromNode) return false; - return toNode == that.toNode; - - } - - @Override - public String toString() { - return "(link:" + fromNode + "-" + toNode + ")"; - } - -} diff --git a/src/test/java/de/tum/msrg/overlay/TestOverlayGossipLatency.java b/src/test/java/de/tum/msrg/overlay/TestOverlayGossipLatency.java deleted file mode 100644 index 1ac0269..0000000 --- a/src/test/java/de/tum/msrg/overlay/TestOverlayGossipLatency.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.tum.msrg.overlay; - -import org.junit.Test; -import static org.junit.Assert.*; -import de.tum.msrg.overlay.OverlayGossipLatency; - -/** - * Created by pxsalehi on 11.01.16. - */ -public class TestOverlayGossipLatency { - @Test - public void testGenerateLatencies() { - int noOfNodes = 20, minGossipLatency = 15, maxGossipLatency = 87; - long seed = 325487; - OverlayGossipLatency gossipLatencies = - new OverlayGossipLatency(noOfNodes, minGossipLatency, maxGossipLatency, seed); - for(int i = 0; i < noOfNodes; i++) - for(int j = 0; j < noOfNodes; j++) { - int latency = gossipLatencies.get(i, j); - if (i == j) - assertEquals(latency, 0); - else { - assertFalse(latency == 0); - assertTrue(latency >= minGossipLatency); - assertTrue(latency <= maxGossipLatency); - } - } - } -} diff --git a/src/test/java/de/tum/msrg/overlay/TestOverlayLink.java b/src/test/java/de/tum/msrg/overlay/TestOverlayLink.java deleted file mode 100644 index 9420c13..0000000 --- a/src/test/java/de/tum/msrg/overlay/TestOverlayLink.java +++ /dev/null @@ -1,87 +0,0 @@ -package de.tum.msrg.overlay; - -import de.tum.msrg.pubsub.PSBroker; -import de.tum.msrg.pubsub.PSOverlay; -import de.tum.msrg.config.ConfigParserException; -import de.tum.msrg.config.Configuration; -import de.tum.msrg.sim.StatsCollector; -import de.tum.msrg.topology.Topology; -import org.junit.After; -import org.junit.Test; -import static org.junit.Assert.*; - -import java.io.IOException; - -/** - * Created by pxsalehi on 08.04.16. - */ -public class TestOverlayLink { - - private Configuration config; - private Topology topology; - private PSOverlay overlay; - PSBroker b0, b1, b2, b3, b4, b5; - int seed; - - public void setUp(boolean applyLinkBW) throws RuntimeSimException, ConfigParserException, IOException { -// seed = 8543546; -// config = new Configuration(new FileReader(Topologies.T01_DIR_PATH + "sim.config")); -// config.setProperty(ConfigKeys.SIM_APPLY_LINK_CONGESTION, applyLinkBW); -// topology = new Topology(new FileReader(Topologies.T01_DIR_PATH + "topology.txt")); -// overlay = new BaselineOverlay(config, topology, seed); -// overlay.initOverlay(); -// b0 = overlay.getBroker(0); b1 = overlay.getBroker(1); b2 = overlay.getBroker(2); -// b3 = overlay.getBroker(3); b4 = overlay.getBroker(4); b5 = overlay.getBroker(5); -// b0.setPubSubLoad(new PubSubNodeWload(b0.getNodeInfo())); -// b1.setPubSubLoad(new PubSubNodeWload(b1.getNodeInfo())); -// b2.setPubSubLoad(new PubSubNodeWload(b2.getNodeInfo())); -// b3.setPubSubLoad(new PubSubNodeWload(b3.getNodeInfo())); -// b4.setPubSubLoad(new PubSubNodeWload(b4.getNodeInfo())); -// b5.setPubSubLoad(new PubSubNodeWload(b5.getNodeInfo())); - } - - @After - public void tearDown() { - StatsCollector.reset(); - } - - @Test - public void testEqualUndirected() throws RuntimeSimException, IOException, ConfigParserException { - setUp(false); - OverlayLink b0tob1 = b0.getLinkTo(b1); - OverlayLink b1tob0 = b1.getLinkTo(b0); - OverlayLink b0tob2 = b0.getLinkTo(b2); - assertEquals(b0tob1, b1tob0); - assertFalse(b0tob1.equals(b0tob2)); - } - - @Test - public void testEqualDirected() throws RuntimeSimException, IOException, ConfigParserException { - setUp(true); - OverlayLink b0tob1 = b0.getLinkTo(b1); - OverlayLink b1tob0 = b1.getLinkTo(b0); - OverlayLink b0tob2 = b0.getLinkTo(b2); - assertFalse(b0tob1.equals(b1tob0)); - assertFalse(b0tob1.equals(b0tob2)); - } - - @Test - public void testHashCodeUndirected() throws RuntimeSimException, IOException, ConfigParserException { - setUp(false); - OverlayLink b0tob1 = b0.getLinkTo(b1); - OverlayLink b1tob0 = b1.getLinkTo(b0); - OverlayLink b0tob2 = b0.getLinkTo(b2); - assertTrue(b0tob1.hashCode() == b1tob0.hashCode()); - assertTrue(b0tob1.hashCode() != b0tob2.hashCode()); - } - - @Test - public void testHashCodeDirected() throws RuntimeSimException, IOException, ConfigParserException { - setUp(true); - OverlayLink b0tob1 = b0.getLinkTo(b1); - OverlayLink b1tob0 = b1.getLinkTo(b0); - OverlayLink b0tob2 = b0.getLinkTo(b2); - assertTrue(b0tob1.hashCode() != b1tob0.hashCode()); - assertTrue(b0tob1.hashCode() != b0tob2.hashCode()); - } -} diff --git a/src/test/java/de/tum/msrg/overlay/TestPubSubNodeWload.java b/src/test/java/de/tum/msrg/overlay/TestPubSubNodeWload.java deleted file mode 100644 index 62a6124..0000000 --- a/src/test/java/de/tum/msrg/overlay/TestPubSubNodeWload.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.tum.msrg.overlay; - -import static org.junit.Assert.*; - -import java.util.Arrays; - -import org.apache.commons.collections4.CollectionUtils; -import org.junit.Test; - -import de.tum.msrg.topology.NodeInfo; - -public class TestPubSubNodeWload { - - @Test - public void testEqual() { - NodeInfo n0 = new NodeInfo(0, 1); - NodeInfo n1 = new NodeInfo(1, 2); - NodeInfo n2 = new NodeInfo(2, 1); - assertFalse(CollectionUtils.isEqualCollection(Arrays.asList(n0, n1), Arrays.asList(n1, n2))); - assertTrue(CollectionUtils.isEqualCollection(Arrays.asList(n0, n1), Arrays.asList(n1, n0))); - } - -} diff --git a/src/test/java/de/tum/msrg/pubsub/TestBaseline.java b/src/test/java/de/tum/msrg/pubsub/TestBaseline.java deleted file mode 100644 index 3fb95b2..0000000 --- a/src/test/java/de/tum/msrg/pubsub/TestBaseline.java +++ /dev/null @@ -1,740 +0,0 @@ -package de.tum.msrg.pubsub; - -import de.tum.msrg.AllTests; -import de.tum.msrg.config.ConfigParserException; -import de.tum.msrg.config.Configuration; -import de.tum.msrg.message.PubMessage; -import de.tum.msrg.message.Publication; -import de.tum.msrg.overlay.BrokerBase; -import org.apache.commons.collections4.CollectionUtils; -import org.junit.After; -import org.junit.Before; -import de.tum.msrg.overlay.Router; -import de.tum.msrg.overlay.RuntimeSimException; -import de.tum.msrg.overlay.PubSubNodeWload; -import de.tum.msrg.sim.StatsCollector; -import de.tum.msrg.resources.topologies.Topologies; -import de.tum.msrg.topology.NodeInfo; -import de.tum.msrg.topology.Topology; - -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.junit.Test; -import de.tum.msrg.utils.Range; - -import static org.junit.Assert.*; - -public class TestBaseline { - private Configuration config; - private Topology topology; - private PSOverlay overlay; - PSBroker b0, b1, b2, b3, b4, b5; - int seed; - - @Before - public void setUp() throws RuntimeSimException, ConfigParserException, IOException { - seed = 8543546; - config = new Configuration(new FileReader(Topologies.T01_DIR_PATH + "sim.config")); - StatsCollector.reset(); - StatsCollector.getInstance().initialize(config.getIntConfig(ConfigKeys.SIM_NO_OF_NODES), - config.getIntConfig(ConfigKeys.WLOAD_NO_OF_CLASSES)); - topology = new Topology(new FileReader(Topologies.T01_DIR_PATH + "topology.txt")); - overlay = new PSOverlay(config, topology, seed); - overlay.initOverlay(); - b0 = overlay.getBroker(0); b1 = overlay.getBroker(1); b2 = overlay.getBroker(2); - b3 = overlay.getBroker(3); b4 = overlay.getBroker(4); b5 = overlay.getBroker(5); - b0.setPubSubLoad(new PubSubNodeWload(b0.getNodeInfo())); - b1.setPubSubLoad(new PubSubNodeWload(b1.getNodeInfo())); - b2.setPubSubLoad(new PubSubNodeWload(b2.getNodeInfo())); - b3.setPubSubLoad(new PubSubNodeWload(b3.getNodeInfo())); - b4.setPubSubLoad(new PubSubNodeWload(b4.getNodeInfo())); - b5.setPubSubLoad(new PubSubNodeWload(b5.getNodeInfo())); - } - - @After - public void tearDown() { - StatsCollector.reset(); - } - - @Test - public void testOverlayLinks() { - assertEquals(b2.getOverlayLinks().size(), 3); - assertEquals(b0.getOverlayLinks().size(), 2); - assertEquals(b1.getOverlayLinks().size(), 2); - assertEquals(b3.getOverlayLinks().size(), 1); - assertEquals(b4.getOverlayLinks().size(), 1); - assertEquals(b5.getOverlayLinks().size(), 1); - } - - @Test - public void testOverlayRoutes() throws IOException, ConfigParserException, RuntimeSimException { - // check overlay routing tables of - // b0 - assertNull(b0.getNextNodeToRoute(b0)); - assertEquals(b0.getNextNodeToRoute(b1), b1); - assertEquals(b0.getNextNodeToRoute(b2), b2); - assertEquals(b0.getNextNodeToRoute(b3), b1); - assertEquals(b0.getNextNodeToRoute(b4), b2); - assertEquals(b0.getNextNodeToRoute(b5), b2); - // b1 - assertEquals(b1.getNextNodeToRoute(b0), b0); - assertNull(b1.getNextNodeToRoute(b1)); - assertEquals(b1.getNextNodeToRoute(b2), b0); - assertEquals(b1.getNextNodeToRoute(b3), b3); - assertEquals(b1.getNextNodeToRoute(b4), b0); - assertEquals(b1.getNextNodeToRoute(b5), b0); - // b2 - assertEquals(b2.getNextNodeToRoute(b0), b0); - assertEquals(b2.getNextNodeToRoute(b1), b0); - assertNull(b2.getNextNodeToRoute(b2)); - assertEquals(b2.getNextNodeToRoute(b3), b0); - assertEquals(b2.getNextNodeToRoute(b4), b4); - assertEquals(b2.getNextNodeToRoute(b5), b5); - // b3 - assertEquals(b3.getNextNodeToRoute(b0), b1); - assertEquals(b3.getNextNodeToRoute(b1), b1); - assertEquals(b3.getNextNodeToRoute(b2), b1); - assertNull(b3.getNextNodeToRoute(b3)); - assertEquals(b3.getNextNodeToRoute(b4), b1); - assertEquals(b3.getNextNodeToRoute(b5), b1); - // b4 - assertEquals(b4.getNextNodeToRoute(b0), b2); - assertEquals(b4.getNextNodeToRoute(b1), b2); - assertEquals(b4.getNextNodeToRoute(b2), b2); - assertEquals(b4.getNextNodeToRoute(b3), b2); - assertNull(b4.getNextNodeToRoute(b4)); - assertEquals(b4.getNextNodeToRoute(b5), b2); - // b5 - assertEquals(b5.getNextNodeToRoute(b0), b2); - assertEquals(b5.getNextNodeToRoute(b1), b2); - assertEquals(b5.getNextNodeToRoute(b2), b2); - assertEquals(b5.getNextNodeToRoute(b3), b2); - assertEquals(b5.getNextNodeToRoute(b4), b2); - assertNull(b5.getNextNodeToRoute(b5)); - // check route latencies - assertEquals(b0.getLatency(b1), 52f, AllTests.ASSERT_DELTA); - assertEquals(b0.getLatency(b4), -1f, AllTests.ASSERT_DELTA); // no direct overlay route between b0 and b4 - } - - @Test - public void testGetNeighbors() { - assertTrue(CollectionUtils.isEqualCollection(b2.getNeighbors(), Arrays.asList(b0, b4, b5))); - assertTrue(CollectionUtils.isEqualCollection(b0.getNeighbors(), Arrays.asList(b1, b2))); - assertTrue(CollectionUtils.isEqualCollection(b4.getNeighbors(), Arrays.asList(b2))); - } - - @Test - public void testFindAllPaths() { - // after initOverlay all paths must have been found - assertNotNull(overlay.getAllPaths()); - List path = overlay.getPathSteps(b0, b0); - assertTrue(path.isEmpty()); - path = overlay.getPathSteps(b0, b1); - assertTrue(CollectionUtils.isEqualCollection(path, Arrays.asList(b0, b1))); - path = overlay.getPathSteps(b5, b4); - assertTrue(CollectionUtils.isEqualCollection(path, Arrays.asList(b5, b2, b4))); - path = overlay.getPathSteps(b5, b3); - assertTrue(CollectionUtils.isEqualCollection(path, Arrays.asList(b5, b2, b0, b1, b3))); - path = overlay.getPathSteps(b3, b5); - assertTrue(CollectionUtils.isEqualCollection(path, Arrays.asList(b3, b1, b0, b2, b5))); - } - - @Test - public void testB0Publish() throws RuntimeSimException { - // pub should go b0->b2->b4 - // check publishing from b0 to b4 - // create a pub - Publication p0 = new Publication(); - p0.setPubClass(0); - p0.setAttributes(new float[]{2.3f, 100f}); - p0.setSourceBroker(b0.getNodeInfo()); - // add subscriber - List subscribers = new ArrayList(); - subscribers.add(b4.getNodeInfo()); - p0.setSubscribers(subscribers); - // load pub - b0.getPubSubLoad().addPub(p0); - // start sim - overlay.getSimInterface().startSim(); - // check counters for messages - // received - assertEquals(b0.getMessagesReceived(), 0); - assertEquals(b1.getMessagesReceived(), 0); - assertEquals(b2.getMessagesReceived(), 1); - assertEquals(b3.getMessagesReceived(), 0); - assertEquals(b4.getMessagesReceived(), 1); - assertEquals(b5.getMessagesReceived(), 0); - // matched - assertEquals(b0.getMessagesDelivered(), 0); - assertEquals(b1.getMessagesDelivered(), 0); - assertEquals(b2.getMessagesDelivered(), 0); - assertEquals(b3.getMessagesDelivered(), 0); - assertEquals(b4.getMessagesDelivered(), 1); - assertEquals(b5.getMessagesDelivered(), 0); - // published - assertEquals(b0.getMessagesPublished(), 1); - assertEquals(b1.getMessagesPublished(), 0); - assertEquals(b2.getMessagesPublished(), 0); - assertEquals(b3.getMessagesPublished(), 0); - assertEquals(b4.getMessagesPublished(), 0); - assertEquals(b5.getMessagesPublished(), 0); - // sent - assertEquals(b0.getMessagesSent(), 1); - assertEquals(b1.getMessagesSent(), 0); - assertEquals(b2.getMessagesSent(), 1); - assertEquals(b3.getMessagesSent(), 0); - assertEquals(b4.getMessagesSent(), 0); - assertEquals(b5.getMessagesSent(), 0); - // check seen publications - assertTrue(CollectionUtils.isEqualCollection(b0.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b2.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b4.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertEquals(b1.getSeenPubIds().size(), 0); - assertEquals(b3.getSeenPubIds().size(), 0); - assertEquals(b5.getSeenPubIds().size(), 0); - // check statsCollector - assertEquals(StatsCollector.getInstance().getTotalDeliveredPubCount(), 1); - assertEquals(StatsCollector.getInstance().getTotalPublishedPubCount(), 1); - assertEquals(StatsCollector.getInstance().getTotalSentPubCount(), 2); - assertEquals(StatsCollector.getInstance().getAverageLatency(), 73, AllTests.ASSERT_DELTA); - assertEquals(StatsCollector.getInstance().getAverageHopCount(), 2, AllTests.ASSERT_DELTA); - } - - @Test - public void testIsDown() throws RuntimeSimException { - b1.addFailTrace(10, 20); - b1.addFailTrace(100, 150); - // check time range - assertTrue(b1.isDown(new Range(15f, 30f))); - assertTrue(b1.isDown(new Range(5f, 10f))); - assertTrue(b1.isDown(new Range(20f, 90f))); - assertFalse(b1.isDown(new Range(21f, 60f))); - assertFalse(b1.isDown(new Range(0f, 9.9f))); - // time point - assertTrue(b1.checkIsDown(15)); - assertTrue(b1.checkIsDown(10)); - assertTrue(b1.checkIsDown(20)); - assertFalse(b1.checkIsDown(9)); - assertFalse(b1.checkIsDown(21)); - // from another broker - assertTrue(b1.checkIsDown(b0, 0)); - assertTrue(b1.checkIsDown(b0, 10)); - assertTrue(b1.checkIsDown(b0, 20)); - assertFalse(b1.checkIsDown(b0, 21)); - assertFalse(b1.checkIsDown(b0, 40)); - assertFalse(b1.checkIsDown(b0, 47)); - assertTrue(b1.checkIsDown(b0, 48)); - } - - @Test(expected= RuntimeException.class) - public void testIsDownNotNeighbours() throws RuntimeSimException { - b1.checkIsDown(b4, 30); - } - - @Test - public void testIsDownWithoutGivingCurrTime() throws RuntimeSimException { - assertFalse(b1.isDown()); - b1.addFailTrace(0, 20); - assertTrue(b1.isDown()); - assertTrue(b1.isDown(b0)); - } - - //@Test(expected=RuntimeException.class) - public void testOverlappingDownTimes() { - b1.addFailTrace(10, 20); - b1.addFailTrace(20, 150); // this is ok - b1.addFailTrace(100, 190); - assertTrue(b1.checkIsDown(10)); - assertTrue(b1.checkIsDown(20)); - assertTrue(b1.checkIsDown(30)); - assertTrue(b1.checkIsDown(50)); - assertTrue(b1.checkIsDown(60)); - assertTrue(b1.checkIsDown(160)); - } - - @Test - public void testB0PublishB0IsDown() { - // pub should go b0->b2->b4 - b0.addFailTrace(0, 100); - // check publishing from b0 to b4, b0 is down - // create a pub - Publication p0 = new Publication(); - p0.setPubClass(0); - p0.setAttributes(new float[]{2.3f, 100f}); - p0.setSourceBroker(b0.getNodeInfo()); - // add subscriber - List subscribers = new ArrayList(); - subscribers.add(b4.getNodeInfo()); subscribers.add(b0.getNodeInfo()); - p0.setSubscribers(subscribers); - // load pub - b0.getPubSubLoad().addPub(p0); - // start sim - overlay.getSimInterface().startSim(); - // check counters for messages - // received - assertEquals(b0.getMessagesReceived(), 0); - assertEquals(b1.getMessagesReceived(), 0); - assertEquals(b2.getMessagesReceived(), 0); - assertEquals(b3.getMessagesReceived(), 0); - assertEquals(b4.getMessagesReceived(), 0); - assertEquals(b5.getMessagesReceived(), 0); - // matched - assertEquals(b0.getMessagesDelivered(), 0); - assertEquals(b0.getMessagesDeliveredToSelf(), 0); - assertEquals(b1.getMessagesDelivered(), 0); - assertEquals(b2.getMessagesDelivered(), 0); - assertEquals(b3.getMessagesDelivered(), 0); - assertEquals(b4.getMessagesDelivered(), 0); - assertEquals(b5.getMessagesDelivered(), 0); - // published - assertEquals(b0.getMessagesPublished(), 0); - assertEquals(b1.getMessagesPublished(), 0); - assertEquals(b2.getMessagesPublished(), 0); - assertEquals(b3.getMessagesPublished(), 0); - assertEquals(b4.getMessagesPublished(), 0); - assertEquals(b5.getMessagesPublished(), 0); - // sent - assertEquals(b0.getMessagesSent(), 0); - assertEquals(b1.getMessagesSent(), 0); - assertEquals(b2.getMessagesSent(), 0); - assertEquals(b3.getMessagesSent(), 0); - assertEquals(b4.getMessagesSent(), 0); - assertEquals(b5.getMessagesSent(), 0); - // check seen publications - assertEquals(b0.getSeenPubIds().size(), 0); - assertEquals(b2.getSeenPubIds().size(), 0); - assertEquals(b4.getSeenPubIds().size(), 0); - assertEquals(b1.getSeenPubIds().size(), 0); - assertEquals(b3.getSeenPubIds().size(), 0); - assertEquals(b5.getSeenPubIds().size(), 0); - // check statsCollector - assertEquals(StatsCollector.getInstance().getTotalDeliveredPubCount(), 0); - assertEquals(StatsCollector.getInstance().getTotalPublishedPubCount(), 0); - assertEquals(StatsCollector.getInstance().getTotalSentPubCount(), 0); - } - - @Test - public void testB0PublishB2IsDown() { - // pub should go b0->b2->b4 - b2.addFailTrace(0, 100); - // check publishing from b0 to b4, b0 is down - // create a pub - Publication p0 = new Publication(); - p0.setPubClass(0); - p0.setAttributes(new float[]{2.3f, 100f}); - p0.setSourceBroker(b0.getNodeInfo()); - // add subscriber - List subscribers = new ArrayList(); - subscribers.add(b4.getNodeInfo()); - p0.setSubscribers(subscribers); - // load pub - b0.getPubSubLoad().addPub(p0); - // start sim - overlay.getSimInterface().startSim(); - // check counters for messages - // received - assertEquals(b0.getMessagesReceived(), 0); - assertEquals(b1.getMessagesReceived(), 0); - assertEquals(b2.getMessagesReceived(), 0); - assertEquals(b3.getMessagesReceived(), 0); - assertEquals(b4.getMessagesReceived(), 0); - assertEquals(b5.getMessagesReceived(), 0); - // matched - assertEquals(b0.getMessagesDelivered(), 0); - assertEquals(b1.getMessagesDelivered(), 0); - assertEquals(b2.getMessagesDelivered(), 0); - assertEquals(b3.getMessagesDelivered(), 0); - assertEquals(b4.getMessagesDelivered(), 0); - assertEquals(b5.getMessagesDelivered(), 0); - // published - assertEquals(b0.getMessagesPublished(), 1); - assertEquals(b1.getMessagesPublished(), 0); - assertEquals(b2.getMessagesPublished(), 0); - assertEquals(b3.getMessagesPublished(), 0); - assertEquals(b4.getMessagesPublished(), 0); - assertEquals(b5.getMessagesPublished(), 0); - // sent - assertEquals(b0.getMessagesSent(), 0); - assertEquals(b1.getMessagesSent(), 0); - assertEquals(b2.getMessagesSent(), 0); - assertEquals(b3.getMessagesSent(), 0); - assertEquals(b4.getMessagesSent(), 0); - assertEquals(b5.getMessagesSent(), 0); - // check seen publications - assertTrue(CollectionUtils.isEqualCollection(b0.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertEquals(b2.getSeenPubIds().size(), 0); - assertEquals(b4.getSeenPubIds().size(), 0); - assertEquals(b1.getSeenPubIds().size(), 0); - assertEquals(b3.getSeenPubIds().size(), 0); - assertEquals(b5.getSeenPubIds().size(), 0); - // check statsCollector - assertEquals(StatsCollector.getInstance().getTotalDeliveredPubCount(), 0); - assertEquals(StatsCollector.getInstance().getTotalPublishedPubCount(), 1); - assertEquals(StatsCollector.getInstance().getTotalSentPubCount(), 0); - } - - @Test - public void testB0PublishB4IsDown() { - // pub should go b0->b2->b4 - b4.addFailTrace(0, 100); - // check publishing from b0 to b4, b0 is down - // create a pub - Publication p0 = new Publication(); - p0.setPubClass(0); - p0.setAttributes(new float[]{2.3f, 100f}); - p0.setSourceBroker(b0.getNodeInfo()); - // add subscriber - List subscribers = new ArrayList(); - subscribers.add(b4.getNodeInfo()); - p0.setSubscribers(subscribers); - // load pub - b0.getPubSubLoad().addPub(p0); - // start sim - overlay.getSimInterface().startSim(); - // check counters for messages - // received - assertEquals(b0.getMessagesReceived(), 0); - assertEquals(b1.getMessagesReceived(), 0); - assertEquals(b2.getMessagesReceived(), 1); - assertEquals(b3.getMessagesReceived(), 0); - assertEquals(b4.getMessagesReceived(), 0); - assertEquals(b5.getMessagesReceived(), 0); - // matched - assertEquals(b0.getMessagesDelivered(), 0); - assertEquals(b1.getMessagesDelivered(), 0); - assertEquals(b2.getMessagesDelivered(), 0); - assertEquals(b3.getMessagesDelivered(), 0); - assertEquals(b4.getMessagesDelivered(), 0); - assertEquals(b5.getMessagesDelivered(), 0); - // published - assertEquals(b0.getMessagesPublished(), 1); - assertEquals(b1.getMessagesPublished(), 0); - assertEquals(b2.getMessagesPublished(), 0); - assertEquals(b3.getMessagesPublished(), 0); - assertEquals(b4.getMessagesPublished(), 0); - assertEquals(b5.getMessagesPublished(), 0); - // sent - assertEquals(b0.getMessagesSent(), 1); - assertEquals(b1.getMessagesSent(), 0); - assertEquals(b2.getMessagesSent(), 0); - assertEquals(b3.getMessagesSent(), 0); - assertEquals(b4.getMessagesSent(), 0); - assertEquals(b5.getMessagesSent(), 0); - // check seen publications - assertTrue(CollectionUtils.isEqualCollection(b0.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b2.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertEquals(b4.getSeenPubIds().size(), 0); - assertEquals(b1.getSeenPubIds().size(), 0); - assertEquals(b3.getSeenPubIds().size(), 0); - assertEquals(b5.getSeenPubIds().size(), 0); - // check statsCollector - assertEquals(StatsCollector.getInstance().getTotalDeliveredPubCount(), 0); - assertEquals(StatsCollector.getInstance().getTotalPublishedPubCount(), 1); - assertEquals(StatsCollector.getInstance().getTotalSentPubCount(), 1); - } - - @Test - public void testB0PublishMultipleSubscribers() throws RuntimeSimException { - b1.addFailTrace(0, 100); - // create a pub - Publication p0 = new Publication(); - p0.setPubClass(0); - p0.setAttributes(new float[]{2.3f, 100f}); - p0.setSourceBroker(b5.getNodeInfo()); - // add subscriber - List subscribers = new ArrayList(); - subscribers.add(b5.getNodeInfo()); subscribers.add(b4.getNodeInfo()); subscribers.add(b3.getNodeInfo()); - p0.setSubscribers(subscribers); - // load pub - b5.getPubSubLoad().addPub(p0); - StatsCollector.getInstance().pubGenerated(p0, p0.getSourceBroker()); - // start sim - overlay.getSimInterface().startSim(); - // check counters for messages - // received - assertEquals(b0.getMessagesReceived(), 1); - assertEquals(b1.getMessagesReceived(), 0); - assertEquals(b2.getMessagesReceived(), 1); - assertEquals(b3.getMessagesReceived(), 0); - assertEquals(b4.getMessagesReceived(), 1); - assertEquals(b5.getMessagesReceived(), 0); - // matched - assertEquals(b0.getMessagesDelivered(), 0); - assertEquals(b1.getMessagesDelivered(), 0); - assertEquals(b2.getMessagesDelivered(), 0); - assertEquals(b3.getMessagesDelivered(), 0); - assertEquals(b4.getMessagesDelivered(), 1); - assertEquals(b5.getMessagesDelivered(), 1); - assertEquals(b5.getMessagesDeliveredToSelf(), 1); - // published - assertEquals(b0.getMessagesPublished(), 0); - assertEquals(b1.getMessagesPublished(), 0); - assertEquals(b2.getMessagesPublished(), 0); - assertEquals(b3.getMessagesPublished(), 0); - assertEquals(b4.getMessagesPublished(), 0); - assertEquals(b5.getMessagesPublished(), 1); - // sent - assertEquals(b0.getMessagesSent(), 0); - assertEquals(b1.getMessagesSent(), 0); - assertEquals(b2.getMessagesSent(), 2); - assertEquals(b3.getMessagesSent(), 0); - assertEquals(b4.getMessagesSent(), 0); - assertEquals(b5.getMessagesSent(), 1); - // check seen publications - assertTrue(CollectionUtils.isEqualCollection(b0.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b2.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b4.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertEquals(b1.getSeenPubIds().size(), 0); - assertEquals(b3.getSeenPubIds().size(), 0); - assertTrue(CollectionUtils.isEqualCollection(b5.getSeenPubIds(), Arrays.asList(p0.getId()))); - // check statsCollector - assertEquals(StatsCollector.getInstance().getTotalDeliveredPubCount(), 2); - assertEquals(StatsCollector.getInstance().getTotalPublishedPubCount(), 1); - assertEquals(StatsCollector.getInstance().getTotalSentPubCount(), 3); - assertEquals(StatsCollector.getInstance().getTotalSubscriptionMatchCount(), 3); - assertEquals(StatsCollector.getInstance().getAverageLatency(), (0 + 45) / 2f, AllTests.ASSERT_DELTA); - assertEquals(StatsCollector.getInstance().getAverageHopCount(), (0 + 2) / 2f, AllTests.ASSERT_DELTA); - assertEquals(StatsCollector.getInstance().getPubDeliveryRate(), 2f/3, AllTests.ASSERT_DELTA); - } - - @Test - public void testOnePublisherMultipleSubscribersNoFault() throws RuntimeSimException { - // create a pub - Publication p0 = new Publication(); - p0.setPubClass(0); - p0.setAttributes(new float[]{2.3f, 100f}); - p0.setSourceBroker(b5.getNodeInfo()); - // add subscriber - List subscribers = new ArrayList(); - subscribers.add(b5.getNodeInfo()); subscribers.add(b4.getNodeInfo()); subscribers.add(b3.getNodeInfo()); - p0.setSubscribers(subscribers); - // load pub - b5.getPubSubLoad().addPub(p0); - StatsCollector.getInstance().pubGenerated(p0, p0.getSourceBroker()); - // start sim - overlay.getSimInterface().startSim(); - // check counters for messages - // received - assertEquals(b0.getMessagesReceived(), 1); - assertEquals(b1.getMessagesReceived(), 1); - assertEquals(b2.getMessagesReceived(), 1); - assertEquals(b3.getMessagesReceived(), 1); - assertEquals(b4.getMessagesReceived(), 1); - assertEquals(b5.getMessagesReceived(), 0); - // matched - assertEquals(b0.getMessagesDelivered(), 0); - assertEquals(b1.getMessagesDelivered(), 0); - assertEquals(b2.getMessagesDelivered(), 0); - assertEquals(b3.getMessagesDelivered(), 1); - assertEquals(b4.getMessagesDelivered(), 1); - assertEquals(b5.getMessagesDelivered(), 1); - assertEquals(b5.getMessagesDeliveredToSelf(), 1); - // published - assertEquals(b0.getMessagesPublished(), 0); - assertEquals(b1.getMessagesPublished(), 0); - assertEquals(b2.getMessagesPublished(), 0); - assertEquals(b3.getMessagesPublished(), 0); - assertEquals(b4.getMessagesPublished(), 0); - assertEquals(b5.getMessagesPublished(), 1); - // sent - assertEquals(b0.getMessagesSent(), 1); - assertEquals(b1.getMessagesSent(), 1); - assertEquals(b2.getMessagesSent(), 2); - assertEquals(b3.getMessagesSent(), 0); - assertEquals(b4.getMessagesSent(), 0); - assertEquals(b5.getMessagesSent(), 1); - // check seen publications - assertTrue(CollectionUtils.isEqualCollection(b0.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b2.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b4.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b1.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b3.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b5.getSeenPubIds(), Arrays.asList(p0.getId()))); - // check statsCollector - assertEquals(StatsCollector.getInstance().getTotalDeliveredPubCount(), 3); - assertEquals(StatsCollector.getInstance().getTotalPublishedPubCount(), 1); - assertEquals(StatsCollector.getInstance().getTotalSentPubCount(), 5); - assertEquals(StatsCollector.getInstance().getTotalSubscriptionMatchCount(), 3); - assertEquals(StatsCollector.getInstance().getAverageLatency(), (0 + 45 + 220) / 3f, AllTests.ASSERT_DELTA); - assertEquals(StatsCollector.getInstance().getAverageHopCount(), (0 + 2 + 4) / 3f, AllTests.ASSERT_DELTA); - assertEquals(StatsCollector.getInstance().getPubDeliveryRate(), 1, AllTests.ASSERT_DELTA); - } - - @Test - public void testSeenPubsAreDropped() { - // create a pub - Publication p0 = new Publication(); - p0.setPubClass(0); - p0.setAttributes(new float[]{2.3f, 100f}); - p0.setSourceBroker(b5.getNodeInfo()); - // add subscriber - List subscribers = new ArrayList(); - subscribers.add(b5.getNodeInfo()); subscribers.add(b4.getNodeInfo()); subscribers.add(b3.getNodeInfo()); - p0.setSubscribers(subscribers); - // load pub - b5.getPubSubLoad().addPub(p0); - // start sim - overlay.getSimInterface().startSim(); - // try resending p0 - PubMessage p0m = new PubMessage(b5.getNodeInfo(), b2.getNodeInfo(), p0); - b2.getNodeSim().receiveMessage(p0m); - // check counters for messages - // received - assertEquals(b0.getMessagesReceived(), 1); - assertEquals(b1.getMessagesReceived(), 1); - assertEquals(b2.getMessagesReceived(), 2); // receives but drops - assertEquals(b3.getMessagesReceived(), 1); - assertEquals(b4.getMessagesReceived(), 1); - assertEquals(b5.getMessagesReceived(), 0); - // matched - assertEquals(b0.getMessagesDelivered(), 0); - assertEquals(b1.getMessagesDelivered(), 0); - assertEquals(b2.getMessagesDelivered(), 0); - assertEquals(b3.getMessagesDelivered(), 1); - assertEquals(b4.getMessagesDelivered(), 1); - assertEquals(b5.getMessagesDelivered(), 1); - assertEquals(b5.getMessagesDeliveredToSelf(), 1); - // published - assertEquals(b0.getMessagesPublished(), 0); - assertEquals(b1.getMessagesPublished(), 0); - assertEquals(b2.getMessagesPublished(), 0); - assertEquals(b3.getMessagesPublished(), 0); - assertEquals(b4.getMessagesPublished(), 0); - assertEquals(b5.getMessagesPublished(), 1); - // sent - assertEquals(b0.getMessagesSent(), 1); - assertEquals(b1.getMessagesSent(), 1); - assertEquals(b2.getMessagesSent(), 2); - assertEquals(b3.getMessagesSent(), 0); - assertEquals(b4.getMessagesSent(), 0); - assertEquals(b5.getMessagesSent(), 1); - // check seen publications - assertTrue(CollectionUtils.isEqualCollection(b0.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b2.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b4.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b1.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b3.getSeenPubIds(), Arrays.asList(p0.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b5.getSeenPubIds(), Arrays.asList(p0.getId()))); - // check messages dropped - assertEquals(b2.getMessagesDropped(), 1); - assertEquals(b5.getMessagesDropped(), 0); - assertEquals(b0.getMessagesDropped(), 0); - // check statsCollector - assertEquals(StatsCollector.getInstance().getTotalDeliveredPubCount(), 3); - assertEquals(StatsCollector.getInstance().getTotalPublishedPubCount(), 1); - assertEquals(StatsCollector.getInstance().getTotalSentPubCount(), 5); - assertEquals(StatsCollector.getInstance().getAverageLatency(), (0 + 45 + 220) / 3f, AllTests.ASSERT_DELTA); - assertEquals(StatsCollector.getInstance().getAverageHopCount(), (0 + 2 + 4) / 3f, AllTests.ASSERT_DELTA); - } - - @Test - public void testRouterAdvBased() throws RuntimeSimException { - Router.isAdvBased = true; - // create a pub - Publication p0 = new Publication(); - p0.setPubClass(0); - p0.setAttributes(new float[]{2.3f, 100f}); - // b5 is the publisher - p0.setSourceBroker(b5.getNodeInfo()); - // add subscriber - List subscribers = new ArrayList(); - // b5 and b3 are matching subscribers for this pub - subscribers.add(b5.getNodeInfo()); subscribers.add(b3.getNodeInfo()); - p0.setSubscribers(subscribers); - PubMessage p0m = new PubMessage(b5.getNodeInfo(), null, p0); - // in the following pubMsg equals, same id is used to make them equal - // in adv based, all except 4 should be able to route the pub - assertEquals(b4.getRouter().route(p0m).size(), 0); - assertTrue(CollectionUtils.isEqualCollection( - b5.getRouter().route(p0m), - Arrays.asList( - new PubMessage(b5.getNodeInfo(), b2.getNodeInfo(), p0, p0m.getId())))); - // on b2, router knows only about b3's sub since b5's sub is local - assertTrue(CollectionUtils.isEqualCollection( - b2.getRouter().route(p0m), - Arrays.asList( - new PubMessage(b2.getNodeInfo(), b0.getNodeInfo(), p0, p0m.getId())))); - // on b0, router knows only about b3's sub since b5's sub is local - assertTrue(CollectionUtils.isEqualCollection( - b2.getRouter().route(p0m), - Arrays.asList( - new PubMessage(b2.getNodeInfo(), b0.getNodeInfo(), p0, p0m.getId())))); - // b0 knows only about b3's sub - assertTrue(CollectionUtils.isEqualCollection( - b0.getRouter().route(p0m), - Arrays.asList( - new PubMessage(b0.getNodeInfo(), b1.getNodeInfo(), p0, p0m.getId())))); - // however, if b0 was the publisher(advertiser), it'd know about b3 and b5's subs - p0.setSourceBroker(b0.getNodeInfo()); - assertTrue(CollectionUtils.isEqualCollection( - b0.getRouter().route(p0m), - Arrays.asList( - new PubMessage(b0.getNodeInfo(), b1.getNodeInfo(), p0, p0m.getId()), - new PubMessage(b0.getNodeInfo(), b2.getNodeInfo(), p0, p0m.getId())))); - p0.setSourceBroker(b5.getNodeInfo()); - // b1 knows only about b3's sub - assertTrue(CollectionUtils.isEqualCollection( - b1.getRouter().route(p0m), - Arrays.asList( - new PubMessage(b1.getNodeInfo(), b3.getNodeInfo(), p0, p0m.getId())))); - // however, if b1 was the publisher(advertiser), it'd know about b3 and b5's subs - p0.setSourceBroker(b1.getNodeInfo()); - assertTrue(CollectionUtils.isEqualCollection( - b1.getRouter().route(p0m), - Arrays.asList( - new PubMessage(b1.getNodeInfo(), b3.getNodeInfo(), p0, p0m.getId()), - new PubMessage(b1.getNodeInfo(), b0.getNodeInfo(), p0, p0m.getId())))); - p0.setSourceBroker(b5.getNodeInfo()); - // b3 knows only about it's own local sub, therefore router knows no sub - assertEquals(b3.getRouter().route(p0m).size(), 0); - } - - @Test - public void testRouterSubBased() throws RuntimeSimException { - Router.isAdvBased = false; - // create a pub - Publication p0 = new Publication(); - p0.setPubClass(0); - p0.setAttributes(new float[]{2.3f, 100f}); - // b0 is the publisher - p0.setSourceBroker(b5.getNodeInfo()); - // add subscriber - List subscribers = new ArrayList(); - // b5 and b3 are matching subscribers for this pub - subscribers.add(b5.getNodeInfo()); subscribers.add(b3.getNodeInfo()); - p0.setSubscribers(subscribers); - PubMessage p0m = new PubMessage(b0.getNodeInfo(), null, p0); - // in sub based, all should be able to route the pub - assertTrue(CollectionUtils.isEqualCollection( - b0.getRouter().route(p0m), - Arrays.asList( - new PubMessage(b0.getNodeInfo(), b1.getNodeInfo(), p0, p0m.getId()), - new PubMessage(b0.getNodeInfo(), b2.getNodeInfo(), p0, p0m.getId())))); - assertTrue(CollectionUtils.isEqualCollection( - b1.getRouter().route(p0m), - Arrays.asList( - new PubMessage(b1.getNodeInfo(), b3.getNodeInfo(), p0, p0m.getId()), - new PubMessage(b1.getNodeInfo(), b0.getNodeInfo(), p0, p0m.getId())))); - assertTrue(CollectionUtils.isEqualCollection( - b2.getRouter().route(p0m), - Arrays.asList( - new PubMessage(b2.getNodeInfo(), b0.getNodeInfo(), p0, p0m.getId()), - new PubMessage(b2.getNodeInfo(), b5.getNodeInfo(), p0, p0m.getId())))); - assertTrue(CollectionUtils.isEqualCollection( - b3.getRouter().route(p0m), - Arrays.asList( - new PubMessage(b3.getNodeInfo(), b1.getNodeInfo(), p0, p0m.getId())))); - assertTrue(CollectionUtils.isEqualCollection( - b4.getRouter().route(p0m), - Arrays.asList( - new PubMessage(b4.getNodeInfo(), b2.getNodeInfo(), p0, p0m.getId())))); - assertTrue(CollectionUtils.isEqualCollection( - b5.getRouter().route(p0m), - Arrays.asList( - new PubMessage(b5.getNodeInfo(), b2.getNodeInfo(), p0, p0m.getId())))); - } -} diff --git a/src/test/java/de/tum/msrg/pubsub/TestBaselineWithBrokerOverloaded.java b/src/test/java/de/tum/msrg/pubsub/TestBaselineWithBrokerOverloaded.java deleted file mode 100644 index 425428c..0000000 --- a/src/test/java/de/tum/msrg/pubsub/TestBaselineWithBrokerOverloaded.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.tum.msrg.pubsub; - -import org.junit.Ignore; -import org.junit.Test; - -/** - * Created by pxsalehi on 08.04.16. - */ -public class TestBaselineWithBrokerOverloaded { - - @Test @Ignore - public void testBrokerOverloaded() { - } -} diff --git a/src/test/java/de/tum/msrg/pubsub/TestBaselineWithLinkCongestion.java b/src/test/java/de/tum/msrg/pubsub/TestBaselineWithLinkCongestion.java deleted file mode 100644 index 015e486..0000000 --- a/src/test/java/de/tum/msrg/pubsub/TestBaselineWithLinkCongestion.java +++ /dev/null @@ -1,138 +0,0 @@ -package de.tum.msrg.pubsub; - -import de.tum.msrg.AllTests; -import de.tum.msrg.config.Configuration; -import de.tum.msrg.message.Advertisement; -import de.tum.msrg.message.Publication; -import de.tum.msrg.message.Subscription; -import de.tum.msrg.sim.StatsCollector; -import de.tum.msrg.topology.NodeInfo; -import de.tum.msrg.topology.Topology; -import org.apache.commons.collections4.CollectionUtils; -import org.junit.After; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.*; - -public class TestBaselineWithLinkCongestion { - private Configuration config; - private Topology topology; - private PSOverlay overlay; - PSBroker b0, b1, b2, b3, b4, b5; - int seed; - -// @Before -// public void setUp() throws RuntimeSimException, ConfigParserException, IOException { -// seed = 8543546; -// config = new Configuration(new FileReader(Topologies.T01_DIR_PATH + "sim.config")); -// config.setProperty(ConfigKeys.SIM_APPLY_LINK_CONGESTION, true); -// Configuration.JistIsRunning = false; -// topology = new Topology(new FileReader(Topologies.T01_DIR_PATH + "topology.txt")); -// overlay = new BaselineOverlay(config, topology, seed); -// overlay.initOverlay(); -// b0 = overlay.getBroker(0); b1 = overlay.getBroker(1); b2 = overlay.getBroker(2); -// b3 = overlay.getBroker(3); b4 = overlay.getBroker(4); b5 = overlay.getBroker(5); -// b0.setPubSubLoad(new PubSubNodeWload(b0.getNodeInfo())); -// b1.setPubSubLoad(new PubSubNodeWload(b1.getNodeInfo())); -// b2.setPubSubLoad(new PubSubNodeWload(b2.getNodeInfo())); -// b3.setPubSubLoad(new PubSubNodeWload(b3.getNodeInfo())); -// b4.setPubSubLoad(new PubSubNodeWload(b4.getNodeInfo())); -// b5.setPubSubLoad(new PubSubNodeWload(b5.getNodeInfo())); -// } - - @After - public void tearDown() { - StatsCollector.reset(); - Advertisement.resetCounter(); - Subscription.resetCounter(); - Publication.resetCounter(); - } - - @Test - public void testOverlayLinks() { - assertEquals(b2.getOverlayLinks().size(), 3); - assertEquals(b0.getOverlayLinks().size(), 2); - assertEquals(b1.getOverlayLinks().size(), 2); - assertEquals(b3.getOverlayLinks().size(), 1); - assertEquals(b4.getOverlayLinks().size(), 1); - assertEquals(b5.getOverlayLinks().size(), 1); - } - - @Test @Ignore - public void testLinkCongestionT01PublishRateHigherThanLinkBW() { - // pub should go b0->b2->b4 - // check publishing from b0 to b4 - // create a pub - Publication p0 = new Publication(0, new float[]{2.3f, 100f}); - p0.setSourceBroker(b0.getNodeInfo()); - // add subscriber - List subscribers = new ArrayList(); - subscribers.add(b4.getNodeInfo()); - p0.setSubscribers(subscribers); - Publication p1 = p0.clonePub(), p2 = p0.clonePub(), p3 = p0.clonePub(), p4 = p0.clonePub(), p5 = p0.clonePub(); - // load pub - b0.getPubSubLoad().addPub(p0); - b0.getPubSubLoad().addPub(p1); - b0.getPubSubLoad().addPub(p2); - b0.getPubSubLoad().addPub(p3); - b0.getPubSubLoad().addPub(p4); - b0.getPubSubLoad().addPub(p5); - b0.getPubSubLoad().setPubInterval(250); - // start sim - overlay.getSimInterface().startSim(); - // check counters for messages - // published - assertEquals(b0.getMessagesPublished(), 6); - assertEquals(b1.getMessagesPublished(), 0); - assertEquals(b2.getMessagesPublished(), 0); - assertEquals(b3.getMessagesPublished(), 0); - assertEquals(b4.getMessagesPublished(), 0); - assertEquals(b5.getMessagesPublished(), 0); - // sent - assertEquals(b0.getMessagesSent(), 6); - assertEquals(b1.getMessagesSent(), 0); - assertEquals(b2.getMessagesSent(), 6); - assertEquals(b3.getMessagesSent(), 0); - assertEquals(b4.getMessagesSent(), 0); - assertEquals(b5.getMessagesSent(), 0); - // received - assertEquals(b0.getMessagesReceived(), 0); - assertEquals(b1.getMessagesReceived(), 0); - assertEquals(b2.getMessagesReceived(), 6); - assertEquals(b3.getMessagesReceived(), 0); - assertEquals(b4.getMessagesReceived(), 6); - assertEquals(b5.getMessagesReceived(), 0); - // matched - assertEquals(b0.getMessagesDelivered(), 0); - assertEquals(b1.getMessagesDelivered(), 0); - assertEquals(b2.getMessagesDelivered(), 0); - assertEquals(b3.getMessagesDelivered(), 0); - assertEquals(b4.getMessagesDelivered(), 6); - assertEquals(b5.getMessagesDelivered(), 0); - // check seen publications - assertTrue(CollectionUtils.isEqualCollection(b0.getSeenPubIds(), Arrays.asList( - p0.getId(), p1.getId(), p2.getId(), p3.getId(), p4.getId(), p5.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b2.getSeenPubIds(), Arrays.asList( - p0.getId(), p1.getId(), p2.getId(), p3.getId(), p4.getId(), p5.getId()))); - assertTrue(CollectionUtils.isEqualCollection(b4.getSeenPubIds(), Arrays.asList( - p0.getId(), p1.getId(), p2.getId(), p3.getId(), p4.getId(), p5.getId()))); - assertEquals(b1.getSeenPubIds().size(), 0); - assertEquals(b3.getSeenPubIds().size(), 0); - assertEquals(b5.getSeenPubIds().size(), 0); - // check statsCollector - assertEquals(StatsCollector.getInstance().getTotalDeliveredPubCount(), 6); - assertEquals(StatsCollector.getInstance().getTotalPublishedPubCount(), 6); - assertEquals(StatsCollector.getInstance().getTotalSentPubCount(), 12); - assertEquals(StatsCollector.getInstance().getAverageLatency(), 73, AllTests.ASSERT_DELTA); - assertEquals(StatsCollector.getInstance().getAverageHopCount(), 2, AllTests.ASSERT_DELTA); - } - - @Test @Ignore - public void testLinkCongestionPerDirection() { - } -} diff --git a/src/test/java/de/tum/msrg/pubsub/TestSim.java b/src/test/java/de/tum/msrg/pubsub/TestSim.java deleted file mode 100644 index e06910d..0000000 --- a/src/test/java/de/tum/msrg/pubsub/TestSim.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.tum.msrg.pubsub; - -/** - * Created by pxsalehi on 21.12.15. - * - * Testing a simulation running under Jist - * Cannot run in JUnit - */ -public class TestSim { -} diff --git a/src/test/java/de/tum/msrg/resources/configs/Configurations.java b/src/test/java/de/tum/msrg/resources/configs/Configurations.java deleted file mode 100644 index b75bcec..0000000 --- a/src/test/java/de/tum/msrg/resources/configs/Configurations.java +++ /dev/null @@ -1,8 +0,0 @@ -package de.tum.msrg.resources.configs; - -/** - * Created by pxsalehi on 13.01.17. - */ -public class Configurations { - public static String SAMPLE_CONF1_PATH = "src/test/java/de/tum/msrg/resources/configs/c1.config"; -} diff --git a/src/test/java/de/tum/msrg/resources/configs/c1.config b/src/test/java/de/tum/msrg/resources/configs/c1.config deleted file mode 100644 index ac42dab..0000000 --- a/src/test/java/de/tum/msrg/resources/configs/c1.config +++ /dev/null @@ -1,65 +0,0 @@ -[simulation] -adv_based = true -no_of_nodes = 6 -no_of_subs = 6 -no_of_advs = 6 -no_of_pubs = 10 -; publication interval is in milliseconds -pub_interval = 1000 -; when to start publishing (each node will send its first pub at this time) -start_publish_time = 2 -max_simulation_time = 500000 -apply_link_congestion = true -apply_node_congestion = false -; pub rate sampling interval -rate_sample_interval = 1000 -; comm monitor run interval -comm_monitor_run_interval = 1000 - -[gossip] -min_gossip_latency = 10 -max_gossip_latency = 80 -fault_detection = true -subs_max_size = 1000 -unsubs_max_size = 1000 -events_max_size = 10000 -event_ids_max_size = 10000 -retrieves_max_size = 1000 -rounds_to_wait_before_retrieve = 6 -run_interval = 2000 -view_size = 6 -fanout = 3 -gossip_per_topic = true -allow_midpath_switch = true - - -[network] -; for random generator -seed = 274994310 - -[workload] -no_of_classes = 4 -no_of_attributes = 3 -attribute_min_value = 0 -attribute_max_value = 1000 -class_popularity_dist = zipf -zipf_exponent = 0.7 -; number between 0-100; 0 -> pref class never selected; 100 -> pref class always selected -pref_class_bias = 80 -pref_class_same = true -; allowed values: UNIFORM, ZIPF -attribute_value_dist = ZIPF -attribute_std_dev_factor = 2 -; allowed values: GAUSIAN, UNIFORM -sub_over_nodes_dist = UNIFORM -sub_over_nodes_std_dev_factor = 2 -adv_over_nodes_dist = UNIFORM -adv_over_nodes_std_dev_factor = 2 -pub_over_nodes_dist = UNIFORM -pub_over_nodes_std_dev_factor = 2 -; whether only leaf nodes act as client (LEAVES) or all nodes (ALL) or a specified list of ids(LIST) -pub_nodes = ALL -pub_nodes_list = 11,13,6 -sub_nodes = ALL -sub_nodes_list = 11,13,6 -load_faults = false diff --git a/src/test/java/de/tum/msrg/resources/topologies/Topologies.java b/src/test/java/de/tum/msrg/resources/topologies/Topologies.java deleted file mode 100644 index 6cadce9..0000000 --- a/src/test/java/de/tum/msrg/resources/topologies/Topologies.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.tum.msrg.resources.topologies; - -/** - * Created by pxsalehi on 11.01.16. - */ -public class Topologies { - public static String T01_DIR_PATH = "src/test/java/de/tum/msrg/resources/topologies/t01_6brokers/"; - public static String T02_DIR_PATH = "src/test/java/de/tum/msrg/resources/topologies/t02_10brokers/"; -/* -t01: -.---1---3 -0---2---4 - '---5 - - -t02: - ,--------3 - .--1--(10)--4--(53)--7--(38)--9 -0---2--------6--------8 - '--------5 -*/ -} diff --git a/src/test/java/de/tum/msrg/resources/topologies/t01_6brokers/sim.config b/src/test/java/de/tum/msrg/resources/topologies/t01_6brokers/sim.config deleted file mode 100755 index 4f0fa38..0000000 --- a/src/test/java/de/tum/msrg/resources/topologies/t01_6brokers/sim.config +++ /dev/null @@ -1,47 +0,0 @@ -[simulation] -adv_based = true -no_of_nodes = 6 -no_of_subs = 6 -no_of_advs = 6 -no_of_pubs = 60 -; publication interval is in milliseconds -pub_interval = 1000 -; when to start publishing (each node will send its first pub at this time) -start_publish_time = 0 -max_simulation_time = 100000 -apply_link_congestion = false -apply_node_congestion = false - -[gossip] -min_gossip_latency = 20 -max_gossip_latency = 60 -fault_detection = true - -[network] -; for random generator -seed = 123456789 - -[workload] -no_of_classes = 10 -no_of_attributes = 3 -attribute_min_value = 0 -attribute_max_value = 1000 -zipf_exponent = 0.7 -; number between 0-100; 0 -> pref class never selected; 100 -> pref class always selected -pref_class_bias = 80 -pref_class_same = true -; allowed values: UNIFORM, ZIPF -attribute_value_dist = ZIPF -attribute_std_dev_factor = 3 -; allowed values: GAUSIAN, UNIFORM -sub_over_nodes_dist = UNIFORM -sub_over_nodes_std_dev_factor = 3 -adv_over_nodes_dist = UNIFORM -adv_over_nodes_std_dev_factor = 3 -pub_over_nodes_dist = UNIFORM -pub_over_nodes_std_dev_factor = 3 -; whether only leaf nodes act as client (LEAVES) or all nodes (ALL) or a specified list of ids(LIST) -pub_nodes = ALL -; pub_nodes_list = 1,2,... -sub_nodes = ALL -; sub_nodes_list = 1,2,... diff --git a/src/test/java/de/tum/msrg/resources/topologies/t01_6brokers/topology.txt b/src/test/java/de/tum/msrg/resources/topologies/t01_6brokers/topology.txt deleted file mode 100755 index b7ef8a1..0000000 --- a/src/test/java/de/tum/msrg/resources/topologies/t01_6brokers/topology.txt +++ /dev/null @@ -1,18 +0,0 @@ -No of nodes:6 -No of edges:5 - -Nodes: -0 2 -1 2 -2 3 -3 1 -4 1 -5 1 - -Edges: -0 0 1 52 5 -1 0 2 63 5 -2 1 3 70 5 -3 2 4 10 5 -4 2 5 35 5 - diff --git a/src/test/java/de/tum/msrg/resources/topologies/t02_10brokers/sim.config b/src/test/java/de/tum/msrg/resources/topologies/t02_10brokers/sim.config deleted file mode 100755 index b745a2b..0000000 --- a/src/test/java/de/tum/msrg/resources/topologies/t02_10brokers/sim.config +++ /dev/null @@ -1,47 +0,0 @@ -[simulation] -adv_based = true -no_of_nodes = 10 -no_of_subs = 10 -no_of_advs = 10 -no_of_pubs = 100 -; publication interval is in milliseconds -pub_interval = 1000 -; when to start publishing (each node will send its first pub at this time) -start_publish_time = 0 -max_simulation_time = 100000 -apply_link_congestion = false -apply_node_congestion = false - -[gossip] -min_gossip_latency = 20 -max_gossip_latency = 60 -fault_detection = true - -[network] -; for random generator -seed = 123456789 - -[workload] -no_of_classes = 10 -no_of_attributes = 3 -attribute_min_value = 0 -attribute_max_value = 1000 -zipf_exponent = 0.7 -; number between 0-100; 0 -> pref class never selected; 100 -> pref class always selected -pref_class_bias = 80 -pref_class_same = true -; allowed values: UNIFORM, ZIPF -attribute_value_dist = ZIPF -attribute_std_dev_factor = 3 -; allowed values: GAUSIAN, UNIFORM -sub_over_nodes_dist = UNIFORM -sub_over_nodes_std_dev_factor = 3 -adv_over_nodes_dist = UNIFORM -adv_over_nodes_std_dev_factor = 3 -pub_over_nodes_dist = UNIFORM -pub_over_nodes_std_dev_factor = 3 -; whether only leaf nodes act as client (LEAVES) or all nodes (ALL) or a specified list of ids(LIST) -pub_nodes = ALL -; pub_nodes_list = 1,2,... -sub_nodes = ALL -; sub_nodes_list = 1,2,... diff --git a/src/test/java/de/tum/msrg/resources/topologies/t02_10brokers/topology.txt b/src/test/java/de/tum/msrg/resources/topologies/t02_10brokers/topology.txt deleted file mode 100755 index 2cb7b3c..0000000 --- a/src/test/java/de/tum/msrg/resources/topologies/t02_10brokers/topology.txt +++ /dev/null @@ -1,25 +0,0 @@ -No of nodes:10 -No of edges:9 - -Nodes: -0 2 -1 3 -2 3 -3 1 -4 2 -5 1 -6 2 -7 2 -8 1 -9 1 - -Edges: -0 0 1 52 -1 0 2 63 -2 1 3 70 -3 1 4 10 -4 2 5 35 -5 2 6 41 -6 4 7 53 -7 6 8 13 -8 7 9 38 diff --git a/src/test/java/de/tum/msrg/sim/TestWorkloadGenerator.java b/src/test/java/de/tum/msrg/sim/TestWorkloadGenerator.java deleted file mode 100644 index 0f17fee..0000000 --- a/src/test/java/de/tum/msrg/sim/TestWorkloadGenerator.java +++ /dev/null @@ -1,354 +0,0 @@ -package de.tum.msrg.sim; - -import de.tum.msrg.pubsub.ConfigKeys; -import de.tum.msrg.config.ConfigParserException; -import de.tum.msrg.config.Configuration; -import de.tum.msrg.message.Advertisement; -import de.tum.msrg.message.Attribute; -import de.tum.msrg.message.Attribute.Operator; -import de.tum.msrg.message.Publication; -import de.tum.msrg.message.Subscription; -import de.tum.msrg.resources.configs.Configurations; -import org.apache.commons.collections4.CollectionUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import de.tum.msrg.overlay.RuntimeSimException; -import de.tum.msrg.overlay.PubSubNodeWload; -import de.tum.msrg.sim.WorkloadGenerator.ClientNodeType; -import de.tum.msrg.sim.WorkloadGenerator.DistType; -import de.tum.msrg.topology.EdgeInfo; -import de.tum.msrg.topology.NodeInfo; -import de.tum.msrg.topology.Topology; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -public class TestWorkloadGenerator { - /** - * .--1---3 - * 0---+--2---4 - * '--5 - */ - private NodeInfo n0 = new NodeInfo(0, 2); - private NodeInfo n1 = new NodeInfo(1, 2); - private NodeInfo n2 = new NodeInfo(2, 3); - private NodeInfo n3 = new NodeInfo(3, 1); - private NodeInfo n4 = new NodeInfo(4, 1); - private NodeInfo n5 = new NodeInfo(5, 1); - private EdgeInfo e0 = new EdgeInfo(0, n0, n1, 52); - private EdgeInfo e1 = new EdgeInfo(1, n0, n2, 63); - private EdgeInfo e2 = new EdgeInfo(2, n1, n3, 70); - private EdgeInfo e3 = new EdgeInfo(3, n2, n4, 10); - private EdgeInfo e4 = new EdgeInfo(4, n2, n5, 35); - private Topology topology; - private long seed = 54987001; - private String configStr; -// private String configStr = "[simulation] \n" -// + "no_of_advs = 6 \n" -// + "no_of_subs = 6 \n" -// + "no_of_pubs = 10 \n" -// + "pub_interval = 1000 \n" -// + "[workload] \n" -// + "no_of_classes = 4 \n" -// + "no_of_attributes = 3 \n" -// + "attribute_min_value = 0 \n" -// + "attribute_max_value = 1000 \n" -// + "zipf_exponent = 0.7 \n" -// + "pref_class_bias = 80 \n" -// + "pref_class_same = true \n" -// + "attribute_value_dist = ZIPF \n" -// + "attribute_std_dev_factor = 2 \n" -// + "sub_over_nodes_dist = UNIFORM \n" -// + "sub_over_nodes_std_dev_factor = 2 \n" -// + "adv_over_nodes_dist = UNIFORM \n" -// + "adv_over_nodes_std_dev_factor = 2 \n" -// + "pub_over_nodes_dist = UNIFORM \n" -// + "pub_over_nodes_std_dev_factor = 2 \n" -// + "pub_nodes = ALL \n" -// + "pub_nodes_list = 11,13,6 \n" -// + "sub_nodes = ALL \n" -// + "sub_nodes_list = 11,13,6 \n"; - - @Before - public void setUp() throws ConfigParserException, IOException { - topology = new Topology(new NodeInfo[] {n0, n1, n2, n3, n4, n5}, - new EdgeInfo[] {e0, e1, e2, e3, e4}); - configStr = ""; - BufferedReader conf = new BufferedReader(new FileReader(Configurations.SAMPLE_CONF1_PATH)); - String l = conf.readLine(); - while(l != null) { - configStr += l + "\n"; - l = conf.readLine(); - } - } - - @After - public void tearDown() { - StatsCollector.reset(); - } - - @Ignore @Test(expected= RuntimeSimException.class) - public void testNotEnoughSubs() throws ConfigParserException, RuntimeSimException, IOException { - Configuration config = new Configuration(configStr); - // six nodes but 4 subs - config.setProperty(ConfigKeys.SIM_NO_OF_SUBS, 4); - WorkloadGenerator wlgen = new WorkloadGenerator(config, topology, seed); - wlgen.generate(); - } - - @Ignore @Test(expected= RuntimeSimException.class) - public void testNotEnoughAdvs() throws ConfigParserException, RuntimeSimException, IOException { - Configuration config = new Configuration(configStr); - // six nodes but 4 advs - config.setProperty(ConfigKeys.SIM_NO_OF_ADVS, 4); - WorkloadGenerator wlgen = new WorkloadGenerator(config, topology, seed); - wlgen.generate(); - } - - @Test @Ignore - public void testNotEnoughPubs() throws ConfigParserException, RuntimeSimException, IOException { - Configuration config = new Configuration(configStr); - // six nodes but 4 pubs - config.setProperty(ConfigKeys.SIM_NO_OF_PUBS, 4); - WorkloadGenerator wlgen = new WorkloadGenerator(config, topology, seed); - wlgen.generate(); - } - - @Test - public void testConstructorLeafClients() throws ConfigParserException, IOException { - Configuration config = new Configuration(configStr); - config.setProperty(ConfigKeys.WLOAD_PUB_NODES, ClientNodeType.LEAVES); - config.setProperty(ConfigKeys.WLOAD_SUB_NODES, ClientNodeType.LEAVES); - WorkloadGenerator wlgen = new WorkloadGenerator(config, topology, seed); - PubSubNodeWload[] clients = {new PubSubNodeWload(n3), new PubSubNodeWload(n4), new PubSubNodeWload(n5)}; - assertTrue(CollectionUtils.isEqualCollection(wlgen.getWorkload(), Arrays.asList(clients))); - } - - @Ignore @Test - public void testConstructorAllClients() throws ConfigParserException, RuntimeSimException, IOException { - Configuration config = new Configuration(configStr); - StatsCollector.getInstance().initialize(config.getIntConfig(ConfigKeys.SIM_NO_OF_NODES), - config.getIntConfig(ConfigKeys.WLOAD_NO_OF_CLASSES)); - WorkloadGenerator wlgen = new WorkloadGenerator(config, topology, seed); - assertEquals(wlgen.getNoOfAdvs(), 6); - assertEquals(wlgen.getNoOfSubs(), 6); - assertEquals(wlgen.getNoOfPubs(), 10); - assertEquals(wlgen.getPublicationInterval(), 1000); - assertEquals(wlgen.getNoOfClasses(), 4); - assertEquals(Attribute.noOfAttributes, 3); - assertEquals(wlgen.getAttDistOverSubs(), DistType.ZIPF); - assertEquals(wlgen.getPubNodeType(), ClientNodeType.ALL); - PubSubNodeWload[] clients = {new PubSubNodeWload(n0), new PubSubNodeWload(n1), - new PubSubNodeWload(n2), new PubSubNodeWload(n3), - new PubSubNodeWload(n4), new PubSubNodeWload(n5)}; - assertTrue(CollectionUtils.isEqualCollection(wlgen.getWorkload(), Arrays.asList(clients))); - wlgen.generate(); - List wload = wlgen.getWorkload(); - assertEquals(StatsCollector.getInstance().getTotalGeneratedPubCount(), 10); - //System.out.println(String.format("-> In test %s:", "testConstructorAllClients()")); - for(PubSubNodeWload client: wload) { - // at least one pub per client since at least one adv per client? - //System.out.println(String.format("N%d has %d pubs.", - // client.getBroker().getEventid(), client.getPubs().size())); - assertTrue(client.getSubs().size() >= 1); - assertTrue(client.getAdvs().size() >= 1); - assertEquals(client.getPubInterval(), 1000); - for(Advertisement adv: client.getAdvs()) { - assertEquals(adv.getAttributes().length, 3); - for(Attribute att: adv.getAttributes()) { - assertTrue(att.lowVal >= 0); - assertTrue(att.highVal <= 1000); - } - } - for(Subscription sub: client.getSubs()) { - assertEquals(sub.getAttributes().length, 3); - for(Attribute att: sub.getAttributes()) { - assertTrue(att.lowVal >= 0); - assertTrue(att.highVal <= 1000); - } - } - for(Publication pub: client.getPubs()) { - assertEquals(pub.getAttributes().length, 3); - for(int i = 0; i < pub.getAttributes().length; ++i) { - float att = pub.getAttributes()[i]; - assertTrue(att >= pub.getMatchingAdv().getAttributes()[i].lowVal); - assertTrue(att <= pub.getMatchingAdv().getAttributes()[i].highVal); - } - } - } - } - - @Test @Ignore - public void testPerformMatchingOnePubOneSubMatch() throws ConfigParserException, IOException, RuntimeSimException { - Configuration config = new Configuration(configStr); - config.setProperty(ConfigKeys.SIM_NO_OF_SUBS, 1); - config.setProperty(ConfigKeys.SIM_NO_OF_PUBS, 1); - config.setProperty(ConfigKeys.WLOAD_NO_OF_CLASSES, 2); - config.setProperty(ConfigKeys.WLOAD_NO_OF_ATTRIBUTES, 2); - WorkloadGenerator wlgen = new WorkloadGenerator(config, topology, seed); - PubSubNodeWload n0Wload = new PubSubNodeWload(n0); - PubSubNodeWload n2Wload = new PubSubNodeWload(n2); - /** - * p1: { 0, 10 , 421 } matches s1 - * s1: { 0, x <= 10 , 90 <= y <= 421 } - */ - Publication p1 = new Publication(0, new float[]{10f, 421f}); - Subscription s1 = new Subscription(0, new Attribute[]{ - new Attribute(Operator.LESS_THAN, Attribute.lowRange, 10f), - new Attribute(Operator.RANGE, 90f, 421f)}); - n0Wload.addPub(p1); - n2Wload.addSub(s1); - wlgen.performMatching(Arrays.asList(n0Wload, n2Wload)); - assertEquals(p1.getSubscribers().size(), 1); - assertEquals(p1.getMatchingSubscriptions().size(), 1); - assertTrue(CollectionUtils.isEqualCollection(p1.getMatchingSubscriptions(), - Arrays.asList(s1.getID()))); - assertTrue(CollectionUtils.isEqualCollection(p1.getSubscribers(), Arrays.asList(n2))); - } - - @Test - public void testPerformMatchingOnePubTwoSubMatch() throws ConfigParserException, IOException, RuntimeSimException { - Configuration config = new Configuration(configStr); - config.setProperty(ConfigKeys.SIM_NO_OF_SUBS, 2); - config.setProperty(ConfigKeys.SIM_NO_OF_PUBS, 1); - config.setProperty(ConfigKeys.WLOAD_NO_OF_CLASSES, 4); - config.setProperty(ConfigKeys.WLOAD_NO_OF_ATTRIBUTES, 2); - WorkloadGenerator wlgen = new WorkloadGenerator(config, topology, seed); - PubSubNodeWload n0Wload = new PubSubNodeWload(n0); - PubSubNodeWload n2Wload = new PubSubNodeWload(n2); - PubSubNodeWload n3Wload = new PubSubNodeWload(n3); - /** - * p1: { 0, 1 , 99 } matches s1, s2 - * - * s1: { 0, x <= 10 , 90 <= y <= 421 } - * s2: { 0, 1 <= x <= 2 , y >= 90] } - */ - Publication p1 = new Publication(0, new float[]{1f, 99f}); - Subscription s1 = new Subscription(0, new Attribute[]{ - new Attribute(Operator.LESS_THAN, Attribute.lowRange, 10f), - new Attribute(Operator.RANGE, 90f, 421f)}); - Subscription s2 = new Subscription(0, new Attribute[]{ - new Attribute(Operator.RANGE, 1f, 2f), - new Attribute(Operator.GREATER_THAN, 90f, Attribute.highRange)}); - n0Wload.addPub(p1); - n2Wload.addSub(s1); - n3Wload.addSub(s2); - wlgen.performMatching(Arrays.asList(n0Wload, n2Wload, n3Wload)); - assertEquals(p1.getSubscribers().size(), 2); - assertEquals(p1.getMatchingSubscriptions().size(), 2); - assertTrue(CollectionUtils.isEqualCollection(p1.getMatchingSubscriptions(), - Arrays.asList(s1.getID(), s2.getID()))); - assertTrue(CollectionUtils.isEqualCollection(p1.getSubscribers(), Arrays.asList(n2, n3))); - } - - @Test - public void testPerformMatchingFourPubFourSubMix() throws ConfigParserException, IOException, RuntimeSimException { - Configuration config = new Configuration(configStr); - config.setProperty(ConfigKeys.SIM_NO_OF_SUBS, 4); - config.setProperty(ConfigKeys.SIM_NO_OF_PUBS, 4); - config.setProperty(ConfigKeys.WLOAD_NO_OF_CLASSES, 4); - config.setProperty(ConfigKeys.WLOAD_NO_OF_ATTRIBUTES, 2); - WorkloadGenerator wlgen = new WorkloadGenerator(config, topology, seed); - PubSubNodeWload n0Wload = new PubSubNodeWload(n0); - PubSubNodeWload n2Wload = new PubSubNodeWload(n2); - PubSubNodeWload n3Wload = new PubSubNodeWload(n3); - PubSubNodeWload n4Wload = new PubSubNodeWload(n4); - PubSubNodeWload n5Wload = new PubSubNodeWload(n5); - /** - * p1: { 0, 10 , 421 } matches s1 - * p2: { 0, 1 , 99 } matches s1, s3 - * p3: { 1, 500, 99.8 } matches s2 - * p4: { 2, 89, 900.5 } matches nothing - * - * s1: { 0, x <= 10 , 90 <= y <= 421 } - * s2: { 1, 300 <= x <= 600 , 90 <= y <= 100] } - * s3: { 0, 1 <= x <= 2 , y >= 90] } - * s4: { 3, *, * } - */ - Publication p1 = new Publication(0, new float[]{10f, 421f}); - Publication p2 = new Publication(0, new float[]{1f, 99f}); - Publication p3 = new Publication(1, new float[]{500f, 99.8f}); - Publication p4 = new Publication(2, new float[]{89f, 900.5f}); - Subscription s1 = new Subscription(0, new Attribute[]{ - new Attribute(Operator.LESS_THAN, Attribute.lowRange, 10f), - new Attribute(Operator.RANGE, 90f, 421f)}); - Subscription s2 = new Subscription(1, new Attribute[]{ - new Attribute(Operator.RANGE, 300f, 600f), - new Attribute(Operator.RANGE, 90f, 100f)}); - Subscription s3 = new Subscription(0, new Attribute[]{ - new Attribute(Operator.RANGE, 1f, 2f), - new Attribute(Operator.GREATER_THAN, 90f, Attribute.highRange)}); - Subscription s4 = new Subscription(3, new Attribute[]{ - new Attribute(Operator.RANGE, Attribute.lowRange, Attribute.highRange), - new Attribute(Operator.RANGE, Attribute.lowRange, Attribute.highRange)}); - n0Wload.addPub(p1); - n0Wload.addPub(p2); - n4Wload.addPub(p3); - n5Wload.addPub(p4); - n2Wload.addSub(s1); - n2Wload.addSub(s3); - n3Wload.addSub(s2); - n0Wload.addSub(s4); - wlgen.performMatching(Arrays.asList(n0Wload, n2Wload, n3Wload, n4Wload, n5Wload)); - - assertEquals(p1.getSubscribers().size(), 1); - assertEquals(p1.getMatchingSubscriptions().size(), 1); - assertTrue(CollectionUtils.isEqualCollection(p1.getMatchingSubscriptions(), Arrays.asList(s1.getID()))); - assertTrue(CollectionUtils.isEqualCollection(p1.getSubscribers(), Arrays.asList(n2))); - - assertEquals(p2.getSubscribers().size(), 1); // both matching subs are from same node - assertEquals(p2.getMatchingSubscriptions().size(), 2); - assertTrue(CollectionUtils.isEqualCollection(p2.getMatchingSubscriptions(), - Arrays.asList(s1.getID(), s3.getID()))); - assertTrue(CollectionUtils.isEqualCollection(p2.getSubscribers(), Arrays.asList(n2))); - - assertEquals(p3.getSubscribers().size(), 1); - assertEquals(p3.getMatchingSubscriptions().size(), 1); - assertTrue(CollectionUtils.isEqualCollection(p3.getMatchingSubscriptions(), - Arrays.asList(s2.getID()))); - assertTrue(CollectionUtils.isEqualCollection(p3.getSubscribers(), Arrays.asList(n3))); - - assertEquals(p4.getSubscribers().size(), 0); - assertEquals(p4.getMatchingSubscriptions().size(), 0); - } - - @Test - public void testPerformMatchingAdvSub() { - // a1={0, x > 10, y < 200} a2={1, x < 100, 150 < y < 400} a3={1, x <10} - // s1={0, x > 0} s2={1, 0 < x < 50, y < 500}, s3={1; x > 999}, s4={1} - Attribute.noOfAttributes = 2; - Attribute.lowRange = 0; - Attribute.highRange = 1000; - Subscription.setTotalClasses(2); - Advertisement a1 = new Advertisement(0, new Attribute[]{Attribute.greaterThan(10), Attribute.lessThan(200)}); - Advertisement a2 = new Advertisement(1, new Attribute[]{Attribute.lessThan(100), Attribute.range(150, 400)}); - Advertisement a3 = new Advertisement(1, new Attribute[]{Attribute.lessThan(10), Attribute.star()}); - Subscription s1 = new Subscription(0, new Attribute[]{Attribute.greaterThan(0), Attribute.star()}); - Subscription s2 = new Subscription(1, new Attribute[]{Attribute.range(0, 50), Attribute.lessThan(500)}); - Subscription s3 = new Subscription(1, new Attribute[]{Attribute.greaterThan(999), Attribute.star()}); - Subscription s4 = new Subscription(1, new Attribute[]{Attribute.star(), Attribute.star()}); - PubSubNodeWload psw1 = new PubSubNodeWload(n1), psw2 = new PubSubNodeWload(n2), psw3 = new PubSubNodeWload(n3), - psw4 = new PubSubNodeWload(n4), psw5 = new PubSubNodeWload(n5); - psw1.addAdv(a1); - psw2.addAdv(a2); - psw2.addAdv(a3); - psw3.addSub(s1); - psw4.addSub(s2); - psw5.addSub(s3); - psw5.addSub(s4); - WorkloadGenerator.performMatching(Arrays.asList(psw1, psw2, psw3, psw4, psw5)); - assertTrue(CollectionUtils.isEqualCollection(s1.getMatchingAdvs(), Arrays.asList(a1))); - assertTrue(CollectionUtils.isEqualCollection(s2.getMatchingAdvs(), Arrays.asList(a2,a3))); - assertTrue(s3.getMatchingAdvs().isEmpty()); - assertTrue(CollectionUtils.isEqualCollection(s4.getMatchingAdvs(), Arrays.asList(a2,a3))); - } -} diff --git a/src/test/java/de/tum/msrg/topology/TestNodeInfo.java b/src/test/java/de/tum/msrg/topology/TestNodeInfo.java deleted file mode 100644 index 02155e3..0000000 --- a/src/test/java/de/tum/msrg/topology/TestNodeInfo.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.tum.msrg.topology; - -import org.apache.commons.collections4.CollectionUtils; -import org.junit.Test; -import static org.junit.Assert.*; -import de.tum.msrg.topology.NodeInfo; - -import java.util.Arrays; - -/** - * Created by pxsalehi on 10.12.15. - */ -public class TestNodeInfo { - @Test - public void testEquals() { - NodeInfo n0 = new NodeInfo(0, 1); - NodeInfo n1 = new NodeInfo(1, 2); - NodeInfo n2 = new NodeInfo(2, 1); - assertTrue(CollectionUtils.isEqualCollection(Arrays.asList(n0, n1), Arrays.asList(n1, n0))); - assertFalse(CollectionUtils.isEqualCollection(Arrays.asList(n0, n1), Arrays.asList(n1, n2))); - } -} diff --git a/src/test/java/de/tum/msrg/underlay/TestEdge.java b/src/test/java/de/tum/msrg/underlay/TestEdge.java deleted file mode 100644 index 63752e3..0000000 --- a/src/test/java/de/tum/msrg/underlay/TestEdge.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.tum.msrg.underlay; - -import static org.junit.Assert.*; - -import org.junit.Test; - -import de.tum.msrg.underlay.Edge; -import de.tum.msrg.underlay.Node; - -public class TestEdge { - - @Test - public void testIsLinkTrue() { - Node n1 = new Node(null, 1, 1); - Node n2 = new Node(null, 2, 1); - Node n3 = new Node(null, 3, 1); - Edge edge = new Edge(null, n1, n2, 100, 20); - assertTrue(edge.isLink(n1, n2)); - assertTrue(edge.isLink(n2, n1)); - assertFalse(edge.isLink(n3, n1)); - assertFalse(edge.isLink(n3, n2)); - assertFalse(edge.isLink(n1, n3)); - assertFalse(edge.isLink(n2, n3)); - } -} diff --git a/src/test/java/de/tum/msrg/underlay/TestNetwork.java b/src/test/java/de/tum/msrg/underlay/TestNetwork.java deleted file mode 100644 index ca7bd68..0000000 --- a/src/test/java/de/tum/msrg/underlay/TestNetwork.java +++ /dev/null @@ -1,143 +0,0 @@ -package de.tum.msrg.underlay; - -import org.junit.Test; -import static org.junit.Assert.*; - -import java.util.Arrays; - -import org.junit.Before; - -import de.tum.msrg.pubsub.ConfigKeys; -import de.tum.msrg.config.Configuration; -import de.tum.msrg.topology.EdgeInfo; -import de.tum.msrg.topology.NodeInfo; -import de.tum.msrg.topology.Topology; - -public class TestNetwork { - /** - * .--1---3 - * 0---+--2---4 - * '--5 - */ - private NodeInfo n0 = new NodeInfo(0, 2); - private NodeInfo n1 = new NodeInfo(1, 2); - private NodeInfo n2 = new NodeInfo(2, 3); - private NodeInfo n2WrongDegree = new NodeInfo(2, 2); - private NodeInfo n3 = new NodeInfo(3, 1); - private NodeInfo n4 = new NodeInfo(4, 1); - private NodeInfo n5 = new NodeInfo(5, 1); - private EdgeInfo e0 = new EdgeInfo(0, n0, n1, 52); - private EdgeInfo e1 = new EdgeInfo(1, n0, n2, 63); - private EdgeInfo e2 = new EdgeInfo(2, n1, n3, 70); - private EdgeInfo e3 = new EdgeInfo(3, n2, n4, 10); - private EdgeInfo e4 = new EdgeInfo(4, n2, n5, 35); - private Topology topology = null; - private Topology topologyWithWrongDegree = null; - private Configuration config = null; - - @Before - public void setupNetworkTopology() { - config = new Configuration(); - config.addProperty(ConfigKeys.NETWORK_RANDOM_SEED, -1); - topology = new Topology(new NodeInfo[] {n0, n1, n2, n3, n4, n5}, - new EdgeInfo[] {e0, e1, e2, e3, e4}); - topologyWithWrongDegree = new Topology(new NodeInfo[] {n0, n1, n2WrongDegree, n3, n4, n5}, - new EdgeInfo[] {e0, e1, e2, e3, e4}); - } - - @Test - public void testCreateNetwork() throws UnderlayException { - Network network = new Network(config, topology); - assertEquals(6, network.getNodes().length); - assertEquals(5, network.getEdges().length); - assertEquals(network.getEdge(0), network.getEdge(network.getNode(0), network.getNode(1))); - assertEquals(network.getEdge(3), network.getEdge(network.getNode(2), network.getNode(4))); - assertNull(network.getEdge(network.getNode(2), network.getNode(1))); - assertEquals(network.getEdge(network.getNode(2), network.getNode(0)), - network.getEdge(network.getNode(0), network.getNode(2))); - } - - // TODO: this belongs to TestNode - @Test(expected=UnderlayException.class) - public void testCreateNetworkFailDueToIncorrectOutDegree() throws UnderlayException { - Network network = new Network(config, topologyWithWrongDegree); - network.buildDijkistraTree(network.getNode(0)); - } - - @Test - public void testBuildDijkstraTree() throws UnderlayException { - Network network = new Network(config, topology); - network.buildDijkistraTree(network.getNode(0)); - assertNull(network.getNode(0).getDijkParentNode()); - assertEquals(network.getNode(0), network.getNode(2).getDijkParentNode()); - assertEquals(network.getNode(0), network.getNode(1).getDijkParentNode()); - assertEquals(network.getNode(2), network.getNode(4).getDijkParentNode()); - assertEquals(network.getNode(2), network.getNode(5).getDijkParentNode()); - assertEquals(network.getNode(1), network.getNode(3).getDijkParentNode()); - network.buildDijkistraTree(network.getNode(2)); - assertNull(network.getNode(2).getDijkParentNode()); - assertEquals(network.getNode(2), network.getNode(0).getDijkParentNode()); - assertEquals(network.getNode(0), network.getNode(1).getDijkParentNode()); - assertEquals(network.getNode(1), network.getNode(3).getDijkParentNode()); - assertEquals(network.getNode(2), network.getNode(4).getDijkParentNode()); - assertEquals(network.getNode(2), network.getNode(5).getDijkParentNode()); - } - - @Test - public void testBuildRouteTablesGetRoute() throws UnderlayException { - Network network = new Network(config, topology); - network.buildRouteTables(); - Integer[][] nextHop = new Integer[][] {{null, 1, 2, 1, 2, 2}, // from node 0 to all others - {0, null, 0, 3, 0, 0}, // ... - {0, 0, null, 0, 4, 5}, - {1, 1, 1, null, 1, 1}, - {2, 2, 2, 2, null, 2}, - {2, 2, 2, 2, 2, null}}; - for(int i = 0; i < network.getNoOfNodes(); ++i) - for(int j = 0; j < network.getNoOfNodes(); ++j) - if(i == j) - assertNull(network.getNode(i).getRoute(network.getNode(j))); - else - assertEquals(network.getNode(nextHop[i][j]), - network.getNode(i).getRoute(network.getNode(j))); - } - - @Test(expected=UnderlayException.class) - public void testFindStaticRouteThrowsIfRoutingTableNotBuilt() throws UnderlayException { - Network network = new Network(config, topology); - network.findRoute(network.getNode(1), network.getNode(2)); - } - - @Test(expected=UnderlayException.class) - public void testFindRouteSameSrcAndDest() throws UnderlayException { - Network network = new Network(config, topology); - network.buildRouteTables(); - RouteChain route = network.findRoute(network.getNode(1), network.getNode(1)); - } - - @Test(expected=UnderlayException.class) - public void testFindRouteNoRoute() throws UnderlayException { - Network network = new Network(config, topologyWithWrongDegree); // 5 is disconnected - network.buildRouteTables(); - } - - @Test - public void testFindRouteSuccessful() throws UnderlayException { - Network network = new Network(config, topology); - network.buildRouteTables(); - RouteChain route = network.findRoute(network.getNode(1), network.getNode(3)); - assertEquals(2, route.getRouteLength()); - assertEquals(route.getRouterChain().get(0), network.getNode(1)); - assertEquals(route.getRouterChain().get(1), network.getNode(3)); - assertEquals(1, route.getDelayChain().size()); - assertEquals(route.getDelayChain().get(0).floatValue(), 70f, 0.001); - route = network.findRoute(network.getNode(4), network.getNode(3)); - assertEquals(5, route.getRouteLength()); - assertEquals(route.getRouterChain(), - Arrays.asList(network.getNode(4), network.getNode(2), network.getNode(0), - network.getNode(1), network.getNode(3))); - assertEquals(4, route.getDelayChain().size()); - assertEquals(route.getDelayChain(), Arrays.asList(10f, 63f, 52f, 70f)); - } -} - diff --git a/src/test/java/de/tum/msrg/underlay/TestNode.java b/src/test/java/de/tum/msrg/underlay/TestNode.java deleted file mode 100644 index cfd40ab..0000000 --- a/src/test/java/de/tum/msrg/underlay/TestNode.java +++ /dev/null @@ -1,57 +0,0 @@ -package de.tum.msrg.underlay; - -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; - -import de.tum.msrg.pubsub.ConfigKeys; -import de.tum.msrg.config.Configuration; -import de.tum.msrg.topology.EdgeInfo; -import de.tum.msrg.topology.NodeInfo; -import de.tum.msrg.topology.Topology; - -public class TestNode { - /** - * .--1---3 - * 0---+--2---4 - * '--5 - */ - private NodeInfo n0 = new NodeInfo(0, 2); - private NodeInfo n1 = new NodeInfo(1, 2); - private NodeInfo n2 = new NodeInfo(2, 3); - private NodeInfo n2WrongDegree = new NodeInfo(2, 2); - private NodeInfo n3 = new NodeInfo(3, 1); - private NodeInfo n4 = new NodeInfo(4, 1); - private NodeInfo n5 = new NodeInfo(5, 1); - private EdgeInfo e0 = new EdgeInfo(0, n0, n1, 52f); - private EdgeInfo e1 = new EdgeInfo(1, n0, n2, 63f); - private EdgeInfo e2 = new EdgeInfo(2, n1, n3, 70f); - private EdgeInfo e3 = new EdgeInfo(3, n2, n4, 10f); - private EdgeInfo e4 = new EdgeInfo(4, n2, n5, 35f); - private Topology topology = null; - private Topology topologyWithWrongDegree = null; - private Configuration config = null; - private static final double DELTA = 1e-5; - - @Before - public void setupNetworkTopology() { - config = new Configuration(); - config.addProperty(ConfigKeys.NETWORK_RANDOM_SEED, -1); - topology = new Topology(new NodeInfo[] {n0, n1, n2, n3, n4, n5}, - new EdgeInfo[] {e0, e1, e2, e3, e4}); - topologyWithWrongDegree = new Topology(new NodeInfo[] {n0, n1, n2WrongDegree, n3, n4, n5}, - new EdgeInfo[] {e0, e1, e2, e3, e4}); - } - - @Test - public void testGetLatency() throws UnderlayException { - Network network = new Network(config, topology); - network.buildRouteTables(); - float routeLatency = network.getNode(1).getLatency(network.getNode(4)); - assertEquals(routeLatency, 125f, DELTA); - routeLatency = network.getNode(0).getLatency(network.getNode(2)); - assertEquals(routeLatency, 63f, DELTA); - } - -} diff --git a/src/test/java/de/tum/msrg/underlay/TestTopology.java b/src/test/java/de/tum/msrg/underlay/TestTopology.java deleted file mode 100644 index 6167fe1..0000000 --- a/src/test/java/de/tum/msrg/underlay/TestTopology.java +++ /dev/null @@ -1,91 +0,0 @@ -package de.tum.msrg.underlay; - -import static org.junit.Assert.*; - -import java.util.Arrays; -import java.util.List; - -import de.tum.msrg.AllTests; -import org.apache.commons.collections4.CollectionUtils; -import org.junit.Test; - -import de.tum.msrg.topology.EdgeInfo; -import de.tum.msrg.topology.NodeInfo; -import de.tum.msrg.topology.Topology; - -public class TestTopology { - - private String correctTopo = "No of nodes:6 \n" - + "No of edges:5 \n\n" - + "Nodes: \n" - + "0 2 \n" - + "1 2 \n" - + "2 2 \n" - + "3 1 \n" - + "4 1 \n" - + "5 1 \n\n" - + "Edges: \n" - + "0 0 1 52 \n" - + "1 0 2 63 \n" - + "2 1 3 70 \n" - + "3 2 4 10 \n" - + "4 2 5 35 \n"; - - private String correctTopoWithBW = "No of nodes:6 \n" - + "No of edges:5 \n\n" - + "Nodes: \n" - + "0 2 \n" - + "1 2 \n" - + "2 2 \n" - + "3 1 \n" - + "4 1 \n" - + "5 1 \n\n" - + "Edges: \n" - + "0 0 1 52 100\n" - + "1 0 2 63 \n" - + "2 1 3 70 500\n" - + "3 2 4 10 200\n" - + "4 2 5 35 \n"; - - NodeInfo n0 = new NodeInfo(0, 2); - NodeInfo n1 = new NodeInfo(1, 2); - NodeInfo n2 = new NodeInfo(2, 2); - NodeInfo n3 = new NodeInfo(3, 1); - NodeInfo n4 = new NodeInfo(4, 1); - NodeInfo n5 = new NodeInfo(5, 1); - EdgeInfo e0 = new EdgeInfo(0, n0, n1, 52f); - EdgeInfo e1 = new EdgeInfo(1, n0, n2, 63f); - EdgeInfo e2 = new EdgeInfo(2, n1, n3, 70f); - EdgeInfo e3 = new EdgeInfo(3, n2, n4, 10f); - EdgeInfo e4 = new EdgeInfo(4, n2, n5, 35f); - - @Test - public void testTopologyFromString() { - Topology topo = new Topology(correctTopo); - assertEquals(6, topo.getNoOfNodes()); - assertEquals(5, topo.getNoOfEdges()); - List nodes = Arrays.asList(topo.getNodes()); - List edges = Arrays.asList(topo.getEdges()); - assertTrue(CollectionUtils.isEqualCollection(nodes, Arrays.asList(n0, n1, n2, n3, n4, n5))); - assertTrue(CollectionUtils.isEqualCollection(edges, Arrays.asList(e0, e1, e2, e3, e4))); - for(EdgeInfo e: edges) - assertEquals(Float.MAX_VALUE, e.getBandwidth(), AllTests.ASSERT_DELTA); - } - - @Test - public void testTopologyFromStringWithString() { - Topology topo = new Topology(correctTopoWithBW); - assertEquals(6, topo.getNoOfNodes()); - assertEquals(5, topo.getNoOfEdges()); - List nodes = Arrays.asList(topo.getNodes()); - List edges = Arrays.asList(topo.getEdges()); - assertTrue(CollectionUtils.isEqualCollection(nodes, Arrays.asList(n0, n1, n2, n3, n4, n5))); - assertTrue(CollectionUtils.isEqualCollection(edges, Arrays.asList(e0, e1, e2, e3, e4))); - - assertEquals(100, edges.get(0).getBandwidth(), AllTests.ASSERT_DELTA); - assertEquals(Float.MAX_VALUE, edges.get(1).getBandwidth(), AllTests.ASSERT_DELTA); - assertEquals(500, edges.get(2).getBandwidth(), AllTests.ASSERT_DELTA); - assertEquals(200, edges.get(3).getBandwidth(), AllTests.ASSERT_DELTA); - assertEquals(Float.MAX_VALUE, edges.get(4).getBandwidth(), AllTests.ASSERT_DELTA); - } -}