Skip to content

Commit a8605bd

Browse files
authored
IGNITE-28440 Use message serializer for test discovery messages (#12974)
1 parent 9859f64 commit a8605bd

18 files changed

+363
-216
lines changed

modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/Message.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ default boolean readFrom(ByteBuffer buf, MessageReader reader) {
5858
throw new UnsupportedOperationException();
5959
}
6060

61-
/**
62-
* Gets message type.
63-
*
64-
* @return Message type.
65-
*/
6661
/**
6762
* Gets message type.
6863
*
@@ -72,9 +67,8 @@ default short directType() {
7267
var clazz = getClass();
7368
Short type = REGISTRATIONS.get(clazz);
7469

75-
if (type == null) {
70+
if (type == null)
7671
throw new IgniteException("No registration for class " + clazz.getSimpleName());
77-
}
7872

7973
return type;
8074
}
@@ -91,8 +85,7 @@ default void registerAsDirectType(short directType) {
9185
var clazz = getClass();
9286
var type = REGISTRATIONS.putIfAbsent(clazz, directType);
9387

94-
if ((type != null) && (type != directType)) {
88+
if ((type != null) && (type != directType))
9589
throw new IgniteException(clazz.getSimpleName() + " is already registered for direct type " + type);
96-
}
9790
}
9891
}

modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/messages/HandshakeWaitMessage.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@ public class HandshakeWaitMessage implements Message {
3131
@Override public String toString() {
3232
return S.toString(HandshakeWaitMessage.class, this);
3333
}
34-
3534
}

modules/core/src/test/java/org/apache/ignite/internal/metric/OutboundIoMessageQueueSizeTest.java

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,17 @@
2323
import org.apache.ignite.cache.query.ContinuousQuery;
2424
import org.apache.ignite.configuration.IgniteConfiguration;
2525
import org.apache.ignite.internal.IgniteEx;
26-
import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
2726
import org.apache.ignite.internal.processors.metric.impl.MaxValueMetric;
2827
import org.apache.ignite.internal.util.typedef.internal.U;
29-
import org.apache.ignite.lang.IgniteUuid;
28+
import org.apache.ignite.spi.MessagesPluginProvider;
3029
import org.apache.ignite.spi.discovery.tcp.BlockTcpDiscoverySpi;
30+
import org.apache.ignite.spi.discovery.tcp.DummyCustomDiscoveryMessage;
3131
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
3232
import org.apache.ignite.testframework.GridTestUtils;
3333
import org.apache.ignite.testframework.ListeningTestLogger;
3434
import org.apache.ignite.testframework.LogListener;
3535
import org.apache.ignite.testframework.junits.WithSystemProperty;
3636
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
37-
import org.jetbrains.annotations.Nullable;
3837
import org.junit.Test;
3938

4039
import static org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.DISCO_METRICS;
@@ -58,6 +57,8 @@ public class OutboundIoMessageQueueSizeTest extends GridCommonAbstractTest {
5857
cfg.setDiscoverySpi(new BlockTcpDiscoverySpi().setIpFinder(((TcpDiscoverySpi)cfg.getDiscoverySpi()).getIpFinder()));
5958
cfg.setGridLogger(log);
6059

60+
cfg.setPluginProviders(new MessagesPluginProvider(DummyCustomDiscoveryMessage.class));
61+
6162
return cfg;
6263
}
6364

@@ -124,7 +125,7 @@ public void testDiscoveryMsgQueue() throws Exception {
124125

125126
metric.reset(); // Reset value accumulated before discovery SPI startup.
126127

127-
srv0.context().discovery().sendCustomEvent(new DummyCustomDiscoveryMessage(IgniteUuid.randomUuid()));
128+
srv0.context().discovery().sendCustomEvent(new DummyCustomDiscoveryMessage());
128129

129130
// Assume our message can be added to queue concurrently with other messages
130131
// (for example, with metrics update message).
@@ -142,35 +143,12 @@ public void testDiscoveryMsgQueue() throws Exception {
142143

143144
try {
144145
for (int i = 0; i <= MSG_LIMIT; i++)
145-
srv0.context().discovery().sendCustomEvent(new DummyCustomDiscoveryMessage(IgniteUuid.randomUuid()));
146+
srv0.context().discovery().sendCustomEvent(new DummyCustomDiscoveryMessage());
146147

147148
assertTrue(metric.value() >= MSG_LIMIT);
148149
}
149150
finally {
150151
latch.countDown();
151152
}
152153
}
153-
154-
/** */
155-
private static class DummyCustomDiscoveryMessage implements DiscoveryCustomMessage {
156-
/** */
157-
private final IgniteUuid id;
158-
159-
/**
160-
* @param id Message id.
161-
*/
162-
DummyCustomDiscoveryMessage(IgniteUuid id) {
163-
this.id = id;
164-
}
165-
166-
/** {@inheritDoc} */
167-
@Override public IgniteUuid id() {
168-
return id;
169-
}
170-
171-
/** {@inheritDoc} */
172-
@Nullable @Override public DiscoveryCustomMessage ackMessage() {
173-
return null;
174-
}
175-
}
176154
}

modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/AbstractSnapshotSelfTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
import org.apache.ignite.lang.IgnitePredicate;
100100
import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage;
101101
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
102+
import org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi;
102103
import org.apache.ignite.spi.encryption.keystore.KeystoreEncryptionSpi;
103104
import org.apache.ignite.testframework.GridTestUtils;
104105
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
@@ -911,7 +912,7 @@ protected static BlockingCustomMessageDiscoverySpi discoSpi(IgniteEx ignite) {
911912
}
912913

913914
/** */
914-
protected static class BlockingCustomMessageDiscoverySpi extends TcpDiscoverySpi {
915+
protected static class BlockingCustomMessageDiscoverySpi extends TestTcpDiscoverySpi {
915916
/** List of messages which have been blocked. */
916917
private final List<DiscoveryCustomMessage> blocked = new CopyOnWriteArrayList<>();
917918

modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotHandlerTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
import org.apache.ignite.internal.IgniteEx;
3737
import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
3838
import org.apache.ignite.internal.processors.cache.persistence.filename.SnapshotFileTree;
39-
import org.apache.ignite.internal.util.distributed.MessagesPluginProvider;
40-
import org.apache.ignite.internal.util.distributed.MessagesPluginProvider.MessagesInjectedTcpDiscoverySpi;
39+
import org.apache.ignite.internal.util.distributed.TestIntegerMessage;
4140
import org.apache.ignite.internal.util.distributed.TestUuidMessage;
4241
import org.apache.ignite.internal.util.typedef.G;
4342
import org.apache.ignite.internal.util.typedef.internal.U;
@@ -48,6 +47,7 @@
4847
import org.apache.ignite.plugin.PluginContext;
4948
import org.apache.ignite.plugin.PluginProvider;
5049
import org.apache.ignite.plugin.extensions.communication.Message;
50+
import org.apache.ignite.spi.MessagesPluginProvider;
5151
import org.apache.ignite.testframework.GridTestUtils;
5252
import org.jetbrains.annotations.Nullable;
5353
import org.junit.Test;
@@ -76,8 +76,10 @@ public class IgniteClusterSnapshotHandlerTest extends IgniteClusterSnapshotResto
7676
/** {@inheritDoc} */
7777
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
7878
return super.getConfiguration(igniteInstanceName)
79-
.setPluginProviders(pluginProvider, new MessagesPluginProvider())
80-
.setDiscoverySpi(new MessagesInjectedTcpDiscoverySpi());
79+
.setPluginProviders(
80+
pluginProvider,
81+
new MessagesPluginProvider(TestIntegerMessage.class, TestUuidMessage.class)
82+
);
8183
}
8284

8385
/** {@inheritDoc} */

modules/core/src/test/java/org/apache/ignite/internal/processors/security/NodeSecurityContextPropagationTest.java

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@
3434
import org.apache.ignite.failure.StopNodeOrHaltFailureHandler;
3535
import org.apache.ignite.internal.IgniteEx;
3636
import org.apache.ignite.internal.events.DiscoveryCustomEvent;
37-
import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
3837
import org.apache.ignite.internal.managers.discovery.SecurityAwareCustomMessageWrapper;
3938
import org.apache.ignite.internal.util.typedef.internal.U;
40-
import org.apache.ignite.lang.IgniteUuid;
39+
import org.apache.ignite.spi.MessagesPluginProvider;
4140
import org.apache.ignite.spi.discovery.DiscoverySpi;
4241
import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage;
4342
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
@@ -87,6 +86,8 @@ public class NodeSecurityContextPropagationTest extends GridCommonAbstractTest {
8786
.setIpFinder(new TcpDiscoveryVmIpFinder()
8887
.setAddresses(Collections.singleton("127.0.0.1:47500")));
8988

89+
cfg.setPluginProviders(new MessagesPluginProvider(TestDiscoveryMessage.class, TestDiscoveryAcknowledgeMessage.class));
90+
9091
return cfg;
9192
}
9293

@@ -218,30 +219,6 @@ private Object discoveryRingMessageWorker(IgniteEx ignite) {
218219
return U.field(impl, "msgWorker");
219220
}
220221

221-
/** */
222-
public static class TestDiscoveryMessage extends AbstractTestDiscoveryMessage {
223-
/** {@inheritDoc} */
224-
@Override public @Nullable DiscoveryCustomMessage ackMessage() {
225-
return new TestDiscoveryAcknowledgeMessage();
226-
}
227-
}
228-
229-
/** */
230-
public static class TestDiscoveryAcknowledgeMessage extends AbstractTestDiscoveryMessage { }
231-
232-
/** */
233-
public abstract static class AbstractTestDiscoveryMessage implements DiscoveryCustomMessage {
234-
/** {@inheritDoc} */
235-
@Override public IgniteUuid id() {
236-
return IgniteUuid.randomUuid();
237-
}
238-
239-
/** {@inheritDoc} */
240-
@Override public @Nullable DiscoveryCustomMessage ackMessage() {
241-
return null;
242-
}
243-
}
244-
245222
/** */
246223
public static class BlockingDequeWrapper<T> implements BlockingDeque<T> {
247224
/** */
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.processors.security;
19+
20+
import org.apache.ignite.internal.Order;
21+
import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
22+
import org.apache.ignite.lang.IgniteUuid;
23+
import org.apache.ignite.plugin.extensions.communication.Message;
24+
import org.apache.ignite.plugin.extensions.communication.MessageFactory;
25+
import org.jetbrains.annotations.Nullable;
26+
27+
/** */
28+
public class TestDiscoveryAcknowledgeMessage implements DiscoveryCustomMessage, Message {
29+
/** */
30+
@Order(0)
31+
IgniteUuid id = IgniteUuid.randomUuid();
32+
33+
/** Constructor for {@link MessageFactory}. */
34+
public TestDiscoveryAcknowledgeMessage() {
35+
// No-op.
36+
}
37+
38+
/** {@inheritDoc} */
39+
@Override public IgniteUuid id() {
40+
return id;
41+
}
42+
43+
/** {@inheritDoc} */
44+
@Override public @Nullable DiscoveryCustomMessage ackMessage() {
45+
return null;
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.processors.security;
19+
20+
import org.apache.ignite.internal.Order;
21+
import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
22+
import org.apache.ignite.lang.IgniteUuid;
23+
import org.apache.ignite.plugin.extensions.communication.Message;
24+
import org.apache.ignite.plugin.extensions.communication.MessageFactory;
25+
import org.jetbrains.annotations.Nullable;
26+
27+
/** */
28+
public class TestDiscoveryMessage implements DiscoveryCustomMessage, Message {
29+
/** */
30+
@Order(0)
31+
IgniteUuid id = IgniteUuid.randomUuid();
32+
33+
/** Constructor for {@link MessageFactory}. */
34+
public TestDiscoveryMessage() {
35+
// No-op.
36+
}
37+
38+
/** {@inheritDoc} */
39+
@Override public IgniteUuid id() {
40+
return id;
41+
}
42+
43+
/** {@inheritDoc} */
44+
@Override public @Nullable DiscoveryCustomMessage ackMessage() {
45+
return new TestDiscoveryAcknowledgeMessage();
46+
}
47+
}

modules/core/src/test/java/org/apache/ignite/internal/util/distributed/DistributedProcessClientAwaitTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
import org.apache.ignite.configuration.IgniteConfiguration;
2929
import org.apache.ignite.internal.GridKernalContext;
3030
import org.apache.ignite.internal.TestRecordingCommunicationSpi;
31-
import org.apache.ignite.internal.util.distributed.MessagesPluginProvider.MessagesInjectedTcpDiscoverySpi;
3231
import org.apache.ignite.internal.util.future.GridFinishedFuture;
3332
import org.apache.ignite.internal.util.typedef.internal.U;
3433
import org.apache.ignite.plugin.extensions.communication.Message;
34+
import org.apache.ignite.spi.MessagesPluginProvider;
3535
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
3636
import org.junit.Test;
3737

@@ -70,9 +70,7 @@ public class DistributedProcessClientAwaitTest extends GridCommonAbstractTest {
7070
IgniteConfiguration cfg = super.getConfiguration(instanceName);
7171

7272
cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());
73-
74-
cfg.setPluginProviders(new MessagesPluginProvider());
75-
cfg.setDiscoverySpi(new MessagesInjectedTcpDiscoverySpi());
73+
cfg.setPluginProviders(new MessagesPluginProvider(TestIntegerMessage.class, TestUuidMessage.class));
7674

7775
return cfg;
7876
}

modules/core/src/test/java/org/apache/ignite/internal/util/distributed/DistributedProcessCoordinatorLeftTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import org.apache.ignite.failure.FailureHandler;
2929
import org.apache.ignite.internal.IgniteEx;
3030
import org.apache.ignite.internal.IgniteInternalFuture;
31-
import org.apache.ignite.internal.util.distributed.MessagesPluginProvider.MessagesInjectedTcpDiscoverySpi;
3231
import org.apache.ignite.internal.util.typedef.G;
32+
import org.apache.ignite.spi.MessagesPluginProvider;
3333
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
3434
import org.junit.Test;
3535

@@ -86,8 +86,7 @@ public class DistributedProcessCoordinatorLeftTest extends GridCommonAbstractTes
8686
}
8787
});
8888

89-
cfg.setPluginProviders(new MessagesPluginProvider());
90-
cfg.setDiscoverySpi(new MessagesInjectedTcpDiscoverySpi());
89+
cfg.setPluginProviders(new MessagesPluginProvider(TestIntegerMessage.class, TestUuidMessage.class));
9190

9291
return cfg;
9392
}

0 commit comments

Comments
 (0)