@Test public void testPartition() { Network<Node> net = new Network<>(); AtomicInteger ai = new AtomicInteger(0); NodeBuilder nb = new NodeBuilder() { @Override protected int getX(int rdi) { return ai.addAndGet(Node.MAX_X / 10); } }; Node n0 = new Node(network.rd, nb); Node n1 = new Node(network.rd, nb); Node n2 = new Node(network.rd, nb); Node n3 = new Node(network.rd, nb); net.addNode(n0); net.addNode(n1); net.addNode(n2); net.addNode(n3); AtomicInteger ab = new AtomicInteger(0); Message<Node> act = new Message<>() { @Override public void action(Network<Node> network, Node from, Node to) { ab.incrementAndGet(); } }; net.partition(0.25f); int bound = (int) (0.25f * Node.MAX_X); Assert.assertTrue(net.partitionsInX.contains(bound)); Assert.assertEquals(0, net.partitionId(n0)); Assert.assertEquals(0, net.partitionId(n1)); Assert.assertEquals(1, net.partitionId(n2)); Assert.assertEquals(1, net.partitionId(n3)); net.send(act, n0, n1); Assert.assertNotNull(net.msgs.peekFirst()); net.msgs.clear(); net.send(act, n1, n2); Assert.assertNull(net.msgs.peekFirst()); net.send(act, n2, n3); Assert.assertNotNull(net.msgs.peekFirst()); net.msgs.clear(); net.partition(0.35f); int bound2 = (int) (0.35f * Node.MAX_X); Assert.assertTrue(net.partitionsInX.contains(bound)); Assert.assertTrue(net.partitionsInX.contains(bound2)); Assert.assertEquals(0, net.partitionId(n0)); Assert.assertEquals(0, net.partitionId(n1)); Assert.assertEquals(1, net.partitionId(n2)); Assert.assertEquals(2, net.partitionId(n3)); net.send(act, n0, n1); Assert.assertNotNull(net.msgs.peekFirst()); net.msgs.clear(); net.send(act, n1, n2); Assert.assertNull(net.msgs.peekFirst()); net.send(act, n2, n3); Assert.assertNull(net.msgs.peekFirst()); net.msgs.clear(); net.send(act, n3, n0); Assert.assertNull(net.msgs.peekFirst()); net.msgs.clear(); }
public void partition(float part) { if (part <= 0 || part >= 1) { throw new IllegalArgumentException("part needs to be a percentage between 0 & 100 excluded"); } int xPoint = (int) (Node.MAX_X * part); if (partitionsInX.contains(xPoint)) { throw new IllegalArgumentException("this partition exists already"); } partitionsInX.add(xPoint); Collections.sort(partitionsInX); }
Network { public void partition(float part) { if (part <= 0 || part >= 1) { throw new IllegalArgumentException("part needs to be a percentage between 0 & 100 excluded"); } int xPoint = (int) (Node.MAX_X * part); if (partitionsInX.contains(xPoint)) { throw new IllegalArgumentException("this partition exists already"); } partitionsInX.add(xPoint); Collections.sort(partitionsInX); } }
Network { public void partition(float part) { if (part <= 0 || part >= 1) { throw new IllegalArgumentException("part needs to be a percentage between 0 & 100 excluded"); } int xPoint = (int) (Node.MAX_X * part); if (partitionsInX.contains(xPoint)) { throw new IllegalArgumentException("this partition exists already"); } partitionsInX.add(xPoint); Collections.sort(partitionsInX); }  }
Network { public void partition(float part) { if (part <= 0 || part >= 1) { throw new IllegalArgumentException("part needs to be a percentage between 0 & 100 excluded"); } int xPoint = (int) (Node.MAX_X * part); if (partitionsInX.contains(xPoint)) { throw new IllegalArgumentException("this partition exists already"); } partitionsInX.add(xPoint); Collections.sort(partitionsInX); }  static BitSet chooseBadNodes(Random rd, int nodeCount, int nodesDown); BitSet getDeadNodes(); TN getNodeById(int id); TN getFirstLiveNode(); void printSpeedDistribution(int segmentCt); @SuppressWarnings("UnusedReturnValue") Network<TN> setMsgDiscardTime(int l); void run(int seconds); void runH(int hours); boolean runMs(int ms); void sendAll(Message<? extends TN> m, int sendTime, TN fromNode); void sendAll(Message<? extends TN> m, TN fromNode); void send(Message<? extends TN> m, TN fromNode, List<TN> dests); void send(Message<? extends TN> m, TN fromNode, TN toNode); void send(Message<? extends TN> mc, int sendTime, TN fromNode, TN toNode); void sendArriveAt(Message<? extends TN> mc, int arriveAt, TN fromNode, TN toNode); boolean hasMessage(); void send(Message<? extends TN> m, int sendTime, TN fromNode, List<? extends Node> dests); void send(
      Message<? extends TN> m,
      int sendTime,
      TN fromNode,
      List<? extends Node> dests,
      int delaysBetweenMessage); static int getPseudoRandom(int nodeId, int randomSeed); void registerTask(final Runnable task, int startAt, TN fromNode); void registerPeriodicTask(final Runnable task, int startAt, int period, TN fromNode); void registerPeriodicTask(
      final Runnable task, int startAt, int period, TN fromNode, Condition c); void registerConditionalTask(
      final Runnable task,
      int startAt,
      int duration,
      TN fromNode,
      Condition startIf,
      Condition repeatIf); void addNode(TN node); List<TN> liveNodes(); Network<TN> setNetworkLatency(int[] distribProp, int[] distribVal); Network<TN> setNetworkLatency(NetworkLatency networkLatency); void printNetworkLatency(); void partition(float part); void endPartition(); }
