|
| 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.compatibility.spi.discovery; |
| 19 | + |
| 20 | +import java.util.Collection; |
| 21 | +import java.util.List; |
| 22 | +import org.apache.ignite.compatibility.IgniteReleasedVersion; |
| 23 | +import org.apache.ignite.compatibility.testframework.junits.IgniteCompatibilityAbstractTest; |
| 24 | +import org.apache.ignite.configuration.IgniteConfiguration; |
| 25 | +import org.apache.ignite.lang.IgniteInClosure; |
| 26 | +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; |
| 27 | +import org.apache.ignite.testframework.GridTestUtils; |
| 28 | +import org.apache.ignite.testframework.ListeningTestLogger; |
| 29 | +import org.apache.ignite.testframework.LogListener; |
| 30 | +import org.junit.Test; |
| 31 | +import org.junit.runner.RunWith; |
| 32 | +import org.junit.runners.Parameterized; |
| 33 | + |
| 34 | +/** */ |
| 35 | +@RunWith(Parameterized.class) |
| 36 | +public class TcpDiscoveryDifferentClusterVersionsTest extends IgniteCompatibilityAbstractTest { |
| 37 | + /** */ |
| 38 | + private static final String INCOMPATIBLE_NODE_MSG = "is this an incompatible Ignite node?"; |
| 39 | + |
| 40 | + /** */ |
| 41 | + private static final IgniteReleasedVersion OLD_VERSION = IgniteReleasedVersion.VER_2_17_0; |
| 42 | + |
| 43 | + /** */ |
| 44 | + private ListeningTestLogger listeningLog; |
| 45 | + |
| 46 | + /** */ |
| 47 | + @Parameterized.Parameter |
| 48 | + public boolean client; |
| 49 | + |
| 50 | + /** */ |
| 51 | + @Parameterized.Parameters(name = "client={0}") |
| 52 | + public static Collection<?> client() { |
| 53 | + return List.of(true, false); |
| 54 | + } |
| 55 | + |
| 56 | + /** {@inheritDoc} */ |
| 57 | + @Override protected void afterTest() throws Exception { |
| 58 | + super.afterTest(); |
| 59 | + |
| 60 | + stopAllGrids(); |
| 61 | + } |
| 62 | + |
| 63 | + /** {@inheritDoc} */ |
| 64 | + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { |
| 65 | + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); |
| 66 | + |
| 67 | + if (listeningLog != null) |
| 68 | + cfg.setGridLogger(listeningLog); |
| 69 | + |
| 70 | + return cfg; |
| 71 | + } |
| 72 | + |
| 73 | + /** Tests that connection from node of old version is properly refused. */ |
| 74 | + @Test |
| 75 | + public void testOldNodeRejected() throws Exception { |
| 76 | + setLoggerDebugLevel(); |
| 77 | + |
| 78 | + listeningLog = new ListeningTestLogger(log); |
| 79 | + |
| 80 | + LogListener logListener = LogListener.matches(INCOMPATIBLE_NODE_MSG).build(); |
| 81 | + |
| 82 | + listeningLog.registerListener(logListener); |
| 83 | + |
| 84 | + startGrid(0); |
| 85 | + |
| 86 | + GridTestUtils.assertThrows( |
| 87 | + log, |
| 88 | + () -> startGrid("old-node", OLD_VERSION.toString(), new ConfigurationClosure()), |
| 89 | + AssertionError.class, |
| 90 | + null |
| 91 | + ); |
| 92 | + |
| 93 | + assertTrue("Expected log about unknown connection.", logListener.check(getTestTimeout())); |
| 94 | + } |
| 95 | + |
| 96 | + /** Setup node closure. */ |
| 97 | + private class ConfigurationClosure implements IgniteInClosure<IgniteConfiguration> { |
| 98 | + /** {@inheritDoc} */ |
| 99 | + @Override public void apply(IgniteConfiguration cfg) { |
| 100 | + cfg.setClientMode(client); |
| 101 | + |
| 102 | + cfg.setLocalHost("127.0.0.1"); |
| 103 | + TcpDiscoverySpi disco = new TcpDiscoverySpi(); |
| 104 | + disco.setIpFinder(LOCAL_IP_FINDER); |
| 105 | + |
| 106 | + cfg.setDiscoverySpi(disco); |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments