use of net.sergeych.tools.AsyncEvent in project universa by UniversaBlockchain.
the class Node2LocalNetworkTest method resyncApproved.
@Test
public void resyncApproved() throws Exception {
AsyncEvent ae = new AsyncEvent();
Contract c = new Contract(TestKeys.privateKey(0));
c.seal();
addToAllLedgers(c, ItemState.APPROVED);
node.getLedger().getRecord(c.getId()).destroy();
assertEquals(ItemState.UNDEFINED, node.checkItem(c.getId()).state);
// Start checking nodes
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
boolean all_is_approved = true;
for (Node n : nodesMap_s.values()) {
// System.out.println(n.getLedger().getRecord(c.getId()));
ItemResult r = n.checkItem(c.getId());
System.out.println(">>>Node: " + n.toString() + " state: " + r.state);
if (r.state != ItemState.APPROVED) {
all_is_approved = false;
}
}
if (all_is_approved)
ae.fire();
}
}, 0, 1000);
node.resync(c.getId());
try {
ae.await(3000);
} catch (TimeoutException e) {
System.out.println("time is up");
}
timer.cancel();
assertEquals(ItemState.APPROVED, node.waitItem(c.getId(), 13000).state);
}
Aggregations