sanpwc commented on code in PR #6641: URL: https://github.com/apache/ignite-3/pull/6641#discussion_r2388246496
########## modules/distribution-zones/src/integrationTest/java/org/apache/ignite/internal/distributionzones/ItEmptyDataNodesTest.java: ########## @@ -0,0 +1,106 @@ +/* + * 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.distributionzones; + +import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl; +import static org.apache.ignite.internal.lang.IgniteStringFormatter.format; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.hasCause; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.function.Predicate; +import org.apache.ignite.internal.ClusterPerTestIntegrationTest; +import org.apache.ignite.internal.TestWrappers; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.distributionzones.exception.EmptyDataNodesException; +import org.apache.ignite.internal.placementdriver.EmptyAssignmentsException; +import org.apache.ignite.sql.SqlException; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.Test; + +class ItEmptyDataNodesTest extends ClusterPerTestIntegrationTest { + private static final String ZONE_NAME = "zone0"; + private static final String TABLE_NAME = "table0"; + + @Test + public void testInitialEmptyAssignmentsWithSuccessfulWaiting() { + createZoneAndTableWithEmptyDataNodes(); + + IgniteImpl node = unwrapIgniteImpl(cluster.aliveNode()); + int zoneId = node.catalogManager().activeCatalog(node.clock().now().longValue()).zone(ZONE_NAME.toUpperCase()).id(); + + assertTrue(currentDataNodes(node, zoneId).isEmpty()); + + setAdditionalNodeFilter(null); + + // Trigger scale down and data nodes recalculation. + stopNode(2); + + // No waiting inside test for non-empty data nodes and assignments. Assignments placement driver should wait for non-empty + // assignments for SQL. + sql("SELECT * FROM " + TABLE_NAME); + } + + //@Test + public void testEmptyAssignmentsException() { + createZoneAndTableWithEmptyDataNodes(); + + IgniteImpl node = unwrapIgniteImpl(cluster.aliveNode()); + int zoneId = node.catalogManager().activeCatalog(node.clock().now().longValue()).zone(ZONE_NAME.toUpperCase()).id(); + + assertTrue(currentDataNodes(node, zoneId).isEmpty()); + + try { + sql("SELECT * FROM " + TABLE_NAME); + fail(); + } catch (Exception e) { + assertInstanceOf(SqlException.class, e); + assertTrue(hasCause(e, EmptyAssignmentsException.class, null)); + assertTrue(hasCause(e, EmptyDataNodesException.class, null)); + } + } + + private void createZoneAndTableWithEmptyDataNodes() { + setAdditionalNodeFilter(n -> false); + + sql(format("CREATE ZONE {} (PARTITIONS 1, AUTO SCALE DOWN 0) STORAGE PROFILES ['default']", ZONE_NAME)); + + sql(format("CREATE TABLE {} (id INT PRIMARY KEY, val INT) ZONE {}", TABLE_NAME, ZONE_NAME)); + } + + private static Set<String> currentDataNodes(IgniteImpl node, int zoneId) { + CompletableFuture<Set<String>> nodeFut = node.distributionZoneManager().currentDataNodes(zoneId); + assertThat(nodeFut, willCompleteSuccessfully()); + return nodeFut.join(); + } + + private void sql(String sql) { + cluster.aliveNode().sql().execute(null, sql); + } + + private void setAdditionalNodeFilter(@Nullable Predicate<NodeWithAttributes> filter) { + cluster.runningNodes() + .map(TestWrappers::unwrapIgniteImpl) + .forEach(node -> node.distributionZoneManager().setAdditionalNodeFilter(filter)); + } +} Review Comment: Test for assignments consistent cut is missing I guess. -- 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]
