@Test public void resynItemTest() throws Exception { PrivateKey issuerKey = new PrivateKey(Do.read("./src/test_contracts/keys/reconfig_key.private.unikey")); TestSpace testSpace = prepareTestSpace(issuerKey); testSpace.nodes.forEach(n -> n.config.setIsFreeRegistrationsAllowedFromYaml(true)); int absentNode = testSpace.nodes.size() - 1; testSpace.nodes.get(absentNode).shutdown(); testSpace.nodes.remove(absentNode); Contract contract = new Contract(issuerKey); contract.seal(); testSpace.client.register(contract.getPackedTransaction(), 1500); assertEquals(testSpace.client.getState(contract.getId()).state, ItemState.APPROVED); testSpace.nodes.forEach(n -> n.shutdown()); Thread.sleep(2000); testSpace = prepareTestSpace(issuerKey); testSpace.nodes.forEach(n -> n.config.setIsFreeRegistrationsAllowedFromYaml(true)); assertEquals(testSpace.client.getState(contract.getId()).state, ItemState.APPROVED); StateRecord r0 = testSpace.nodes.get(0).node.getLedger().getRecord(contract.getId()); r0.setExpiresAt(r0.getExpiresAt().minusHours(1)); r0.save(); StateRecord r1 = testSpace.nodes.get(1).node.getLedger().getRecord(contract.getId()); r1.setCreatedAt(r1.getCreatedAt().plusHours(1)); r1.save(); Client absentNodeClient = new Client(testSpace.myKey, testSpace.nodes.get(absentNode).myInfo, null); assertEquals(absentNodeClient.getState(contract.getId()).state, ItemState.UNDEFINED); absentNodeClient.resyncItem(contract.getId()); assertEquals(testSpace.client.getState(contract.getId()).state, ItemState.APPROVED); ItemResult rr; while (true) { rr = absentNodeClient.getState(contract.getId()); if (!rr.state.isPending()) break; Thread.sleep(500); } assertEquals(rr.state, ItemState.APPROVED); Average createdAverage = new Average(); Average expiredAverage = new Average(); ItemResult ir0 = testSpace.nodes.get(0).node.checkItem(contract.getId()); ItemResult ir1 = testSpace.nodes.get(1).node.checkItem(contract.getId()); ItemResult ir2 = testSpace.nodes.get(2).node.checkItem(contract.getId()); createdAverage.update(ir0.createdAt.toEpochSecond()); createdAverage.update(ir2.createdAt.toEpochSecond()); expiredAverage.update(ir1.expiresAt.toEpochSecond()); expiredAverage.update(ir2.expiresAt.toEpochSecond()); assertEquals(rr.createdAt.toEpochSecond(), (long) createdAverage.average()); assertEquals(rr.expiresAt.toEpochSecond(), (long) expiredAverage.average()); testSpace.nodes.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; }