Пример #1
0
  @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));
  }