use of io.atomix.protocols.raft.storage.RaftStorage in project atomix by atomix.
the class RaftTest method testSnapshotSentOnDataLoss.
@Test
public void testSnapshotSentOnDataLoss() throws Throwable {
final List<RaftMember> members = Lists.newArrayList(createMember(), createMember(), createMember());
final Map<MemberId, RaftStorage> storages = members.stream().map(RaftMember::memberId).collect(Collectors.toMap(Function.identity(), this::createStorage));
final Map<MemberId, RaftServer> servers = storages.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, this::createServer));
// wait for cluster to start
startCluster(servers);
// fill two segments then compact so we have at least one snapshot
final RaftClient client = createClient(members);
final TestPrimitive primitive = createPrimitive(client);
fillSegment(primitive);
fillSegment(primitive);
Futures.allOf(servers.values().stream().map(RaftServer::compact)).thenRun(this::resume);
await(30000);
// partition into leader/followers
final Map<Boolean, List<RaftMember>> collect = members.stream().collect(Collectors.partitioningBy(m -> servers.get(m.memberId()).isLeader()));
final RaftMember leader = collect.get(true).get(0);
final RaftStorage leaderStorage = storages.get(leader.memberId());
final RaftMember slave = collect.get(false).get(0);
final RaftStorage slaveStorage = storages.get(slave.memberId());
// shutdown client + primitive
primitive.close().thenCompose(nothing -> client.close()).thenRun(this::resume);
await(30000);
// shutdown other node
final RaftMember other = collect.get(false).get(1);
servers.get(other.memberId()).shutdown().thenRun(this::resume);
await(30000);
// shutdown slave and recreate from scratch
final RaftServer slaveServer = recreateServerWithDataLoss(leader, slave, servers.get(slave.memberId()), slaveStorage);
assertEquals(leaderStorage.openSnapshotStore().getCurrentSnapshotIndex(), slaveStorage.openSnapshotStore().getCurrentSnapshotIndex());
// and again a second time to ensure the snapshot index of the member is reset
recreateServerWithDataLoss(leader, slave, slaveServer, slaveStorage);
assertEquals(leaderStorage.openSnapshotStore().getCurrentSnapshotIndex(), slaveStorage.openSnapshotStore().getCurrentSnapshotIndex());
}
use of io.atomix.protocols.raft.storage.RaftStorage in project atomix by atomix.
the class RaftServiceManagerTest method setupContext.
@Before
public void setupContext() throws IOException {
deleteStorage();
RaftStorage storage = RaftStorage.builder().withPrefix("test").withDirectory(PATH.toFile()).withNamespace(NAMESPACE).build();
PrimitiveTypeRegistry registry = new PrimitiveTypeRegistry() {
@Override
public Collection<PrimitiveType> getPrimitiveTypes() {
return Collections.singleton(new TestType());
}
@Override
public PrimitiveType getPrimitiveType(String typeName) {
return new TestType();
}
};
raft = new RaftContext("test", MemberId.from("test-1"), mock(ClusterMembershipService.class), mock(RaftServerProtocol.class), storage, registry, ThreadModel.SHARED_THREAD_POOL.factory("raft-server-test-%d", 1, LoggerFactory.getLogger(RaftServer.class)), true);
snapshotTaken = new AtomicBoolean();
snapshotInstalled = new AtomicBoolean();
}
Aggregations