@Ignore @Test public void udpDisruptionTest() throws Exception { List<Main> mm = new ArrayList<>(); final int NODE_COUNT = 4; final int PORT_BASE = 12000; final int TEST_MODE = UDPAdapter.PacketTypes.HELLO; for (int i = 0; i < NODE_COUNT; i++) { mm.add(createMain("node" + (i + 1), false)); } class TestRunnable implements Runnable { int finalI; int finalJ; boolean alive = true; @Override public void run() { try { NodeInfo source = mm.get(finalI).myInfo; NodeInfo destination = mm.get(finalJ).myInfo; DatagramSocket socket = new DatagramSocket(PORT_BASE + finalI * NODE_COUNT + finalJ); while (alive) { if (TEST_MODE == UDPAdapter.PacketTypes.HELLO) sendHello(source, destination, mm.get(finalI).network.getUDPAdapter(), socket); else if (TEST_MODE == UDPAdapter.PacketTypes.WELCOME) sendWelcome(source, destination, mm.get(finalI).network.getUDPAdapter(), socket); else sendDataGarbage(source, destination, mm.get(finalI).network.getUDPAdapter(), socket); Thread.sleep(4); } } catch (Exception e) { System.out.println("runnable exception: " + e.toString()); } } } List<Thread> threadsList = new ArrayList<>(); List<TestRunnable> runnableList = new ArrayList<>(); for (int i = 0; i < NODE_COUNT; i++) { for (int j = 0; j < NODE_COUNT; j++) { if (j == i) continue; final int finalI = i; final int finalJ = j; TestRunnable runnableSingle = new TestRunnable(); runnableList.add(runnableSingle); threadsList.add( new Thread(() -> { runnableSingle.finalI = finalI; runnableSingle.finalJ = finalJ; runnableSingle.run(); })); } } for (Thread th : threadsList) { th.start(); } Thread.sleep(5000); PrivateKey myKey = TestKeys.privateKey(0); Client client = new Client(myKey, mm.get(0).myInfo, null); Contract contract = new Contract(myKey); contract.seal(); Parcel parcel = createParcelWithFreshU(client, contract, Do.listOf(myKey)); client.registerParcelWithState(parcel.pack(), 60000); ItemResult rr; while (true) { rr = client.getState(contract.getId()); if (!rr.state.isPending()) break; } assertEquals(rr.state, ItemState.APPROVED); for (TestRunnable tr : runnableList) { tr.alive = false; } for (Thread th : threadsList) { th.interrupt(); } mm.forEach(x -> x.shutdown()); }
public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } Main(String[] args); }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } Main(String[] args); static void main(String[] args); void waitReady(); void shutdown(); void setVerboseLevel(int level); void setUDPVerboseLevel(int level); void restartUDPAdapter(); PublicKey getNodePublicKey(); }
Main { public void shutdown() { try { if (hookThread != null) Runtime.getRuntime().removeShutdownHook(hookThread); ledger.close(); log("shutting down"); network.shutdown(); clientHTTPServer.shutdown(); } catch (Exception e) { } synchronized (parser) { parser.notifyAll(); } try { logger.close(); } catch (Exception e) { e.printStackTrace(); } } Main(String[] args); static void main(String[] args); void waitReady(); void shutdown(); void setVerboseLevel(int level); void setUDPVerboseLevel(int level); void restartUDPAdapter(); PublicKey getNodePublicKey(); static final String NODE_VERSION; final Reporter reporter; final BufferedLogger logger; public NetConfig netConfig; public NetworkV2 network; final Config config; public NodeInfo myInfo; public Node node; public ItemCache cache; public ParcelCache parcelCache; public PaidOperationCache paidOperationCache; }