MCPcopy Create free account
hub / github.com/akeranen/the-one / testRouting

Method testRouting

test/ProphetRouterTest.java:31–122  ·  view source on GitHub ↗

Tests normal routing

()

Source from the content-addressed store, hash-verified

29 * Tests normal routing
30 */
31 public void testRouting() {
32 Message m1 = new Message(h1,h2, msgId2, 1);
33 h1.createNewMessage(m1);
34 Message m2 = new Message(h1,h3, msgId3, 1);
35 h1.createNewMessage(m2);
36 Message m3 = new Message(h1,h4, msgId4, 1);
37 h1.createNewMessage(m3);
38 Message m4 = new Message(h1,h6, "dummy", 1); // this message should not be fwded
39 h1.createNewMessage(m4);
40 Message m5 = new Message(h1,h5, msgId5, 1);
41 h1.createNewMessage(m5);
42 Message m6 = new Message(h4,h1, "d1", 1);
43 h4.createNewMessage(m6);
44
45 ProphetRouter r4 = (ProphetRouter)h4.getRouter();
46 ProphetRouter r5 = (ProphetRouter)h5.getRouter();
47
48 checkCreates(6);
49
50 h4.connect(h5);
51 assertEquals(ProphetRouter.P_INIT, r4.getPredFor(h5));
52 assertEquals(ProphetRouter.P_INIT, r5.getPredFor(h4));
53
54 updateAllNodes();
55 // h4 has message for h1 but it shouldn't forward it to h5 since
56 // h5 has not heard about h1
57 assertFalse(mc.next());
58
59 disconnect(h5);
60 h5.connect(h3); // now h3 knows h5 has met h4
61
62 h1.connect(h3);
63 // now h1-h3-h5 connected and h5 knows h4
64
65 // first h1 should transfer msgId2 to h3 (final recipient)
66 updateAllNodes();
67 assertTrue(mc.next());
68 assertEquals(mc.TYPE_START, mc.getLastType());
69 assertEquals(msgId3, mc.getLastMsg().getId());
70 assertEquals(h1, mc.getLastFrom());
71 assertFalse(mc.next());
72
73 clock.advance(10);
74 updateAllNodes();
75 assertTrue(mc.next());
76 assertEquals(mc.TYPE_RELAY, mc.getLastType()); // finished transfer
77 assertEquals(msgId3, mc.getLastMsg().getId());
78 assertTrue(mc.getLastFirstDelivery());
79
80 // h1 should next transfer msgId5 to h3 because h3 is connected to h5
81 assertTrue(mc.next());
82 assertEquals(mc.TYPE_START, mc.getLastType());
83 assertEquals(msgId5, mc.getLastMsg().getId());
84 assertEquals(h1, mc.getLastFrom());
85 assertFalse(mc.next());
86
87 clock.advance(10);
88 updateAllNodes();

Callers

nothing calls this directly

Calls 15

getPredForMethod · 0.95
doRelayMethod · 0.95
getRouterMethod · 0.80
checkCreatesMethod · 0.80
updateAllNodesMethod · 0.80
nextMethod · 0.80
getLastTypeMethod · 0.80
getIdMethod · 0.80
getLastMsgMethod · 0.80
getLastFromMethod · 0.80
advanceMethod · 0.80
getLastFirstDeliveryMethod · 0.80

Tested by

no test coverage detected