@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(expected = RuntimeException.class, timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testNegativeTimeout() { List<NetworkConfiguration> conf = getNetConfs(2); newCloseableNetwork(conf.get(1), Duration.ofMillis(-10)); }
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(expected = RuntimeException.class, timeout = TWO_MINUTE_TIMEOUT_MILLIS) public void testFailToBind() throws Throwable { ServerSocket socket = null; try { List<NetworkConfiguration> confs = getNetConfs(2); socket = ServerSocketFactory.getDefault().createServerSocket(confs.get(1).getMe().getPort()); newCloseableNetwork(confs.get(1)); } finally { socket.close(); } }