@Test public void testPlay() { Paxos p1 = new Paxos(new Paxos.PaxosParameters()); p1.play(); }
void play() { List<StatsHelper.StatsGetter> statsToGet = new ArrayList<>(); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).doneAt); } @Override public String toString() { return "doneAt"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).timeoutCount); } @Override public String toString() { return "timeoutCount"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).reject1Count); } @Override public String toString() { return "reject1Count"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).reject2Count); } @Override public String toString() { return "reject2Count"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { return StatsHelper.getStatsOn(liveNodes, Node::getMsgReceived); } @Override public String toString() { return "getMsgReceived"; } }); Predicate<Paxos> finalCheck = paxos -> { Integer val = null; for (ProposerNode pn : paxos.proposers) { if (val == null) { val = pn.valueAccepted; } else { if (!val.equals(pn.valueAccepted)) { return false; } } } return true; }; RunMultipleTimes<Paxos> rmt = new RunMultipleTimes<>(this, 10, 5000, statsToGet, finalCheck); List<StatsHelper.Stat> res = rmt.run( protocol -> { for (Node n : protocol.network().allNodes) { if (n instanceof ProposerNode && n.doneAt == 0) { return true; } } return false; }); StatsHelper.SimpleStats da = (StatsHelper.SimpleStats) res.get(0); StatsHelper.SimpleStats to = (StatsHelper.SimpleStats) res.get(1); StatsHelper.SimpleStats r1 = (StatsHelper.SimpleStats) res.get(2); StatsHelper.SimpleStats r2 = (StatsHelper.SimpleStats) res.get(3); StatsHelper.SimpleStats mr = (StatsHelper.SimpleStats) res.get(4); System.out.println( this + ", doneAt=(" + da + "), timeout=(" + to + "), rejectRound1=(" + r1 + "), rejectRound2=" + r2 + "), msg received=(" + mr + ")"); }
Paxos implements Protocol { void play() { List<StatsHelper.StatsGetter> statsToGet = new ArrayList<>(); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).doneAt); } @Override public String toString() { return "doneAt"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).timeoutCount); } @Override public String toString() { return "timeoutCount"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).reject1Count); } @Override public String toString() { return "reject1Count"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).reject2Count); } @Override public String toString() { return "reject2Count"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { return StatsHelper.getStatsOn(liveNodes, Node::getMsgReceived); } @Override public String toString() { return "getMsgReceived"; } }); Predicate<Paxos> finalCheck = paxos -> { Integer val = null; for (ProposerNode pn : paxos.proposers) { if (val == null) { val = pn.valueAccepted; } else { if (!val.equals(pn.valueAccepted)) { return false; } } } return true; }; RunMultipleTimes<Paxos> rmt = new RunMultipleTimes<>(this, 10, 5000, statsToGet, finalCheck); List<StatsHelper.Stat> res = rmt.run( protocol -> { for (Node n : protocol.network().allNodes) { if (n instanceof ProposerNode && n.doneAt == 0) { return true; } } return false; }); StatsHelper.SimpleStats da = (StatsHelper.SimpleStats) res.get(0); StatsHelper.SimpleStats to = (StatsHelper.SimpleStats) res.get(1); StatsHelper.SimpleStats r1 = (StatsHelper.SimpleStats) res.get(2); StatsHelper.SimpleStats r2 = (StatsHelper.SimpleStats) res.get(3); StatsHelper.SimpleStats mr = (StatsHelper.SimpleStats) res.get(4); System.out.println( this + ", doneAt=(" + da + "), timeout=(" + to + "), rejectRound1=(" + r1 + "), rejectRound2=" + r2 + "), msg received=(" + mr + ")"); } }
Paxos implements Protocol { void play() { List<StatsHelper.StatsGetter> statsToGet = new ArrayList<>(); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).doneAt); } @Override public String toString() { return "doneAt"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).timeoutCount); } @Override public String toString() { return "timeoutCount"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).reject1Count); } @Override public String toString() { return "reject1Count"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).reject2Count); } @Override public String toString() { return "reject2Count"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { return StatsHelper.getStatsOn(liveNodes, Node::getMsgReceived); } @Override public String toString() { return "getMsgReceived"; } }); Predicate<Paxos> finalCheck = paxos -> { Integer val = null; for (ProposerNode pn : paxos.proposers) { if (val == null) { val = pn.valueAccepted; } else { if (!val.equals(pn.valueAccepted)) { return false; } } } return true; }; RunMultipleTimes<Paxos> rmt = new RunMultipleTimes<>(this, 10, 5000, statsToGet, finalCheck); List<StatsHelper.Stat> res = rmt.run( protocol -> { for (Node n : protocol.network().allNodes) { if (n instanceof ProposerNode && n.doneAt == 0) { return true; } } return false; }); StatsHelper.SimpleStats da = (StatsHelper.SimpleStats) res.get(0); StatsHelper.SimpleStats to = (StatsHelper.SimpleStats) res.get(1); StatsHelper.SimpleStats r1 = (StatsHelper.SimpleStats) res.get(2); StatsHelper.SimpleStats r2 = (StatsHelper.SimpleStats) res.get(3); StatsHelper.SimpleStats mr = (StatsHelper.SimpleStats) res.get(4); System.out.println( this + ", doneAt=(" + da + "), timeout=(" + to + "), rejectRound1=(" + r1 + "), rejectRound2=" + r2 + "), msg received=(" + mr + ")"); } Paxos(PaxosParameters params); }
Paxos implements Protocol { void play() { List<StatsHelper.StatsGetter> statsToGet = new ArrayList<>(); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).doneAt); } @Override public String toString() { return "doneAt"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).timeoutCount); } @Override public String toString() { return "timeoutCount"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).reject1Count); } @Override public String toString() { return "reject1Count"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).reject2Count); } @Override public String toString() { return "reject2Count"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { return StatsHelper.getStatsOn(liveNodes, Node::getMsgReceived); } @Override public String toString() { return "getMsgReceived"; } }); Predicate<Paxos> finalCheck = paxos -> { Integer val = null; for (ProposerNode pn : paxos.proposers) { if (val == null) { val = pn.valueAccepted; } else { if (!val.equals(pn.valueAccepted)) { return false; } } } return true; }; RunMultipleTimes<Paxos> rmt = new RunMultipleTimes<>(this, 10, 5000, statsToGet, finalCheck); List<StatsHelper.Stat> res = rmt.run( protocol -> { for (Node n : protocol.network().allNodes) { if (n instanceof ProposerNode && n.doneAt == 0) { return true; } } return false; }); StatsHelper.SimpleStats da = (StatsHelper.SimpleStats) res.get(0); StatsHelper.SimpleStats to = (StatsHelper.SimpleStats) res.get(1); StatsHelper.SimpleStats r1 = (StatsHelper.SimpleStats) res.get(2); StatsHelper.SimpleStats r2 = (StatsHelper.SimpleStats) res.get(3); StatsHelper.SimpleStats mr = (StatsHelper.SimpleStats) res.get(4); System.out.println( this + ", doneAt=(" + da + "), timeout=(" + to + "), rejectRound1=(" + r1 + "), rejectRound2=" + r2 + "), msg received=(" + mr + ")"); } Paxos(PaxosParameters params); @Override Network<PaxosNode> network(); @Override Paxos copy(); @Override void init(); @Override String toString(); static void main(String... args); }
Paxos implements Protocol { void play() { List<StatsHelper.StatsGetter> statsToGet = new ArrayList<>(); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).doneAt); } @Override public String toString() { return "doneAt"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).timeoutCount); } @Override public String toString() { return "timeoutCount"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).reject1Count); } @Override public String toString() { return "reject1Count"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { List<Node> proposers = liveNodes.stream() .filter(n -> n instanceof ProposerNode) .collect(Collectors.toList()); return StatsHelper.getStatsOn(proposers, p -> ((ProposerNode) p).reject2Count); } @Override public String toString() { return "reject2Count"; } }); statsToGet.add( new StatsHelper.SimpleStatsGetter() { @Override public StatsHelper.Stat get(List<? extends Node> liveNodes) { return StatsHelper.getStatsOn(liveNodes, Node::getMsgReceived); } @Override public String toString() { return "getMsgReceived"; } }); Predicate<Paxos> finalCheck = paxos -> { Integer val = null; for (ProposerNode pn : paxos.proposers) { if (val == null) { val = pn.valueAccepted; } else { if (!val.equals(pn.valueAccepted)) { return false; } } } return true; }; RunMultipleTimes<Paxos> rmt = new RunMultipleTimes<>(this, 10, 5000, statsToGet, finalCheck); List<StatsHelper.Stat> res = rmt.run( protocol -> { for (Node n : protocol.network().allNodes) { if (n instanceof ProposerNode && n.doneAt == 0) { return true; } } return false; }); StatsHelper.SimpleStats da = (StatsHelper.SimpleStats) res.get(0); StatsHelper.SimpleStats to = (StatsHelper.SimpleStats) res.get(1); StatsHelper.SimpleStats r1 = (StatsHelper.SimpleStats) res.get(2); StatsHelper.SimpleStats r2 = (StatsHelper.SimpleStats) res.get(3); StatsHelper.SimpleStats mr = (StatsHelper.SimpleStats) res.get(4); System.out.println( this + ", doneAt=(" + da + "), timeout=(" + to + "), rejectRound1=(" + r1 + "), rejectRound2=" + r2 + "), msg received=(" + mr + ")"); } Paxos(PaxosParameters params); @Override Network<PaxosNode> network(); @Override Paxos copy(); @Override void init(); @Override String toString(); static void main(String... args);  }