rpuch commented on code in PR #2403: URL: https://github.com/apache/ignite-3/pull/2403#discussion_r1283101404
########## modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogParamsValidationUtils.java: ########## @@ -0,0 +1,186 @@ +/* + * 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.catalog.commands.CatalogUtils.INFINITE_TIMER_VALUE; + +import com.jayway.jsonpath.InvalidPathException; +import com.jayway.jsonpath.JsonPath; +import org.apache.ignite.internal.catalog.commands.AlterZoneParams; +import org.apache.ignite.internal.catalog.commands.CreateZoneParams; +import org.apache.ignite.internal.catalog.commands.DropZoneParams; +import org.apache.ignite.internal.catalog.commands.RenameZoneParams; +import org.apache.ignite.internal.util.StringUtils; +import org.apache.ignite.lang.ErrorGroups.DistributionZones; +import org.apache.ignite.lang.IgniteInternalException; +import org.jetbrains.annotations.Nullable; + +/** + * Utility class for validating catalog commands parameters. + */ +class CatalogParamsValidationUtils { + static void validateCreateZoneParams(CreateZoneParams params) { + validateUpdateZoneFieldsParameters( + params.zoneName(), + params.partitions(), + params.replicas(), + params.dataNodesAutoAdjust(), + params.dataNodesAutoAdjustScaleUp(), + params.dataNodesAutoAdjustScaleDown(), + params.filter() + ); + } + + static void validateAlterZoneParams(AlterZoneParams params) { + validateUpdateZoneFieldsParameters( + params.zoneName(), + params.partitions(), + params.replicas(), + params.dataNodesAutoAdjust(), + params.dataNodesAutoAdjustScaleUp(), + params.dataNodesAutoAdjustScaleDown(), + params.filter() + ); + } + + static void validateDropZoneParams(DropZoneParams params) { + validateZoneName(params.zoneName()); + } + + static void validateRenameZoneParams(RenameZoneParams params) { + validateZoneName(params.zoneName()); + validateZoneName(params.newZoneName(), "Missing new zone name"); + } + + private static void validateUpdateZoneFieldsParameters( + String zoneName, + @Nullable Integer partitions, + @Nullable Integer replicas, + @Nullable Integer dataNodesAutoAdjust, + @Nullable Integer dataNodesAutoAdjustScaleUp, + @Nullable Integer dataNodesAutoAdjustScaleDown, + @Nullable String filter + ) { + validateZoneName(zoneName); + + validateZonePartitions(partitions); + validateZoneReplicas(replicas); + + validateZoneDataNodesAutoAdjust(dataNodesAutoAdjust); + validateZoneDataNodesAutoAdjustScaleUp(dataNodesAutoAdjustScaleUp); + validateZoneDataNodesAutoAdjustScaleDown(dataNodesAutoAdjustScaleDown); + + validateZoneDataNodesAutoAdjustParametersCompatibility( + dataNodesAutoAdjust, + dataNodesAutoAdjustScaleUp, + dataNodesAutoAdjustScaleDown + ); + + validateZoneFilter(filter); + } + + private static void validateZoneName(String zoneName) { + if (StringUtils.nullOrBlank(zoneName)) { Review Comment: Let's reuse the overload instead of duplicating its code ########## modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogParamsValidationUtils.java: ########## @@ -0,0 +1,186 @@ +/* + * 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.catalog.commands.CatalogUtils.INFINITE_TIMER_VALUE; + +import com.jayway.jsonpath.InvalidPathException; +import com.jayway.jsonpath.JsonPath; +import org.apache.ignite.internal.catalog.commands.AlterZoneParams; +import org.apache.ignite.internal.catalog.commands.CreateZoneParams; +import org.apache.ignite.internal.catalog.commands.DropZoneParams; +import org.apache.ignite.internal.catalog.commands.RenameZoneParams; +import org.apache.ignite.internal.util.StringUtils; +import org.apache.ignite.lang.ErrorGroups.DistributionZones; +import org.apache.ignite.lang.IgniteInternalException; +import org.jetbrains.annotations.Nullable; + +/** + * Utility class for validating catalog commands parameters. + */ +class CatalogParamsValidationUtils { + static void validateCreateZoneParams(CreateZoneParams params) { + validateUpdateZoneFieldsParameters( + params.zoneName(), + params.partitions(), + params.replicas(), + params.dataNodesAutoAdjust(), + params.dataNodesAutoAdjustScaleUp(), + params.dataNodesAutoAdjustScaleDown(), + params.filter() + ); + } + + static void validateAlterZoneParams(AlterZoneParams params) { + validateUpdateZoneFieldsParameters( + params.zoneName(), + params.partitions(), + params.replicas(), + params.dataNodesAutoAdjust(), + params.dataNodesAutoAdjustScaleUp(), + params.dataNodesAutoAdjustScaleDown(), + params.filter() + ); + } + + static void validateDropZoneParams(DropZoneParams params) { + validateZoneName(params.zoneName()); + } + + static void validateRenameZoneParams(RenameZoneParams params) { + validateZoneName(params.zoneName()); + validateZoneName(params.newZoneName(), "Missing new zone name"); + } + + private static void validateUpdateZoneFieldsParameters( + String zoneName, + @Nullable Integer partitions, + @Nullable Integer replicas, + @Nullable Integer dataNodesAutoAdjust, + @Nullable Integer dataNodesAutoAdjustScaleUp, + @Nullable Integer dataNodesAutoAdjustScaleDown, + @Nullable String filter + ) { + validateZoneName(zoneName); + + validateZonePartitions(partitions); + validateZoneReplicas(replicas); + + validateZoneDataNodesAutoAdjust(dataNodesAutoAdjust); + validateZoneDataNodesAutoAdjustScaleUp(dataNodesAutoAdjustScaleUp); + validateZoneDataNodesAutoAdjustScaleDown(dataNodesAutoAdjustScaleDown); + + validateZoneDataNodesAutoAdjustParametersCompatibility( + dataNodesAutoAdjust, + dataNodesAutoAdjustScaleUp, + dataNodesAutoAdjustScaleDown + ); + + validateZoneFilter(filter); + } + + private static void validateZoneName(String zoneName) { + if (StringUtils.nullOrBlank(zoneName)) { + throw new IgniteInternalException( + DistributionZones.ZONE_DEFINITION_ERR, + "Missing zone name" + ); + } + } + + private static void validateZoneName(String zoneName, String errorMessage) { + if (StringUtils.nullOrBlank(zoneName)) { + throw new IgniteInternalException( + DistributionZones.ZONE_DEFINITION_ERR, + errorMessage + ); + } + } + + private static void validateZonePartitions(@Nullable Integer partitions) { + validateZoneField(partitions, 1, 65_000, "Invalid number of partitions"); Review Comment: Let's move 65000 to a constant ########## modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogParamsValidationUtils.java: ########## @@ -0,0 +1,186 @@ +/* + * 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.catalog.commands.CatalogUtils.INFINITE_TIMER_VALUE; + +import com.jayway.jsonpath.InvalidPathException; +import com.jayway.jsonpath.JsonPath; +import org.apache.ignite.internal.catalog.commands.AlterZoneParams; +import org.apache.ignite.internal.catalog.commands.CreateZoneParams; +import org.apache.ignite.internal.catalog.commands.DropZoneParams; +import org.apache.ignite.internal.catalog.commands.RenameZoneParams; +import org.apache.ignite.internal.util.StringUtils; +import org.apache.ignite.lang.ErrorGroups.DistributionZones; +import org.apache.ignite.lang.IgniteInternalException; +import org.jetbrains.annotations.Nullable; + +/** + * Utility class for validating catalog commands parameters. + */ +class CatalogParamsValidationUtils { + static void validateCreateZoneParams(CreateZoneParams params) { + validateUpdateZoneFieldsParameters( + params.zoneName(), + params.partitions(), + params.replicas(), + params.dataNodesAutoAdjust(), + params.dataNodesAutoAdjustScaleUp(), + params.dataNodesAutoAdjustScaleDown(), + params.filter() + ); + } + + static void validateAlterZoneParams(AlterZoneParams params) { + validateUpdateZoneFieldsParameters( + params.zoneName(), + params.partitions(), + params.replicas(), + params.dataNodesAutoAdjust(), + params.dataNodesAutoAdjustScaleUp(), + params.dataNodesAutoAdjustScaleDown(), + params.filter() + ); + } + + static void validateDropZoneParams(DropZoneParams params) { + validateZoneName(params.zoneName()); + } + + static void validateRenameZoneParams(RenameZoneParams params) { + validateZoneName(params.zoneName()); + validateZoneName(params.newZoneName(), "Missing new zone name"); + } + + private static void validateUpdateZoneFieldsParameters( + String zoneName, + @Nullable Integer partitions, + @Nullable Integer replicas, + @Nullable Integer dataNodesAutoAdjust, + @Nullable Integer dataNodesAutoAdjustScaleUp, + @Nullable Integer dataNodesAutoAdjustScaleDown, + @Nullable String filter + ) { + validateZoneName(zoneName); + + validateZonePartitions(partitions); + validateZoneReplicas(replicas); + + validateZoneDataNodesAutoAdjust(dataNodesAutoAdjust); + validateZoneDataNodesAutoAdjustScaleUp(dataNodesAutoAdjustScaleUp); + validateZoneDataNodesAutoAdjustScaleDown(dataNodesAutoAdjustScaleDown); + + validateZoneDataNodesAutoAdjustParametersCompatibility( + dataNodesAutoAdjust, + dataNodesAutoAdjustScaleUp, + dataNodesAutoAdjustScaleDown + ); + + validateZoneFilter(filter); + } + + private static void validateZoneName(String zoneName) { + if (StringUtils.nullOrBlank(zoneName)) { + throw new IgniteInternalException( + DistributionZones.ZONE_DEFINITION_ERR, + "Missing zone name" + ); + } + } + + private static void validateZoneName(String zoneName, String errorMessage) { + if (StringUtils.nullOrBlank(zoneName)) { + throw new IgniteInternalException( + DistributionZones.ZONE_DEFINITION_ERR, + errorMessage + ); + } + } + + private static void validateZonePartitions(@Nullable Integer partitions) { + validateZoneField(partitions, 1, 65_000, "Invalid number of partitions"); + } + + private static void validateZoneReplicas(@Nullable Integer replicas) { + validateZoneField(replicas, 1, null, "Invalid number of replicas"); + } + + private static void validateZoneDataNodesAutoAdjust(@Nullable Integer dataNodesAutoAdjust) { + validateZoneField(dataNodesAutoAdjust, 0, null, "Invalid data nodes auto adjust"); + } + + private static void validateZoneDataNodesAutoAdjustScaleUp(@Nullable Integer dataNodesAutoAdjustScaleUp) { + validateZoneField(dataNodesAutoAdjustScaleUp, 0, null, "Invalid data nodes auto adjust scale up"); + } + + private static void validateZoneDataNodesAutoAdjustScaleDown(@Nullable Integer dataNodesAutoAdjustScaleDown) { + validateZoneField(dataNodesAutoAdjustScaleDown, 0, null, "Invalid data nodes auto adjust scale down"); + } + + static void validateZoneDataNodesAutoAdjustParametersCompatibility( + @Nullable Integer dataNodesAutoAdjust, + @Nullable Integer dataNodesAutoAdjustScaleUp, + @Nullable Integer dataNodesAutoAdjustScaleDown + ) { + if (dataNodesAutoAdjust == null || dataNodesAutoAdjust == INFINITE_TIMER_VALUE) { + return; + } + + if ((dataNodesAutoAdjustScaleUp != null && dataNodesAutoAdjustScaleUp != INFINITE_TIMER_VALUE) + || (dataNodesAutoAdjustScaleDown != null && dataNodesAutoAdjustScaleDown != INFINITE_TIMER_VALUE)) { + throw new IgniteInternalException( + DistributionZones.ZONE_DEFINITION_ERR, + "Not compatible parameters [dataNodesAutoAdjust={}, dataNodesAutoAdjustScaleUp={}, dataNodesAutoAdjustScaleDown={}]", + dataNodesAutoAdjust, dataNodesAutoAdjustScaleUp, dataNodesAutoAdjustScaleDown + ); + } + } + + private static void validateZoneFilter(@Nullable String filter) { + if (filter == null) { + return; + } + + try { + JsonPath.compile(filter); Review Comment: Is it possible to add more validations beyond checking the parseability? ########## modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogParamsValidationUtils.java: ########## @@ -0,0 +1,186 @@ +/* + * 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.catalog.commands.CatalogUtils.INFINITE_TIMER_VALUE; + +import com.jayway.jsonpath.InvalidPathException; +import com.jayway.jsonpath.JsonPath; +import org.apache.ignite.internal.catalog.commands.AlterZoneParams; +import org.apache.ignite.internal.catalog.commands.CreateZoneParams; +import org.apache.ignite.internal.catalog.commands.DropZoneParams; +import org.apache.ignite.internal.catalog.commands.RenameZoneParams; +import org.apache.ignite.internal.util.StringUtils; +import org.apache.ignite.lang.ErrorGroups.DistributionZones; +import org.apache.ignite.lang.IgniteInternalException; +import org.jetbrains.annotations.Nullable; + +/** + * Utility class for validating catalog commands parameters. + */ +class CatalogParamsValidationUtils { + static void validateCreateZoneParams(CreateZoneParams params) { + validateUpdateZoneFieldsParameters( + params.zoneName(), + params.partitions(), + params.replicas(), + params.dataNodesAutoAdjust(), + params.dataNodesAutoAdjustScaleUp(), + params.dataNodesAutoAdjustScaleDown(), + params.filter() + ); + } + + static void validateAlterZoneParams(AlterZoneParams params) { + validateUpdateZoneFieldsParameters( + params.zoneName(), + params.partitions(), + params.replicas(), + params.dataNodesAutoAdjust(), + params.dataNodesAutoAdjustScaleUp(), + params.dataNodesAutoAdjustScaleDown(), + params.filter() + ); + } + + static void validateDropZoneParams(DropZoneParams params) { + validateZoneName(params.zoneName()); + } + + static void validateRenameZoneParams(RenameZoneParams params) { + validateZoneName(params.zoneName()); + validateZoneName(params.newZoneName(), "Missing new zone name"); + } + + private static void validateUpdateZoneFieldsParameters( + String zoneName, + @Nullable Integer partitions, + @Nullable Integer replicas, + @Nullable Integer dataNodesAutoAdjust, + @Nullable Integer dataNodesAutoAdjustScaleUp, + @Nullable Integer dataNodesAutoAdjustScaleDown, + @Nullable String filter + ) { + validateZoneName(zoneName); + + validateZonePartitions(partitions); + validateZoneReplicas(replicas); + + validateZoneDataNodesAutoAdjust(dataNodesAutoAdjust); + validateZoneDataNodesAutoAdjustScaleUp(dataNodesAutoAdjustScaleUp); + validateZoneDataNodesAutoAdjustScaleDown(dataNodesAutoAdjustScaleDown); + + validateZoneDataNodesAutoAdjustParametersCompatibility( + dataNodesAutoAdjust, + dataNodesAutoAdjustScaleUp, + dataNodesAutoAdjustScaleDown + ); + + validateZoneFilter(filter); + } + + private static void validateZoneName(String zoneName) { + if (StringUtils.nullOrBlank(zoneName)) { + throw new IgniteInternalException( + DistributionZones.ZONE_DEFINITION_ERR, + "Missing zone name" + ); + } + } + + private static void validateZoneName(String zoneName, String errorMessage) { + if (StringUtils.nullOrBlank(zoneName)) { + throw new IgniteInternalException( Review Comment: I suggest creating a specific exception class like `CatalogValidationException` and use it instead of the generic class ########## modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogManagerValidationTest.java: ########## @@ -0,0 +1,539 @@ +/* + * 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.catalog.commands.CatalogUtils.DEFAULT_FILTER; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_PARTITION_COUNT; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_REPLICA_COUNT; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.IMMEDIATE_TIMER_VALUE; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.INFINITE_TIMER_VALUE; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrowFast; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.nullValue; + +import org.apache.ignite.internal.catalog.commands.AlterZoneParams; +import org.apache.ignite.internal.catalog.commands.CreateZoneParams; +import org.apache.ignite.internal.catalog.commands.DropZoneParams; +import org.apache.ignite.internal.catalog.commands.RenameZoneParams; +import org.apache.ignite.lang.IgniteInternalException; +import org.junit.jupiter.api.Test; + +/** + * Catalog manager validation test. + */ +public class CatalogManagerValidationTest extends BaseCatalogManagerTest { + private static final String ZONE_NAME = "test_zone"; + + @Test + void testValidateZoneNameOnCreateZone() { + assertThat( + manager.createZone(CreateZoneParams.builder().build()), + willThrowFast(IgniteInternalException.class, "Missing zone name") + ); + + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + } + + @Test + void testValidateZoneNameOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(AlterZoneParams.builder().build()), + willThrowFast(IgniteInternalException.class, "Missing zone name") + ); + + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + } + + @Test + void testValidateZonePartitionsOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).partitions(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).partitions(0).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).partitions(65_001).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + // Let's check the success cases. + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 0).partitions(1).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 1).partitions(65_000).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 2).partitions(10).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 3).partitions(DEFAULT_PARTITION_COUNT).build()), willBe(nullValue())); + } + + @Test + void testValidateZonePartitionsOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(0).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(65_001).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + // Let's check the success cases. + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(1).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(65_000).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(10).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(DEFAULT_PARTITION_COUNT).build()), willBe(nullValue())); + } + + @Test + void testValidateZoneReplicasOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).replicas(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of replicas") + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).replicas(0).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of replicas") + ); + + // Let's check the success cases. + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 0).replicas(1).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 1).replicas(Integer.MAX_VALUE).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 2).replicas(DEFAULT_REPLICA_COUNT).build()), willBe(nullValue())); + } + + @Test + void testValidateZoneReplicasOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of replicas") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(0).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of replicas") + ); + + // Let's check the success cases. + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(1).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(Integer.MAX_VALUE).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(DEFAULT_REPLICA_COUNT).build()), willBe(nullValue())); + } + + @Test + void testValidateDataNodesAutoAdjustOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust") + ); + + // Let's check the success cases. + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 0).dataNodesAutoAdjust(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 1).dataNodesAutoAdjust(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 2).dataNodesAutoAdjust(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 3).dataNodesAutoAdjust(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust") + ); + + // Let's check the success cases. + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(0).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(Integer.MAX_VALUE).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(INFINITE_TIMER_VALUE).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(IMMEDIATE_TIMER_VALUE).build()), willBe(nullValue())); + } + + @Test + void testValidateDataNodesAutoAdjustScaleUpOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust scale up") + ); + + // Let's check the success cases. + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 0).dataNodesAutoAdjustScaleUp(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 1).dataNodesAutoAdjustScaleUp(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 2).dataNodesAutoAdjustScaleUp(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 3).dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustScaleUpOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust scale up") + ); + + // Let's check the success cases. + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustScaleDownOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust scale down") + ); + + // Let's check the success cases. + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 0).dataNodesAutoAdjustScaleDown(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 1).dataNodesAutoAdjustScaleDown(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 2).dataNodesAutoAdjustScaleDown(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 3).dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustScaleDownOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust scale down") + ); + + // Let's check the success cases. + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustCompatibilityParametersOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(666).dataNodesAutoAdjustScaleUp(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(666).dataNodesAutoAdjustScaleDown(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.createZone( + createZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(666) + .dataNodesAutoAdjustScaleDown(666) + .build() + ), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + // Let's check the success cases. + assertThat( + manager.createZone( + createZoneBuilder(ZONE_NAME + 0) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + assertThat( + manager.createZone( + createZoneBuilder(ZONE_NAME + 1) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + assertThat( + manager.createZone( + createZoneBuilder(ZONE_NAME + 2) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE) + .dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustCompatibilityParametersOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(666).dataNodesAutoAdjustScaleUp(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(666).dataNodesAutoAdjustScaleDown(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.alterZone( + alterZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(666) + .dataNodesAutoAdjustScaleDown(666) + .build() + ), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + // Let's check the success cases. + assertThat( + manager.alterZone( + alterZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone( + alterZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone( + alterZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE) + .dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + // Let's check the compatibility of the parameters and what is already stored in the catalog. + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(666).dataNodesAutoAdjustScaleDown(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + } + + @Test + void testValidateFilterOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).filter("some text").build()), + willThrowFast(IgniteInternalException.class, "Invalid filter") + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).filter("['nodeAttributes'[?(@.['region'] == 'EU')]").build()), + willThrowFast(IgniteInternalException.class, "Invalid filter") + ); + + // Let's check the success cases. + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 0).filter("['nodeAttributes'][?(@.['region'] == 'EU')]").build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 1).filter(DEFAULT_FILTER).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateFilterOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).filter("some text").build()), Review Comment: ```suggestion manager.alterZone(alterZoneBuilder(ZONE_NAME).filter("not a JsonPath").build()), ``` ########## modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogManagerValidationTest.java: ########## @@ -0,0 +1,539 @@ +/* + * 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.catalog.commands.CatalogUtils.DEFAULT_FILTER; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_PARTITION_COUNT; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_REPLICA_COUNT; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.IMMEDIATE_TIMER_VALUE; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.INFINITE_TIMER_VALUE; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrowFast; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.nullValue; + +import org.apache.ignite.internal.catalog.commands.AlterZoneParams; +import org.apache.ignite.internal.catalog.commands.CreateZoneParams; +import org.apache.ignite.internal.catalog.commands.DropZoneParams; +import org.apache.ignite.internal.catalog.commands.RenameZoneParams; +import org.apache.ignite.lang.IgniteInternalException; +import org.junit.jupiter.api.Test; + +/** + * Catalog manager validation test. + */ +public class CatalogManagerValidationTest extends BaseCatalogManagerTest { + private static final String ZONE_NAME = "test_zone"; + + @Test + void testValidateZoneNameOnCreateZone() { + assertThat( + manager.createZone(CreateZoneParams.builder().build()), + willThrowFast(IgniteInternalException.class, "Missing zone name") + ); + + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); Review Comment: This test is about validation and it seems to be an excessive detail that the future completes specifically with `null`. I suggest replacing `willBe(nullValue())` with `willCompleteSuccessfully()` to reduce distractions ########## modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogManagerValidationTest.java: ########## @@ -0,0 +1,539 @@ +/* + * 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.catalog.commands.CatalogUtils.DEFAULT_FILTER; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_PARTITION_COUNT; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_REPLICA_COUNT; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.IMMEDIATE_TIMER_VALUE; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.INFINITE_TIMER_VALUE; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrowFast; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.nullValue; + +import org.apache.ignite.internal.catalog.commands.AlterZoneParams; +import org.apache.ignite.internal.catalog.commands.CreateZoneParams; +import org.apache.ignite.internal.catalog.commands.DropZoneParams; +import org.apache.ignite.internal.catalog.commands.RenameZoneParams; +import org.apache.ignite.lang.IgniteInternalException; +import org.junit.jupiter.api.Test; + +/** + * Catalog manager validation test. + */ +public class CatalogManagerValidationTest extends BaseCatalogManagerTest { + private static final String ZONE_NAME = "test_zone"; + + @Test + void testValidateZoneNameOnCreateZone() { + assertThat( + manager.createZone(CreateZoneParams.builder().build()), + willThrowFast(IgniteInternalException.class, "Missing zone name") + ); + + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + } + + @Test + void testValidateZoneNameOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(AlterZoneParams.builder().build()), + willThrowFast(IgniteInternalException.class, "Missing zone name") + ); + + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + } + + @Test + void testValidateZonePartitionsOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).partitions(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).partitions(0).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).partitions(65_001).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + // Let's check the success cases. + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 0).partitions(1).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 1).partitions(65_000).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 2).partitions(10).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 3).partitions(DEFAULT_PARTITION_COUNT).build()), willBe(nullValue())); + } + + @Test + void testValidateZonePartitionsOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(0).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(65_001).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + // Let's check the success cases. + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(1).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(65_000).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(10).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(DEFAULT_PARTITION_COUNT).build()), willBe(nullValue())); + } + + @Test + void testValidateZoneReplicasOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).replicas(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of replicas") + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).replicas(0).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of replicas") + ); + + // Let's check the success cases. + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 0).replicas(1).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 1).replicas(Integer.MAX_VALUE).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 2).replicas(DEFAULT_REPLICA_COUNT).build()), willBe(nullValue())); + } + + @Test + void testValidateZoneReplicasOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of replicas") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(0).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of replicas") + ); + + // Let's check the success cases. + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(1).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(Integer.MAX_VALUE).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(DEFAULT_REPLICA_COUNT).build()), willBe(nullValue())); + } + + @Test + void testValidateDataNodesAutoAdjustOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust") + ); + + // Let's check the success cases. + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 0).dataNodesAutoAdjust(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 1).dataNodesAutoAdjust(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 2).dataNodesAutoAdjust(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 3).dataNodesAutoAdjust(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust") + ); + + // Let's check the success cases. + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(0).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(Integer.MAX_VALUE).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(INFINITE_TIMER_VALUE).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(IMMEDIATE_TIMER_VALUE).build()), willBe(nullValue())); + } + + @Test + void testValidateDataNodesAutoAdjustScaleUpOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust scale up") + ); + + // Let's check the success cases. + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 0).dataNodesAutoAdjustScaleUp(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 1).dataNodesAutoAdjustScaleUp(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 2).dataNodesAutoAdjustScaleUp(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 3).dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustScaleUpOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust scale up") + ); + + // Let's check the success cases. + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustScaleDownOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust scale down") + ); + + // Let's check the success cases. + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 0).dataNodesAutoAdjustScaleDown(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 1).dataNodesAutoAdjustScaleDown(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 2).dataNodesAutoAdjustScaleDown(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 3).dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustScaleDownOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust scale down") + ); + + // Let's check the success cases. + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustCompatibilityParametersOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(666).dataNodesAutoAdjustScaleUp(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(666).dataNodesAutoAdjustScaleDown(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.createZone( + createZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(666) + .dataNodesAutoAdjustScaleDown(666) + .build() + ), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + // Let's check the success cases. + assertThat( + manager.createZone( + createZoneBuilder(ZONE_NAME + 0) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + assertThat( + manager.createZone( + createZoneBuilder(ZONE_NAME + 1) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + assertThat( + manager.createZone( + createZoneBuilder(ZONE_NAME + 2) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE) + .dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustCompatibilityParametersOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(666).dataNodesAutoAdjustScaleUp(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(666).dataNodesAutoAdjustScaleDown(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.alterZone( + alterZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(666) + .dataNodesAutoAdjustScaleDown(666) + .build() + ), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + // Let's check the success cases. + assertThat( + manager.alterZone( + alterZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone( + alterZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone( + alterZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE) + .dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + // Let's check the compatibility of the parameters and what is already stored in the catalog. + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(666).dataNodesAutoAdjustScaleDown(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + } + + @Test + void testValidateFilterOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).filter("some text").build()), + willThrowFast(IgniteInternalException.class, "Invalid filter") + ); + + assertThat( Review Comment: Please add a comment explaining what's wrong with the JsonPath ########## modules/catalog/src/test/java/org/apache/ignite/internal/catalog/CatalogManagerValidationTest.java: ########## @@ -0,0 +1,539 @@ +/* + * 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.catalog.commands.CatalogUtils.DEFAULT_FILTER; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_PARTITION_COUNT; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_REPLICA_COUNT; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.IMMEDIATE_TIMER_VALUE; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.INFINITE_TIMER_VALUE; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrowFast; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.nullValue; + +import org.apache.ignite.internal.catalog.commands.AlterZoneParams; +import org.apache.ignite.internal.catalog.commands.CreateZoneParams; +import org.apache.ignite.internal.catalog.commands.DropZoneParams; +import org.apache.ignite.internal.catalog.commands.RenameZoneParams; +import org.apache.ignite.lang.IgniteInternalException; +import org.junit.jupiter.api.Test; + +/** + * Catalog manager validation test. + */ +public class CatalogManagerValidationTest extends BaseCatalogManagerTest { + private static final String ZONE_NAME = "test_zone"; + + @Test + void testValidateZoneNameOnCreateZone() { + assertThat( + manager.createZone(CreateZoneParams.builder().build()), + willThrowFast(IgniteInternalException.class, "Missing zone name") + ); + + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + } + + @Test + void testValidateZoneNameOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(AlterZoneParams.builder().build()), + willThrowFast(IgniteInternalException.class, "Missing zone name") + ); + + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + } + + @Test + void testValidateZonePartitionsOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).partitions(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).partitions(0).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).partitions(65_001).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + // Let's check the success cases. + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 0).partitions(1).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 1).partitions(65_000).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 2).partitions(10).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 3).partitions(DEFAULT_PARTITION_COUNT).build()), willBe(nullValue())); + } + + @Test + void testValidateZonePartitionsOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(0).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(65_001).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of partitions") + ); + + // Let's check the success cases. + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(1).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(65_000).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(10).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).partitions(DEFAULT_PARTITION_COUNT).build()), willBe(nullValue())); + } + + @Test + void testValidateZoneReplicasOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).replicas(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of replicas") + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).replicas(0).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of replicas") + ); + + // Let's check the success cases. + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 0).replicas(1).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 1).replicas(Integer.MAX_VALUE).build()), willBe(nullValue())); + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME + 2).replicas(DEFAULT_REPLICA_COUNT).build()), willBe(nullValue())); + } + + @Test + void testValidateZoneReplicasOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of replicas") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(0).build()), + willThrowFast(IgniteInternalException.class, "Invalid number of replicas") + ); + + // Let's check the success cases. + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(1).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(Integer.MAX_VALUE).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).replicas(DEFAULT_REPLICA_COUNT).build()), willBe(nullValue())); + } + + @Test + void testValidateDataNodesAutoAdjustOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust") + ); + + // Let's check the success cases. + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 0).dataNodesAutoAdjust(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 1).dataNodesAutoAdjust(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 2).dataNodesAutoAdjust(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 3).dataNodesAutoAdjust(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust") + ); + + // Let's check the success cases. + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(0).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(Integer.MAX_VALUE).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(INFINITE_TIMER_VALUE).build()), willBe(nullValue())); + assertThat(manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(IMMEDIATE_TIMER_VALUE).build()), willBe(nullValue())); + } + + @Test + void testValidateDataNodesAutoAdjustScaleUpOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust scale up") + ); + + // Let's check the success cases. + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 0).dataNodesAutoAdjustScaleUp(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 1).dataNodesAutoAdjustScaleUp(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 2).dataNodesAutoAdjustScaleUp(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 3).dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustScaleUpOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust scale up") + ); + + // Let's check the success cases. + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustScaleDownOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust scale down") + ); + + // Let's check the success cases. + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 0).dataNodesAutoAdjustScaleDown(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 1).dataNodesAutoAdjustScaleDown(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 2).dataNodesAutoAdjustScaleDown(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME + 3).dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustScaleDownOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(-1).build()), + willThrowFast(IgniteInternalException.class, "Invalid data nodes auto adjust scale down") + ); + + // Let's check the success cases. + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(0).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(Integer.MAX_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(IMMEDIATE_TIMER_VALUE).build()), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustCompatibilityParametersOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(666).dataNodesAutoAdjustScaleUp(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(666).dataNodesAutoAdjustScaleDown(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.createZone( + createZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(666) + .dataNodesAutoAdjustScaleDown(666) + .build() + ), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + // Let's check the success cases. + assertThat( + manager.createZone( + createZoneBuilder(ZONE_NAME + 0) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + assertThat( + manager.createZone( + createZoneBuilder(ZONE_NAME + 1) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + assertThat( + manager.createZone( + createZoneBuilder(ZONE_NAME + 2) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE) + .dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + } + + @Test + void testValidateDataNodesAutoAdjustCompatibilityParametersOnAlterZone() { + assertThat(manager.createZone(createZoneBuilder(ZONE_NAME).build()), willBe(nullValue())); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(666).dataNodesAutoAdjustScaleUp(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjust(666).dataNodesAutoAdjustScaleDown(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.alterZone( + alterZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(666) + .dataNodesAutoAdjustScaleDown(666) + .build() + ), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + // Let's check the success cases. + assertThat( + manager.alterZone( + alterZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone( + alterZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + assertThat( + manager.alterZone( + alterZoneBuilder(ZONE_NAME) + .dataNodesAutoAdjust(666) + .dataNodesAutoAdjustScaleUp(INFINITE_TIMER_VALUE) + .dataNodesAutoAdjustScaleDown(INFINITE_TIMER_VALUE) + .build() + ), + willBe(nullValue()) + ); + + // Let's check the compatibility of the parameters and what is already stored in the catalog. + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleDown(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + + assertThat( + manager.alterZone(alterZoneBuilder(ZONE_NAME).dataNodesAutoAdjustScaleUp(666).dataNodesAutoAdjustScaleDown(666).build()), + willThrowFast(IgniteInternalException.class, "Not compatible parameters") + ); + } + + @Test + void testValidateFilterOnCreateZone() { + assertThat( + manager.createZone(createZoneBuilder(ZONE_NAME).filter("some text").build()), Review Comment: ```suggestion manager.createZone(createZoneBuilder(ZONE_NAME).filter("not a JsonPath").build()), ``` -- 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]
