Package net.kuujo.copycat.cluster

Examples of net.kuujo.copycat.cluster.Member


  public void testCompactEndOfLog() throws Exception {
    appendEntries();
    log.compact(5,
      new SnapshotEntry(1, new ClusterConfig()
        .withLocalMember(new Member("foo"))
        .withRemoteMembers(new Member("bar"), new Member("baz")), "Hello world!".getBytes()));

    assertEquals(log.firstIndex(), 5);
    assertEquals(log.lastIndex(), 5);
    SnapshotEntry entry = log.getEntry(5);
    assertEquals(entry.term(), 1);
View Full Code Here


  public void testCompactMiddleOfLog() throws Exception {
    appendEntries();
    log.compact(3,
      new SnapshotEntry(1, new ClusterConfig()
        .withLocalMember(new Member("foo"))
        .withRemoteMembers(new Member("bar"), new Member("baz")), "Hello world!".getBytes()));

    assertEquals(log.firstIndex(), 3);
    assertEquals(log.lastIndex(), 5);
    SnapshotEntry entry = log.getEntry(3);
    assertEquals(entry.term(), 1);
View Full Code Here

    assertNotEquals(size, size = log.size());
  }

  private void appendEntries() {
    log.appendEntry(new SnapshotEntry(1, new ClusterConfig()
      .withLocalMember(new Member("foo"))
      .withRemoteMembers(new Member("bar"), new Member("baz")), new byte[10]));
    log.appendEntry(new ConfigurationEntry(1, new ClusterConfig()
      .withLocalMember(new Member("foo"))
      .withRemoteMembers(new Member("bar"), new Member("baz"))));
    log.appendEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")));
    log.appendEntry(new OperationEntry(1, "bar", Arrays.asList("bar", "baz")));
    log.appendEntry(new OperationEntry(1, "baz", Arrays.asList("bar", "baz")));
  }
View Full Code Here

   * @param members The test node cluster members.
   * @return The test node.
   */
  public TestNode withCluster(String... members) {
    ClusterConfig<Member> config = new ClusterConfig<>();
    config.setLocalMember(new Member(members[0]));
    for (int i = 1; i < members.length; i++) {
      config.addRemoteMember(new Member(members[i]));
    }
    this.cluster = new Cluster<>(config);
    return this;
  }
View Full Code Here

  private Object[][] entryProvider() {
    return new Object[][] {
      {OperationEntry.class, new OperationEntry(1, "foo", Arrays.asList("bar", "baz"))},
      {
        ConfigurationEntry.class,
        new ConfigurationEntry(1, new ClusterConfig().withLocalMember(new Member("foo"))
          .withRemoteMembers(new Member("bar"), new Member("baz")))},
      {
        SnapshotEntry.class,
        new SnapshotEntry(1, new ClusterConfig().withLocalMember(new Member("foo"))
          .withRemoteMembers(new Member("bar"), new Member("baz")), new byte[] {1, 2, 3})}};
  }
View Full Code Here

  /**
   * Tests writing/reading a sync request.
   */
  public void testWriteReadSyncRequest() {
    ClusterConfig<Member> clusterConfig = new ClusterConfig<>()
      .withLocalMember(new Member(new MemberConfig("foo")))
      .withRemoteMembers(new Member(new MemberConfig("bar")), new Member(new MemberConfig("baz")));
    SnapshotEntry snapshotEntry = new SnapshotEntry(1, clusterConfig, new byte[50]);
    ConfigurationEntry configurationEntry = new ConfigurationEntry(1, clusterConfig);
    OperationEntry operationEntry = new OperationEntry(1, "foo", Arrays.asList("bar", "baz"));
    List<Entry> entries = Arrays.asList(snapshotEntry, configurationEntry, operationEntry);
    SyncRequest request = new SyncRequest(UUID.randomUUID().toString(), 1, "foo", 4, 1, entries, 3);
View Full Code Here

      .withTerm(3)
      .withLeader("baz")
      .withStateMachine(new TestStateMachine())
      .withLog(new TestLog()
        .withEntry(new ConfigurationEntry(1, new ClusterConfig()
          .withLocalMember(new Member("foo"))
          .withRemoteMembers(new Member("bar"), new Member("baz"))))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(2, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(2, "foo", Arrays.asList("bar", "baz"))))
      .withState(CopycatState.FOLLOWER)
      .withCommitIndex(6)
      .withLastApplied(6);
    cluster.addNode(node1);

    TestNode node2 = new TestNode()
      .withCluster("bar", "foo", "baz")
      .withProtocol(protocol)
      .withTerm(3)
      .withLeader("baz")
      .withStateMachine(new TestStateMachine())
      .withLog(new TestLog()
        .withEntry(new ConfigurationEntry(1, new ClusterConfig()
          .withLocalMember(new Member("bar"))
          .withRemoteMembers(new Member("foo"), new Member("baz"))))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(2, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(2, "foo", Arrays.asList("bar", "baz"))))
      .withState(CopycatState.FOLLOWER)
      .withCommitIndex(6)
      .withLastApplied(6);
    cluster.addNode(node2);

    TestNode node3 = new TestNode()
      .withCluster("baz", "bar", "foo")
      .withProtocol(protocol)
      .withTerm(3)
      .withLeader("baz")
      .withStateMachine(new TestStateMachine())
      .withLog(new TestLog()
        .withEntry(new ConfigurationEntry(1, new ClusterConfig()
          .withLocalMember(new Member("baz"))
          .withRemoteMembers(new Member("foo"), new Member("bar"))))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(2, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(2, "foo", Arrays.asList("bar", "baz"))))
      .withState(CopycatState.LEADER)
      .withCommitIndex(6)
      .withLastApplied(6);
    cluster.addNode(node3);

    cluster.start();

    node3.instance().cluster().config().addRemoteMember(new Member("foobarbaz"));

    // First, the leader should have replicated a join configuration.
    node1.await().membershipChange();
    Assert.assertNotNull(node1.instance().clusterManager().cluster().remoteMember("foobarbaz"));
    cluster.stop();
View Full Code Here

      .withTerm(3)
      .withLeader("baz")
      .withStateMachine(new TestStateMachine())
      .withLog(new TestLog()
        .withEntry(new ConfigurationEntry(1, new ClusterConfig()
          .withLocalMember(new Member("foo"))
          .withRemoteMembers(new Member("bar"), new Member("baz"), new Member("foobarbaz"))))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(2, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(2, "foo", Arrays.asList("bar", "baz"))))
      .withState(CopycatState.FOLLOWER)
      .withCommitIndex(6)
      .withLastApplied(6);
    cluster.addNode(node1);

    TestNode node2 = new TestNode()
      .withCluster("bar", "foo", "baz", "foobarbaz")
      .withProtocol(protocol)
      .withTerm(3)
      .withLeader("baz")
      .withStateMachine(new TestStateMachine())
      .withLog(new TestLog()
        .withEntry(new ConfigurationEntry(1, new ClusterConfig()
          .withLocalMember(new Member("bar"))
          .withRemoteMembers(new Member("foo"), new Member("baz"), new Member("foobarbaz"))))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(2, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(2, "foo", Arrays.asList("bar", "baz"))))
      .withState(CopycatState.FOLLOWER)
      .withCommitIndex(6)
      .withLastApplied(6);
    cluster.addNode(node2);

    TestNode node3 = new TestNode()
      .withCluster("baz", "bar", "foo", "foobarbaz")
      .withProtocol(protocol)
      .withTerm(3)
      .withLeader("baz")
      .withStateMachine(new TestStateMachine())
      .withLog(new TestLog()
        .withEntry(new ConfigurationEntry(1, new ClusterConfig()
          .withLocalMember(new Member("baz"))
          .withRemoteMembers(new Member("foo"), new Member("bar"), new Member("foobarbaz"))))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(2, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(2, "foo", Arrays.asList("bar", "baz"))))
      .withState(CopycatState.LEADER)
      .withCommitIndex(6)
      .withLastApplied(6);
    cluster.addNode(node3);

    cluster.start();

    node3.instance().cluster().config().removeRemoteMember(new Member("foobarbaz"));

    // First, the leader should have replicated a join configuration.
    if (node1.instance().clusterManager().cluster().remoteMember("foobarbaz") == null) {
      Assert.assertNull(node1.instance().clusterManager().cluster().remoteMember("foobarbaz"));
    } else {
View Full Code Here

   */
  public void testRegisterAndUnregisterVoteCastHandlerByMethod() {
    AtomicBoolean succeeded = new AtomicBoolean();
    EventHandler<VoteCastEvent> handler = (event) -> succeeded.set(true);
    handlers.voteCast().registerHandler(handler);
    handlers.voteCast().handle(new VoteCastEvent(1, new Member("foo")));
    Assert.assertTrue(succeeded.get());
    handlers.voteCast().unregisterHandler(handler);
    succeeded.set(false);
    handlers.voteCast().handle(new VoteCastEvent(1, new Member("foo")));
    Assert.assertFalse(succeeded.get());
  }
View Full Code Here

   */
  public void testRegisterAndUnregisterVoteCastHandlerByEvent() {
    AtomicBoolean succeeded = new AtomicBoolean();
    EventHandler<VoteCastEvent> handler = (event) -> succeeded.set(true);
    handlers.event(VoteCastEvent.class).registerHandler(handler);
    handlers.event(VoteCastEvent.class).handle(new VoteCastEvent(1, new Member("foo")));
    Assert.assertTrue(succeeded.get());
    handlers.event(VoteCastEvent.class).unregisterHandler(handler);
    succeeded.set(false);
    handlers.event(VoteCastEvent.class).handle(new VoteCastEvent(1, new Member("foo")));
    Assert.assertFalse(succeeded.get());
  }
View Full Code Here

TOP

Related Classes of net.kuujo.copycat.cluster.Member

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.