tkalkirill commented on code in PR #1146: URL: https://github.com/apache/ignite-3/pull/1146#discussion_r985873917
########## modules/compute/src/main/java/org/apache/ignite/internal/compute/configuration/ComputeConfigurationModule.java: ########## @@ -0,0 +1,40 @@ +/* + * 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.compute.configuration; + +import java.util.Collection; +import java.util.Collections; +import org.apache.ignite.configuration.RootKey; +import org.apache.ignite.configuration.annotation.ConfigurationType; +import org.apache.ignite.configuration.schemas.compute.ComputeConfiguration; +import org.apache.ignite.internal.configuration.ConfigurationModule; + +/** + * {@link ConfigurationModule} for cluster-wide configuration provided by compute. + */ +public class ComputeConfigurationModule implements ConfigurationModule { + @Override + public ConfigurationType type() { + return ConfigurationType.LOCAL; Review Comment: Maybe a cluster? ########## modules/cluster-management/src/integrationTest/java/org/apache/ignite/internal/cluster/management/raft/ItCmgRaftServiceTest.java: ########## @@ -63,9 +66,13 @@ * Class with tests for the {@link CmgRaftService}. */ @ExtendWith(WorkDirectoryExtension.class) +@ExtendWith(ConfigurationExtension.class) Review Comment: ```suggestion @ExtendWith({WorkDirectoryExtension.class, ConfigurationExtension.class}) ``` ########## modules/configuration/src/testFixtures/java/org/apache/ignite/internal/configuration/testframework/ConfigurationExtension.java: ########## @@ -84,58 +91,100 @@ public class ConfigurationExtension implements BeforeEachCallback, AfterEachCall /** Key to store {@link ExecutorService} in {@link ExtensionContext.Store}. */ private static final Object POOL_KEY = new Object(); - /** Key to store {@link StorageRevisionListenerHolderImpl} in {@link ExtensionContext.Store}. */ + /** Key to store {@link StorageRevisionListenerHolderImpl} in {@link ExtensionContext.Store} for all tests. */ private static final Object REVISION_LISTENER_HOLDER_KEY = new Object(); Review Comment: Maybe: REVISION_LISTENER_ALL_TEST_HOLDER_KEY ? ########## modules/configuration/src/testFixtures/java/org/apache/ignite/internal/configuration/testframework/ConfigurationExtension.java: ########## @@ -300,22 +360,22 @@ public long notificationCount() { return cfgRef.get(); } - private static List<Field> getInjectConfigurationFields(Class<?> testClass) { + private static List<Field> getInjectConfigurationFields(Class<?> testClass, boolean forStatic) { return AnnotationSupport.findAnnotatedFields( testClass, InjectConfiguration.class, field -> supportsAsConfigurationType(field.getType()), HierarchyTraversalMode.TOP_DOWN - ); + ).stream().filter(field -> Modifier.isStatic(field.getModifiers()) == forStatic).collect(Collectors.toList()); } - private static List<Field> getInjectRevisionListenerHolderFields(Class<?> testClass) { + private static List<Field> getInjectRevisionListenerHolderFields(Class<?> testClass, boolean forStatic) { return AnnotationSupport.findAnnotatedFields( testClass, InjectRevisionListenerHolder.class, field -> isRevisionListenerHolder(field.getType()), HierarchyTraversalMode.TOP_DOWN - ); + ).stream().filter(field -> Modifier.isStatic(field.getModifiers()) == forStatic).collect(Collectors.toList()); Review Comment: Can we pass this condition to a predicate? ########## modules/configuration/src/testFixtures/java/org/apache/ignite/internal/configuration/testframework/ConfigurationExtension.java: ########## @@ -300,22 +360,22 @@ public long notificationCount() { return cfgRef.get(); } - private static List<Field> getInjectConfigurationFields(Class<?> testClass) { + private static List<Field> getInjectConfigurationFields(Class<?> testClass, boolean forStatic) { return AnnotationSupport.findAnnotatedFields( testClass, InjectConfiguration.class, field -> supportsAsConfigurationType(field.getType()), HierarchyTraversalMode.TOP_DOWN - ); + ).stream().filter(field -> Modifier.isStatic(field.getModifiers()) == forStatic).collect(Collectors.toList()); Review Comment: Can we pass this condition to a predicate? ########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/configuration/storage/ItDistributedConfigurationStorageTest.java: ########## @@ -52,7 +55,11 @@ * Tests for the {@link DistributedConfigurationStorage}. */ @ExtendWith(WorkDirectoryExtension.class) +@ExtendWith(ConfigurationExtension.class) Review Comment: ```suggestion @ExtendWith({WorkDirectoryExtension.class, ConfigurationExtension.class}) ``` ########## modules/configuration/src/testFixtures/java/org/apache/ignite/internal/configuration/testframework/ConfigurationExtension.java: ########## @@ -205,10 +254,21 @@ private static Object cfgValue( // classes, extension is designed to mock actual configurations from public API to configure Ignite components. Class<?> schemaClass = Class.forName(type.getCanonicalName() + "Schema"); + List<Class<?>> internalExtensions = new ArrayList<>(INTERNAL_EXTENSIONS); Review Comment: Can make copies of collections only when the annotation has a field value? ########## modules/configuration/src/testFixtures/java/org/apache/ignite/internal/configuration/testframework/ConfigurationExtension.java: ########## @@ -84,58 +91,100 @@ public class ConfigurationExtension implements BeforeEachCallback, AfterEachCall /** Key to store {@link ExecutorService} in {@link ExtensionContext.Store}. */ private static final Object POOL_KEY = new Object(); - /** Key to store {@link StorageRevisionListenerHolderImpl} in {@link ExtensionContext.Store}. */ + /** Key to store {@link StorageRevisionListenerHolderImpl} in {@link ExtensionContext.Store} for all tests. */ private static final Object REVISION_LISTENER_HOLDER_KEY = new Object(); + /** Key to store {@link StorageRevisionListenerHolderImpl} in {@link ExtensionContext.Store} for each test. */ + private static final Object REVISION_LISTENER_PER_TEST_HOLDER_KEY = new Object(); + + /** All {@link InternalConfiguration} classes in classpath. */ + private static final List<Class<?>> INTERNAL_EXTENSIONS; + + /** All {@link PolymorphicConfigInstance} classes in classpath. */ + private static final List<Class<?>> POLYMORPHIC_EXTENSIONS; + + static { + // Automatically find all @InternalConfiguration and PolymorphicConfigInstance classes Review Comment: ```suggestion // Automatically find all @InternalConfiguration and @PolymorphicConfigInstance classes ``` ########## modules/client-handler/src/main/java/org/apache/ignite/client/handler/configuration/ClientHandlerConfigurationModule.java: ########## @@ -15,35 +15,26 @@ * limitations under the License. */ -package org.apache.ignite.internal.configuration; +package org.apache.ignite.client.handler.configuration; import java.util.Collection; -import java.util.List; +import java.util.Collections; import org.apache.ignite.configuration.RootKey; import org.apache.ignite.configuration.annotation.ConfigurationType; import org.apache.ignite.configuration.schemas.clientconnector.ClientConnectorConfiguration; -import org.apache.ignite.configuration.schemas.compute.ComputeConfiguration; -import org.apache.ignite.configuration.schemas.network.NetworkConfiguration; -import org.apache.ignite.configuration.schemas.rest.RestConfiguration; +import org.apache.ignite.internal.configuration.ConfigurationModule; /** - * {@link ConfigurationModule} for node-local configuration provided by ignite-api. + * {@link ConfigurationModule} for cluster-wide configuration provided by client-handler. */ -public class CoreLocalConfigurationModule implements ConfigurationModule { - /** {@inheritDoc} */ +public class ClientHandlerConfigurationModule implements ConfigurationModule { @Override public ConfigurationType type() { return ConfigurationType.LOCAL; Review Comment: Must be a cluster. ########## modules/configuration/src/testFixtures/java/org/apache/ignite/internal/configuration/testframework/ConfigurationExtension.java: ########## @@ -84,58 +91,100 @@ public class ConfigurationExtension implements BeforeEachCallback, AfterEachCall /** Key to store {@link ExecutorService} in {@link ExtensionContext.Store}. */ private static final Object POOL_KEY = new Object(); - /** Key to store {@link StorageRevisionListenerHolderImpl} in {@link ExtensionContext.Store}. */ + /** Key to store {@link StorageRevisionListenerHolderImpl} in {@link ExtensionContext.Store} for all tests. */ private static final Object REVISION_LISTENER_HOLDER_KEY = new Object(); + /** Key to store {@link StorageRevisionListenerHolderImpl} in {@link ExtensionContext.Store} for each test. */ + private static final Object REVISION_LISTENER_PER_TEST_HOLDER_KEY = new Object(); + + /** All {@link InternalConfiguration} classes in classpath. */ + private static final List<Class<?>> INTERNAL_EXTENSIONS; + + /** All {@link PolymorphicConfigInstance} classes in classpath. */ + private static final List<Class<?>> POLYMORPHIC_EXTENSIONS; + + static { + // Automatically find all @InternalConfiguration and PolymorphicConfigInstance classes + // to avoid configuring extensions manually in every test. + ServiceLoader<ConfigurationModule> modules = ServiceLoader.load(ConfigurationModule.class); + + List<Class<?>> internalExtensions = new ArrayList<>(); + List<Class<?>> polymorphicExtensions = new ArrayList<>(); + + modules.forEach(configurationModule -> { + internalExtensions.addAll(configurationModule.internalSchemaExtensions()); + polymorphicExtensions.addAll(configurationModule.polymorphicSchemaExtensions()); + }); + + INTERNAL_EXTENSIONS = List.copyOf(internalExtensions); + POLYMORPHIC_EXTENSIONS = List.copyOf(polymorphicExtensions); + } + /** {@inheritDoc} */ @Override public void beforeAll(ExtensionContext context) throws Exception { + context.getStore(NAMESPACE).put(CGEN_KEY, new ConfigurationAsmGenerator()); context.getStore(NAMESPACE).put(POOL_KEY, newSingleThreadExecutor()); + + injectFields(context, true); } /** {@inheritDoc} */ @Override public void afterAll(ExtensionContext context) throws Exception { - ExecutorService pool = context.getStore(NAMESPACE).remove(POOL_KEY, ExecutorService.class); + context.getStore(NAMESPACE).remove(CGEN_KEY); - pool.shutdownNow(); + context.getStore(NAMESPACE).remove(POOL_KEY, ExecutorService.class).shutdownNow(); + + context.getStore(NAMESPACE).remove(REVISION_LISTENER_HOLDER_KEY); } /** {@inheritDoc} */ @Override public void beforeEach(ExtensionContext context) throws Exception { - ConfigurationAsmGenerator cgen = new ConfigurationAsmGenerator(); + injectFields(context, false); + } - context.getStore(NAMESPACE).put(CGEN_KEY, cgen); + private void injectFields(ExtensionContext context, boolean forStatic) throws Exception { + Class<?> testClass = context.getRequiredTestClass(); + Object testInstance = context.getTestInstance().orElse(null); - Object testInstance = context.getRequiredTestInstance(); + assert forStatic || testInstance != null; - ExecutorService pool = context.getStore(NAMESPACE).get(POOL_KEY, ExecutorService.class); + Store store = context.getStore(NAMESPACE); + + ConfigurationAsmGenerator cgen = store.get(CGEN_KEY, ConfigurationAsmGenerator.class); + ExecutorService pool = store.get(POOL_KEY, ExecutorService.class); StorageRevisionListenerHolderImpl revisionListenerHolder = new StorageRevisionListenerHolderImpl(); - context.getStore(NAMESPACE).put(REVISION_LISTENER_HOLDER_KEY, revisionListenerHolder); + if (forStatic) { + store.put(REVISION_LISTENER_HOLDER_KEY, revisionListenerHolder); + } else { + store.put(REVISION_LISTENER_PER_TEST_HOLDER_KEY, revisionListenerHolder); + } - for (Field field : getInjectConfigurationFields(testInstance.getClass())) { + for (Field field : getInjectConfigurationFields(testClass, forStatic)) { field.setAccessible(true); InjectConfiguration annotation = field.getAnnotation(InjectConfiguration.class); - field.set(testInstance, cfgValue(field.getType(), annotation, cgen, pool, revisionListenerHolder)); + Object cfgValue = cfgValue(field.getType(), annotation, cgen, pool, revisionListenerHolder); + + field.set(forStatic ? null : testInstance, cfgValue); } - for (Field field : getInjectRevisionListenerHolderFields(testInstance.getClass())) { + for (Field field : getInjectRevisionListenerHolderFields(testClass, forStatic)) { field.setAccessible(true); - field.set(testInstance, revisionListenerHolder); + field.set(forStatic ? null : testInstance, revisionListenerHolder); Review Comment: Maybe skip this cycle for static fields? ########## modules/client-handler/src/main/resources/META-INF/services/org.apache.ignite.internal.configuration.ConfigurationModule: ########## @@ -0,0 +1,17 @@ +# +# 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. +# Review Comment: ```suggestion # # 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. # ``` ########## modules/network/src/main/java/org/apache/ignite/network/configuration/NetworkConfigurationModule.java: ########## @@ -0,0 +1,40 @@ +/* + * 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.network.configuration; + +import java.util.Collection; +import java.util.Collections; +import org.apache.ignite.configuration.RootKey; +import org.apache.ignite.configuration.annotation.ConfigurationType; +import org.apache.ignite.configuration.schemas.network.NetworkConfiguration; +import org.apache.ignite.internal.configuration.ConfigurationModule; + +/** + * {@link ConfigurationModule} for cluster-wide configuration provided by ignite-network. + */ +public class NetworkConfigurationModule implements ConfigurationModule { + @Override + public ConfigurationType type() { + return ConfigurationType.LOCAL; Review Comment: Mb cluster? ########## modules/raft/src/integrationTest/java/org/apache/ignite/internal/raft/ItRaftGroupServiceTest.java: ########## @@ -54,10 +57,14 @@ */ @ExtendWith(WorkDirectoryExtension.class) @TestInstance(TestInstance.Lifecycle.PER_CLASS) +@ExtendWith(ConfigurationExtension.class) Review Comment: ```suggestion @ExtendWith({WorkDirectoryExtension.class, ConfigurationExtension.class}) @TestInstance(TestInstance.Lifecycle.PER_CLASS) ``` ########## modules/raft/src/integrationTest/java/org/apache/ignite/internal/raft/ItLozaTest.java: ########## @@ -54,13 +57,17 @@ * Tests for {@link Loza} functionality. */ @ExtendWith(WorkDirectoryExtension.class) +@ExtendWith(ConfigurationExtension.class) Review Comment: ```suggestion @ExtendWith({WorkDirectoryExtension.class, ConfigurationExtension.class}) ``` ########## modules/raft/src/main/java/org/apache/ignite/internal/raft/configuration/RaftConfigurationSchema.java: ########## @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.raft.configuration; + +import org.apache.ignite.configuration.annotation.ConfigValue; +import org.apache.ignite.configuration.annotation.ConfigurationRoot; +import org.apache.ignite.configuration.annotation.ConfigurationType; +import org.apache.ignite.configuration.schemas.table.VolatileRaftConfigurationSchema; + +/** + * Raft configuration schema. + */ +@SuppressWarnings("PMD.UnusedPrivateField") +@ConfigurationRoot(rootName = "raft", type = ConfigurationType.LOCAL) +public class RaftConfigurationSchema { Review Comment: And how now to configure for each table separately? ########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/configuration/storage/ItRebalanceDistributedTest.java: ########## @@ -103,6 +104,7 @@ * Test suite for rebalance process, when replicas' number changed. */ @ExtendWith(WorkDirectoryExtension.class) +@ExtendWith(ConfigurationExtension.class) Review Comment: ```suggestion @ExtendWith({WorkDirectoryExtension.class, ConfigurationExtension.class}) ``` ########## modules/raft/src/main/java/org/apache/ignite/internal/raft/configuration/RaftConfigurationModule.java: ########## @@ -15,56 +15,36 @@ * limitations under the License. */ -package org.apache.ignite.internal.configuration; +package org.apache.ignite.internal.raft.configuration; -import java.lang.annotation.Annotation; import java.util.Collection; +import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.Set; import org.apache.ignite.configuration.RootKey; import org.apache.ignite.configuration.annotation.ConfigurationType; -import org.apache.ignite.configuration.schemas.store.KnownDataStorage; -import org.apache.ignite.configuration.schemas.store.UnknownDataStorageConfigurationSchema; import org.apache.ignite.configuration.schemas.table.EntryCountBudgetConfigurationSchema; -import org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema; -import org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema; -import org.apache.ignite.configuration.schemas.table.TablesConfiguration; import org.apache.ignite.configuration.schemas.table.UnlimitedBudgetConfigurationSchema; -import org.apache.ignite.configuration.validation.Validator; -import org.apache.ignite.internal.schema.configuration.KnownDataStorageValidator; +import org.apache.ignite.internal.configuration.ConfigurationModule; /** - * {@link ConfigurationModule} for cluster-wide configuration provided by ignite-api. + * {@link ConfigurationModule} for cluster-wide configuration provided by ignite-raft. */ -public class CoreDistributedConfigurationModule implements ConfigurationModule { - /** {@inheritDoc} */ +public class RaftConfigurationModule implements ConfigurationModule { @Override public ConfigurationType type() { - return ConfigurationType.DISTRIBUTED; + return ConfigurationType.LOCAL; Review Comment: Mb cluster? ########## modules/rest/src/main/java/org/apache/ignite/internal/rest/configuration/RestConfigurationModule.java: ########## @@ -0,0 +1,40 @@ +/* + * 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.rest.configuration; + +import java.util.Collection; +import java.util.Collections; +import org.apache.ignite.configuration.RootKey; +import org.apache.ignite.configuration.annotation.ConfigurationType; +import org.apache.ignite.configuration.schemas.rest.RestConfiguration; +import org.apache.ignite.internal.configuration.ConfigurationModule; + +/** + * {@link ConfigurationModule} for cluster-wide configuration provided by ignite-rest. + */ +public class RestConfigurationModule implements ConfigurationModule { + @Override + public ConfigurationType type() { + return ConfigurationType.LOCAL; Review Comment: Mb cluster? ########## modules/client-handler/src/main/java/org/apache/ignite/client/handler/configuration/ClientHandlerConfigurationModule.java: ########## @@ -15,35 +15,26 @@ * limitations under the License. */ -package org.apache.ignite.internal.configuration; +package org.apache.ignite.client.handler.configuration; import java.util.Collection; -import java.util.List; +import java.util.Collections; import org.apache.ignite.configuration.RootKey; import org.apache.ignite.configuration.annotation.ConfigurationType; import org.apache.ignite.configuration.schemas.clientconnector.ClientConnectorConfiguration; -import org.apache.ignite.configuration.schemas.compute.ComputeConfiguration; -import org.apache.ignite.configuration.schemas.network.NetworkConfiguration; -import org.apache.ignite.configuration.schemas.rest.RestConfiguration; +import org.apache.ignite.internal.configuration.ConfigurationModule; /** - * {@link ConfigurationModule} for node-local configuration provided by ignite-api. + * {@link ConfigurationModule} for cluster-wide configuration provided by client-handler. */ -public class CoreLocalConfigurationModule implements ConfigurationModule { - /** {@inheritDoc} */ +public class ClientHandlerConfigurationModule implements ConfigurationModule { @Override public ConfigurationType type() { return ConfigurationType.LOCAL; Review Comment: Mb cluster? -- 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]
