@Ignore @Test public void networkReconfigurationTestParallel() throws Exception { if(1 > 0) return; List<Main> mm = new ArrayList<>(); for (int i = 0; i < 4; i++) { mm.add(createMain("node" + (i + 1), "_dynamic_test", false)); } for (Main m : mm) { m.shutdown(); } mm.clear(); List<String> dbUrls = new ArrayList<>(); dbUrls.add("jdbc:postgresql: dbUrls.add("jdbc:postgresql: dbUrls.add("jdbc:postgresql: dbUrls.add("jdbc:postgresql: Random rand = new Random(); rand.setSeed(new Date().getTime()); final ArrayList<Integer> clientSleeps = new ArrayList<>(); final ArrayList<Integer> nodeSleeps = new ArrayList<>(); for (int i = 0; i < 4; i++) { mm.add(createMainFromDb(dbUrls.get(i), false)); nodeSleeps.add(rand.nextInt(100)); } PrivateKey myKey = TestKeys.privateKey(3); final ArrayList<Client> clients = new ArrayList<>(); final ArrayList<Integer> clientNodes = new ArrayList<>(); final ArrayList<Contract> contracts = new ArrayList<>(); final ArrayList<Parcel> parcels = new ArrayList<>(); final ArrayList<Boolean> contractsApproved = new ArrayList<>(); for (int i = 0; i < 40; i++) { Contract contract = new Contract(myKey); contract.seal(); assertTrue(contract.isOk()); contracts.add(contract); contractsApproved.add(false); NodeInfo info = mm.get(rand.nextInt(3)).myInfo; clientNodes.add(info.getNumber()); Client client = new Client(TestKeys.privateKey(i), info, null); clients.add(client); clientSleeps.add(rand.nextInt(100)); Parcel parcel = createParcelWithFreshU(client, contract, Do.listOf(myKey)); parcels.add(parcel); } Semaphore semaphore = new Semaphore(-39); final AtomicInteger atomicInteger = new AtomicInteger(40); for (int i = 0; i < 40; i++) { int finalI = i; Thread th = new Thread(() -> { try { Thread.sleep(clientSleeps.get(finalI)); Contract contract = contracts.get(finalI); Client client = clients.get(finalI); System.out.println("Register item " + contract.getId().toBase64String() + " @ node #" + clientNodes.get(finalI)); client.registerParcelWithState(parcels.get(finalI).pack(), 15000); ItemResult rr; while (true) { rr = client.getState(contract.getId()); Thread.currentThread().sleep(500); if (!rr.state.isPending()) break; } assertEquals(rr.state, ItemState.APPROVED); semaphore.release(); atomicInteger.decrementAndGet(); contractsApproved.set(finalI, true); } catch (ClientError clientError) { clientError.printStackTrace(); fail(clientError.getMessage()); } catch (InterruptedException e) { e.printStackTrace(); fail(e.getMessage()); } catch (IOException e) { e.printStackTrace(); fail(e.getMessage()); } }); th.start(); } for (int i = 0; i < 3; i++) { int finalI = i; Thread th = new Thread(() -> { try { Thread.sleep(nodeSleeps.get(finalI)); } catch (InterruptedException e) { e.printStackTrace(); fail(e.getMessage()); } System.out.println("Adding new node @ node #" + (finalI + 1)); mm.get(finalI).node.addNode(mm.get(3).myInfo); System.out.println("Done new node @ node #" + (finalI + 1)); }); th.start(); } Thread.sleep(5000); if (!semaphore.tryAcquire(15, TimeUnit.SECONDS)) { for (int i = 0; i < contractsApproved.size(); i++) { if (!contractsApproved.get(i)) { System.out.println("Stuck item:" + contracts.get(i).getId().toBase64String()); } } System.out.print("Client sleeps: "); for (Integer s : clientSleeps) { System.out.print(s + ", "); } System.out.println(); System.out.print("Node sleeps: "); for (Integer s : nodeSleeps) { System.out.print(s + ", "); } System.out.println(); fail("Items stuck: " + atomicInteger.get()); } for (Main m : mm) { m.shutdown(); } System.gc(); }
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; }