sanpwc commented on code in PR #1655: URL: https://github.com/apache/ignite-3/pull/1655#discussion_r1109394339
########## modules/table/src/test/java/org/apache/ignite/internal/utils/RebalanceUtilUpdateAssignmentsTest.java: ########## @@ -0,0 +1,437 @@ +/* + * 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.utils; + +import static java.util.stream.Collectors.toSet; +import static org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED; +import static org.apache.ignite.internal.affinity.AffinityUtils.calculateAssignmentForPartition; +import static org.apache.ignite.internal.util.ByteUtils.toBytes; +import static org.apache.ignite.internal.utils.RebalanceUtil.pendingPartAssignmentsKey; +import static org.apache.ignite.internal.utils.RebalanceUtil.plannedPartAssignmentsKey; +import static org.apache.ignite.internal.utils.RebalanceUtil.stablePartAssignmentsKey; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.io.Serializable; +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.IntStream; +import org.apache.ignite.internal.affinity.Assignment; +import org.apache.ignite.internal.configuration.ConfigurationManager; +import org.apache.ignite.internal.configuration.storage.TestConfigurationStorage; +import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension; +import org.apache.ignite.internal.distributionzones.configuration.DistributionZonesConfiguration; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.apache.ignite.internal.metastorage.MetaStorageManager; +import org.apache.ignite.internal.metastorage.command.MetaStorageCommandsFactory; +import org.apache.ignite.internal.metastorage.command.MultiInvokeCommand; +import org.apache.ignite.internal.metastorage.dsl.Iif; +import org.apache.ignite.internal.metastorage.server.SimpleInMemoryKeyValueStorage; +import org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener; +import org.apache.ignite.internal.raft.Command; +import org.apache.ignite.internal.raft.WriteCommand; +import org.apache.ignite.internal.raft.service.CommandClosure; +import org.apache.ignite.internal.raft.service.RaftGroupService; +import org.apache.ignite.internal.table.distributed.replicator.TablePartitionId; +import org.apache.ignite.internal.testframework.IgniteAbstractTest; +import org.apache.ignite.internal.util.ByteUtils; +import org.apache.ignite.lang.IgniteInternalException; +import org.apache.ignite.network.ClusterService; +import org.apache.ignite.network.MessagingService; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; + +/** + * Tests for updating assignment in the meta storage. + */ +@ExtendWith({MockitoExtension.class, ConfigurationExtension.class}) +@MockitoSettings(strictness = Strictness.LENIENT) +public class RebalanceUtilUpdateAssignmentsTest extends IgniteAbstractTest { + private static final IgniteLogger LOG = Loggers.forClass(RebalanceUtilUpdateAssignmentsTest.class); + + private SimpleInMemoryKeyValueStorage keyValueStorage; + + private ConfigurationManager clusterCfgMgr; + + private ClusterService clusterService; + + private MetaStorageManager metaStorageManager; + + static int partNum = 2; Review Comment: Related to all that static values: - Do you really need them to be non-private? - If not, what about converting them to constants? ########## modules/table/src/test/java/org/apache/ignite/internal/utils/RebalanceUtilUpdateAssignmentsTest.java: ########## @@ -0,0 +1,437 @@ +/* + * 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.utils; + +import static java.util.stream.Collectors.toSet; +import static org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED; +import static org.apache.ignite.internal.affinity.AffinityUtils.calculateAssignmentForPartition; +import static org.apache.ignite.internal.util.ByteUtils.toBytes; +import static org.apache.ignite.internal.utils.RebalanceUtil.pendingPartAssignmentsKey; +import static org.apache.ignite.internal.utils.RebalanceUtil.plannedPartAssignmentsKey; +import static org.apache.ignite.internal.utils.RebalanceUtil.stablePartAssignmentsKey; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.io.Serializable; +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.IntStream; +import org.apache.ignite.internal.affinity.Assignment; +import org.apache.ignite.internal.configuration.ConfigurationManager; +import org.apache.ignite.internal.configuration.storage.TestConfigurationStorage; +import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension; +import org.apache.ignite.internal.distributionzones.configuration.DistributionZonesConfiguration; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.apache.ignite.internal.metastorage.MetaStorageManager; +import org.apache.ignite.internal.metastorage.command.MetaStorageCommandsFactory; +import org.apache.ignite.internal.metastorage.command.MultiInvokeCommand; +import org.apache.ignite.internal.metastorage.dsl.Iif; +import org.apache.ignite.internal.metastorage.server.SimpleInMemoryKeyValueStorage; +import org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener; +import org.apache.ignite.internal.raft.Command; +import org.apache.ignite.internal.raft.WriteCommand; +import org.apache.ignite.internal.raft.service.CommandClosure; +import org.apache.ignite.internal.raft.service.RaftGroupService; +import org.apache.ignite.internal.table.distributed.replicator.TablePartitionId; +import org.apache.ignite.internal.testframework.IgniteAbstractTest; +import org.apache.ignite.internal.util.ByteUtils; +import org.apache.ignite.lang.IgniteInternalException; +import org.apache.ignite.network.ClusterService; +import org.apache.ignite.network.MessagingService; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; + +/** + * Tests for updating assignment in the meta storage. + */ +@ExtendWith({MockitoExtension.class, ConfigurationExtension.class}) +@MockitoSettings(strictness = Strictness.LENIENT) +public class RebalanceUtilUpdateAssignmentsTest extends IgniteAbstractTest { + private static final IgniteLogger LOG = Loggers.forClass(RebalanceUtilUpdateAssignmentsTest.class); + + private SimpleInMemoryKeyValueStorage keyValueStorage; + + private ConfigurationManager clusterCfgMgr; + + private ClusterService clusterService; + + private MetaStorageManager metaStorageManager; + + static int partNum = 2; + static int replicas = 2; + + static Set<String> nodes1 = IntStream.of(5).mapToObj(i -> "nodes1_" + i).collect(toSet()); + static Set<String> nodes2 = IntStream.of(5).mapToObj(i -> "nodes2_" + i).collect(toSet()); + static Set<String> nodes3 = IntStream.of(5).mapToObj(i -> "nodes3_" + i).collect(toSet()); + static Set<String> nodes4 = IntStream.of(5).mapToObj(i -> "nodes4_" + i).collect(toSet()); + + static Set<Assignment> assignments1 = calculateAssignmentForPartition(nodes1, partNum, replicas); + static Set<Assignment> assignments2 = calculateAssignmentForPartition(nodes2, partNum, replicas); + static Set<Assignment> assignments3 = calculateAssignmentForPartition(nodes3, partNum, replicas); + static Set<Assignment> assignments4 = calculateAssignmentForPartition(nodes4, partNum, replicas); + + @BeforeEach Review Comment: Why it's beforeEach and not beforeAll? ########## modules/table/src/test/java/org/apache/ignite/internal/utils/RebalanceUtilUpdateAssignmentsTest.java: ########## @@ -0,0 +1,437 @@ +/* + * 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.utils; + +import static java.util.stream.Collectors.toSet; +import static org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED; +import static org.apache.ignite.internal.affinity.AffinityUtils.calculateAssignmentForPartition; +import static org.apache.ignite.internal.util.ByteUtils.toBytes; +import static org.apache.ignite.internal.utils.RebalanceUtil.pendingPartAssignmentsKey; +import static org.apache.ignite.internal.utils.RebalanceUtil.plannedPartAssignmentsKey; +import static org.apache.ignite.internal.utils.RebalanceUtil.stablePartAssignmentsKey; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.io.Serializable; +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.IntStream; +import org.apache.ignite.internal.affinity.Assignment; +import org.apache.ignite.internal.configuration.ConfigurationManager; +import org.apache.ignite.internal.configuration.storage.TestConfigurationStorage; +import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension; +import org.apache.ignite.internal.distributionzones.configuration.DistributionZonesConfiguration; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.apache.ignite.internal.metastorage.MetaStorageManager; +import org.apache.ignite.internal.metastorage.command.MetaStorageCommandsFactory; +import org.apache.ignite.internal.metastorage.command.MultiInvokeCommand; +import org.apache.ignite.internal.metastorage.dsl.Iif; +import org.apache.ignite.internal.metastorage.server.SimpleInMemoryKeyValueStorage; +import org.apache.ignite.internal.metastorage.server.raft.MetaStorageListener; +import org.apache.ignite.internal.raft.Command; +import org.apache.ignite.internal.raft.WriteCommand; +import org.apache.ignite.internal.raft.service.CommandClosure; +import org.apache.ignite.internal.raft.service.RaftGroupService; +import org.apache.ignite.internal.table.distributed.replicator.TablePartitionId; +import org.apache.ignite.internal.testframework.IgniteAbstractTest; +import org.apache.ignite.internal.util.ByteUtils; +import org.apache.ignite.lang.IgniteInternalException; +import org.apache.ignite.network.ClusterService; +import org.apache.ignite.network.MessagingService; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; + +/** + * Tests for updating assignment in the meta storage. + */ +@ExtendWith({MockitoExtension.class, ConfigurationExtension.class}) +@MockitoSettings(strictness = Strictness.LENIENT) +public class RebalanceUtilUpdateAssignmentsTest extends IgniteAbstractTest { + private static final IgniteLogger LOG = Loggers.forClass(RebalanceUtilUpdateAssignmentsTest.class); + + private SimpleInMemoryKeyValueStorage keyValueStorage; + + private ConfigurationManager clusterCfgMgr; + + private ClusterService clusterService; + + private MetaStorageManager metaStorageManager; + + static int partNum = 2; + static int replicas = 2; + + static Set<String> nodes1 = IntStream.of(5).mapToObj(i -> "nodes1_" + i).collect(toSet()); + static Set<String> nodes2 = IntStream.of(5).mapToObj(i -> "nodes2_" + i).collect(toSet()); + static Set<String> nodes3 = IntStream.of(5).mapToObj(i -> "nodes3_" + i).collect(toSet()); + static Set<String> nodes4 = IntStream.of(5).mapToObj(i -> "nodes4_" + i).collect(toSet()); + + static Set<Assignment> assignments1 = calculateAssignmentForPartition(nodes1, partNum, replicas); + static Set<Assignment> assignments2 = calculateAssignmentForPartition(nodes2, partNum, replicas); + static Set<Assignment> assignments3 = calculateAssignmentForPartition(nodes3, partNum, replicas); + static Set<Assignment> assignments4 = calculateAssignmentForPartition(nodes4, partNum, replicas); + + @BeforeEach + public void setUp() { + clusterCfgMgr = new ConfigurationManager( + List.of(DistributionZonesConfiguration.KEY), + Set.of(), + new TestConfigurationStorage(DISTRIBUTED), + List.of(), + List.of() + ); + + clusterService = mock(ClusterService.class); + + metaStorageManager = mock(MetaStorageManager.class); + + clusterCfgMgr.start(); Review Comment: As a rule of thumb if you start something you need to stop it, and if you start the IgniteComponent you should also call beforeNodeStop before calling the stop. -- 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]