Network { public void partition(float part) { if (part <= 0 || part >= 1) { throw new IllegalArgumentException("part needs to be a percentage between 0 & 100 excluded"); } int xPoint = (int) (Node.MAX_X * part); if (partitionsInX.contains(xPoint)) { throw new IllegalArgumentException("this partition exists already"); } partitionsInX.add(xPoint); Collections.sort(partitionsInX); }  static BitSet chooseBadNodes(Random rd, int nodeCount, int nodesDown); BitSet getDeadNodes(); TN getNodeById(int id); TN getFirstLiveNode(); void printSpeedDistribution(int segmentCt); @SuppressWarnings("UnusedReturnValue") Network<TN> setMsgDiscardTime(int l); void run(int seconds); void runH(int hours); boolean runMs(int ms); void sendAll(Message<? extends TN> m, int sendTime, TN fromNode); void sendAll(Message<? extends TN> m, TN fromNode); void send(Message<? extends TN> m, TN fromNode, List<TN> dests); void send(Message<? extends TN> m, TN fromNode, TN toNode); void send(Message<? extends TN> mc, int sendTime, TN fromNode, TN toNode); void sendArriveAt(Message<? extends TN> mc, int arriveAt, TN fromNode, TN toNode); boolean hasMessage(); void send(Message<? extends TN> m, int sendTime, TN fromNode, List<? extends Node> dests); void send(
      Message<? extends TN> m,
      int sendTime,
      TN fromNode,
      List<? extends Node> dests,
      int delaysBetweenMessage); static int getPseudoRandom(int nodeId, int randomSeed); void registerTask(final Runnable task, int startAt, TN fromNode); void registerPeriodicTask(final Runnable task, int startAt, int period, TN fromNode); void registerPeriodicTask(
      final Runnable task, int startAt, int period, TN fromNode, Condition c); void registerConditionalTask(
      final Runnable task,
      int startAt,
      int duration,
      TN fromNode,
      Condition startIf,
      Condition repeatIf); void addNode(TN node); List<TN> liveNodes(); Network<TN> setNetworkLatency(int[] distribProp, int[] distribVal); Network<TN> setNetworkLatency(NetworkLatency networkLatency); void printNetworkLatency(); void partition(float part); void endPartition(); final MessageStorage msgs; final List<ConditionalTask<TN>> conditionalTasks; final List<TN> allNodes; final Random rd; public NetworkLatency networkLatency; public int time; }