37 private final int MODULE_ID_DATA_CHECK = 902; |
37 private final int MODULE_ID_DATA_CHECK = 902; |
38 private final int MODULE_ID_NO_REPLY = 903; // no reply is sent |
38 private final int MODULE_ID_NO_REPLY = 903; // no reply is sent |
39 private final int MODULE_ID_SLEEP_1S = 1000; // reply msg is delayed by 1s |
39 private final int MODULE_ID_SLEEP_1S = 1000; // reply msg is delayed by 1s |
40 private final int MODULE_ID_SLEEP_5S = 5000; |
40 private final int MODULE_ID_SLEEP_5S = 5000; |
41 private final int MODULE_ID_SLEEP_10S = 10000; |
41 private final int MODULE_ID_SLEEP_10S = 10000; |
|
42 private final int MODULE_ID_DELAY_REPLY = 11000; |
42 |
43 |
43 private final int PLUGIN_ID_JAVACAPTAIN_COMMS_TESTER_C = 101; // see comms.h |
44 private final int PLUGIN_ID_JAVACAPTAIN_COMMS_TESTER_C = 101; // see comms.h |
44 |
45 |
45 private final int SERVER_ADDRESS = CommsEndpoint.JAVA_CAPTAIN; |
46 private final int SERVER_ADDRESS = CommsEndpoint.JAVA_CAPTAIN; |
46 private final String SERVER_NAME = "InstallerJavaCaptain"; |
47 private final String SERVER_NAME = "InstallerJavaCaptain"; |
198 aSuite.addTest(new TestCommsEndpoint("testDestroy", new TestMethod() |
199 aSuite.addTest(new TestCommsEndpoint("testDestroy", new TestMethod() |
199 { |
200 { |
200 public void run(TestCase tc) |
201 public void run(TestCase tc) |
201 { |
202 { |
202 ((TestCommsEndpoint) tc).testDestroy(); |
203 ((TestCommsEndpoint) tc).testDestroy(); |
|
204 } |
|
205 })); |
|
206 |
|
207 aSuite.addTest(new TestCommsEndpoint("testDelayedReply", new TestMethod() |
|
208 { |
|
209 public void run(TestCase tc) |
|
210 { |
|
211 ((TestCommsEndpoint) tc).testDelayedReply(); |
|
212 } |
|
213 })); |
|
214 |
|
215 aSuite.addTest(new TestCommsEndpoint("testNoUnregisterWhenDetaching", new TestMethod() |
|
216 { |
|
217 public void run(TestCase tc) |
|
218 { |
|
219 ((TestCommsEndpoint) tc).testNoUnregisterWhenDetaching(); |
203 } |
220 } |
204 })); |
221 })); |
205 |
222 |
206 return aSuite; |
223 return aSuite; |
207 } |
224 } |
1481 comms = null; |
1498 comms = null; |
1482 } |
1499 } |
1483 |
1500 |
1484 } |
1501 } |
1485 |
1502 |
|
1503 public void testDelayedReply() |
|
1504 { |
|
1505 System.out.println("TestCommsEndpoint.testDelayedReply()"); |
|
1506 |
|
1507 class SendReceiver extends Thread |
|
1508 { |
|
1509 public void run() |
|
1510 { |
|
1511 try |
|
1512 { |
|
1513 CommsEndpoint client = new CommsEndpoint(); |
|
1514 client.connect(SERVER_ADDRESS); |
|
1515 CommsMessage message = new CommsMessage(); |
|
1516 message.setModuleId(MODULE_ID_DELAY_REPLY); |
|
1517 |
|
1518 CommsMessage reply = client.sendReceive(message, CommsEndpoint.WAIT_FOR_EVER); |
|
1519 client.disconnect(); |
|
1520 client.destroy(); |
|
1521 } |
|
1522 catch (Exception e) |
|
1523 { |
|
1524 e.printStackTrace(); |
|
1525 fail("SendReceiver.run"); |
|
1526 } |
|
1527 } |
|
1528 } |
|
1529 |
|
1530 try |
|
1531 { |
|
1532 // reply to first message is delayed until second message is received |
|
1533 // by the server |
|
1534 SendReceiver client1 = new SendReceiver(); |
|
1535 SendReceiver client2 = new SendReceiver(); |
|
1536 |
|
1537 client1.start(); |
|
1538 client2.start(); |
|
1539 client1.join(); |
|
1540 client2.join(); |
|
1541 } |
|
1542 catch (Exception e) |
|
1543 { |
|
1544 e.printStackTrace(); |
|
1545 fail("testDelayedReply failed"); |
|
1546 } |
|
1547 } |
|
1548 |
|
1549 public void testNoUnregisterWhenDetaching() |
|
1550 { |
|
1551 System.out.println("TestCommsEndpoint.testNoUnregisterWhenDetaching()"); |
|
1552 class TestListener implements CommsListener |
|
1553 { |
|
1554 public void processMessage(CommsMessage message) {} |
|
1555 } |
|
1556 |
|
1557 CommsEndpoint comms = null; |
|
1558 try |
|
1559 { |
|
1560 comms = CommsEndpoint.find(SERVER_NAME); |
|
1561 assertNotNull(comms); |
|
1562 |
|
1563 // leave listeners unregistered |
|
1564 comms.registerListener(MODULE_ID_A, new TestListener()); |
|
1565 comms.registerDefaultListener(new TestListener()); |
|
1566 CommsMessage msg = new CommsMessage(); |
|
1567 msg.setModuleId(MODULE_ID_A); |
|
1568 comms.send(msg); |
|
1569 msg.setModuleId(MODULE_ID_B); |
|
1570 comms.send(msg); |
|
1571 msg = comms.sendReceive(msg, 1); |
|
1572 } |
|
1573 catch (CommsException e) |
|
1574 { |
|
1575 e.printStackTrace(); |
|
1576 fail("ok case"); |
|
1577 } |
|
1578 finally |
|
1579 { |
|
1580 comms.destroy(); |
|
1581 comms = null; |
|
1582 } |
|
1583 } |
1486 } |
1584 } |
1487 |
1585 |