ignite-sql-tests - throw exception if table not found
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/03c67029 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/03c67029 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/03c67029 Branch: refs/heads/ignite-sql-tests Commit: 03c67029c41f374c60f42cf560d435f5cd74352f Parents: 9ed2a39 Author: S.Vladykin <[email protected]> Authored: Wed Feb 25 03:36:09 2015 +0300 Committer: S.Vladykin <[email protected]> Committed: Wed Feb 25 03:36:09 2015 +0300 ---------------------------------------------------------------------- .../processors/query/GridQueryProcessor.java | 10 +- .../processors/query/h2/IgniteH2Indexing.java | 5 +- .../cache/IgniteCacheAbstractQuerySelfTest.java | 228 +++++-------------- .../cache/IgniteCacheQueryLoadSelfTest.java | 4 +- 4 files changed, 72 insertions(+), 175 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/03c67029/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index f3eee9b..af8aeeb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -407,7 +407,7 @@ public class GridQueryProcessor extends GridProcessorAdapter { TypeDescriptor type = typesByName.get(new TypeName(space, resType)); if (type == null || !type.registered()) - return new GridEmptyCloseableIterator<>(); + throw new CacheException("Failed to find SQL table for type: " + resType); return idx.query(space, clause, params, type, filters); } @@ -485,7 +485,7 @@ public class GridQueryProcessor extends GridProcessorAdapter { TypeDescriptor typeDesc = typesByName.get(new TypeName(space, type)); if (typeDesc == null || !typeDesc.registered()) - return new GridEmptyCloseableIterator<>(); + throw new CacheException("Failed to find SQL table for type: " + type); final GridCloseableIterator<IgniteBiTuple<K,V>> i = idx.query(space, sqlQry, F.asList(params), typeDesc, idx.backupFilter()); @@ -663,7 +663,7 @@ public class GridQueryProcessor extends GridProcessorAdapter { TypeDescriptor type = typesByName.get(new TypeName(space, resType)); if (type == null || !type.registered()) - return new GridEmptyCloseableIterator<>(); + throw new CacheException("Failed to find SQL table for type: " + resType); return idx.queryText(space, clause, type, filters); } @@ -1141,11 +1141,11 @@ public class GridQueryProcessor extends GridProcessorAdapter { } /** - * Gets type for space and type name. + * Gets type descriptor for space and type name. * * @param space Space name. * @param typeName Type name. - * @return Type. + * @return Type descriptor. * @throws IgniteCheckedException If failed. */ public GridQueryTypeDescriptor type(@Nullable String space, String typeName) throws IgniteCheckedException { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/03c67029/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index b45a2ef..7cf2d4f 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -55,6 +55,7 @@ import org.h2.value.*; import org.jdk8.backport.*; import org.jetbrains.annotations.*; +import javax.cache.*; import javax.cache.Cache; import java.io.*; import java.lang.reflect.*; @@ -681,7 +682,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { final TableDescriptor tbl = tableDescriptor(spaceName, type); if (tbl == null) - return new GridEmptyCloseableIterator<>(); + throw new CacheException("Failed to find SQL table for type: " + type.name()); setFilters(filters); @@ -707,7 +708,7 @@ public class IgniteH2Indexing implements GridQueryIndexing { TableDescriptor tblDesc = tableDescriptor(type, space); if (tblDesc == null) - return new QueryCursorImpl<>(Collections.<Cache.Entry<K,V>>emptyIterator()); + throw new CacheException("Failed to find SQL table for type: " + type); String qry; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/03c67029/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java index 64dce47..63f92ed 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java @@ -130,6 +130,16 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac cc.setSwapEnabled(true); cc.setEvictNearSynchronized(false); cc.setSqlFunctionClasses(SqlFunctions.class); + cc.setIndexedTypes( + BadHashKeyObject.class, Byte.class, + ObjectValue.class, Long.class, + Integer.class, Integer.class, + Integer.class, String.class, + Integer.class, ObjectValue.class, + String.class, ObjectValueOther.class, + Integer.class, ArrayObject.class, + Key.class, GridCacheQueryTestValue.class + ); // Explicitly set number of backups equal to number of grids. if (cacheMode() == CacheMode.PARTITIONED) @@ -163,13 +173,17 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testDifferentKeyTypes() throws Exception { - GridCache<Object, Object> cache = ((IgniteKernal)ignite).cache(null); + final IgniteCache<Object, Object> cache = ignite.jcache(null); - cache.putx("key", "value"); + cache.put(1, "value"); - // Put the same value but for other key type. - // Operation should succeed but with warning log message. - cache.putx(1, "value"); + GridTestUtils.assertThrows(log(), new Callable<Object>() { + @Override public Object call() throws Exception { + cache.put("key", "value"); + + return null; + } + }, CacheException.class, null); } /** @@ -178,13 +192,13 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testDifferentValueTypes() throws Exception { - GridCache<Object, Object> cache = ((IgniteKernal)ignite).cache(null); + GridCache<Integer, Object> cache = ((IgniteKernal)ignite).cache(null); - cache.putx("key", "value"); + cache.putx(7, "value"); // Put value of different type but for the same key type. // Operation should succeed but with warning log message. - cache.putx("key", 1); + cache.putx(7, 1); } /** @@ -193,15 +207,16 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testStringType() throws Exception { - IgniteCache<String, String> cache = ignite.jcache(null); + IgniteCache<Integer, String> cache = ignite.jcache(null); - cache.put("tst", "test"); + cache.put(666, "test"); - QueryCursor<Cache.Entry<String, String>> qry = cache.query(new SqlQuery(String.class, "_val='test'")); + QueryCursor<Cache.Entry<Integer, String>> qry = cache.query(new SqlQuery(String.class, "_val='test'")); - Cache.Entry<String, String> entry = F.first(qry.getAll()); + Cache.Entry<Integer, String> entry = F.first(qry.getAll()); assert entry != null; + assertEquals(666, entry.getKey().intValue()); } /** @@ -210,22 +225,23 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testIntegerType() throws Exception { - IgniteCache<String, Integer> cache = ignite.jcache(null); + IgniteCache<Integer, Integer> cache = ignite.jcache(null); - String key = "k"; + int key = 898; int val = 2; cache.put(key, val); - QueryCursor<Cache.Entry<String, Integer>> qry = - cache.query(new SqlQuery(Integer.class, "_key = 'k' and _val > 1")); + QueryCursor<Cache.Entry<Integer, Integer>> qry = + cache.query(new SqlQuery(Integer.class, "_key = ? and _val > 1").setArgs(key)); - Cache.Entry<String, Integer> entry = F.first(qry.getAll()); + Cache.Entry<Integer, Integer> entry = F.first(qry.getAll()); assert entry != null; - assertEquals(Integer.valueOf(val), entry.getValue()); + assertEquals(key, entry.getKey().intValue()); + assertEquals(val, entry.getValue().intValue()); } /** @@ -288,13 +304,13 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac */ public void testExpiration() throws Exception { ignite.jcache(null). - withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, 1000))).put("key1", 1); + withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, 1000))).put(7, 1); - IgniteCache<String, Integer> cache = ignite.jcache(null); + IgniteCache<Integer, Integer> cache = ignite.jcache(null); - List<Cache.Entry<String, Integer>> qry = cache.query(new SqlQuery(Integer.class, "1=1")).getAll(); + List<Cache.Entry<Integer, Integer>> qry = cache.query(new SqlQuery(Integer.class, "1=1")).getAll(); - Cache.Entry<String, Integer> res = F.first(qry); + Cache.Entry<Integer, Integer> res = F.first(qry); assertEquals(1, res.getValue().intValue()); @@ -397,13 +413,13 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * @throws Exception In case of error. */ public void testSelectQuery() throws Exception { - IgniteCache<String, String> cache = ignite.jcache(null); + IgniteCache<Integer, String> cache = ignite.jcache(null); - cache.put("key", "value"); + cache.put(10, "value"); - QueryCursor<Cache.Entry<String, String>> qry = cache.query(new SqlQuery(String.class, "true")); + QueryCursor<Cache.Entry<Integer, String>> qry = cache.query(new SqlQuery(String.class, "true")); - Iterator<Cache.Entry<String, String>> iter = qry.iterator(); + Iterator<Cache.Entry<Integer, String>> iter = qry.iterator(); assert iter != null; assert iter.next() != null; @@ -590,60 +606,24 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac * * @throws Exception In case of error. */ - public void testRemoveIndex() throws Exception { - GridCache<Integer, ObjectValue> cache = ((IgniteKernal)ignite).cache(null); - GridCache<Integer, ObjectValue> cache1 = ((IgniteKernal)ignite).cache("c1"); - - ObjectValue val = new ObjectValue("test full text", 0); - - int key = 1; - - cache.putx(key, val); - cache1.putx(key, val); - - GridCacheQueryManager<Object, Object> qryMgr = ((IgniteKernal) ignite).internalCache().context().queries(); - GridCacheQueryManager<Object, Object> qryMgr1 = ((IgniteKernal) ignite).internalCache("c1").context().queries(); - - assert hasIndexTable(ObjectValue.class, qryMgr); - assert hasIndexTable(ObjectValue.class, qryMgr1); - - assert qryMgr != null; - - qryMgr.onUndeploy(ObjectValue.class.getClassLoader()); - - assert !hasIndexTable(ObjectValue.class, qryMgr); - assert hasIndexTable(ObjectValue.class, qryMgr1); - - // Put again. - cache.putx(key, val); - - assert hasIndexTable(ObjectValue.class, qryMgr); - assert hasIndexTable(ObjectValue.class, qryMgr1); - } - - /** - * JUnit. - * - * @throws Exception In case of error. - */ public void testScanQuery() throws Exception { - IgniteCache<String, String> c1 = ignite.jcache(null); + IgniteCache<Integer, String> c1 = ignite.jcache(null); - c1.put("key", "value"); + c1.put(777, "value"); // Scan query. - QueryCursor<Cache.Entry<String, String>> qry = c1.query(new ScanQuery<String, String>()); + QueryCursor<Cache.Entry<Integer, String>> qry = c1.query(new ScanQuery<String, String>()); - Iterator<Cache.Entry<String, String>> iter = qry.iterator(); + Iterator<Cache.Entry<Integer, String>> iter = qry.iterator(); assert iter != null; int expCnt = 1; for (int i = 0; i < expCnt; i++) { - Cache.Entry<String, String> e1 = iter.next(); + Cache.Entry<Integer, String> e1 = iter.next(); - assertEquals("key", e1.getKey()); + assertEquals(777, e1.getKey().intValue()); assertEquals("value", e1.getValue()); } @@ -834,118 +814,32 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac } /** - * @throws Exception If failed. - */ - public void testEmptyGrid() throws Exception { - IgniteCache<String, Integer> cache = ignite.jcache(null); - - String key = "k"; - - int val = 2; - - cache.put(key, val); - - QueryCursor<Cache.Entry<String, Integer>> qry = cache.query(new SqlQuery(Integer.class, - "_key = 'k' and _val > 1")); - - Cache.Entry<String, Integer> entry = F.first(qry.getAll()); - - assert entry != null; - - assertEquals(Integer.valueOf(val), entry.getValue()); - } - - /** * @throws IgniteCheckedException if failed. */ public void testBadHashObjectKey() throws IgniteCheckedException { - IgniteCache<BadHashKeyObject, Integer> cache = ignite.jcache(null); + IgniteCache<BadHashKeyObject, Byte> cache = ignite.jcache(null); - cache.put(new BadHashKeyObject("test_key1"), 9); - cache.put(new BadHashKeyObject("test_key0"), 1005001); - cache.put(new BadHashKeyObject("test_key1"), 7); + cache.put(new BadHashKeyObject("test_key1"), (byte)1); + cache.put(new BadHashKeyObject("test_key0"), (byte)10); + cache.put(new BadHashKeyObject("test_key1"), (byte)7); - assertEquals(1005001, cache.query(new SqlQuery(Integer.class, "_key = ?").setArgs( - new BadHashKeyObject("test_key0"))).iterator().next().getValue().intValue()); + assertEquals(10, cache.query(new SqlQuery(Byte.class, "_key = ?").setArgs( + new BadHashKeyObject("test_key0"))).getAll().get(0).getValue().intValue()); } /** * @throws IgniteCheckedException if failed. */ public void testTextIndexedKey() throws IgniteCheckedException { - IgniteCache<ObjectValue, Integer> cache = ignite.jcache(null); - - cache.put(new ObjectValue("test_key1", 10), 19); - cache.put(new ObjectValue("test_key0", 11), 11005); - cache.put(new ObjectValue("test_key1", 12), 17); - - assertEquals(11005, - cache.query(new TextQuery(Integer.class, "test_key0")) - .iterator().next().getValue().intValue()); - } - - /** - * @throws Exception If failed. - */ - public void testAnonymousClasses() throws Exception { - IgniteCache<Integer, Object> cache = ignite.jcache(null); + IgniteCache<ObjectValue, Long> cache = ignite.jcache(null); - Object val = new Object() { - @QuerySqlField - private int field1 = 10; - - @Override public String toString() { - return "Test anonymous object."; - } - }; - - assertTrue(val.getClass().getName(), val.getClass().getName().endsWith("IgniteCacheAbstractQuerySelfTest$5")); - - cache.put(1, val); - - QueryCursor<Cache.Entry<Integer, Object>> q = cache.query(new SqlQuery(val.getClass(), "_key >= 0")); - - Collection<Cache.Entry<Integer, Object>> res = q.getAll(); - - assertEquals(1, res.size()); + cache.put(new ObjectValue("test_key1", 10), 19L); + cache.put(new ObjectValue("test_key0", 11), 11005L); + cache.put(new ObjectValue("test_key1", 12), 17L); - List<List<?>> fieldsRes = cache.queryFields(new SqlFieldsQuery( - "select field1 from IgniteCacheAbstractQuerySelfTest_5")).getAll(); - - assertEquals(1, fieldsRes.size()); - - List<?> fields = F.first(fieldsRes); - - assertEquals(1, fields.size()); - assertEquals(10, fields.get(0)); - } - - /** - * @throws Exception If failed. - */ - public void testTwoAnonymousClasses() throws Exception { - IgniteCache<Integer, Object> cache = ignite.jcache(null); - - Object val1 = new Object() { - @Override public String toString() { - return "Test anonymous object1."; - } - }; - - Object val2 = new Object() { - @Override public String toString() { - return "Test anonymous object2."; - } - }; - - cache.put(1, val1); - cache.put(2, val2); - - QueryCursor<Cache.Entry<Integer, Object>> q = cache.query(new SqlQuery(val1.getClass(), "_key >= 0")); - - Collection<Cache.Entry<Integer, Object>> res = q.getAll(); - - assertEquals(1, res.size()); + assertEquals(11005L, + cache.query(new TextQuery(Long.class, "test_key0")) + .getAll().get(0).getValue().intValue()); } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/03c67029/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryLoadSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryLoadSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryLoadSelfTest.java index dd84744..f64564e 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryLoadSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryLoadSelfTest.java @@ -19,7 +19,6 @@ package org.apache.ignite.internal.processors.cache; import org.apache.ignite.*; import org.apache.ignite.cache.*; -import org.apache.ignite.cache.query.annotations.*; import org.apache.ignite.cache.query.*; import org.apache.ignite.cache.query.annotations.*; import org.apache.ignite.cache.store.*; @@ -73,6 +72,9 @@ public class IgniteCacheQueryLoadSelfTest extends GridCommonAbstractTest { ccfg.setWriteThrough(true); ccfg.setLoadPreviousValue(true); ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setIndexedTypes( + Integer.class, ValueObject.class + ); cfg.setCacheConfiguration(ccfg);
