private void testMultiplePartiesReconnect(int numParties, int noOfRetries) { List<NetworkConfiguration> confs = getNetConfs(numParties); for (int i = 0; i < noOfRetries; i++) { networks = createNetworks(confs); closeNetworks(networks); } }
@Test(expected = RuntimeException.class, timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testConnectTimeout() { List<NetworkConfiguration> confs = getNetConfs(2); // This should time out waiting for a connection to a party that is not listening newCloseableNetwork(confs.get(0), Duration.ofMillis(10)); }
@Test(timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testPartiesReconnect() { testMultiplePartiesReconnect(2, 10); testMultiplePartiesReconnect(5, 20); }
protected Map<Integer, CloseableNetwork> createNetworks(int numParties) { List<NetworkConfiguration> confs = getNetConfs(numParties); return createNetworks(confs); }
@Test(timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testClose() { networks = createNetworks(3); closeNetworks(networks); }
networks = createNetworks(numParties); ExecutorService es = Executors.newFixedThreadPool(numParties); List<Future<?>> fs = new ArrayList<>(numParties); byte[] expectedData = new byte[messageSize]; Arrays.fill(data, (byte) id); Arrays.fill(expectedData, (byte) prevParty(id, numParties)); networks.get(id).send(nextParty(id, numParties), data); byte[] receivedData = networks.get(id).receive(prevParty(id, numParties)); assertArrayEquals(expectedData, receivedData); });
@Test(timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testConnectTwoParties() { networks = createNetworks(2); }
@Test(timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testSendEmpty() { circularSendSingleMessage(2, 0); }
@Test(timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testManyPartiesSendToOneReceiver() throws InterruptedException, ExecutionException { sendMultipleToSingleReceiver(5, 100); }
@After public void tearDown() { closeNetworks(networks); }
@Test(timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testAlternateReceivers() throws InterruptedException, ExecutionException { alternateReceivers(10000); }
protected Map<Integer, CloseableNetwork> createNetworks(List<NetworkConfiguration> confs) { int numParties = confs.get(0).noOfParties(); ExecutorService es = Executors.newFixedThreadPool(numParties); Map<Integer, CloseableNetwork> netMap = new HashMap<>(numParties); Map<Integer, Future<CloseableNetwork>> futureMap = new HashMap<>(numParties); try { for (NetworkConfiguration conf : confs) { Future<CloseableNetwork> f = es.submit(() -> newCloseableNetwork(conf)); futureMap.put(conf.getMyId(), f); } for (Entry<Integer, Future<CloseableNetwork>> entry : futureMap.entrySet()) { netMap.put(entry.getKey(), entry.getValue().get()); } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); fail("Failed to setup networks."); } finally { es.shutdownNow(); } return netMap; }
@Test(timeout = TWO_MINUTE_TIMEOUT_MILLIS, expected = RuntimeException.class) public void testSendAfterClose() { networks = createNetworks(3); closeNetworks(networks); networks.get(1).send(2, new byte[] {}); }
@Test(timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testConnectOneParty() { networks = createNetworks(1); }
@Test(timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testSendByte() { circularSendSingleMessage(2, 1); }
@Test(timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testSendManyMessagesToOneReceiver() throws InterruptedException, ExecutionException { sendMultipleToSingleReceiver(2, 10000); }
@Test(expected = RuntimeException.class, timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testNegativeTimeout() { List<NetworkConfiguration> conf = getNetConfs(2); newCloseableNetwork(conf.get(1), Duration.ofMillis(-10)); }
@Test(timeout = TWO_MINUTE_TIMEOUT_MILLIS, expected = RuntimeException.class) public void testReceiveAfterClose() { networks = createNetworks(3); closeNetworks(networks); networks.get(1).receive(2); }
@Test(timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testConnectMultipleParties() { networks = createNetworks(7); }
@Test(timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testSelfSendOneParty() { circularSendSingleMessage(1, 1024); }