You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ni...@apache.org on 2021/04/07 17:25:18 UTC

[ignite] branch ignite-ducktape updated: IGNITE-13970 Thin client compatibility test (#8968)

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

nizhikov pushed a commit to branch ignite-ducktape
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/ignite-ducktape by this push:
     new 26c40bd  IGNITE-13970 Thin client compatibility test (#8968)
26c40bd is described below

commit 26c40bda07bdd592a857a7112c92c72dc56edc9b
Author: eadha <58...@users.noreply.github.com>
AuthorDate: Wed Apr 7 20:24:48 2021 +0300

    IGNITE-13970 Thin client compatibility test (#8968)
    
    Co-authored-by: emvdovets <em...@sberbank.ru>
    Co-authored-by: Nikolay <ni...@apache.org>
---
 .../ThinClientSelfTestApplication.java             | 44 +++++++++++++++
 .../ducktest/utils/IgniteAwareApplication.java     |  4 ++
 .../utils/IgniteAwareApplicationService.java       | 21 +++++++-
 .../ignitetest/services/utils/ignite_aware.py      |  5 ++
 .../utils/ignite_configuration/__init__.py         |  2 +
 .../utils/ssl/client_connector_configuration.py    | 28 ++++++++++
 .../services/utils/templates/ignite.xml.j2         |  8 +++
 .../tests/ignitetest/tests/thin_client_test.py     | 63 ++++++++++++++++++++++
 8 files changed, 174 insertions(+), 1 deletion(-)

diff --git a/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/thin_client_test/ThinClientSelfTestApplication.java b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/thin_client_test/ThinClientSelfTestApplication.java
new file mode 100644
index 0000000..105e2eb
--- /dev/null
+++ b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/thin_client_test/ThinClientSelfTestApplication.java
@@ -0,0 +1,44 @@
+/*
+ * 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.ducktest.tests.thin_client_test;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.ignite.client.ClientCache;
+import org.apache.ignite.internal.ducktest.utils.IgniteAwareApplication;
+
+/**
+ * Thin client. Cache test: put, get, remove.
+ */
+public class ThinClientSelfTestApplication extends IgniteAwareApplication {
+    /** {@inheritDoc} */
+    @Override protected void run(JsonNode jsonNode) throws Exception {
+        markInitialized();
+
+        ClientCache<Integer, Integer> cache = client.getOrCreateCache("testCache");
+
+        cache.put(0, 0);
+
+        assert cache.get(0) == 0;
+
+        cache.remove(0);
+
+        client.destroyCache("testCache");
+
+        markFinished();
+    }
+}
diff --git a/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/utils/IgniteAwareApplication.java b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/utils/IgniteAwareApplication.java
index 3d65ab5..1c273e4 100644
--- a/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/utils/IgniteAwareApplication.java
+++ b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/utils/IgniteAwareApplication.java
@@ -21,6 +21,7 @@ import java.lang.management.ManagementFactory;
 import java.lang.management.ThreadInfo;
 import com.fasterxml.jackson.databind.JsonNode;
 import org.apache.ignite.Ignite;
+import org.apache.ignite.client.IgniteClient;
 import org.apache.ignite.cluster.ClusterState;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteInterruptedCheckedException;
@@ -67,6 +68,9 @@ public abstract class IgniteAwareApplication {
     /** Ignite. */
     protected Ignite ignite;
 
+    /** Client. */
+    protected IgniteClient client;
+
     /** Cfg path. */
     protected String cfgPath;
 
diff --git a/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/utils/IgniteAwareApplicationService.java b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/utils/IgniteAwareApplicationService.java
index 7e85180..3d0de0c 100644
--- a/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/utils/IgniteAwareApplicationService.java
+++ b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/utils/IgniteAwareApplicationService.java
@@ -18,10 +18,13 @@
 package org.apache.ignite.internal.ducktest.utils;
 
 import java.util.Base64;
+import java.util.Optional;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.Ignition;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.configuration.ClientConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgnitionEx;
 import org.apache.ignite.internal.processors.resource.GridSpringResourceContext;
@@ -36,6 +39,9 @@ public class IgniteAwareApplicationService {
     /** Logger. */
     private static final Logger log = LogManager.getLogger(IgniteAwareApplicationService.class.getName());
 
+    /** Thin client connection string variable. */
+    public static final String THIN_CLIENT_CONNECTION = "thin_client_connection";
+
     /**
      * @param args Args.
      */
@@ -55,6 +61,10 @@ public class IgniteAwareApplicationService {
         JsonNode jsonNode = params.length > 3 ?
             mapper.readTree(Base64.getDecoder().decode(params[3])) : mapper.createObjectNode();
 
+        String tcConnStr = Optional.ofNullable(jsonNode.get(THIN_CLIENT_CONNECTION))
+            .map(JsonNode::asText)
+            .orElse(null);
+
         IgniteAwareApplication app =
             (IgniteAwareApplication)clazz.getConstructor().newInstance();
 
@@ -76,7 +86,16 @@ public class IgniteAwareApplicationService {
                 log.info("Ignite instance closed. [interrupted=" + Thread.currentThread().isInterrupted() + "]");
             }
         }
-        else
+        else if (tcConnStr != null && !tcConnStr.isEmpty()) {
+            try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(tcConnStr))) {
+                app.client = client;
+
+                app.start(jsonNode);
+            }
+            finally {
+                log.info("Thin client instance closed. [interrupted=" + Thread.currentThread().isInterrupted() + "]");
+            }
+        } else
             app.start(jsonNode);
     }
 }
diff --git a/modules/ducktests/tests/ignitetest/services/utils/ignite_aware.py b/modules/ducktests/tests/ignitetest/services/utils/ignite_aware.py
index a2089df..69308a4 100644
--- a/modules/ducktests/tests/ignitetest/services/utils/ignite_aware.py
+++ b/modules/ducktests/tests/ignitetest/services/utils/ignite_aware.py
@@ -43,6 +43,7 @@ from ignitetest.services.utils.ssl.ssl_params import get_ssl_params, is_ssl_enab
 from ignitetest.utils.enum import constructible
 
 
+# pylint: disable=R0902
 class IgniteAwareService(BackgroundThreadService, IgnitePathAware, metaclass=ABCMeta):
     """
     The base class to build services aware of Ignite.
@@ -77,6 +78,7 @@ class IgniteAwareService(BackgroundThreadService, IgnitePathAware, metaclass=ABC
         self.init_logs_attribute()
 
         self.disconnected_nodes = []
+        self.start_ignite = kwargs.get("start_ignite", True)
 
     @property
     def version(self):
@@ -120,6 +122,9 @@ class IgniteAwareService(BackgroundThreadService, IgnitePathAware, metaclass=ABC
         """
         Awaits start finished.
         """
+        if not self.start_ignite:
+            return
+
         self.logger.info("Waiting for IgniteAware(s) to start ...")
 
         self.await_event("Topology snapshot", self.startup_timeout_sec, from_the_beginning=True)
diff --git a/modules/ducktests/tests/ignitetest/services/utils/ignite_configuration/__init__.py b/modules/ducktests/tests/ignitetest/services/utils/ignite_configuration/__init__.py
index c430d0f..c93f9e0 100644
--- a/modules/ducktests/tests/ignitetest/services/utils/ignite_configuration/__init__.py
+++ b/modules/ducktests/tests/ignitetest/services/utils/ignite_configuration/__init__.py
@@ -20,6 +20,7 @@ This module contains IgniteConfiguration classes and utilities.
 from typing import NamedTuple
 
 from ignitetest.services.utils.ignite_configuration.communication import CommunicationSpi, TcpCommunicationSpi
+from ignitetest.services.utils.ssl.client_connector_configuration import ClientConnectorConfiguration
 from ignitetest.services.utils.ssl.connector_configuration import ConnectorConfiguration
 from ignitetest.services.utils.ignite_configuration.data_storage import DataStorageConfiguration
 from ignitetest.services.utils.ignite_configuration.discovery import DiscoverySpi, TcpDiscoverySpi
@@ -45,6 +46,7 @@ class IgniteConfiguration(NamedTuple):
     local_host: str = None
     ssl_params: SslParams = None
     connector_configuration: ConnectorConfiguration = None
+    client_connector_configuration: ClientConnectorConfiguration = None
     auth_enabled: bool = False
     plugins: list = []
     metric_exporter: str = None
diff --git a/modules/ducktests/tests/ignitetest/services/utils/ssl/client_connector_configuration.py b/modules/ducktests/tests/ignitetest/services/utils/ssl/client_connector_configuration.py
new file mode 100644
index 0000000..819e8b1
--- /dev/null
+++ b/modules/ducktests/tests/ignitetest/services/utils/ssl/client_connector_configuration.py
@@ -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
+
+"""
+This module contains classes and utilities for Ignite ConnectorConfiguration.
+"""
+
+from typing import NamedTuple
+
+
+class ClientConnectorConfiguration(NamedTuple):
+    """
+    Ignite ClientConnectorConfiguration.
+    Used to configure thin client properties.
+    """
+    port: int = 10800
diff --git a/modules/ducktests/tests/ignitetest/services/utils/templates/ignite.xml.j2 b/modules/ducktests/tests/ignitetest/services/utils/templates/ignite.xml.j2
index d7bf18f..a74a5d8 100644
--- a/modules/ducktests/tests/ignitetest/services/utils/templates/ignite.xml.j2
+++ b/modules/ducktests/tests/ignitetest/services/utils/templates/ignite.xml.j2
@@ -89,5 +89,13 @@
                 {{ connector_configuration_util.connector_configuration(config.connector_configuration) }}
             </property>
         {% endif %}
+
+        {% if config.client_connector_configuration %}
+            <property name="clientConnectorConfiguration">
+                <bean class="org.apache.ignite.configuration.ClientConnectorConfiguration">
+                        <property name="port" value="{{ config.client_connector_configuration.port }}"/>
+                </bean>
+            </property>
+        {% endif %}
     </bean>
 </beans>
diff --git a/modules/ducktests/tests/ignitetest/tests/thin_client_test.py b/modules/ducktests/tests/ignitetest/tests/thin_client_test.py
new file mode 100644
index 0000000..9f7fe23
--- /dev/null
+++ b/modules/ducktests/tests/ignitetest/tests/thin_client_test.py
@@ -0,0 +1,63 @@
+# 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.
+
+"""
+This module contains client tests.
+"""
+from ducktape.mark import matrix
+
+from ignitetest.services.ignite import IgniteService
+from ignitetest.services.ignite_app import IgniteApplicationService
+from ignitetest.services.utils.ignite_configuration import IgniteConfiguration
+from ignitetest.services.utils.ssl.client_connector_configuration import ClientConnectorConfiguration
+from ignitetest.utils import cluster
+from ignitetest.utils.ignite_test import IgniteTest
+from ignitetest.utils.version import DEV_BRANCH, LATEST, IgniteVersion
+
+
+# pylint: disable=W0223
+class ThinClientTest(IgniteTest):
+    """
+    cluster - cluster size.
+    JAVA_CLIENT_CLASS_NAME - running classname.
+    """
+
+    JAVA_CLIENT_CLASS_NAME = "org.apache.ignite.internal.ducktest.tests.thin_client_test.ThinClientSelfTestApplication"
+
+    @cluster(num_nodes=2)
+    @matrix(server_version=[str(DEV_BRANCH), str(LATEST)], thin_client_version=[str(DEV_BRANCH), str(LATEST)])
+    def test_thin_client_compatibility(self, server_version, thin_client_version):
+        """
+        Thin client compatibility test.
+        """
+
+        server_config = IgniteConfiguration(version=IgniteVersion(server_version),
+                                            client_connector_configuration=ClientConnectorConfiguration())
+
+        ignite = IgniteService(self.test_context, server_config, 1)
+
+        thin_client_connection = ignite.nodes[0].account.hostname + ":" + str(server_config.
+                                                                              client_connector_configuration.port)
+
+        thin_clients = IgniteApplicationService(self.test_context,
+                                                IgniteConfiguration(version=IgniteVersion(thin_client_version)),
+                                                java_class_name=self.JAVA_CLIENT_CLASS_NAME,
+                                                num_nodes=1,
+                                                params={"thin_client_connection": thin_client_connection},
+                                                start_ignite=False)
+
+        ignite.start()
+        thin_clients.run()
+        ignite.stop()