This is an automated email from the ASF dual-hosted git repository.

ptupitsyn pushed a commit to branch ignite-16771
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/ignite-16771 by this push:
     new a86ea81bc wip ClientComputeTest - mock cluster service
a86ea81bc is described below

commit a86ea81bcaf8aeedba1e9bb19c488f4fbd8ac9bb
Author: Pavel Tupitsyn <ptupit...@apache.org>
AuthorDate: Thu Apr 14 18:28:44 2022 +0300

    wip ClientComputeTest - mock cluster service
---
 .../ignite/client/TestClientHandlerModule.java     | 14 +++++++-------
 .../java/org/apache/ignite/client/TestServer.java  | 22 +++++++++++++++++++---
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git 
a/modules/client/src/test/java/org/apache/ignite/client/TestClientHandlerModule.java
 
b/modules/client/src/test/java/org/apache/ignite/client/TestClientHandlerModule.java
index d4d2e662d..5c94e6882 100644
--- 
a/modules/client/src/test/java/org/apache/ignite/client/TestClientHandlerModule.java
+++ 
b/modules/client/src/test/java/org/apache/ignite/client/TestClientHandlerModule.java
@@ -17,7 +17,6 @@
 
 package org.apache.ignite.client;
 
-import static org.mockito.Answers.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 
 import io.netty.bootstrap.ServerBootstrap;
@@ -59,6 +58,9 @@ public class TestClientHandlerModule implements 
IgniteComponent {
     /** Connection drop condition. */
     private final Function<Integer, Boolean> shouldDropConnection;
 
+    /** Cluster service. */
+    private final ClusterService clusterService;
+
     /** Netty channel. */
     private volatile Channel channel;
 
@@ -67,17 +69,18 @@ public class TestClientHandlerModule implements 
IgniteComponent {
 
     /**
      * Constructor.
-     *
      * @param ignite               Ignite.
      * @param registry             Configuration registry.
      * @param bootstrapFactory     Bootstrap factory.
      * @param shouldDropConnection Connection drop condition.
+     * @param clusterService       Cluster service.
      */
     public TestClientHandlerModule(
             Ignite ignite,
             ConfigurationRegistry registry,
             NettyBootstrapFactory bootstrapFactory,
-            Function<Integer, Boolean> shouldDropConnection) {
+            Function<Integer, Boolean> shouldDropConnection,
+            ClusterService clusterService) {
         assert ignite != null;
         assert registry != null;
         assert bootstrapFactory != null;
@@ -86,6 +89,7 @@ public class TestClientHandlerModule implements 
IgniteComponent {
         this.registry = registry;
         this.bootstrapFactory = bootstrapFactory;
         this.shouldDropConnection = shouldDropConnection;
+        this.clusterService = clusterService;
     }
 
     /** {@inheritDoc} */
@@ -141,10 +145,6 @@ public class TestClientHandlerModule implements 
IgniteComponent {
 
         ServerBootstrap bootstrap = bootstrapFactory.createServerBootstrap();
 
-        ClusterService clusterService = mock(ClusterService.class, 
RETURNS_DEEP_STUBS);
-        
Mockito.when(clusterService.topologyService().localMember().id()).thenReturn("id");
-        
Mockito.when(clusterService.topologyService().localMember().name()).thenReturn("consistent-id");
-
         bootstrap.childHandler(new ChannelInitializer<>() {
                     @Override
                     protected void initChannel(Channel ch) {
diff --git 
a/modules/client/src/test/java/org/apache/ignite/client/TestServer.java 
b/modules/client/src/test/java/org/apache/ignite/client/TestServer.java
index 3cf50e8b2..ed7d407a4 100644
--- a/modules/client/src/test/java/org/apache/ignite/client/TestServer.java
+++ b/modules/client/src/test/java/org/apache/ignite/client/TestServer.java
@@ -19,6 +19,7 @@ package org.apache.ignite.client;
 
 import static 
org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL;
 import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.mock;
 
 import java.net.InetSocketAddress;
@@ -36,9 +37,13 @@ import 
org.apache.ignite.configuration.schemas.network.NetworkConfiguration;
 import org.apache.ignite.internal.configuration.ConfigurationRegistry;
 import 
org.apache.ignite.internal.configuration.storage.TestConfigurationStorage;
 import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.network.ClusterNode;
 import org.apache.ignite.network.ClusterService;
 import org.apache.ignite.network.NettyBootstrapFactory;
+import org.apache.ignite.network.NetworkAddress;
+import org.jetbrains.annotations.NotNull;
 import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
 
 /**
  * Test server.
@@ -101,12 +106,19 @@ public class TestServer implements AutoCloseable {
 
         bootstrapFactory.start();
 
+        if (nodeName == null) {
+            nodeName = "consistent-id";
+        }
+
         ClusterService clusterService = mock(ClusterService.class, 
RETURNS_DEEP_STUBS);
-        
Mockito.when(clusterService.topologyService().localMember().id()).thenReturn(nodeName
 == null ? "id" : nodeName + "-id");
-        
Mockito.when(clusterService.topologyService().localMember().name()).thenReturn(nodeName
 == null ? "consistent-id" : nodeName);
+        
Mockito.when(clusterService.topologyService().localMember().id()).thenReturn(nodeName
 + "-id");
+        
Mockito.when(clusterService.topologyService().localMember().name()).thenReturn(nodeName);
+        
Mockito.when(clusterService.topologyService().localMember()).thenReturn(getClusterNode(nodeName));
+        
Mockito.when(clusterService.topologyService().getByConsistentId(anyString())).thenAnswer(
+                i -> getClusterNode(i.getArgument(0, String.class)));
 
         module = shouldDropConnection != null
-                ? new TestClientHandlerModule(ignite, cfg, bootstrapFactory, 
shouldDropConnection)
+                ? new TestClientHandlerModule(ignite, cfg, bootstrapFactory, 
shouldDropConnection, clusterService)
                 : new ClientHandlerModule(
                         ((FakeIgnite) ignite).queryEngine(),
                         ignite.tables(),
@@ -140,4 +152,8 @@ public class TestServer implements AutoCloseable {
         bootstrapFactory.stop();
         cfg.stop();
     }
+
+    private ClusterNode getClusterNode(String name) {
+        return new ClusterNode(name+ "-id", name, new 
NetworkAddress("127.0.0.1", 8080));
+    }
 }

Reply via email to