use of io.atomix.protocols.raft.RaftClient in project atomix by atomix.
the class RaftPerformanceTest method createClient.
/**
* Creates a Raft client.
*/
private RaftClient createClient() throws Exception {
Member member = nextNode();
RaftClientProtocol protocol;
if (USE_NETTY) {
MessagingService messagingService = new NettyMessagingService("test", member.address(), new MessagingConfig()).start().join();
protocol = new RaftClientMessagingProtocol(messagingService, PROTOCOL_SERIALIZER, addressMap::get);
} else {
protocol = protocolFactory.newClientProtocol(member.id());
}
RaftClient client = RaftClient.builder().withMemberId(member.id()).withPartitionId(PartitionId.from("test", 1)).withProtocol(protocol).withThreadModel(ThreadModel.SHARED_THREAD_POOL).build();
client.connect(members.stream().map(Member::id).collect(Collectors.toList())).join();
clients.add(client);
return client;
}
use of io.atomix.protocols.raft.RaftClient in project atomix by atomix.
the class RaftFuzzTest method createClient.
/**
* Creates a Raft client.
*/
private RaftClient createClient() throws Exception {
MemberId memberId = nextNodeId();
RaftClientProtocol protocol;
if (USE_NETTY) {
Address address = Address.from(++port);
MessagingService messagingManager = new NettyMessagingService("test", address, new MessagingConfig()).start().join();
addressMap.put(memberId, address);
protocol = new RaftClientMessagingProtocol(messagingManager, PROTOCOL_SERIALIZER, addressMap::get);
} else {
protocol = protocolFactory.newClientProtocol(memberId);
}
RaftClient client = RaftClient.builder().withMemberId(memberId).withProtocol(protocol).build();
client.connect(members.stream().map(RaftMember::memberId).collect(Collectors.toList())).join();
clients.add(client);
return client;
}
use of io.atomix.protocols.raft.RaftClient in project atomix by atomix.
the class RaftFuzzTest method runFuzzTest.
/**
* Runs a single fuzz test.
*/
private void runFuzzTest() throws Exception {
reset();
createServers(randomNumber(5) + 3);
final Object lock = new Object();
final AtomicLong index = new AtomicLong();
final Map<Integer, Long> indexes = new HashMap<>();
ThreadContext context = new SingleThreadContext("fuzz-test");
int clients = randomNumber(10) + 1;
for (int i = 0; i < clients; i++) {
ReadConsistency consistency = randomConsistency();
RaftClient client = createClient();
SessionClient proxy = createProxy(client, consistency);
Scheduler scheduler = new SingleThreadContext("fuzz-test-" + i);
final int clientId = i;
scheduler.schedule(Duration.ofMillis((100 * clients) + (randomNumber(50) - 25)), Duration.ofMillis((100 * clients) + (randomNumber(50) - 25)), () -> {
long lastLinearizableIndex = index.get();
int type = randomNumber(4);
switch(type) {
case 0:
proxy.execute(operation(PUT, CLIENT_SERIALIZER.encode(Maps.immutableEntry(randomKey(), randomString(1024 * 16))))).<Long>thenApply(CLIENT_SERIALIZER::decode).thenAccept(result -> {
synchronized (lock) {
if (result < lastLinearizableIndex) {
System.out.println(result + " is less than last linearizable index " + lastLinearizableIndex);
System.exit(1);
} else if (result > index.get()) {
index.set(result);
}
Long lastSequentialIndex = indexes.get(clientId);
if (lastSequentialIndex == null) {
indexes.put(clientId, result);
} else if (result < lastSequentialIndex) {
System.out.println(result + " is less than last sequential index " + lastSequentialIndex);
System.exit(1);
} else {
indexes.put(clientId, lastSequentialIndex);
}
}
});
break;
case 1:
proxy.execute(operation(GET, CLIENT_SERIALIZER.encode(randomKey())));
break;
case 2:
proxy.execute(operation(REMOVE, CLIENT_SERIALIZER.encode(randomKey()))).<Long>thenApply(CLIENT_SERIALIZER::decode).thenAccept(result -> {
synchronized (lock) {
if (result < lastLinearizableIndex) {
System.out.println(result + " is less than last linearizable index " + lastLinearizableIndex);
System.exit(1);
} else if (result > index.get()) {
index.set(result);
}
Long lastSequentialIndex = indexes.get(clientId);
if (lastSequentialIndex == null) {
indexes.put(clientId, result);
} else if (result < lastSequentialIndex) {
System.out.println(result + " is less than last sequential index " + lastSequentialIndex);
System.exit(1);
} else {
indexes.put(clientId, lastSequentialIndex);
}
}
});
break;
case 3:
proxy.execute(operation(INDEX)).<Long>thenApply(CLIENT_SERIALIZER::decode).thenAccept(result -> {
synchronized (lock) {
switch(consistency) {
case LINEARIZABLE:
case LINEARIZABLE_LEASE:
if (result < lastLinearizableIndex) {
System.out.println(result + " is less than last linearizable index " + lastLinearizableIndex);
System.exit(1);
} else if (result > index.get()) {
index.set(result);
}
case SEQUENTIAL:
Long lastSequentialIndex = indexes.get(clientId);
if (lastSequentialIndex == null) {
indexes.put(clientId, result);
} else if (result < lastSequentialIndex) {
System.out.println(result + " is less than last sequential index " + lastSequentialIndex);
System.exit(1);
} else {
indexes.put(clientId, lastSequentialIndex);
}
}
}
});
}
});
}
scheduleRestarts(context);
Thread.sleep(Duration.ofMinutes(15).toMillis());
}
Aggregations