tkalkirill commented on a change in pull request #336:
URL: https://github.com/apache/ignite-3/pull/336#discussion_r712238820



##########
File path: 
modules/configuration-api/src/main/java/org/apache/ignite/configuration/ConfigurationException.java
##########
@@ -0,0 +1,32 @@
+/*
+ * 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.configuration;
+
+/**
+ * This exception is used to indicate any error condition in the configuration.

Review comment:
       I propose to discuss this in a separate ticket.

##########
File path: 
modules/configuration/src/test/java/org/apache/ignite/internal/configuration/notifications/ConfigurationListenerTest.java
##########
@@ -644,4 +667,366 @@ public void dataRace() throws Exception {
 
         assertEquals(List.of("deleted"), log);
     }
+
+    /** */
+    @Test
+    void testNoGetOrUpdateConfigValueForAny() throws Exception {
+        ChildConfiguration any0 = configuration.elements().any();
+
+        assertThrows(ConfigurationException.class, () -> any0.value());
+        assertThrows(ConfigurationException.class, () -> 
any0.change(doNothingConsumer()));
+
+        assertThrows(ConfigurationException.class, () -> any0.str().value());
+        assertThrows(ConfigurationException.class, () -> 
any0.str().update(""));
+
+        assertThrows(ConfigurationException.class, () -> 
any0.child2().value());
+        assertThrows(ConfigurationException.class, () -> 
any0.child2().change(doNothingConsumer()));
+
+        assertThrows(ConfigurationException.class, () -> 
any0.child2().i().value());
+        assertThrows(ConfigurationException.class, () -> 
any0.child2().i().update(100));
+
+        assertThrows(ConfigurationException.class, () -> 
any0.elements2().value());
+        assertThrows(ConfigurationException.class, () -> 
any0.elements2().change(doNothingConsumer()));
+        assertThrows(ConfigurationException.class, () -> 
any0.elements2().get("test"));
+
+        Child2Configuration any1 = any0.elements2().any();
+
+        assertThrows(ConfigurationException.class, () -> any1.value());
+        assertThrows(ConfigurationException.class, () -> 
any1.change(doNothingConsumer()));
+
+        assertThrows(ConfigurationException.class, () -> any1.i().value());
+        assertThrows(ConfigurationException.class, () -> any1.i().update(200));
+
+        configuration.elements().change(c0 -> c0.create("test", c1 -> 
c1.changeStr("foo"))).get(1, SECONDS);
+
+        Child2Configuration any2 = 
configuration.elements().get("test").elements2().any();
+
+        assertThrows(ConfigurationException.class, () -> any2.value());
+        assertThrows(ConfigurationException.class, () -> 
any2.change(doNothingConsumer()));
+
+        assertThrows(ConfigurationException.class, () -> any2.i().value());
+        assertThrows(ConfigurationException.class, () -> any2.i().update(300));
+    }
+
+    /** */
+    @Test
+    void testAnyListeners() throws Exception {
+        List<String> events = new ArrayList<>();
+
+        // Add "regular" listeners.
+        configuration.listen(configListener(ctx -> events.add("root")));
+
+        configuration.child().listen(configListener(ctx -> 
events.add("root.child")));
+        configuration.child().str().listen(configListener(ctx -> 
events.add("root.child.str")));
+        configuration.child().child2().listen(configListener(ctx -> 
events.add("root.child.child2")));
+        configuration.child().child2().i().listen(configListener(ctx -> 
events.add("root.child.child2.i")));
+
+        configuration.elements().listen(configListener(ctx -> 
events.add("root.elements")));
+        
configuration.elements().listenElements(configNamedListenerOnCreate(ctx -> 
events.add("root.elements.onCrt")));
+        
configuration.elements().listenElements(configNamedListenerOnUpdate(ctx -> 
events.add("root.elements.onUpd")));
+        
configuration.elements().listenElements(configNamedListenerOnRename(ctx -> 
events.add("root.elements.onRen")));
+        
configuration.elements().listenElements(configNamedListenerOnDelete(ctx -> 
events.add("root.elements.onDel")));
+
+        configuration.elements().change(c -> c.create("0", 
doNothingConsumer())).get(1, SECONDS);
+
+        ChildConfiguration childCfg = this.configuration.elements().get("0");
+
+        childCfg.listen(configListener(ctx -> events.add("root.elements.0")));
+        childCfg.str().listen(configListener(ctx -> 
events.add("root.elements.0.str")));
+        childCfg.child2().listen(configListener(ctx -> 
events.add("root.elements.0.child2")));
+        childCfg.child2().i().listen(configListener(ctx -> 
events.add("root.elements.0.child2.i")));
+
+        NamedConfigurationTree<Child2Configuration, Child2View, Child2Change> 
elements2 = childCfg.elements2();
+
+        elements2.listen(configListener(ctx -> 
events.add("root.elements.0.elements2")));
+        elements2.listenElements(configNamedListenerOnCreate(ctx -> 
events.add("root.elements.0.elements2.onCrt")));
+        elements2.listenElements(configNamedListenerOnUpdate(ctx -> 
events.add("root.elements.0.elements2.onUpd")));
+        elements2.listenElements(configNamedListenerOnRename(ctx -> 
events.add("root.elements.0.elements2.onRen")));
+        elements2.listenElements(configNamedListenerOnDelete(ctx -> 
events.add("root.elements.0.elements2.onDel")));
+
+        elements2.change(c -> c.create("0", doNothingConsumer())).get(1, 
SECONDS);
+
+        Child2Configuration child2 = elements2.get("0");
+
+        child2.listen(configListener(ctx -> 
events.add("root.elements.0.elements2.0")));
+        child2.i().listen(configListener(ctx -> 
events.add("root.elements.0.elements2.0.i")));
+
+        // Adding "any" listeners.
+        ChildConfiguration anyChild = configuration.elements().any();
+
+        anyChild.listen(configListener(ctx -> 
events.add("root.elements.any")));
+        anyChild.str().listen(configListener(ctx -> 
events.add("root.elements.any.str")));
+        anyChild.child2().listen(configListener(ctx -> 
events.add("root.elements.any.child2")));
+        anyChild.child2().i().listen(configListener(ctx -> 
events.add("root.elements.any.child2.i")));
+
+        NamedConfigurationTree<Child2Configuration, Child2View, Child2Change> 
anyEl2 = anyChild.elements2();
+
+        anyEl2.listen(configListener(ctx -> 
events.add("root.elements.any.elements2")));
+        anyEl2.listenElements(configNamedListenerOnCreate(ctx -> 
events.add("root.elements.any.elements2.onCrt")));
+        anyEl2.listenElements(configNamedListenerOnUpdate(ctx -> 
events.add("root.elements.any.elements2.onUpd")));
+        anyEl2.listenElements(configNamedListenerOnRename(ctx -> 
events.add("root.elements.any.elements2.onRen")));
+        anyEl2.listenElements(configNamedListenerOnDelete(ctx -> 
events.add("root.elements.any.elements2.onDel")));
+
+        Child2Configuration anyChild2 = anyEl2.any();
+
+        anyChild2.listen(configListener(ctx -> 
events.add("root.elements.any.elements2.any")));
+        anyChild2.i().listen(configListener(ctx -> 
events.add("root.elements.any.elements2.any.i")));
+
+        childCfg.elements2().any().listen(configListener(ctx -> 
events.add("root.elements.0.elements2.any")));
+        childCfg.elements2().any().i().listen(configListener(ctx -> 
events.add("root.elements.0.elements2.any.i")));
+
+        // Tests.
+        checkListeners(
+            () -> configuration.child().change(c -> 
c.changeStr("x").changeChild2(c0 -> c0.changeI(100))),
+            List.of("root", "root.child", "root.child.str", 
"root.child.child2", "root.child.child2.i"),
+            events
+        );
+
+        checkListeners(
+            () -> configuration.elements().get("0").str().update("x"),
+            List.of(
+                "root",
+                "root.elements",
+                "root.elements.onUpd",
+                //
+                "root.elements.any",
+                "root.elements.0",
+                //
+                "root.elements.any.str",
+                "root.elements.0.str"
+            ),
+            events
+        );
+
+        checkListeners(
+            () -> 
configuration.elements().get("0").elements2().get("0").i().update(200),
+            List.of(
+                "root",
+                "root.elements",
+                "root.elements.onUpd",
+                //
+                "root.elements.any",
+                "root.elements.0",
+                //
+                "root.elements.any.elements2",
+                "root.elements.0.elements2",
+                "root.elements.any.elements2.onUpd",
+                "root.elements.0.elements2.onUpd",
+                //
+                "root.elements.any.elements2.any",
+                "root.elements.0.elements2.any",
+                "root.elements.0.elements2.0",
+                //
+                "root.elements.any.elements2.any.i",
+                "root.elements.0.elements2.any.i",
+                "root.elements.0.elements2.0.i"
+            ),
+            events
+        );
+
+        checkListeners(
+            () -> configuration.elements().get("0").elements2().change(c -> 
c.create("1", doNothingConsumer())),
+            List.of(
+                "root",
+                "root.elements",
+                "root.elements.onUpd",
+                //
+                "root.elements.any",
+                "root.elements.0",
+                //
+                "root.elements.any.elements2",
+                "root.elements.0.elements2",
+                "root.elements.any.elements2.onCrt",
+                "root.elements.0.elements2.onCrt",
+                //
+                "root.elements.any.elements2.onUpd",
+                "root.elements.0.elements2.onUpd"
+            ),
+            events
+        );
+
+        checkListeners(
+            () -> configuration.elements()

Review comment:
       I propose to discuss this in a separate ticket.




-- 
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]


Reply via email to