Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/core/src/test/config/io-manager-benchmark.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
<list/>
</property>

<property name="pluginProviders">
<list>
<bean class="org.apache.ignite.loadtests.communication.LoadTestsCommunicationPluginProvider"/>
</list>
</property>

<!-- Configure load balancing SPI in the way that do not require extra event subscription. -->
<property name="loadBalancingSpi">
<bean class="org.apache.ignite.spi.loadbalancing.roundrobin.RoundRobinLoadBalancingSpi">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@

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;

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.
Expand All @@ -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();

Expand All @@ -64,7 +68,7 @@ public void testSendMessage() throws Exception {
try {
startGridsMultiThreaded(2);

doSend(new TestValidByteIdMessage());
doSend(new GridCommunicationSendTestMessage());
}
finally {
stopAllGrids();
Expand All @@ -79,7 +83,7 @@ public void testSendMessageOverByteId() throws Exception {
try {
startGridsMultiThreaded(2);

doSend(new TestOverByteIdMessage());
doSend(new GridCommunicationSendOverByteIdTestMessage());
}
finally {
stopAllGrids();
Expand All @@ -94,7 +98,7 @@ public void testSendMessageWithBuffer() throws Exception {
try {
startGridsMultiThreaded(2);

doSend(new TestValidByteIdMessage());
doSend(new GridCommunicationSendTestMessage());
}
finally {
stopAllGrids();
Expand Down Expand Up @@ -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());
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public GridIoManagerSelfTest() throws IgniteCheckedException {
public void testSendIfOneOfNodesIsLocalAndTopicIsEnum() throws Exception {
GridTestUtils.assertThrows(log, new Callable<Object>() {
@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;
Expand Down Expand Up @@ -221,12 +222,4 @@ private static class IsEqualCollection implements ArgumentMatcher<Collection<? e
return CollectionUtils.isEqualCollection(expCol, colToCheck);
}
}

/** */
private static class TestMessage implements Message {
/** {@inheritDoc} */
@Override public short directType() {
return 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import org.apache.ignite.plugin.extensions.communication.Message;

/** Test message. */
public class TestMessage1 implements Message {
/** Test message 1 type. */
static final short TEST_MSG_1_TYPE = 1;
public class GridIoManagerSelfTestMessage implements Message {
/** */
public static final short DIRECT_TYPE = 0;

/** */
@Order(0)
int val;
byte marker;

/** {@inheritDoc} */
@Override public short directType() {
return TEST_MSG_1_TYPE;
return DIRECT_TYPE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,22 @@
import org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider;
import org.junit.Test;

import static org.apache.ignite.internal.managers.communication.TestMessage1.TEST_MSG_1_TYPE;
import static org.apache.ignite.internal.managers.communication.TestMessage2.TEST_MSG_2_TYPE;
import static org.apache.ignite.internal.managers.communication.TestMessage42.TEST_MSG_42_TYPE;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;

/**
* Tests for default implementation of {@link CoreMessagesProvider} interface.
*/
public class IgniteMessageFactoryImplTest {
/** Test message 1 type. */
private static final short TEST_MSG_1_TYPE = IgniteMessageFactoryImplTestMessage1.DIRECT_TYPE;

/** Test message 2 type. */
private static final short TEST_MSG_2_TYPE = IgniteMessageFactoryImplTestMessage2.DIRECT_TYPE;

/** Test message 42 type. */
private static final short TEST_MSG_42_TYPE = IgniteMessageFactoryImplTestMessage42.DIRECT_TYPE;

/** Unknown message type. */
private static final short UNKNOWN_MSG_TYPE = 0;

Expand All @@ -42,7 +48,7 @@ public class IgniteMessageFactoryImplTest {
*/
@Test(expected = IllegalStateException.class)
public void testReadOnly() {
MessageFactoryProvider[] factories = {new TestMessageFactoryPovider(), new TestMessageFactory()};
MessageFactoryProvider[] factories = {new TestMessageFactoryProvider(), new AdditionalTestMessageFactoryProvider()};

MessageFactory msgFactory = new IgniteMessageFactoryImpl(factories);

Expand All @@ -54,20 +60,20 @@ public void testReadOnly() {
*/
@Test
public void testCreate() {
MessageFactoryProvider[] factories = {new TestMessageFactoryPovider(), new TestMessageFactory()};
MessageFactoryProvider[] factories = {new TestMessageFactoryProvider(), new AdditionalTestMessageFactoryProvider()};

IgniteMessageFactoryImpl msgFactory = new IgniteMessageFactoryImpl(factories);

Message msg;

msg = msgFactory.create(TEST_MSG_1_TYPE);
assertTrue(msg instanceof TestMessage1);
assertTrue(msg instanceof IgniteMessageFactoryImplTestMessage1);

msg = msgFactory.create(TEST_MSG_2_TYPE);
assertTrue(msg instanceof TestMessage2);
assertTrue(msg instanceof IgniteMessageFactoryImplTestMessage2);

msg = msgFactory.create(TEST_MSG_42_TYPE);
assertTrue(msg instanceof TestMessage42);
assertTrue(msg instanceof IgniteMessageFactoryImplTestMessage42);

short[] directTypes = msgFactory.registeredDirectTypes();

Expand All @@ -79,7 +85,7 @@ public void testCreate() {
*/
@Test(expected = IgniteException.class)
public void testCreate_UnknownMessageType() {
MessageFactoryProvider[] factories = {new TestMessageFactoryPovider(), new TestMessageFactory()};
MessageFactoryProvider[] factories = {new TestMessageFactoryProvider(), new AdditionalTestMessageFactoryProvider()};

MessageFactory msgFactory = new IgniteMessageFactoryImpl(factories);

Expand All @@ -93,9 +99,9 @@ public void testCreate_UnknownMessageType() {
@SuppressWarnings("ResultOfObjectAllocationIgnored")
public void testRegisterTheSameType() {
MessageFactoryProvider[] factories = {
new TestMessageFactoryPovider(),
new TestMessageFactory(),
new TestMessageFactoryPoviderWithTheSameDirectType()
new TestMessageFactoryProvider(),
new AdditionalTestMessageFactoryProvider(),
new TestMessageFactoryProviderWithTheSameDirectType()
};

new IgniteMessageFactoryImpl(factories);
Expand All @@ -104,31 +110,35 @@ public void testRegisterTheSameType() {
/**
* {@link MessageFactoryProvider} implementation.
*/
private static class TestMessageFactoryPovider implements MessageFactoryProvider {
private static class TestMessageFactoryProvider implements MessageFactoryProvider {
/** {@inheritDoc} */
@Override public void registerAll(MessageFactory factory) {
factory.register(TEST_MSG_1_TYPE, TestMessage1::new, new TestMessage1Serializer());
factory.register(TEST_MSG_42_TYPE, TestMessage42::new, new TestMessage42Serializer());
factory.register(TEST_MSG_1_TYPE, IgniteMessageFactoryImplTestMessage1::new,
new IgniteMessageFactoryImplTestMessage1Serializer());
factory.register(TEST_MSG_42_TYPE, IgniteMessageFactoryImplTestMessage42::new,
new IgniteMessageFactoryImplTestMessage42Serializer());
}
}

/**
* {@link MessageFactoryProvider} implementation with message direct type which is already registered.
*/
private static class TestMessageFactoryPoviderWithTheSameDirectType implements MessageFactoryProvider {
private static class TestMessageFactoryProviderWithTheSameDirectType implements MessageFactoryProvider {
/** {@inheritDoc} */
@Override public void registerAll(MessageFactory factory) {
factory.register(TEST_MSG_1_TYPE, TestMessage1::new, new TestMessage1Serializer());
factory.register(TEST_MSG_1_TYPE, IgniteMessageFactoryImplTestMessage1::new,
new IgniteMessageFactoryImplTestMessage1Serializer());
}
}

/**
* {@link MessageFactoryProvider} implementation whish still uses creation with switch-case.
* Additional {@link MessageFactoryProvider} implementation.
*/
private static class TestMessageFactory implements MessageFactoryProvider {
private static class AdditionalTestMessageFactoryProvider implements MessageFactoryProvider {
/** {@inheritDoc} */
@Override public void registerAll(MessageFactory factory) {
factory.register(TEST_MSG_2_TYPE, TestMessage2::new, new TestMessage2Serializer());
factory.register(TEST_MSG_2_TYPE, IgniteMessageFactoryImplTestMessage2::new,
new IgniteMessageFactoryImplTestMessage2Serializer());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import org.apache.ignite.plugin.extensions.communication.Message;

/** Test message. */
public class TestMessage2 implements Message {
/** Test message 2 type. */
static final short TEST_MSG_2_TYPE = 2;
public class IgniteMessageFactoryImplTestMessage1 implements Message {
/** */
public static final short DIRECT_TYPE = 1;

/** */
@Order(0)
int val;
byte marker;

/** {@inheritDoc} */
@Override public short directType() {
return TEST_MSG_2_TYPE;
return DIRECT_TYPE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import org.apache.ignite.plugin.extensions.communication.Message;

/** Test message. */
public class TestMessage42 implements Message {
/** Test message 42 type. */
static final short TEST_MSG_42_TYPE = 42;
public class IgniteMessageFactoryImplTestMessage2 implements Message {
/** */
public static final short DIRECT_TYPE = 2;

/** */
@Order(0)
int val;
byte marker;

/** {@inheritDoc} */
@Override public short directType() {
return TEST_MSG_42_TYPE;
return DIRECT_TYPE;
}
}
Loading