chesnokoff commented on code in PR #12974:
URL: https://github.com/apache/ignite/pull/12974#discussion_r3040232713


##########
modules/core/src/test/java/org/apache/ignite/spi/MessagesPluginProvider.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.spi;
+
+import java.util.function.Supplier;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.plugin.AbstractTestPluginProvider;
+import org.apache.ignite.plugin.ExtensionRegistry;
+import org.apache.ignite.plugin.PluginContext;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import 
org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider;
+import org.apache.ignite.plugin.extensions.communication.MessageSerializer;
+import org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi;
+
+/**
+ * Plugin provider for registering test messages in the communication and 
discovery protocols.
+ */
+public class MessagesPluginProvider extends AbstractTestPluginProvider {
+    /** */
+    private final MessageFactoryProvider msgFactoryProvider;
+
+    /** */
+    @SafeVarargs
+    public MessagesPluginProvider(Class<? extends Message>... msgs) {
+        msgFactoryProvider = f -> {
+            short directType = 10_000;
+
+            for (Class<? extends Message> msg : msgs) {
+                Supplier<Message> msgSupp = () -> {
+                    try {
+                        return U.newInstance(msg);
+                    }
+                    catch (IgniteCheckedException e) {
+                        throw new RuntimeException(e);
+                    }
+                };
+
+                f.register(directType, msgSupp, loadSerializer(msg));
+
+                directType++;
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public String name() {
+        return "Test messages plugin";
+    }
+
+    /** {@inheritDoc} */
+    @Override public void initExtensions(PluginContext ctx, ExtensionRegistry 
registry) {
+        // Register messages into the communication protocol.
+        registry.registerExtension(MessageFactoryProvider.class, 
msgFactoryProvider);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void start(PluginContext ctx) throws 
IgniteCheckedException {
+        // Register messages into the discovery protocol.
+        TestTcpDiscoverySpi discoSpi = 
(TestTcpDiscoverySpi)ctx.igniteConfiguration().getDiscoverySpi();
+
+        discoSpi.messageFactory(msgFactoryProvider);
+    }
+
+    /** */
+    private MessageSerializer<? extends Message> loadSerializer(Class<? 
extends Message> msgCls) {
+        try {
+            Class<?> serCls = U.gridClassLoader()
+                .loadClass(msgCls.getPackage().getName() + "." + 
msgCls.getSimpleName() + "Serializer");
+
+            return (MessageSerializer<? extends Message>)U.newInstance(serCls);
+        }
+        catch (Exception e) {
+            throw new RuntimeException("Unable to found serializer for 
message: " + msgCls, e);

Review Comment:
   ```suggestion
               throw new RuntimeException("Unable to find serializer for 
message: " + msgCls, e);
   ```



##########
modules/core/src/test/java/org/apache/ignite/spi/discovery/FilterDataForClientNodeDiscoveryTest.java:
##########
@@ -118,24 +115,21 @@ private IgniteConfiguration configuration(int nodeIdx) 
throws Exception {
 
         cfg.setDiscoverySpi(testSpi);
 
+        cfg.setPluginProviders(new 
MessagesPluginProvider(MessageForServer.class));
+
         return cfg;
     }
 
-    /**
-     *
-     */
-    private class TestDiscoverySpi extends TcpDiscoverySpi {
+    /** */
+    private class TestDiscoverySpi extends 
org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi {

Review Comment:
   Do we need fully qualified name here?



##########
modules/core/src/test/java/org/apache/ignite/spi/MessagesPluginProvider.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.spi;
+
+import java.util.function.Supplier;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.plugin.AbstractTestPluginProvider;
+import org.apache.ignite.plugin.ExtensionRegistry;
+import org.apache.ignite.plugin.PluginContext;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import 
org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider;
+import org.apache.ignite.plugin.extensions.communication.MessageSerializer;
+import org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi;
+
+/**
+ * Plugin provider for registering test messages in the communication and 
discovery protocols.
+ */
+public class MessagesPluginProvider extends AbstractTestPluginProvider {
+    /** */
+    private final MessageFactoryProvider msgFactoryProvider;
+
+    /** */
+    @SafeVarargs
+    public MessagesPluginProvider(Class<? extends Message>... msgs) {
+        msgFactoryProvider = f -> {
+            short directType = 10_000;
+
+            for (Class<? extends Message> msg : msgs) {
+                Supplier<Message> msgSupp = () -> {
+                    try {
+                        return U.newInstance(msg);
+                    }
+                    catch (IgniteCheckedException e) {
+                        throw new RuntimeException(e);
+                    }
+                };
+
+                f.register(directType, msgSupp, loadSerializer(msg));
+
+                directType++;
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public String name() {
+        return "Test messages plugin";
+    }
+
+    /** {@inheritDoc} */
+    @Override public void initExtensions(PluginContext ctx, ExtensionRegistry 
registry) {
+        // Register messages into the communication protocol.
+        registry.registerExtension(MessageFactoryProvider.class, 
msgFactoryProvider);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void start(PluginContext ctx) throws 
IgniteCheckedException {
+        // Register messages into the discovery protocol.
+        TestTcpDiscoverySpi discoSpi = 
(TestTcpDiscoverySpi)ctx.igniteConfiguration().getDiscoverySpi();
+
+        discoSpi.messageFactory(msgFactoryProvider);
+    }
+
+    /** */
+    private MessageSerializer<? extends Message> loadSerializer(Class<? 
extends Message> msgCls) {
+        try {
+            Class<?> serCls = U.gridClassLoader()
+                .loadClass(msgCls.getPackage().getName() + "." + 
msgCls.getSimpleName() + "Serializer");

Review Comment:
   ```suggestion
               Class<?> serCls = 
U.gridClassLoader().loadClass(msgCls.getPackage().getName() + "." + 
msgCls.getSimpleName() + "Serializer");
   ```



##########
modules/core/src/test/java/org/apache/ignite/spi/MessagesPluginProvider.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.spi;
+
+import java.util.function.Supplier;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.plugin.AbstractTestPluginProvider;
+import org.apache.ignite.plugin.ExtensionRegistry;
+import org.apache.ignite.plugin.PluginContext;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import 
org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider;
+import org.apache.ignite.plugin.extensions.communication.MessageSerializer;
+import org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi;
+
+/**
+ * Plugin provider for registering test messages in the communication and 
discovery protocols.
+ */
+public class MessagesPluginProvider extends AbstractTestPluginProvider {
+    /** */
+    private final MessageFactoryProvider msgFactoryProvider;
+
+    /** */
+    @SafeVarargs
+    public MessagesPluginProvider(Class<? extends Message>... msgs) {
+        msgFactoryProvider = f -> {
+            short directType = 10_000;
+
+            for (Class<? extends Message> msg : msgs) {
+                Supplier<Message> msgSupp = () -> {
+                    try {
+                        return U.newInstance(msg);
+                    }
+                    catch (IgniteCheckedException e) {
+                        throw new RuntimeException(e);
+                    }
+                };
+
+                f.register(directType, msgSupp, loadSerializer(msg));
+
+                directType++;
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public String name() {
+        return "Test messages plugin";
+    }
+
+    /** {@inheritDoc} */
+    @Override public void initExtensions(PluginContext ctx, ExtensionRegistry 
registry) {
+        // Register messages into the communication protocol.
+        registry.registerExtension(MessageFactoryProvider.class, 
msgFactoryProvider);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void start(PluginContext ctx) throws 
IgniteCheckedException {
+        // Register messages into the discovery protocol.
+        TestTcpDiscoverySpi discoSpi = 
(TestTcpDiscoverySpi)ctx.igniteConfiguration().getDiscoverySpi();
+
+        discoSpi.messageFactory(msgFactoryProvider);
+    }
+
+    /** */
+    private MessageSerializer<? extends Message> loadSerializer(Class<? 
extends Message> msgCls) {
+        try {
+            Class<?> serCls = U.gridClassLoader()
+                .loadClass(msgCls.getPackage().getName() + "." + 
msgCls.getSimpleName() + "Serializer");

Review Comment:
   It will be less than 140 symbols



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