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/24 13:53:54 UTC
[GitHub] [ratis] softgitron opened a new pull request #469: Ratis 1367 Add null check for RaftConfigurationImpl
softgitron opened a new pull request #469:
URL: https://github.com/apache/ratis/pull/469
## What changes were proposed in this pull request?
Add null check for target in isHighestPriority function.
## What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/RATIS-1367
## How was this patch tested?
Patch was tested using existing and new automated test cases. New test cases are somewhat overkill for the current scope of the change. However infrastructure that was created during this change can be used in the future for more broad testing in the RaftConfigurationImpl.
--
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
[GitHub] [ratis] szetszwo merged pull request #469: RATIS-1367 Add null check for RaftConfigurationImpl
Posted by GitBox <gi...@apache.org>.
szetszwo merged pull request #469:
URL: https://github.com/apache/ratis/pull/469
--
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
[GitHub] [ratis] szetszwo commented on a change in pull request #469: Ratis 1367 Add null check for RaftConfigurationImpl
Posted by GitBox <gi...@apache.org>.
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
[GitHub] [ratis] softgitron commented on a change in pull request #469: RATIS-1367 Add null check for RaftConfigurationImpl
Posted by GitBox <gi...@apache.org>.
softgitron commented on a change in pull request #469:
URL: https://github.com/apache/ratis/pull/469#discussion_r625949437
##########
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:
Fixed and I raised Jira ticket for code style configurations: https://issues.apache.org/jira/browse/RATIS-1374 I may look into this Jira issue later, but I don't promise anything yet.
--
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
[GitHub] [ratis] softgitron commented on a change in pull request #469: RATIS-1367 Add null check for RaftConfigurationImpl
Posted by GitBox <gi...@apache.org>.
softgitron commented on a change in pull request #469:
URL: https://github.com/apache/ratis/pull/469#discussion_r625940534
##########
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:
Okay, should be now fixed!
--
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