You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by av...@apache.org on 2020/08/11 08:50:32 UTC
[ignite] branch ignite-ducktape updated: Cellular affinity test
(#8130)
This is an automated email from the ASF dual-hosted git repository.
av 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 77c3ff4 Cellular affinity test (#8130)
77c3ff4 is described below
commit 77c3ff45c5249cf024c2cfe9b11f60f283de2cd6
Author: Anton Vinogradov <av...@apache.org>
AuthorDate: Tue Aug 11 11:50:06 2020 +0300
Cellular affinity test (#8130)
---
.../CellularAffinityBackupFilter.java | 59 +++++++++++
.../DistributionChecker.java | 65 ++++++++++++
.../ducktests/tests/ignitetest/services/ignite.py | 5 +-
.../tests/ignitetest/services/ignite_app.py | 5 +-
.../ducktests/tests/ignitetest/services/spark.py | 2 +-
.../ignitetest/services/utils/ignite_aware.py | 8 +-
.../ignitetest/services/utils/ignite_aware_app.py | 6 +-
.../ignitetest/tests/cellular_affinity_test.py | 111 +++++++++++++++++++++
8 files changed, 252 insertions(+), 9 deletions(-)
diff --git a/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/cellular_affinity_test/CellularAffinityBackupFilter.java b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/cellular_affinity_test/CellularAffinityBackupFilter.java
new file mode 100644
index 0000000..6ecdd3f
--- /dev/null
+++ b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/cellular_affinity_test/CellularAffinityBackupFilter.java
@@ -0,0 +1,59 @@
+/*
+ * 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.cellular_affinity_test;
+
+import java.util.List;
+import java.util.Objects;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.lang.IgniteBiPredicate;
+
+/**
+ *
+ */
+public class CellularAffinityBackupFilter implements IgniteBiPredicate<ClusterNode, List<ClusterNode>> {
+ /** */
+ private static final long serialVersionUID = 1L;
+
+ /** Attribute name. */
+ private final String attrName;
+
+ /**
+ * @param attrName The attribute name for the attribute to compare.
+ */
+ public CellularAffinityBackupFilter(String attrName) {
+ this.attrName = attrName;
+ }
+
+ /**
+ * Defines a predicate which returns {@code true} if a node is acceptable for a backup
+ * or {@code false} otherwise. An acceptable node is one where its attribute value
+ * is exact match with previously selected nodes. If an attribute does not
+ * exist on exactly one node of a pair, then the attribute does not match. If the attribute
+ * does not exist both nodes of a pair, then the attribute matches.
+ *
+ * @param candidate A node that is a candidate for becoming a backup node for a partition.
+ * @param previouslySelected A list of primary/backup nodes already chosen for a partition.
+ * The primary is first.
+ */
+ @Override public boolean apply(ClusterNode candidate, List<ClusterNode> previouslySelected) {
+ for (ClusterNode node : previouslySelected)
+ return Objects.equals(candidate.attribute(attrName), node.attribute(attrName));
+
+ return true;
+ }
+}
diff --git a/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/cellular_affinity_test/DistributionChecker.java b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/cellular_affinity_test/DistributionChecker.java
new file mode 100644
index 0000000..38ec2a4
--- /dev/null
+++ b/modules/ducktests/src/main/java/org/apache/ignite/internal/ducktest/tests/cellular_affinity_test/DistributionChecker.java
@@ -0,0 +1,65 @@
+/*
+ * 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.cellular_affinity_test;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.stream.Collectors;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.ducktest.utils.IgniteAwareApplication;
+
+/**
+ *
+ */
+public class DistributionChecker extends IgniteAwareApplication {
+ /**
+ * @param ignite Ignite.
+ */
+ public DistributionChecker(Ignite ignite) {
+ super(ignite);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override protected void run(JsonNode jsonNode) {
+ String cacheName = jsonNode.get("cacheName").asText();
+ String attr = jsonNode.get("attr").asText();
+ int nodesPerCell = jsonNode.get("nodesPerCell").intValue();
+
+ assert ignite.cluster().forServers().nodes().size() > nodesPerCell : "Cluster should contain more than one cell";
+
+ for (int i = 0; i < 10_000; i++) {
+ Collection<ClusterNode> nodes = ignite.affinity(cacheName).mapKeyToPrimaryAndBackups(i);
+
+ Map<Object, Long> stat = nodes.stream().collect(
+ Collectors.groupingBy(n -> n.attributes().get(attr), Collectors.counting()));
+
+ log.info("Checking [key=" + i + ", stat=" + stat + "]");
+
+ assert 1 == stat.keySet().size() : "Partition should be located on nodes from only one cell [stat=" + stat + "]";
+
+ assert nodesPerCell == stat.values().iterator().next() :
+ "Partition should be located on all nodes of the cell [stat=" + stat + "]";
+ }
+
+ markSyncExecutionComplete();
+ }
+}
diff --git a/modules/ducktests/tests/ignitetest/services/ignite.py b/modules/ducktests/tests/ignitetest/services/ignite.py
index 08732c6..4e2ea96 100644
--- a/modules/ducktests/tests/ignitetest/services/ignite.py
+++ b/modules/ducktests/tests/ignitetest/services/ignite.py
@@ -45,8 +45,9 @@ class IgniteService(IgniteAwareService):
}
# pylint: disable=R0913
- def __init__(self, context, num_nodes, modules=None, client_mode=False, version=DEV_BRANCH, properties=""):
- super(IgniteService, self).__init__(context, num_nodes, modules, client_mode, version, properties)
+ def __init__(self, context, num_nodes, modules=None, client_mode=False, version=DEV_BRANCH, properties="",
+ jvm_opts=None):
+ super(IgniteService, self).__init__(context, num_nodes, modules, client_mode, version, properties, jvm_opts)
# pylint: disable=W0221
def start(self, timeout_sec=180):
diff --git a/modules/ducktests/tests/ignitetest/services/ignite_app.py b/modules/ducktests/tests/ignitetest/services/ignite_app.py
index ec9007d..8e89911 100644
--- a/modules/ducktests/tests/ignitetest/services/ignite_app.py
+++ b/modules/ducktests/tests/ignitetest/services/ignite_app.py
@@ -29,6 +29,7 @@ class IgniteApplicationService(IgniteAwareApplicationService):
# pylint: disable=R0913
def __init__(self, context, java_class_name, modules=None, client_mode=True, version=DEV_BRANCH,
- properties="", params="", timeout_sec=60):
+ properties="", params="", jvm_options=None, timeout_sec=60):
super(IgniteApplicationService, self).__init__(context, java_class_name, modules, client_mode, version,
- properties, params, timeout_sec, self.service_java_class_name)
+ properties, params, jvm_options, timeout_sec,
+ self.service_java_class_name)
diff --git a/modules/ducktests/tests/ignitetest/services/spark.py b/modules/ducktests/tests/ignitetest/services/spark.py
index 4b4b9cd..72ce9bc 100644
--- a/modules/ducktests/tests/ignitetest/services/spark.py
+++ b/modules/ducktests/tests/ignitetest/services/spark.py
@@ -44,7 +44,7 @@ class SparkService(IgniteAwareService):
modules = modules or []
modules.extend(["ignite-spark"])
- IgniteAwareService.__init__(self, context, num_nodes, modules, False, version, properties)
+ IgniteAwareService.__init__(self, context, num_nodes, modules, False, version, properties, None)
self.log_level = "DEBUG"
diff --git a/modules/ducktests/tests/ignitetest/services/utils/ignite_aware.py b/modules/ducktests/tests/ignitetest/services/utils/ignite_aware.py
index 2e292a3..7830082 100644
--- a/modules/ducktests/tests/ignitetest/services/utils/ignite_aware.py
+++ b/modules/ducktests/tests/ignitetest/services/utils/ignite_aware.py
@@ -49,10 +49,14 @@ class IgniteAwareService(BackgroundThreadService):
}
# pylint: disable=R0913
- def __init__(self, context, num_nodes, modules, client_mode, version, properties):
+ def __init__(self, context, num_nodes, modules, client_mode, version, properties, jvm_options):
super(IgniteAwareService, self).__init__(context, num_nodes)
- self.jvm_options = context.globals.get("jvm_opts", "")
+ global_jvm_options = context.globals.get("jvm_opts", "")
+
+ service_jvm_options = " ".join(map(lambda x: '-J' + x, jvm_options)) if jvm_options else ""
+
+ self.jvm_options = " ".join(filter(None, [global_jvm_options, service_jvm_options]))
self.log_level = "DEBUG"
self.properties = properties
diff --git a/modules/ducktests/tests/ignitetest/services/utils/ignite_aware_app.py b/modules/ducktests/tests/ignitetest/services/utils/ignite_aware_app.py
index eece2a6..b376ff3 100644
--- a/modules/ducktests/tests/ignitetest/services/utils/ignite_aware_app.py
+++ b/modules/ducktests/tests/ignitetest/services/utils/ignite_aware_app.py
@@ -30,9 +30,11 @@ class IgniteAwareApplicationService(IgniteAwareService):
"""
# pylint: disable=R0913
- def __init__(self, context, java_class_name, modules, client_mode, version, properties, params, timeout_sec,
+ def __init__(self, context, java_class_name, modules, client_mode, version, properties, params, jvm_options,
+ timeout_sec,
service_java_class_name="org.apache.ignite.internal.ducktest.utils.IgniteAwareApplicationService"):
- super(IgniteAwareApplicationService, self).__init__(context, 1, modules, client_mode, version, properties)
+ super(IgniteAwareApplicationService, self).__init__(context, 1, modules, client_mode, version, properties,
+ jvm_options)
self.servicejava_class_name = service_java_class_name
self.java_class_name = java_class_name
diff --git a/modules/ducktests/tests/ignitetest/tests/cellular_affinity_test.py b/modules/ducktests/tests/ignitetest/tests/cellular_affinity_test.py
new file mode 100644
index 0000000..8087012
--- /dev/null
+++ b/modules/ducktests/tests/ignitetest/tests/cellular_affinity_test.py
@@ -0,0 +1,111 @@
+# 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 Cellular Affinity tests.
+"""
+
+from ducktape.mark import parametrize
+from ducktape.mark.resource import cluster
+from jinja2 import Template
+
+from ignitetest.services.ignite import IgniteService
+from ignitetest.services.ignite_app import IgniteApplicationService
+from ignitetest.tests.utils.ignite_test import IgniteTest
+from ignitetest.tests.utils.version import DEV_BRANCH
+
+
+# pylint: disable=W0223
+class CellularAffinity(IgniteTest):
+ """
+ Tests Cellular Affinity scenarios.
+ """
+ NUM_NODES = 3
+
+ ATTRIBUTE = "CELL"
+
+ CACHE_NAME = "test-cache"
+
+ CONFIG_TEMPLATE = """
+ <property name="cacheConfiguration">
+ <list>
+ <bean class="org.apache.ignite.configuration.CacheConfiguration">
+ <property name="affinity">
+ <bean class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction">
+ <property name="affinityBackupFilter">
+ <bean class="org.apache.ignite.internal.ducktest.tests.cellular_affinity_test.CellularAffinityBackupFilter">
+ <constructor-arg value="{{ attr }}"/>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ <property name="name" value="{{ cacheName }}"/>
+ <property name="backups" value="{{ nodes }}"/>
+ </bean>
+ </list>
+ </property>
+ """
+
+ @staticmethod
+ def properties():
+ """
+ :return: Configuration properties.
+ """
+ return Template(CellularAffinity.CONFIG_TEMPLATE) \
+ .render(nodes=CellularAffinity.NUM_NODES, # bigger than cell capacity (to handle single cell useless test)
+ attr=CellularAffinity.ATTRIBUTE,
+ cacheName=CellularAffinity.CACHE_NAME)
+
+ def __init__(self, test_context):
+ super(CellularAffinity, self).__init__(test_context=test_context)
+
+ def setUp(self):
+ pass
+
+ def teardown(self):
+ pass
+
+ @cluster(num_nodes=NUM_NODES * 3 + 1)
+ @parametrize(version=str(DEV_BRANCH))
+ def test(self, version):
+ """
+ Test Cellular Affinity scenario (partition distribution).
+ """
+ self.start_cell(version, ['-D' + CellularAffinity.ATTRIBUTE + '=1'])
+ self.start_cell(version, ['-D' + CellularAffinity.ATTRIBUTE + '=2'])
+ self.start_cell(version, ['-D' + CellularAffinity.ATTRIBUTE + '=XXX', '-DRANDOM=42'])
+
+ checker = IgniteApplicationService(
+ self.test_context,
+ java_class_name="org.apache.ignite.internal.ducktest.tests.cellular_affinity_test.DistributionChecker",
+ params={"cacheName": CellularAffinity.CACHE_NAME,
+ "attr": CellularAffinity.ATTRIBUTE,
+ "nodesPerCell": self.NUM_NODES},
+ version=version)
+
+ checker.run()
+
+ def start_cell(self, ignite_version, jvm_opts):
+ """
+ Starts cell.
+ """
+ ignites = IgniteService(
+ self.test_context,
+ num_nodes=CellularAffinity.NUM_NODES,
+ version=ignite_version,
+ properties=self.properties(),
+ jvm_opts=jvm_opts)
+
+ ignites.start()