alievmirza commented on a change in pull request #446:
URL: https://github.com/apache/ignite-3/pull/446#discussion_r752140475
##########
File path: modules/raft/src/main/java/org/apache/ignite/internal/raft/Loza.java
##########
@@ -176,12 +212,34 @@ public void stop() throws Exception {
Collection<ClusterNode> deltaNodes,
Supplier<RaftGroupListener> lsnrSupplier
) {
+ if (!busyLock.enterBusy()) {
+ throw new IgniteException(new NodeStoppingException());
+ }
+
+ try {
+ return updateRaftGroupInternal(groupId, nodes, deltaNodes,
lsnrSupplier);
+ } finally {
+ busyLock.leaveBusy();
+ }
+ }
+
+ /**
+ * Internal mthod for creates a raft group.
Review comment:
```suggestion
* Internal method for creating a raft group.
```
##########
File path: modules/raft/src/main/java/org/apache/ignite/internal/raft/Loza.java
##########
@@ -213,9 +271,29 @@ public void stop() throws Exception {
* @return Future which will complete when peers change.
*/
public CompletableFuture<Void> chagePeers(String groupId,
List<ClusterNode> expectedNodes, List<ClusterNode> changedNodes) {
+ if (!busyLock.enterBusy()) {
+ throw new IgniteException(new NodeStoppingException());
+ }
+
+ try {
+ return chagePeersInternal(groupId, expectedNodes, changedNodes);
+ } finally {
+ busyLock.leaveBusy();
+ }
+ }
+
+ /**
+ * Internal method for change peers for a RAFT group.
Review comment:
```suggestion
* Internal method for changing peers for a RAFT group.
```
##########
File path:
modules/raft/src/test/java/org/apache/ignite/internal/raft/LozaTest.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.ignite.internal.raft;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Supplier;
+import org.apache.ignite.internal.testframework.IgniteAbstractTest;
+import org.apache.ignite.lang.IgniteException;
+import org.apache.ignite.network.ClusterLocalConfiguration;
+import org.apache.ignite.network.ClusterNode;
+import org.apache.ignite.network.ClusterService;
+import org.apache.ignite.network.MessagingService;
+import org.apache.ignite.network.NetworkAddress;
+import org.apache.ignite.network.TopologyService;
+import org.apache.ignite.raft.client.service.RaftGroupListener;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+
+/**
+ * Thre are tests for RAFT manager.
+ * It is mocking all components except Loza and checks API methods of the
component in various conditions.
+ */
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings()
+public class LozaTest extends IgniteAbstractTest {
+ /** Mock for network service. */
+ @Mock
+ private ClusterService clusterNetSvc;
+
+ /**
+ * Checks that the all API methods throw the exception (caused by {@link
org.apache.ignite.lang.NodeStoppingException})
+ * when Loza is closed.
+ *
+ * @throws Exception If fail.
+ */
+ @Test
+ public void testLozaStop() throws Exception {
+ Mockito.doReturn(new ClusterLocalConfiguration("test_node",
null)).when(clusterNetSvc).localConfiguration();
+
Mockito.doReturn(Mockito.mock(MessagingService.class)).when(clusterNetSvc).messagingService();
+
Mockito.doReturn(Mockito.mock(TopologyService.class)).when(clusterNetSvc).topologyService();
+
+ Loza loza = new Loza(clusterNetSvc, workDir);
+
+ loza.start();
+
+ loza.beforeNodeStop();
+ loza.stop();
+
+ String raftGroupId = "test_raft_group";
+
+ List<ClusterNode> nodes = List.of(
+ new ClusterNode(UUID.randomUUID().toString(),
UUID.randomUUID().toString(), NetworkAddress.from("127.0.0.1:123")));
+
+ List<ClusterNode> newNodes = List.of(
+ new ClusterNode(UUID.randomUUID().toString(),
UUID.randomUUID().toString(), NetworkAddress.from("127.0.0.1:124")),
+ new ClusterNode(UUID.randomUUID().toString(),
UUID.randomUUID().toString(), NetworkAddress.from("127.0.0.1:125")));
+
+ Supplier<RaftGroupListener> lsnrSupplier = () -> null;
+
+ assertThrows(IgniteException.class, () ->
loza.updateRaftGroup(raftGroupId, nodes, newNodes, lsnrSupplier));
Review comment:
lets check cause of exceptions
##########
File path:
modules/raft/src/test/java/org/apache/ignite/internal/raft/LozaTest.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.ignite.internal.raft;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Supplier;
+import org.apache.ignite.internal.testframework.IgniteAbstractTest;
+import org.apache.ignite.lang.IgniteException;
+import org.apache.ignite.network.ClusterLocalConfiguration;
+import org.apache.ignite.network.ClusterNode;
+import org.apache.ignite.network.ClusterService;
+import org.apache.ignite.network.MessagingService;
+import org.apache.ignite.network.NetworkAddress;
+import org.apache.ignite.network.TopologyService;
+import org.apache.ignite.raft.client.service.RaftGroupListener;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+
+/**
+ * Thre are tests for RAFT manager.
+ * It is mocking all components except Loza and checks API methods of the
component in various conditions.
+ */
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings()
Review comment:
Why do we need this?
##########
File path:
modules/raft/src/test/java/org/apache/ignite/internal/raft/LozaTest.java
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.ignite.internal.raft;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Supplier;
+import org.apache.ignite.internal.testframework.IgniteAbstractTest;
+import org.apache.ignite.lang.IgniteException;
+import org.apache.ignite.network.ClusterLocalConfiguration;
+import org.apache.ignite.network.ClusterNode;
+import org.apache.ignite.network.ClusterService;
+import org.apache.ignite.network.MessagingService;
+import org.apache.ignite.network.NetworkAddress;
+import org.apache.ignite.network.TopologyService;
+import org.apache.ignite.raft.client.service.RaftGroupListener;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+
+/**
+ * Thre are tests for RAFT manager.
Review comment:
```suggestion
* There are tests for RAFT manager.
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]