@Before public void init() throws Exception { _node1 = new ServerDispatcher(); Core myCore = new Core( new MemoryLogStorage(), CheckpointHandle.NO_CHECKPOINT, new Listener() { public void transition(StateEvent anEvent) {} }); LastListenerImpl myListener = new LastListenerImpl(myCore); _node2 = new ServerDispatcher(myCore, myListener); _tport1 = new TransportImpl(new FailureDetectorImpl(5000, FailureDetectorImpl.OPEN_PIN)); _tport1.routeTo(_node1); _node1.init(_tport1); _tport2 = new TransportImpl(new FailureDetectorImpl(5000, FailureDetectorImpl.OPEN_PIN)); _tport2.routeTo(_node2); _node2.init(_tport2); }
@Test public void post() throws Exception { ListenerImpl myListener = new ListenerImpl(); _node1.add(myListener); ClientDispatcher myClient = new ClientDispatcher(); TransportImpl myTransport = new TransportImpl(null); myTransport.routeTo(myClient); myClient.init(myTransport); ByteBuffer myBuffer = ByteBuffer.allocate(4); myBuffer.putInt(55); Proposal myProposal = new Proposal("data", myBuffer.array()); FailureDetector myFd = _tport1.getFD(); FDUtil.ensureFD(myFd); myClient.send(new Envelope(myProposal), _tport1.getLocalAddress()); VoteOutcome myEv = myClient.getNext(10000); Assert.assertFalse((myEv == null)); /* * Leader will have another value so will tell us the original proposal has been replaced by the last. * It will then push through what was the last, leading to an update on the listener. Client code would * have to re-submit the request for it's value but we're not doing that in this case... */ Assert.assertTrue(myEv.getResult() == VoteOutcome.Reason.OTHER_VALUE); Thread.sleep(5000); // Listener should see announce of a leader and a value // Assert.assertTrue( "Listener count should be 2 but is: " + myListener.getCount(), myListener.testCount(2)); }