You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by GitBox <gi...@apache.org> on 2021/04/27 07:14:02 UTC

[GitHub] [ratis] szetszwo commented on a change in pull request #469: Ratis 1367 Add null check for RaftConfigurationImpl

szetszwo commented on a change in pull request #469:
URL: https://github.com/apache/ratis/pull/469#discussion_r620927789



##########
File path: ratis-test/src/test/java/org/apache/ratis/server/impl/TestRaftConfiguration.java
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.ratis.BaseTest;
+import org.apache.ratis.protocol.RaftPeer;
+import org.apache.ratis.protocol.RaftPeerId;
+import org.apache.ratis.server.RaftConfiguration;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+
+public class TestRaftConfiguration extends BaseTest {
+    @Test
+    public void testIsHighestPriority() {
+        Integer node1 = 0;
+        Integer node2 = 1;
+        Integer node3 = 2;
+        PeerConfiguration peerConfig = new PeerConfiguration(raftPeersWithPriority(node1, node2, node3));
+        RaftConfiguration config = RaftConfigurationImpl.newBuilder().setConf(peerConfig).build();
+        RaftPeer[] allRaftPeers = peerConfig.getPeers().toArray(new RaftPeer[peerConfig.getPeers().size()]);
+
+        // First member should not have highest priority
+        Assert.assertFalse(RaftConfigurationTestUtil.isHighestPriority(config,
+                allRaftPeers[0].getId()));
+
+        // Last member should have highest priority
+        Assert.assertTrue(RaftConfigurationTestUtil.isHighestPriority(config,
+                allRaftPeers[allRaftPeers.length -1].getId()));
+
+        // Should return false for non existent peer id
+        Assert.assertFalse(RaftConfigurationTestUtil.isHighestPriority(config, RaftPeerId.valueOf("123456789")));
+    }
+
+    private Collection<RaftPeer> raftPeersWithPriority(Integer... voters) {
+        return Arrays.stream(voters)
+                .map(id -> RaftPeer.newBuilder().setPriority(id).setId(id.toString()).build())
+                .collect(Collectors.toSet());
+    }
+}

Review comment:
       We use 2-space indentation and 4-space continuation indentation in Ratis.  Could you fix it?

##########
File path: ratis-server/src/test/java/org/apache/ratis/server/impl/RaftConfigurationTestUtil.java
##########
@@ -0,0 +1,27 @@
+/*
+ * 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.ratis.protocol.*;
+import org.apache.ratis.server.*;
+
+public class RaftConfigurationTestUtil {
+    public static boolean isHighestPriority(RaftConfiguration config, RaftPeerId peerId) {
+        return ((RaftConfigurationImpl)config).isHighestPriority(peerId);
+    }

Review comment:
       Let's put this in RaftServerTestUtil since there are some other conf related methods.




-- 
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