timoninmaxim commented on a change in pull request #8206:
URL: https://github.com/apache/ignite/pull/8206#discussion_r497490324



##########
File path: 
modules/core/src/test/java/org/apache/ignite/internal/client/thin/ReliableChannelTest.java
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.client.thin;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.ignite.client.ClientAddressFinder;
+import org.apache.ignite.client.ClientAuthorizationException;
+import org.apache.ignite.client.ClientConnectionException;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Class test ReliableChannel channels re-initialization.
+ */
+public class ReliableChannelTest {
+    /** Mock factory for creating new channels. */
+    private final Function<ClientChannelConfiguration, ClientChannel> 
chFactory = cfg -> new TestClientChannel();
+
+    /** Checks that channel holders are not reinited for static address 
configuration. */
+    @Test
+    public void testChannelsNotReinitForStaticAddressConfiguration() {
+        ClientConfiguration ccfg = new ClientConfiguration()
+            .setAddresses("127.0.0.1:8000", "127.0.0.1:8001", 
"127.0.0.1:8002");
+
+        checkDoesNotReinit(ccfg);
+    }
+
+    /** Checks that channel holders are not reinited if address finder return 
the same list of addresses. */
+    @Test
+    public void testChannelsNotReinitForStableDynamicAddressConfiguration() {
+        ClientConfiguration ccfg = new ClientConfiguration()
+            .setAddressesFinder(new TestAddressFinder("127.0.0.1:8000", 
"127.0.0.1:8001", "127.0.0.1:8002"));

Review comment:
       fixed.

##########
File path: 
modules/core/src/test/java/org/apache/ignite/internal/client/thin/ReliableChannelTest.java
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.client.thin;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.ignite.client.ClientAddressFinder;
+import org.apache.ignite.client.ClientAuthorizationException;
+import org.apache.ignite.client.ClientConnectionException;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Class test ReliableChannel channels re-initialization.
+ */
+public class ReliableChannelTest {
+    /** Mock factory for creating new channels. */
+    private final Function<ClientChannelConfiguration, ClientChannel> 
chFactory = cfg -> new TestClientChannel();
+
+    /** Checks that channel holders are not reinited for static address 
configuration. */
+    @Test
+    public void testChannelsNotReinitForStaticAddressConfiguration() {
+        ClientConfiguration ccfg = new ClientConfiguration()
+            .setAddresses("127.0.0.1:8000", "127.0.0.1:8001", 
"127.0.0.1:8002");
+
+        checkDoesNotReinit(ccfg);
+    }
+
+    /** Checks that channel holders are not reinited if address finder return 
the same list of addresses. */
+    @Test
+    public void testChannelsNotReinitForStableDynamicAddressConfiguration() {
+        ClientConfiguration ccfg = new ClientConfiguration()
+            .setAddressesFinder(new TestAddressFinder("127.0.0.1:8000", 
"127.0.0.1:8001", "127.0.0.1:8002"));
+
+        checkDoesNotReinit(ccfg);
+    }
+
+    /** */
+    private void checkDoesNotReinit(ClientConfiguration ccfg) {
+        ReliableChannel rc = new ReliableChannel(chFactory, ccfg, null);
+        rc.initConnection();
+        List<ReliableChannel.ClientChannelHolder> originalChannels = 
rc.getChannelHolders();
+
+        // Imitate topology change.
+        rc.initChannelHolders(true);
+        List<ReliableChannel.ClientChannelHolder> newChannels = 
rc.getChannelHolders();
+
+        assertSame(originalChannels, newChannels);
+        IntStream.range(0, 3).forEach(i -> {
+            assertSame(originalChannels.get(i), newChannels.get(i));
+            assertFalse(originalChannels.get(i).isClosed());
+        });
+        assertEquals(3, newChannels.size());
+    }
+
+    /** Checks that node channels are persisted if channels are reinit with 
static address configuration. */
+    @Test
+    public void testNodeChannelsAreNotCleaned() {
+        ClientConfiguration ccfg = new ClientConfiguration()
+            .setAddresses("127.0.0.1:8000", "127.0.0.1:8001", 
"127.0.0.1:8002");
+
+        ReliableChannel rc = new ReliableChannel(chFactory, ccfg, null);
+        rc.initConnection();
+        // Trigger TestClientChannel creation.
+        rc.service(null, null, null);
+
+        assertEquals(1, rc.nodeChannels.size());
+
+        // Imitate topology change.
+        rc.initChannelHolders(true);
+
+        assertEquals(1, rc.nodeChannels.size());
+    }
+
+    /** Checks that channels are changed (add new, remove old) and close 
channels if reinitialization performed. */
+    @Test
+    public void testDynamicAddressReinitializedCorrectly() {
+        ClientConfiguration ccfg = new ClientConfiguration()
+            .setAddressesFinder(new TestAddressFinder("127.0.0.1:8000", 
"127.0.0.1:8003"));
+
+        ReliableChannel rc = new ReliableChannel(chFactory, ccfg, null);
+        rc.initConnection();
+
+        List<ReliableChannel.ClientChannelHolder> originChannels = 
Collections.unmodifiableList(rc.getChannelHolders());
+        // Imitate topology change.
+        rc.initChannelHolders(true);
+
+        List<ReliableChannel.ClientChannelHolder> closedChannels = 
originChannels.stream()
+            .filter(r -> r.isClosed())
+            .collect(Collectors.toList());
+
+        assertEquals(2, closedChannels.size());

Review comment:
       fixed.

##########
File path: 
modules/core/src/test/java/org/apache/ignite/internal/client/thin/ReliableChannelTest.java
##########
@@ -0,0 +1,229 @@
+/*
+ * 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.client.thin;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.ignite.client.ClientAddressFinder;
+import org.apache.ignite.client.ClientAuthorizationException;
+import org.apache.ignite.client.ClientConnectionException;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Class test ReliableChannel channels re-initialization.
+ */
+public class ReliableChannelTest {
+    /** Mock factory for creating new channels. */
+    private final Function<ClientChannelConfiguration, ClientChannel> 
chFactory = cfg -> new TestClientChannel();
+
+    /** Checks that channel holders are not reinited for static address 
configuration. */
+    @Test
+    public void testChannelsNotReinitForStaticAddressConfiguration() {
+        ClientConfiguration ccfg = new ClientConfiguration()
+            .setAddresses("127.0.0.1:8000", "127.0.0.1:8001", 
"127.0.0.1:8002");
+
+        checkDoesNotReinit(ccfg);
+    }
+
+    /** Checks that channel holders are not reinited if address finder return 
the same list of addresses. */
+    @Test
+    public void testChannelsNotReinitForStableDynamicAddressConfiguration() {
+        ClientConfiguration ccfg = new ClientConfiguration()
+            .setAddressesFinder(new TestAddressFinder("127.0.0.1:8000", 
"127.0.0.1:8001", "127.0.0.1:8002"));
+
+        checkDoesNotReinit(ccfg);
+    }
+
+    /** */
+    private void checkDoesNotReinit(ClientConfiguration ccfg) {
+        ReliableChannel rc = new ReliableChannel(chFactory, ccfg, null);
+        rc.initConnection();
+        List<ReliableChannel.ClientChannelHolder> originalChannels = 
rc.getChannelHolders();
+
+        // Imitate topology change.
+        rc.initChannelHolders(true);
+        List<ReliableChannel.ClientChannelHolder> newChannels = 
rc.getChannelHolders();
+
+        assertSame(originalChannels, newChannels);
+        IntStream.range(0, 3).forEach(i -> {

Review comment:
       fixed.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to