Package org.robotninjas.barge

Examples of org.robotninjas.barge.Replica


          Term term = entry.getTerm();
          visitor.term(mark, term.getTerm());
        } else if (entry.hasVote()) {
          Vote vote = entry.getVote();
          String votedfor = vote.getVotedFor();
          Replica replica = votedfor == null
            ? null : config.getReplica(votedfor);
          visitor.vote(mark, Optional.fromNullable(replica));
        }

      }
View Full Code Here


    //  If votedFor is null or candidateId, and candidate's log is at
    //  least as up-to-date as receiver’s log, grant vote (§5.2, §5.4)
     
    Optional<Replica> votedFor = log.votedFor();
    Replica candidate = log.getReplica(request.getCandidateId());

    if (votedFor.isPresent()) {
      if (!votedFor.get().equals(candidate)) {
        return false;
      }
View Full Code Here

          ctx.setState(this, FOLLOWER);
        }

      }

      Replica candidate = log.getReplica(request.getCandidateId());
      voteGranted = shouldVoteFor(log, request);

      if (voteGranted) {
        log.votedFor(Optional.of(candidate));
      }
View Full Code Here

      .setLastLogIndex(2)
      .setLastLogTerm(3)
      .setTerm(2)
      .build();

    Replica otherCandidate = config.getReplica("other");
    when(mockRaftLog.votedFor()).thenReturn(Optional.of(otherCandidate));
    boolean shouldVote = state.shouldVoteFor(mockRaftLog, requestVote);

    assertTrue(shouldVote);
  }
View Full Code Here

      .setLastLogIndex(2)
      .setLastLogTerm(1)
      .setTerm(2)
      .build();

    Replica otherCandidate = config.getReplica("other");
    when(mockRaftLog.votedFor()).thenReturn(Optional.of(otherCandidate));
    boolean shouldVote = state.shouldVoteFor(mockRaftLog, requestVote);

    assertFalse(shouldVote);
  }
View Full Code Here

      .setLastLogIndex(1)
      .setLastLogTerm(2)
      .setTerm(2)
      .build();

    Replica otherCandidate = config.getReplica("other");
    when(mockRaftLog.votedFor()).thenReturn(Optional.of(otherCandidate));
    boolean shouldVote = state.shouldVoteFor(mockRaftLog, requestVote);

    assertFalse(shouldVote);
  }
View Full Code Here

      .setLastLogIndex(3)
      .setLastLogTerm(2)
      .setTerm(2)
      .build();

    Replica otherCandidate = config.getReplica("other");
    when(mockRaftLog.votedFor()).thenReturn(Optional.of(otherCandidate));
    boolean shouldVote = state.shouldVoteFor(mockRaftLog, requestVote);

    assertTrue(shouldVote);
  }
View Full Code Here

  public void testRequestVoteWithNewerTerm() throws Exception {

    Candidate candidate = new Candidate(mockRaftLog, scheduler, 150, mockRaftClient);
    candidate.init(mockRaftStateContext);

    Replica mockCandidate = config.getReplica("other");

    RequestVote request =
      RequestVote.newBuilder()
        .setCandidateId(mockCandidate.toString())
        .setLastLogIndex(1L)
        .setLastLogTerm(1L)
        .setTerm(4L)
        .build();
View Full Code Here

  @Test
  public void testRequestVoteWithOlderTerm() throws Exception {
    Candidate candidate = new Candidate(mockRaftLog, scheduler, 150, mockRaftClient);
    candidate.init(mockRaftStateContext);

    Replica mockCandidate = config.getReplica("other");

    RequestVote request =
      RequestVote.newBuilder()
        .setCandidateId(mockCandidate.toString())
        .setLastLogIndex(1L)
        .setLastLogTerm(1L)
        .setTerm(1L)
        .build();
View Full Code Here

  @Test
  public void testRequestVoteWithSameTerm() throws Exception {
    Candidate candidate = new Candidate(mockRaftLog, scheduler, 150, mockRaftClient);
    candidate.init(mockRaftStateContext);

    Replica mockCandidate = config.getReplica("other");

    RequestVote request =
      RequestVote.newBuilder()
        .setCandidateId(mockCandidate.toString())
        .setLastLogIndex(1L)
        .setLastLogTerm(1L)
        .setTerm(2L)
        .build();
View Full Code Here

TOP

Related Classes of org.robotninjas.barge.Replica

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.