/** * Tests sending 1, 2 (OOB) and 3, where they are received in the order 1, 3, 2. Message 3 should * not get delivered until message 4 is received (http://jira.jboss.com/jira/browse/JGRP-780) */ public void testRegularAndOOBUnicasts() throws Exception { DISCARD discard = new DISCARD(); ProtocolStack stack = a.getProtocolStack(); stack.insertProtocol(discard, ProtocolStack.BELOW, UNICAST.class, UNICAST2.class); Address dest = b.getAddress(); Message m1 = new Message(dest, null, 1); Message m2 = new Message(dest, null, 2); m2.setFlag(Message.OOB); Message m3 = new Message(dest, null, 3); MyReceiver receiver = new MyReceiver("C2"); b.setReceiver(receiver); a.send(m1); discard.setDropDownUnicasts(1); a.send(m2); a.send(m3); Collection<Integer> list = receiver.getMsgs(); int count = 10; while (list.size() < 3 && --count > 0) { Util.sleep(500); // time for potential retransmission sendStableMessages(a, b); } assert list.size() == 3 : "list is " + list; assert list.contains(1) && list.contains(2) && list.contains(3); }
/** Tests https://jira.jboss.org/jira/browse/JGRP-1079 */ public void testOOBMessageLoss() throws Exception { Util.close(b); // we only need 1 channel MyReceiver receiver = new MySleepingReceiver("C1", 1000); a.setReceiver(receiver); TP transport = a.getProtocolStack().getTransport(); transport.setOOBRejectionPolicy("discard"); final int NUM = 10; for (int i = 1; i <= NUM; i++) { Message msg = new Message(null, null, i); msg.setFlag(Message.OOB); a.send(msg); } STABLE stable = (STABLE) a.getProtocolStack().findProtocol(STABLE.class); if (stable != null) stable.runMessageGarbageCollection(); Collection<Integer> msgs = receiver.getMsgs(); for (int i = 0; i < 20; i++) { if (msgs.size() == NUM) break; Util.sleep(1000); sendStableMessages(a, b); } System.out.println("msgs = " + Util.print(msgs)); assert msgs.size() == NUM : "expected " + NUM + " messages but got " + msgs.size() + ", msgs=" + Util.print(msgs); for (int i = 1; i <= NUM; i++) { assert msgs.contains(i); } }
/** Tests https://jira.jboss.org/jira/browse/JGRP-1079 for unicast messages */ public void testOOBUnicastMessageLoss() throws Exception { MyReceiver receiver = new MySleepingReceiver("C2", 1000); b.setReceiver(receiver); a.getProtocolStack().getTransport().setOOBRejectionPolicy("discard"); final int NUM = 10; final Address dest = b.getAddress(); for (int i = 1; i <= NUM; i++) { Message msg = new Message(dest, null, i); msg.setFlag(Message.OOB); a.send(msg); } Collection<Integer> msgs = receiver.getMsgs(); for (int i = 0; i < 20; i++) { if (msgs.size() == NUM) break; Util.sleep(1000); // sendStableMessages(c1,c2); // not needed for unicasts ! } assert msgs.size() == NUM : "expected " + NUM + " messages but got " + msgs.size() + ", msgs=" + Util.print(msgs); for (int i = 1; i <= NUM; i++) { assert msgs.contains(i); } }
public void testRegularAndOOBMulticasts() throws Exception { DISCARD discard = new DISCARD(); ProtocolStack stack = a.getProtocolStack(); stack.insertProtocol(discard, ProtocolStack.BELOW, NAKACK2.class); a.setDiscardOwnMessages(true); Address dest = null; // send to all Message m1 = new Message(dest, null, 1); Message m2 = new Message(dest, null, 2); m2.setFlag(Message.OOB); Message m3 = new Message(dest, null, 3); MyReceiver receiver = new MyReceiver("C2"); b.setReceiver(receiver); a.send(m1); discard.setDropDownMulticasts(1); a.send(m2); a.send(m3); Util.sleep(500); Collection<Integer> list = receiver.getMsgs(); for (int i = 0; i < 10; i++) { System.out.println("list = " + list); if (list.size() == 3) break; Util.sleep(1000); // give the asynchronous msgs some time to be received sendStableMessages(a, b); } assert list.size() == 3 : "list is " + list; assert list.contains(1) && list.contains(2) && list.contains(3); }
public void testRegularAndOOBUnicasts2() throws Exception { DISCARD discard = new DISCARD(); ProtocolStack stack = a.getProtocolStack(); stack.insertProtocol( discard, ProtocolStack.BELOW, (Class<? extends Protocol>[]) Util.getUnicastProtocols()); Address dest = b.getAddress(); Message m1 = new Message(dest, 1); Message m2 = new Message(dest, 2).setFlag(Message.Flag.OOB); Message m3 = new Message(dest, 3).setFlag(Message.Flag.OOB); Message m4 = new Message(dest, 4); MyReceiver receiver = new MyReceiver("B"); b.setReceiver(receiver); a.send(m1); discard.setDropDownUnicasts(2); a.send(m2); // dropped a.send(m3); // dropped a.send(m4); Collection<Integer> list = receiver.getMsgs(); int count = 10; while (list.size() < 4 && --count > 0) { Util.sleep(500); // time for potential retransmission sendStableMessages(a, b); } System.out.println("list = " + list); assert list.size() == 4 : "list is " + list; assert list.contains(1) && list.contains(2) && list.contains(3) && list.contains(4); }
@Test(invocationCount = 5) @SuppressWarnings("unchecked") public void testRandomRegularAndOOBMulticasts() throws Exception { DISCARD discard = new DISCARD(); discard.setLocalAddress(a.getAddress()); discard.setDownDiscardRate(0.5); ProtocolStack stack = a.getProtocolStack(); stack.insertProtocol(discard, ProtocolStack.BELOW, NAKACK2.class); MyReceiver r1 = new MyReceiver("C1"), r2 = new MyReceiver("C2"); a.setReceiver(r1); b.setReceiver(r2); final int NUM_MSGS = 20; final int NUM_THREADS = 10; send(null, NUM_MSGS, NUM_THREADS, 0.5); // send on random channel (c1 or c2) Collection<Integer> one = r1.getMsgs(), two = r2.getMsgs(); for (int i = 0; i < 10; i++) { if (one.size() == NUM_MSGS && two.size() == NUM_MSGS) break; System.out.println("one size " + one.size() + ", two size " + two.size()); Util.sleep(1000); sendStableMessages(a, b); } System.out.println("one size " + one.size() + ", two size " + two.size()); stack.removeProtocol("DISCARD"); for (int i = 0; i < 5; i++) { if (one.size() == NUM_MSGS && two.size() == NUM_MSGS) break; sendStableMessages(a, b); Util.sleep(500); } System.out.println( "C1 received " + one.size() + " messages (" + NUM_MSGS + " expected)" + "\nC2 received " + two.size() + " messages (" + NUM_MSGS + " expected)"); check(NUM_MSGS, one, two); }
private void check( MyReceiver receiver, int expected_size, boolean oob, Tuple<Address, Integer>... vals) { Map<Address, Collection<Long>> msgs = receiver.getMsgs(); for (int i = 0; i < 10; i++) { if (msgs.size() >= expected_size) break; Util.sleep(1000); } assert msgs.size() == expected_size : "expected size=" + expected_size + ", msgs: " + msgs.keySet(); for (Tuple<Address, Integer> tuple : vals) { Address addr = tuple.getVal1(); Collection<Long> list = msgs.get(addr); assert list != null : "no list available for " + addr; int expected_values = tuple.getVal2(); for (int i = 0; i < 20; i++) { if (list.size() >= expected_values) break; Util.sleep(1000); sendStableMessages(c1, c2, c3); } System.out.println("[" + receiver.getName() + "]: " + addr + ": " + list); assert list.size() == expected_values : addr + "'s list's size is not " + tuple.getVal2() + ", list: " + list + " (size=" + list.size() + ")"; if (!oob) // if OOB messages, ordering is not guaranteed check(addr, list); else checkPresence(list); } }
public void testRegularAndOOBUnicasts2() throws Exception { DISCARD discard = new DISCARD(); ProtocolStack stack = c1.getProtocolStack(); stack.insertProtocol(discard, ProtocolStack.BELOW, UNICAST.class, UNICAST2.class); Address dest = c2.getAddress(); Message m1 = new Message(dest, null, 1); Message m2 = new Message(dest, null, 2); m2.setFlag(Message.OOB); Message m3 = new Message(dest, null, 3); m3.setFlag(Message.OOB); Message m4 = new Message(dest, null, 4); MyReceiver receiver = new MyReceiver("C2"); c2.setReceiver(receiver); c1.send(m1); discard.setDropDownUnicasts(1); c1.send(m3); discard.setDropDownUnicasts(1); c1.send(m2); c1.send(m4); Util.sleep(1000); // sleep some time to receive all messages Collection<Integer> list = receiver.getMsgs(); int count = 10; while (list.size() < 4 && --count > 0) { Util.sleep(500); // time for potential retransmission sendStableMessages(c1, c2); } log.info("list = " + list); assert list.size() == 4 : "list is " + list; assert list.contains(1) && list.contains(2) && list.contains(3) && list.contains(4); }