IGNITE-5307: Several basic tests for SQL schema operations.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6f1a900f Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6f1a900f Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6f1a900f Branch: refs/heads/ignite-5075 Commit: 6f1a900fcf40c780769befd897742206455128ac Parents: 43ab98b Author: devozerov <[email protected]> Authored: Fri Jun 2 17:14:37 2017 +0300 Committer: devozerov <[email protected]> Committed: Fri Jun 2 17:14:37 2017 +0300 ---------------------------------------------------------------------- .../query/IgniteSqlSchemaIndexingTest.java | 3 +- .../query/SqlPublicSchemaSelfTest.java | 198 +++++++++++++++++++ .../IgniteCacheQuerySelfTestSuite.java | 3 + 3 files changed, 202 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/6f1a900f/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java index 3cecbc8..33e35e0 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSchemaIndexingTest.java @@ -123,8 +123,7 @@ public class IgniteSqlSchemaIndexingTest extends GridCommonAbstractTest { IgniteCache<Integer, Fact> cache = ignite(0).createCache(cfg); - SqlFieldsQuery qry = new SqlFieldsQuery("select f.id, f.name " + - "from InSENSitive_Cache.Fact f"); + SqlFieldsQuery qry = new SqlFieldsQuery("select f.id, f.name from InSENSitive_Cache.Fact f"); cache.put(1, new Fact(1, "cacheInsensitive")); http://git-wip-us.apache.org/repos/asf/ignite/blob/6f1a900f/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlPublicSchemaSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlPublicSchemaSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlPublicSchemaSelfTest.java new file mode 100644 index 0000000..cbd8972 --- /dev/null +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlPublicSchemaSelfTest.java @@ -0,0 +1,198 @@ +/* + * 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.IgniteCache; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * Tests for public schema. + */ +public class SqlPublicSchemaSelfTest extends GridCommonAbstractTest { + /** Person cache name. */ + private static final String CACHE_PERSON = "PersonCache"; + + /** Person cache 2 name. */ + private static final String CACHE_PERSON_2 = "PersonCache2"; + + /** Node. */ + private IgniteEx node; + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + node = (IgniteEx)startGrid(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** + * Test simple query. + * + * @throws Exception If failed. + */ + public void testSchemaChange() throws Exception { + IgniteCache<PersonKey, Person> cache = node.createCache(new CacheConfiguration<PersonKey, Person>() + .setName(CACHE_PERSON) + .setIndexedTypes(PersonKey.class, Person.class)); + + node.createCache(new CacheConfiguration<PersonKey, Person>() + .setName(CACHE_PERSON_2) + .setIndexedTypes(PersonKey.class, Person.class)); + + cache.put(new PersonKey(1), new Person("Vasya", 2)); + + // Normal calls. + assertEquals(1, cache.query( + new SqlFieldsQuery("SELECT id, name, orgId FROM Person") + ).getAll().size()); + + assertEquals(1, cache.query( + new SqlFieldsQuery("SELECT id, name, orgId FROM Person").setSchema(CACHE_PERSON) + ).getAll().size()); + + assertEquals(1, cache.query( + new SqlFieldsQuery("SELECT id, name, orgId FROM \"PersonCache\".Person") + ).getAll().size()); + + // Call from default schema. + assertEquals(1, cache.query( + new SqlFieldsQuery("SELECT id, name, orgId FROM \"PersonCache\".Person").setSchema(QueryUtils.DFLT_SCHEMA) + ).getAll().size()); + + // Call from another schema. + assertEquals(1, cache.query( + new SqlFieldsQuery("SELECT id, name, orgId FROM \"PersonCache\".Person").setSchema(CACHE_PERSON_2) + ).getAll().size()); + } + + /** + * Test simple query. + * + * @throws Exception If failed. + */ + public void testSchemaChangeOnCacheWithPublicSchema() throws Exception { + IgniteCache<PersonKey, Person> cache = node.createCache(new CacheConfiguration<PersonKey, Person>() + .setName(CACHE_PERSON) + .setIndexedTypes(PersonKey.class, Person.class) + .setSqlSchema(QueryUtils.DFLT_SCHEMA)); + + node.createCache(new CacheConfiguration<PersonKey, Person>() + .setName(CACHE_PERSON_2) + .setIndexedTypes(PersonKey.class, Person.class)); + + cache.put(new PersonKey(1), new Person("Vasya", 2)); + + // Normal calls. + assertEquals(1, cache.query( + new SqlFieldsQuery("SELECT id, name, orgId FROM Person") + ).getAll().size()); + + assertEquals(1, cache.query( + new SqlFieldsQuery("SELECT id, name, orgId FROM Person").setSchema(QueryUtils.DFLT_SCHEMA) + ).getAll().size()); + + // Call from another schema. + assertEquals(1, cache.query( + new SqlFieldsQuery("SELECT id, name, orgId FROM public.Person").setSchema(CACHE_PERSON_2) + ).getAll().size()); + + assertEquals(1, cache.query( + new SqlFieldsQuery("SELECT id, name, orgId FROM \"PUBLIC\".Person").setSchema(CACHE_PERSON_2) + ).getAll().size()); + } + + /** + * Test type conflict in public schema. + * + * @throws Exception If failed. + */ + public void _testTypeConflictInPublicSchema() throws Exception { + // TODO: IGNITE-5380: uncomment work after fix. + fail("Hang for now, need to fix"); + + node.createCache(new CacheConfiguration<PersonKey, Person>() + .setName(CACHE_PERSON) + .setIndexedTypes(PersonKey.class, Person.class) + .setSqlSchema(QueryUtils.DFLT_SCHEMA)); + + node.createCache(new CacheConfiguration<PersonKey, Person>() + .setName(CACHE_PERSON_2) + .setIndexedTypes(PersonKey.class, Person.class) + .setSqlSchema(QueryUtils.DFLT_SCHEMA)); + } + + /** + * Person key. + */ + public static class PersonKey { + @QuerySqlField + public long id; + + /** + * Constructor. + * + * @param id ID. + */ + PersonKey(long id) { + this.id = id; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return (int)id; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object obj) { + return obj != null && obj instanceof PersonKey && (F.eq(id, ((PersonKey)obj).id)); + } + } + + /** + * Person. + */ + public static class Person { + /** Name. */ + @QuerySqlField + public String name; + + /** Organization ID. */ + @QuerySqlField(index = true) + public long orgId; + + /** + * Constructor. + * + * @param name Name. + * @param orgId Orgainzation ID. + */ + public Person(String name, long orgId) { + this.name = name; + this.orgId = orgId; + } + } + +} http://git-wip-us.apache.org/repos/asf/ignite/blob/6f1a900f/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java index 13dfef7..848ab49 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java @@ -115,6 +115,7 @@ import org.apache.ignite.internal.processors.query.IgniteSqlSchemaIndexingTest; import org.apache.ignite.internal.processors.query.IgniteSqlSegmentedIndexMultiNodeSelfTest; import org.apache.ignite.internal.processors.query.IgniteSqlSegmentedIndexSelfTest; import org.apache.ignite.internal.processors.query.IgniteSqlSplitterSelfTest; +import org.apache.ignite.internal.processors.query.SqlPublicSchemaSelfTest; import org.apache.ignite.internal.processors.query.h2.GridH2IndexingInMemSelfTest; import org.apache.ignite.internal.processors.query.h2.GridH2IndexingOffheapSelfTest; import org.apache.ignite.internal.processors.query.h2.IgniteSqlQueryMinMaxTest; @@ -136,6 +137,8 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite { public static TestSuite suite() throws Exception { IgniteTestSuite suite = new IgniteTestSuite("Ignite Cache Queries Test Suite"); + suite.addTestSuite(SqlPublicSchemaSelfTest.class); + // Misc tests. // TODO: Enable when IGNITE-1094 is fixed. // suite.addTest(new TestSuite(QueryEntityValidationSelfTest.class));
