diff --git a/modules/core/src/test/config/io-manager-benchmark.xml b/modules/core/src/test/config/io-manager-benchmark.xml index f04aaa987ea80..5f3bd89e16cc9 100644 --- a/modules/core/src/test/config/io-manager-benchmark.xml +++ b/modules/core/src/test/config/io-manager-benchmark.xml @@ -34,6 +34,12 @@ + + + + + + diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendMessageSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendMessageSelfTest.java index 90d9027ad7b67..a06cca4c0705f 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendMessageSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendMessageSelfTest.java @@ -17,15 +17,12 @@ package org.apache.ignite.internal.managers.communication; +import java.util.Map; import java.util.UUID; import java.util.concurrent.CountDownLatch; import org.apache.ignite.configuration.IgniteConfiguration; -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.MessageFactory; -import org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider; +import org.apache.ignite.spi.MessagesPluginProvider; import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import org.junit.Test; @@ -33,8 +30,6 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.NANOSECONDS; import static java.util.concurrent.TimeUnit.SECONDS; -import static org.apache.ignite.internal.managers.communication.TestOverByteIdMessage.DIRECT_TYPE_OVER_BYTE; -import static org.apache.ignite.internal.managers.communication.TestValidByteIdMessage.DIRECT_TYPE; /** * Send message test. @@ -43,11 +38,20 @@ public class GridCommunicationSendMessageSelfTest extends GridCommonAbstractTest /** Sample count. */ private static final int SAMPLE_CNT = 1; + /** */ + private static final short DIRECT_TYPE = -127; + + /** */ + private static final short DIRECT_TYPE_OVER_BYTE = 1000; + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration c = super.getConfiguration(igniteInstanceName); - c.setPluginProviders(new TestPluginProvider()); + c.setPluginProviders(new MessagesPluginProvider(Map.of( + DIRECT_TYPE, GridCommunicationSendTestMessage.class, + DIRECT_TYPE_OVER_BYTE, GridCommunicationSendOverByteIdTestMessage.class + ))); TcpCommunicationSpi commSpi = new TcpCommunicationSpi(); @@ -64,7 +68,7 @@ public void testSendMessage() throws Exception { try { startGridsMultiThreaded(2); - doSend(new TestValidByteIdMessage()); + doSend(new GridCommunicationSendTestMessage()); } finally { stopAllGrids(); @@ -79,7 +83,7 @@ public void testSendMessageOverByteId() throws Exception { try { startGridsMultiThreaded(2); - doSend(new TestOverByteIdMessage()); + doSend(new GridCommunicationSendOverByteIdTestMessage()); } finally { stopAllGrids(); @@ -94,7 +98,7 @@ public void testSendMessageWithBuffer() throws Exception { try { startGridsMultiThreaded(2); - doSend(new TestValidByteIdMessage()); + doSend(new GridCommunicationSendTestMessage()); } finally { stopAllGrids(); @@ -139,22 +143,4 @@ private void doSend(Message msg) throws Exception { info(">>> send() time (ms): " + MILLISECONDS.convert(time, NANOSECONDS)); info(">>>"); } - - /** */ - public static class TestPluginProvider extends AbstractTestPluginProvider { - /** {@inheritDoc} */ - @Override public String name() { - return "TEST_PLUGIN"; - } - - /** {@inheritDoc} */ - @Override public void initExtensions(PluginContext ctx, ExtensionRegistry registry) { - registry.registerExtension(MessageFactoryProvider.class, new MessageFactoryProvider() { - @Override public void registerAll(MessageFactory factory) { - factory.register(DIRECT_TYPE, TestValidByteIdMessage::new, new TestValidByteIdMessageSerializer()); - factory.register(DIRECT_TYPE_OVER_BYTE, TestOverByteIdMessage::new, new TestOverByteIdMessageSerializer()); - } - }); - } - } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendOverByteIdTestMessage.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendOverByteIdTestMessage.java new file mode 100644 index 0000000000000..07df2655c43f4 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendOverByteIdTestMessage.java @@ -0,0 +1,28 @@ +/* + * 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.managers.communication; + +import org.apache.ignite.internal.Order; +import org.apache.ignite.plugin.extensions.communication.Message; + +/** Test message. */ +public class GridCommunicationSendOverByteIdTestMessage implements Message { + /** */ + @Order(0) + byte marker; +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendTestMessage.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendTestMessage.java new file mode 100644 index 0000000000000..09a360ea6d455 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendTestMessage.java @@ -0,0 +1,28 @@ +/* + * 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.managers.communication; + +import org.apache.ignite.internal.Order; +import org.apache.ignite.plugin.extensions.communication.Message; + +/** Test message. */ +public class GridCommunicationSendTestMessage implements Message { + /** */ + @Order(0) + byte marker; +} diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridIoManagerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridIoManagerSelfTest.java index 45c72def55846..742223eb68ec9 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridIoManagerSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridIoManagerSelfTest.java @@ -90,7 +90,8 @@ public GridIoManagerSelfTest() throws IgniteCheckedException { public void testSendIfOneOfNodesIsLocalAndTopicIsEnum() throws Exception { GridTestUtils.assertThrows(log, new Callable() { @Override public Object call() throws Exception { - new GridIoManager(ctx).sendToGridTopic(F.asList(locNode, rmtNode), GridTopic.TOPIC_CACHE, new TestMessage(), + new GridIoManager(ctx).sendToGridTopic(F.asList(locNode, rmtNode), GridTopic.TOPIC_CACHE, + new GridIoManagerSelfTestMessage(), GridIoPolicy.P2P_POOL); return null; @@ -221,12 +222,4 @@ private static class IsEqualCollection implements ArgumentMatcher)this::startGrid, IgniteCheckedException.class, "Message factory is already registered for direct type: " + DIRECT_TYPE); } - - /** */ - public static class TestPluginProvider extends AbstractTestPluginProvider { - /** {@inheritDoc} */ - @Override public String name() { - return "TEST_PLUGIN"; - } - - /** {@inheritDoc} */ - @Override public void initExtensions(PluginContext ctx, ExtensionRegistry registry) { - registry.registerExtension(MessageFactoryProvider.class, new MessageFactoryProvider() { - @Override public void registerAll(MessageFactory factory) { - factory.register(DIRECT_TYPE, DuplicateDirectTypeIdMessage::new, new DuplicateDirectTypeIdMessageSerializer()); - } - }); - } - } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/DuplicateDirectTypeIdMessage.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/MessageDirectTypeIdConflictTestMessage.java similarity index 81% rename from modules/core/src/test/java/org/apache/ignite/internal/managers/communication/DuplicateDirectTypeIdMessage.java rename to modules/core/src/test/java/org/apache/ignite/internal/managers/communication/MessageDirectTypeIdConflictTestMessage.java index d293affedcc3b..5125c6efe2401 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/DuplicateDirectTypeIdMessage.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/MessageDirectTypeIdConflictTestMessage.java @@ -22,13 +22,13 @@ import org.apache.ignite.plugin.extensions.communication.Message; /** Test message with already registered direct type. */ -public class DuplicateDirectTypeIdMessage implements Message { - /** Message direct type. Message with this direct type will be registered by {@link CoreMessagesProvider} first. */ - static final short DIRECT_TYPE = CoreMessagesProvider.HANDSHAKE_MSG_TYPE; +public class MessageDirectTypeIdConflictTestMessage implements Message { + /** */ + public static final short DIRECT_TYPE = CoreMessagesProvider.HANDSHAKE_MSG_TYPE; /** */ @Order(0) - int val; + byte marker; /** {@inheritDoc} */ @Override public short directType() { diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/TestOverByteIdMessage.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/TestOverByteIdMessage.java deleted file mode 100644 index 99df96d8c5665..0000000000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/TestOverByteIdMessage.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.managers.communication; - -import org.apache.ignite.internal.Order; -import org.apache.ignite.plugin.extensions.communication.Message; - -/** Test message with over byte direct type. */ -public class TestOverByteIdMessage implements Message { - /** Direct type. */ - static final short DIRECT_TYPE_OVER_BYTE = 1000; - - /** */ - @Order(0) - int val; - - /** {@inheritDoc} */ - @Override public short directType() { - return DIRECT_TYPE_OVER_BYTE; - } -} diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridIoManagerBenchmark0.java b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridIoManagerBenchmark0.java index bdf263afe52ec..d8ebf16428e74 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridIoManagerBenchmark0.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridIoManagerBenchmark0.java @@ -40,6 +40,7 @@ import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; import org.apache.ignite.plugin.extensions.communication.Message; +import org.apache.ignite.spi.MessagesPluginProvider; import org.apache.ignite.spi.communication.CommunicationSpi; import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; import org.apache.ignite.testframework.GridTestUtils; @@ -74,6 +75,7 @@ public class GridIoManagerBenchmark0 extends GridCommonAbstractTest { IgniteConfiguration c = super.getConfiguration(igniteInstanceName); c.setCommunicationSpi(getCommunication()); + c.setPluginProviders(new MessagesPluginProvider(GridTestMessage.class)); return c; } diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTestMessage.java b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTestMessage.java index b129cd0043f5c..e7ce17cc72023 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTestMessage.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/GridTestMessage.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; +import org.apache.ignite.internal.Order; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; import org.apache.ignite.plugin.extensions.communication.Message; @@ -30,19 +31,24 @@ */ class GridTestMessage implements Message, Externalizable { /** */ - private IgniteUuid id; + @Order(0) + IgniteUuid id; /** */ - private long field1; + @Order(1) + long field1; /** */ - private long field2; + @Order(2) + long field2; /** */ - private String str; + @Order(3) + String str; /** */ - private byte[] bytes; + @Order(4) + byte[] bytes; /** * @param id Message ID. diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/communication/LoadTestsCommunicationPluginProvider.java b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/LoadTestsCommunicationPluginProvider.java new file mode 100644 index 0000000000000..6aa8bf38b3daa --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/communication/LoadTestsCommunicationPluginProvider.java @@ -0,0 +1,33 @@ +/* + * 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.loadtests.communication; + +import org.apache.ignite.spi.MessagesPluginProvider; + +/** Registers communication messages used by load tests. */ +public class LoadTestsCommunicationPluginProvider extends MessagesPluginProvider { + /** */ + public LoadTestsCommunicationPluginProvider() { + super(GridTestMessage.class); + } + + /** {@inheritDoc} */ + @Override public String name() { + return "LOAD_TESTS_COMMUNICATION_PLUGIN"; + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/spi/MessagesPluginProvider.java b/modules/core/src/test/java/org/apache/ignite/spi/MessagesPluginProvider.java index 865d9ba164444..391cc198d297d 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/MessagesPluginProvider.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/MessagesPluginProvider.java @@ -17,6 +17,8 @@ package org.apache.ignite.spi; +import java.util.HashMap; +import java.util.Map; import java.util.function.Supplier; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.CoreMessagesProvider; @@ -40,22 +42,25 @@ public class MessagesPluginProvider extends AbstractTestPluginProvider { /** */ @SafeVarargs public MessagesPluginProvider(Class... msgs) { + this(registrations(msgs)); + } + + /** */ + public MessagesPluginProvider(Map> msgs) { msgFactoryProvider = f -> { - short directType = CoreMessagesProvider.MAX_MESSAGE_ID + 1; + for (Map.Entry> msg : msgs.entrySet()) { + Class msgCls = msg.getValue(); - for (Class msg : msgs) { Supplier msgSupp = () -> { try { - return U.newInstance(msg); + return U.newInstance(msgCls); } catch (IgniteCheckedException e) { throw new RuntimeException(e); } }; - f.register(directType, msgSupp, loadSerializer(msg, null, null)); - - directType++; + f.register(msg.getKey(), msgSupp, loadSerializer(msgCls, null, null)); } }; } @@ -78,4 +83,20 @@ public MessagesPluginProvider(Class... msgs) { discoSpi.messageFactory(msgFactoryProvider, ctx.igniteConfiguration()); } + + /** + * @param msgs Message classes. + * @return Message registrations with generated direct types. + */ + @SafeVarargs + private static Map> registrations(Class... msgs) { + Map> regs = new HashMap<>(); + + short directType = CoreMessagesProvider.MAX_MESSAGE_ID + 1; + + for (Class msg : msgs) + regs.put(directType++, msg); + + return regs; + } }