Package net.kuujo.copycat.internal.log

Examples of net.kuujo.copycat.internal.log.SnapshotEntry


  }

  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);
    assertEquals("Hello world!", new String(entry.data()));
  }
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);
    assertEquals("Hello world!", new String(entry.data()));
    OperationEntry entry2 = log.getEntry(4);
    assertEquals(entry2.term(), 1);
    assertEquals("bar", entry2.operation());
    OperationEntry entry3 = log.getEntry(5);
    assertEquals(entry3.term(), 1);
View Full Code Here

    log.appendEntry(new OperationEntry(1, "foo", "bar"));
    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"))));
View Full Code Here

        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

   * @return A snapshot of the state machine state.
   */
  protected SnapshotEntry createSnapshot() {
    byte[] snapshot = context.stateMachineExecutor().stateMachine().takeSnapshot();
    if (snapshot != null) {
      return new SnapshotEntry(context.currentTerm(), context.clusterManager().cluster().config().copy(), snapshot);
    }
    return null;
  }
View Full Code Here

    // out-of-sync followers.
    if (context.log().size() > context.config().getMaxLogSize()) {
      synchronized (context.log()) {
        logger().info("{} - Compacting log", context.clusterManager().localNode());
        final long lastApplied = context.lastApplied();
        final SnapshotEntry snapshot = createSnapshot();
        if (snapshot != null) {
          try {
            context.log().compact(lastApplied, snapshot);
          } catch (IOException e) {
            throw new CopycatException(e, "Failed to compact log.");
View Full Code Here

   */
  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);
    SyncRequest result = reader.readRequest(writer.writeRequest(request));
View Full Code Here

      .withLocalMember(new Member("foo"))
      .withRemoteMembers(new Member("bar"), new Member("baz"))));
    for (long i = 0; i < 1000; i++) {
      log1.appendEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")));
    }
    SnapshotEntry snapshot1 = new SnapshotEntry(1, new ClusterConfig()
      .withLocalMember(new Member("foo"))
      .withRemoteMembers(new Member("bar"), new Member("baz")),
      "Hello world!".getBytes());
    log1.compact(800, snapshot1);

    TestCluster cluster = new TestCluster();
    TestNode node1 = new TestNode()
      .withCluster("foo", "bar", "baz")
      .withProtocol(protocol)
      .withTerm(1)
      .withLeader("baz")
      .withStateMachine(new TestStateMachine())
      .withLog(log1)
      .withState(CopycatState.FOLLOWER)
      .withCommitIndex(999)
      .withLastApplied(999);
    cluster.addNode(node1);

    TestNode node2 = new TestNode()
      .withCluster("bar", "foo", "baz")
      .withProtocol(protocol)
      .withTerm(1)
      .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(1, "foo", Arrays.asList("bar", "baz")))
        .withEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz"))))
      .withState(CopycatState.FOLLOWER)
      .withCommitIndex(0)
      .withLastApplied(0);
    cluster.addNode(node2);

    TestLog log3 = new TestLog();
    log1.appendEntry(new ConfigurationEntry(1, new ClusterConfig()
      .withLocalMember(new Member("baz"))
      .withRemoteMembers(new Member("bar"), new Member("foo"))));
    for (long i = 0; i < 1000; i++) {
      log3.appendEntry(new OperationEntry(1, "foo", Arrays.asList("bar", "baz")));
    }
    SnapshotEntry snapshot3 = new SnapshotEntry(1, new ClusterConfig()
      .withLocalMember(new Member("baz"))
      .withRemoteMembers(new Member("bar"), new Member("foo")),
      "Hello world!".getBytes());
    log3.compact(800, snapshot3);
View Full Code Here

  }

  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);
    assertEquals("Hello world!", new String(entry.data()));
  }
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);
    assertEquals("Hello world!", new String(entry.data()));
    OperationEntry entry2 = log.getEntry(4);
    assertEquals(entry2.term(), 1);
    assertEquals("bar", entry2.operation());
    OperationEntry entry3 = log.getEntry(5);
    assertEquals(entry3.term(), 1);
View Full Code Here

TOP

Related Classes of net.kuujo.copycat.internal.log.SnapshotEntry

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.