You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/01/12 08:01:31 UTC
[05/24] ignite git commit: gg-11414: distributed join test
gg-11414: distributed join test
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ccc19564
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ccc19564
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ccc19564
Branch: refs/heads/ignite-gg-11810
Commit: ccc1956463eae5f46457824bed251cd1d4c2552b
Parents: 37eb93b
Author: Sergey Sidorov <ss...@gridgain.com>
Authored: Fri Nov 25 12:01:45 2016 +0300
Committer: Sergey Sidorov <ss...@gridgain.com>
Committed: Fri Nov 25 12:01:45 2016 +0300
----------------------------------------------------------------------
.../query/IgniteSqlDistributedJoinSelfTest.java | 172 +++++++++++++++++++
1 file changed, 172 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/ccc19564/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlDistributedJoinSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlDistributedJoinSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlDistributedJoinSelfTest.java
new file mode 100644
index 0000000..d851a31
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlDistributedJoinSelfTest.java
@@ -0,0 +1,172 @@
+/*
+ * 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.processors.query;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cache.query.*;
+import org.apache.ignite.cache.query.annotations.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.plugin.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.*;
+
+/**
+ * Tests for correct distributed sql joins.
+ */
+public class IgniteSqlDistributedJoinSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+ private static final int NODES_COUNT = 2;
+ private static final int ORG_COUNT = NODES_COUNT;
+ private static final int PERSON_PER_ORG_COUNT = 50;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setPeerClassLoadingEnabled(false);
+
+ TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+ disco.setIpFinder(IP_FINDER);
+
+ cfg.setDiscoverySpi(disco);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGridsMultiThreaded(NODES_COUNT, false);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * @param name Cache name.
+ * @param partitioned Partition or replicated cache.
+ * @param idxTypes Indexed types.
+ * @return Cache configuration.
+ */
+ private static CacheConfiguration cacheConfig(String name, boolean partitioned, Class<?>... idxTypes) {
+ return new CacheConfiguration()
+ .setName(name)
+ .setCacheMode(partitioned ? CacheMode.PARTITIONED : CacheMode.REPLICATED)
+ .setAtomicityMode(CacheAtomicityMode.ATOMIC)
+ .setBackups(1)
+ .setIndexedTypes(idxTypes);
+ }
+
+ public void testNonCollocatedDistributedJoin() throws Exception {
+ CacheConfiguration ccfg1 = cacheConfig("pers", true, String.class, Person.class);
+ CacheConfiguration ccfg2 = cacheConfig("org", true, String.class, Organization.class);
+
+ IgniteCache<String, Person> c1 = ignite(0).getOrCreateCache(ccfg1);
+ IgniteCache<String, Organization> c2 = ignite(0).getOrCreateCache(ccfg2);
+
+ try {
+ awaitPartitionMapExchange();
+
+ populateDataIntoCaches(c1, c2);
+
+ String joinSql =
+ "select * from Person, \"org\".Organization as org " +
+ "where Person.orgId = org.id " +
+ "and lower(org.name) = lower(?)";
+
+ SqlQuery qry = new SqlQuery<String, Person>(Person.class, joinSql).setArgs("Organization #0");
+
+ qry.setDistributedJoins(true);
+
+ List<Person> prns = c1.query(qry).getAll();
+
+ assertEquals(PERSON_PER_ORG_COUNT, prns.size());
+ }
+ finally {
+ c1.destroy();
+ c2.destroy();
+ }
+ }
+
+ private void populateDataIntoCaches(IgniteCache<String, Person> c1, IgniteCache<String, Organization> c2) {
+ int personId = 0;
+
+ for (int i = 0; i < ORG_COUNT; i++) {
+ Organization org = new Organization();
+ org.setId("org" + i);
+ org.setName("Organization #" + i);
+
+ c2.put(org.getId(), org);
+
+ for (int j = 0; j < PERSON_PER_ORG_COUNT; j++) {
+ Person prsn = new Person();
+ prsn.setId("pers" + personId);
+ prsn.setOrgId(org.getId());
+ prsn.setName("Person name #" + personId);
+
+ c1.put(prsn.getId(), prsn);
+
+ personId++;
+ }
+ }
+ }
+
+ private static class Person {
+ @QuerySqlField(index = true)
+ private String id;
+ @QuerySqlField(index = true)
+ private String orgId;
+ @QuerySqlField(index = true)
+ private String name;
+
+ public String getId() { return id; }
+
+ public void setId(String id) { this.id = id; }
+
+ public String getOrgId() { return orgId; }
+
+ public void setOrgId(String orgId) { this.orgId = orgId; }
+
+ public String getName() { return name; }
+
+ public void setName(String name) { this.name = name; }
+ }
+
+ private static class Organization {
+ @QuerySqlField(index = true)
+ private String id;
+ @QuerySqlField(index = true)
+ private String name;
+
+ public void setId(String id) { this.id = id; }
+
+ public String getId() { return id; }
+
+ public String getName() { return name; }
+
+ public void setName(String name) { this.name = name; }
+ }
+}