ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [02/50] [abbrv] ignite git commit: Added test.
Date Wed, 06 Jul 2016 18:23:01 GMT
Added test.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/72819375
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/72819375
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/72819375

Branch: refs/heads/ignite-3227
Commit: 72819375004ea3c9ce8f49a99f636845f70e660e
Parents: f91b699
Author: sboikov <sboikov@gridgain.com>
Authored: Mon Jul 4 14:48:44 2016 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Mon Jul 4 14:48:44 2016 +0300

----------------------------------------------------------------------
 .../cache/IgniteCacheUnionDuplicatesTest.java   | 151 +++++++++++++++++++
 .../h2/sql/AbstractH2CompareQueryTest.java      |   2 +-
 2 files changed, 152 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/72819375/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheUnionDuplicatesTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheUnionDuplicatesTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheUnionDuplicatesTest.java
new file mode 100644
index 0000000..abebff2
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheUnionDuplicatesTest.java
@@ -0,0 +1,151 @@
+/*
+ * 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.cache;
+
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Statement;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.processors.query.h2.sql.AbstractH2CompareQueryTest;
+import org.apache.ignite.internal.processors.query.h2.sql.BaseH2CompareQueryTest;
+
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ *
+ */
+public class IgniteCacheUnionDuplicatesTest extends AbstractH2CompareQueryTest {
+    /** {@inheritDoc} */
+    @Override protected void setIndexedTypes(CacheConfiguration<?, ?> cc, CacheMode
mode) {
+        if (mode == PARTITIONED)
+            cc.setIndexedTypes(Integer.class, Organization.class);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void initCacheAndDbData() throws Exception {
+        Integer k1 = primaryKey(ignite(0).cache(pCache.getName()));
+        Integer k2 = primaryKey(ignite(1).cache(pCache.getName()));
+
+        Organization org1 = new Organization(k1, "org", "org1");
+        Organization org2 = new Organization(k2, "org", "org2");
+
+        pCache.put(k1, org1);
+        pCache.put(k2, org2);
+
+        insertInDb(org1);
+        insertInDb(org2);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void checkAllDataEquals() throws Exception {
+        // No-op.
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testUnionDuplicateFilter() throws Exception {
+        compareQueryRes0(pCache, "select name from \"part\".Organization " +
+            "union " +
+            "select name2 from \"part\".Organization");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Statement initializeH2Schema() throws SQLException {
+        Statement st = super.initializeH2Schema();
+
+        st.execute("create table \"part\".ORGANIZATION" +
+            "  (_key int not null," +
+            "  _val other not null," +
+            "  id int unique," +
+            "  name varchar(255)," +
+            "  name2 varchar(255))");
+
+        return st;
+    }
+
+    /**
+     * Insert {@link BaseH2CompareQueryTest.Organization} at h2 database.
+     *
+     * @param org Organization.
+     * @throws SQLException If exception.
+     */
+    private void insertInDb(Organization org) throws SQLException {
+        try(PreparedStatement st = conn.prepareStatement(
+            "insert into \"part\".ORGANIZATION (_key, _val, id, name, name2) values(?, ?,
?, ?, ?)")) {
+            st.setObject(1, org.id);
+            st.setObject(2, org);
+            st.setObject(3, org.id);
+            st.setObject(4, org.name);
+            st.setObject(5, org.name2);
+
+            st.executeUpdate();
+        }
+    }
+
+    /**
+     * Organization class. Stored at partitioned cache.
+     */
+    private static class Organization implements Serializable {
+        /** */
+        @QuerySqlField(index = true)
+        private int id;
+
+        /** */
+        @QuerySqlField(index = true)
+        private String name;
+
+        /** */
+        @QuerySqlField(index = true)
+        private String name2;
+
+        /**
+         * Create Organization.
+         *
+         * @param id Organization ID.
+         * @param name Organization name.
+         * @param name2 Name2.
+         */
+        Organization(int id, String name, String name2) {
+            this.id = id;
+            this.name = name;
+            this.name2 = name2;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            return this == o || o instanceof Organization && id == ((Organization)o).id;
+
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return id;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "Organization [id=" + id +
+                ", name=" + name +
+                ", name2=" + name2 + ']';
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/72819375/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
index b251d63..ffe137f 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
@@ -147,7 +147,7 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest
     /**
      * Populate cache and h2 database with test data.
      */
-    protected abstract void initCacheAndDbData() throws SQLException;
+    protected abstract void initCacheAndDbData() throws Exception;
 
     /**
      * @throws Exception If failed.


Mime
View raw message