korlov42 commented on code in PR #4042: URL: https://github.com/apache/ignite-3/pull/4042#discussion_r1665737538
########## modules/catalog/src/integrationTest/java/org/apache/ignite/internal/catalog/ItCatalogCompactionCoordinatorChoosingTest.java: ########## @@ -0,0 +1,118 @@ +/* + * 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.catalog; + +import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import org.apache.ignite.internal.ClusterPerClassIntegrationTest; +import org.apache.ignite.internal.app.IgniteImpl; +import org.hamcrest.CustomMatcher; +import org.hamcrest.Matcher; +import org.junit.jupiter.api.Test; + +/** + * Tests to verify choosing of coordinator for catalog compaction. + */ +class ItCatalogCompactionCoordinatorChoosingTest extends ClusterPerClassIntegrationTest { + private static final int CLUSTER_SIZE = 5; + private static final int MINORITY_SIZE = (CLUSTER_SIZE - 1) / 2; + + // test is sensible to count of nodes in custer + @Override + protected int initialNodes() { + return CLUSTER_SIZE; + } + + @Override + protected int[] cmgMetastoreNodes() { + return IntStream.range(0, CLUSTER_SIZE).toArray(); + } + + @Test + void coordinatorIsChosenAfterStartAndReelectedAfterNodeCrash() throws Exception { + Set<String> coordinators = new HashSet<>(); + + int coordinatorHasNotBeanUpdatedCount = 0; + for (IgniteImpl node : runningNodes()) { + String coordinatorNodeId = ((CatalogManagerImpl) node.catalogManager()).compactionCoordinator(); + + if (coordinatorNodeId == null) { + coordinatorHasNotBeanUpdatedCount++; + } else { + coordinators.add(coordinatorNodeId); + } + } + + assertThat(coordinatorHasNotBeanUpdatedCount, lessOrEqualTo(MINORITY_SIZE)); Review Comment: not exactly. In this test metastorage group consists of all nodes of cluster, but leader can be elected as soon as majority get to consensus. Given that said, it's possible, that leader will be elected when majority of the node started. If minority of the nodes join the cluster _after_ leader had been elected, they won't receive notification, thus `compactionCoordinatorNodeName` on such nodes may remain `null`. This assertion makes sure, that expectations are true, and election happens as soon as (at least) majority of the node started. -- 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]
