Skip to content

Commit

Permalink
RATIS-2091. Fix other checkstyle issues in test-directory
Browse files Browse the repository at this point in the history
  • Loading branch information
symious committed May 16, 2024
1 parent c81902a commit 1b9aeb3
Show file tree
Hide file tree
Showing 37 changed files with 262 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ void runGaussLegendre(RaftClient client) throws IOException {
final Variable p0 = new Variable("p" + i_1);
final Variable a1 = defineVariable(client, "a"+i, DIV.apply(ADD.apply(a0, b0), 2));
final Variable b1 = defineVariable(client, "b"+i, SQRT.apply(MULT.apply(a0, b0)));
final Variable t1 = defineVariable(client, "t"+i, SUBTRACT.apply(t0, MULT.apply(p0, SQUARE.apply(SUBTRACT.apply(a0, a1)))));
final Variable t1 = defineVariable(client, "t"+i,
SUBTRACT.apply(t0, MULT.apply(p0, SQUARE.apply(SUBTRACT.apply(a0, a1)))));
final Variable p1 = defineVariable(client, "p"+i, MULT.apply(2, p0));

final Variable pi_i = new Variable("pi_"+i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;

class FileStoreWriter implements Closeable {
final class FileStoreWriter implements Closeable {
public static final Logger LOG = LoggerFactory.getLogger(FileStoreWriter.class);

final long seed = ThreadLocalRandom.current().nextLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import org.apache.ratis.datastream.MiniRaftClusterWithRpcTypeGrpcAndDataStreamTypeNetty;

public class TestFileStoreStreamingWithGrpcCluster extends FileStoreStreamingBaseTest<MiniRaftClusterWithRpcTypeGrpcAndDataStreamTypeNetty>
public class TestFileStoreStreamingWithGrpcCluster
extends FileStoreStreamingBaseTest<MiniRaftClusterWithRpcTypeGrpcAndDataStreamTypeNetty>
implements MiniRaftClusterWithRpcTypeGrpcAndDataStreamTypeNetty.FactoryGet {

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testAddRemoveReporter() {
Consumer<RatisMetricRegistry> reporter = v-> cntr.incrementAndGet();
Consumer<RatisMetricRegistry> stopReporter = v-> cntr.incrementAndGet();
r.addReporterRegistration(reporter, stopReporter);

// check if add and remove of metric do reporting counter increase
MetricRegistryInfo info = new MetricRegistryInfo("t1", "t1", "t1", "t1");
r.create(info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ private static class StateMachineWithMultiNestedSnapshotFile extends SimpleState
File file2;

@Override
public synchronized void initialize(RaftServer server, RaftGroupId groupId, RaftStorage raftStorage) throws IOException {
public synchronized void initialize(RaftServer server, RaftGroupId groupId, RaftStorage raftStorage)
throws IOException {
super.initialize(server, groupId, raftStorage);

// contains two snapshot files
Expand Down Expand Up @@ -215,7 +216,8 @@ private static class StateMachineWithSeparatedSnapshotPath extends SimpleStateMa
private File tmpDir;

@Override
public synchronized void initialize(RaftServer server, RaftGroupId groupId, RaftStorage raftStorage) throws IOException {
public synchronized void initialize(RaftServer server, RaftGroupId groupId, RaftStorage raftStorage)
throws IOException {
super.initialize(server, groupId, raftStorage);
this.root = new File("/tmp/ratis-tests/statemachine/" + getId().toString());
this.snapshotDir = new File(root, "snapshot");
Expand All @@ -238,7 +240,8 @@ public synchronized void pause() {
public long takeSnapshot() {
final TermIndex lastApplied = getLastAppliedTermIndex();
final File snapshotTmpDir = new File(tmpDir, UUID.randomUUID().toString());
final File snapshotRealDir = new File(snapshotDir, String.format("%d_%d", lastApplied.getTerm(), lastApplied.getIndex()));
final File snapshotRealDir = new File(snapshotDir,
String.format("%d_%d", lastApplied.getTerm(), lastApplied.getIndex()));

try {
FileUtils.deleteFully(snapshotRealDir);
Expand Down
60 changes: 30 additions & 30 deletions ratis-server/src/test/java/org/apache/ratis/RaftBasicTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,27 @@ public void testBasicAppendEntriesKillLeader() throws Exception {
}

static CompletableFuture<Void> killAndRestartServer(
RaftPeerId id, long killSleepMs, long restartSleepMs, MiniRaftCluster cluster, Logger LOG) {
RaftPeerId id, long killSleepMs, long restartSleepMs, MiniRaftCluster cluster, Logger log) {
final CompletableFuture<Void> future = new CompletableFuture<>();
new Thread(() -> {
try {
Thread.sleep(killSleepMs);
cluster.killServer(id);
Thread.sleep(restartSleepMs);
LOG.info("restart server: " + id);
log.info("restart server: " + id);
cluster.restartServer(id, false);
future.complete(null);
} catch (Exception e) {
ExitUtils.terminate(-1, "Failed to kill/restart server: " + id, e, LOG);
ExitUtils.terminate(-1, "Failed to kill/restart server: " + id, e, log);
}
}).start();
return future;
}

static void runTestBasicAppendEntries(
boolean async, boolean killLeader, int numMessages, MiniRaftCluster cluster, Logger LOG)
boolean async, boolean killLeader, int numMessages, MiniRaftCluster cluster, Logger log)
throws Exception {
LOG.info("runTestBasicAppendEntries: async? {}, killLeader={}, numMessages={}",
log.info("runTestBasicAppendEntries: async? {}, killLeader={}, numMessages={}",
async, killLeader, numMessages);
for (RaftServer s : cluster.getServers()) {
cluster.restartServer(s.getId(), false);
Expand All @@ -125,16 +125,16 @@ static void runTestBasicAppendEntries(
final long term = leader.getInfo().getCurrentTerm();

final CompletableFuture<Void> killAndRestartFollower = killAndRestartServer(
cluster.getFollowers().get(0).getId(), 0, 1000, cluster, LOG);
cluster.getFollowers().get(0).getId(), 0, 1000, cluster, log);
final CompletableFuture<Void> killAndRestartLeader;
if (killLeader) {
LOG.info("killAndRestart leader " + leader.getId());
killAndRestartLeader = killAndRestartServer(leader.getId(), 2000, 4000, cluster, LOG);
log.info("killAndRestart leader " + leader.getId());
killAndRestartLeader = killAndRestartServer(leader.getId(), 2000, 4000, cluster, log);
} else {
killAndRestartLeader = CompletableFuture.completedFuture(null);
}

LOG.info(cluster.printServers());
log.info(cluster.printServers());

final SimpleMessage[] messages = SimpleMessage.create(numMessages);

Expand Down Expand Up @@ -163,14 +163,14 @@ static void runTestBasicAppendEntries(
}
}
Thread.sleep(cluster.getTimeoutMax().toIntExact(TimeUnit.MILLISECONDS) + 100);
LOG.info(cluster.printAllLogs());
log.info(cluster.printAllLogs());
killAndRestartFollower.join();
killAndRestartLeader.join();


final List<RaftServer.Division> divisions = cluster.getServerAliveStream().collect(Collectors.toList());
for(RaftServer.Division impl: divisions) {
RaftTestUtil.assertLogEntries(impl, term, messages, 50, LOG);
RaftTestUtil.assertLogEntries(impl, term, messages, 50, log);
}
}

Expand Down Expand Up @@ -271,16 +271,16 @@ static class Client4TestWithLoad extends Thread {
final AtomicReference<Throwable> exceptionInClientThread = new AtomicReference<>();

final MiniRaftCluster cluster;
final Logger LOG;
final Logger log;

Client4TestWithLoad(int index, int numMessages, boolean useAsync,
MiniRaftCluster cluster, Logger LOG) {
MiniRaftCluster cluster, Logger log) {
super("client-" + index);
this.index = index;
this.messages = SimpleMessage.create(numMessages, index + "-");
this.useAsync = useAsync;
this.cluster = cluster;
this.LOG = LOG;
this.log = log;
}

boolean isRunning() {
Expand Down Expand Up @@ -317,10 +317,10 @@ public void run() {
}
} catch(Exception t) {
if (exceptionInClientThread.compareAndSet(null, t)) {
LOG.error(this + " failed", t);
log.error(this + " failed", t);
} else {
exceptionInClientThread.get().addSuppressed(t);
LOG.error(this + " failed again!", t);
log.error(this + " failed again!", t);
}
} finally {
isRunning.set(false);
Expand All @@ -345,15 +345,15 @@ public void testWithLoad() throws Exception {
}

static void testWithLoad(final int numClients, final int numMessages,
boolean useAsync, MiniRaftCluster cluster, Logger LOG) throws Exception {
LOG.info("Running testWithLoad: numClients=" + numClients
boolean useAsync, MiniRaftCluster cluster, Logger log) throws Exception {
log.info("Running testWithLoad: numClients=" + numClients
+ ", numMessages=" + numMessages + ", async=" + useAsync);

waitForLeader(cluster);

final List<Client4TestWithLoad> clients
= Stream.iterate(0, i -> i+1).limit(numClients)
.map(i -> new Client4TestWithLoad(i, numMessages, useAsync, cluster, LOG))
.map(i -> new Client4TestWithLoad(i, numMessages, useAsync, cluster, log))
.collect(Collectors.toList());
final AtomicInteger lastStep = new AtomicInteger();

Expand All @@ -363,24 +363,24 @@ static void testWithLoad(final int numClients, final int numMessages,

@Override
public void run() {
LOG.info(cluster.printServers());
LOG.info(BlockRequestHandlingInjection.getInstance().toString());
LOG.info(cluster.toString());
clients.forEach(c -> LOG.info(" " + c));
JavaUtils.dumpAllThreads(s -> LOG.info(s));
log.info(cluster.printServers());
log.info(BlockRequestHandlingInjection.getInstance().toString());
log.info(cluster.toString());
clients.forEach(c -> log.info(" " + c));
JavaUtils.dumpAllThreads(s -> log.info(s));

final int last = lastStep.get();
if (last != previousLastStep) {
previousLastStep = last;
} else {
final RaftServer.Division leader = cluster.getLeader();
LOG.info("NO PROGRESS at " + last + ", try to restart leader=" + leader);
log.info("NO PROGRESS at " + last + ", try to restart leader=" + leader);
if (leader != null) {
try {
cluster.restartServer(leader.getId(), false);
LOG.info("Restarted leader=" + leader);
log.info("Restarted leader=" + leader);
} catch (IOException e) {
LOG.error("Failed to restart leader=" + leader);
log.error("Failed to restart leader=" + leader);
}
}
}
Expand Down Expand Up @@ -411,10 +411,10 @@ public void run() {
RaftTestUtil.changeLeader(cluster, leader.getId());
}
} catch (IllegalStateException e) {
LOG.error("Failed to change leader ", e);
log.error("Failed to change leader ", e);
}
}
LOG.info("Leader change count=" + count);
log.info("Leader change count=" + count);
timer.cancel();

for(Client4TestWithLoad c : clients) {
Expand All @@ -425,7 +425,7 @@ public void run() {
}
}

public static void testRequestTimeout(boolean async, MiniRaftCluster cluster, Logger LOG) throws Exception {
public static void testRequestTimeout(boolean async, MiniRaftCluster cluster, Logger log) throws Exception {
waitForLeader(cluster);
final Timestamp startTime = Timestamp.currentTime();
try (final RaftClient client = cluster.createClient()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ static List<LogEntryProto> getStateMachineLogEntries(RaftLog log, Consumer<Strin
return entries;
}

static Void assertLogEntries(RaftLog log, long expectedTerm, SimpleMessage[] expectedMessages, Consumer<String> print) {
static Void assertLogEntries(RaftLog log, long expectedTerm, SimpleMessage[] expectedMessages,
Consumer<String> print) {
final List<LogEntryProto> entries = getStateMachineLogEntries(log, print);
try {
assertLogEntries(entries, expectedTerm, expectedMessages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public static void assertReply(RaftClientReply reply, RaftClient client, long ca
Assertions.assertTrue(reply.isSuccess());
}

public void assertServer(MiniRaftCluster cluster, ClientId clientId, long callId, long oldLastApplied) throws Exception {
public void assertServer(MiniRaftCluster cluster, ClientId clientId, long callId, long oldLastApplied)
throws Exception {
final long leaderApplied = cluster.getLeader().getInfo().getLastAppliedIndex();
// make sure retry cache has the entry
for (RaftServer.Division server : cluster.iterateDivisions()) {
Expand Down
Loading

0 comments on commit 1b9aeb3

Please sign in to comment.