You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ratis.apache.org by GitBox <gi...@apache.org> on 2020/12/10 16:17:42 UTC

[GitHub] [incubator-ratis] errose28 commented on a change in pull request #344: RATIS-1216. State machine preAppend callback can throw exception without having leader to step down.

errose28 commented on a change in pull request #344:
URL: https://github.com/apache/incubator-ratis/pull/344#discussion_r540301156



##########
File path: ratis-server/src/test/java/org/apache/ratis/server/impl/PreAppendLeaderStepDownTest.java
##########
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ratis.server.impl;
+
+import org.apache.log4j.Level;
+import org.apache.ratis.BaseTest;
+import org.apache.ratis.RaftTestUtil;
+import org.apache.ratis.client.RaftClient;
+import org.apache.ratis.client.RaftClientRpc;
+import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.protocol.RaftClientReply;
+import org.apache.ratis.protocol.RaftClientRequest;
+import org.apache.ratis.protocol.exceptions.StateMachineException;
+import org.apache.ratis.server.RaftServer;
+import org.apache.ratis.server.raftlog.RaftLog;
+import org.apache.ratis.statemachine.SimpleStateMachine4Testing;
+import org.apache.ratis.statemachine.StateMachine;
+import org.apache.ratis.statemachine.TransactionContext;
+import org.apache.ratis.util.Log4jUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+/**
+ * Tests the leader step down flag in {@link StateMachineException}, which
+ * determines whether the leader should step down or not when it receives the
+ * exception from {@link StateMachine#preAppendTransaction}.
+ */
+public abstract class PreAppendLeaderStepDownTest<CLUSTER extends MiniRaftCluster>
+    extends BaseTest implements MiniRaftCluster.Factory.Get<CLUSTER> {
+  {
+    Log4jUtils.setLogLevel(RaftServer.Division.LOG, Level.DEBUG);
+    Log4jUtils.setLogLevel(RaftLog.LOG, Level.DEBUG);
+    Log4jUtils.setLogLevel(RaftClient.LOG, Level.DEBUG);
+  }
+
+  private static volatile boolean leaderShouldStepDown = false;
+
+  protected static class StateMachineWithException extends
+      SimpleStateMachine4Testing {
+
+    @Override
+    public TransactionContext preAppendTransaction(TransactionContext trx)
+        throws IOException {
+      StateMachineException ex = new StateMachineException(
+          "Fake Exception in preAppend");
+      if (!leaderShouldStepDown) {
+        ex.setLeaderShouldStepDown(false);

Review comment:
       Will do




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org