ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/7] incubator-ignite git commit: ignite-sal-tests CacheConfiguration#setQueryIndexEnabled checked
Date Fri, 13 Feb 2015 13:14:39 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-sql-tests 1f6d6611e -> 365812721


ignite-sal-tests CacheConfiguration#setQueryIndexEnabled checked


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

Branch: refs/heads/ignite-sql-tests
Commit: 10efad1900566a3fb338d420ce3498d83b0ca51a
Parents: f84e19e
Author: avinogradov <avinogradov@gridgain.com>
Authored: Thu Feb 12 18:13:23 2015 +0300
Committer: avinogradov <avinogradov@gridgain.com>
Committed: Thu Feb 12 18:13:23 2015 +0300

----------------------------------------------------------------------
 .../processors/cache/IgniteCacheProxy.java      |   3 +
 .../GridCacheQueryIndexDisabledSelfTest.java    | 174 +++++++++++++++++++
 .../IgniteCacheQuerySelfTestSuite.java          |   1 +
 3 files changed, 178 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/10efad19/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index 20d40e6..d026b95 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -337,6 +337,9 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K,
V
         GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
 
         try {
+            if (!(qry instanceof ScanQuery) && !ctx.config().isQueryIndexEnabled())
+                throw new CacheException("Indexing is disabled for cache: " + ctx.cache().name());
+
             if (qry instanceof SqlQuery) {
                 SqlQuery p = (SqlQuery)qry;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/10efad19/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexDisabledSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexDisabledSelfTest.java
new file mode 100644
index 0000000..ebb7eec
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexDisabledSelfTest.java
@@ -0,0 +1,174 @@
+/*
+ * 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 org.apache.ignite.*;
+import org.apache.ignite.cache.query.*;
+import org.apache.ignite.cache.query.annotations.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import javax.cache.*;
+import java.io.*;
+import java.util.*;
+
+/**
+ * Test {@link CacheConfiguration#setQueryIndexEnabled} checked before executing query
+ */
+public class GridCacheQueryIndexDisabledSelfTest extends GridCommonAbstractTest {
+    /** */
+    public GridCacheQueryIndexDisabledSelfTest() {
+        super(true);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @SuppressWarnings("unchecked")
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        CacheConfiguration ccfg = defaultCacheConfiguration();
+
+        ccfg.setQueryIndexEnabled(false);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        cfg.setDiscoverySpi(disco);
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSqlQuery() throws Exception {
+        IgniteCache<Integer, SqlValue> cache = jcache();
+
+        try {
+            Collection<Cache.Entry<Integer, SqlValue>> res =
+                cache.query(new SqlQuery(SqlValue.class, "val >= 0")).getAll();
+
+            assert false;
+        }
+        catch (CacheException e) {
+            X.println("Caught expected exception: " + e);
+        }
+        catch (Exception e) {
+            assert false;
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSqlFieldsQuery() throws Exception {
+        IgniteCache<Integer, SqlValue> cache = jcache();
+
+        try {
+            Collection<Cache.Entry<Integer, SqlValue>> res =
+                cache.query(new SqlFieldsQuery("select * from Person")).getAll();
+
+            assert false;
+        }
+        catch (CacheException e) {
+            X.println("Caught expected exception: " + e);
+        }
+        catch (Exception e) {
+            assert false;
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFullTextQuery() throws Exception {
+        IgniteCache<Integer, String> cache = jcache();
+
+        try {
+            Collection<Cache.Entry<Integer, String>> res =
+                cache.query(new TextQuery(String.class, "text")).getAll();
+
+            assert false;
+        }
+        catch (CacheException e) {
+            X.println("Caught expected exception: " + e);
+        }
+        catch (Exception e) {
+            assert false;
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testScanQuery() throws Exception {
+        IgniteCache<Integer, String> cache = jcache();
+
+        try {
+            Collection<Cache.Entry<Integer, String>> res =
+                cache.query(new ScanQuery<>(new IgniteBiPredicate<Integer, String>()
{
+                    @Override public boolean apply(Integer id, String s) {
+                        return s.equals("");
+                    }
+                })).getAll();
+
+        }
+        catch (IgniteException e) {
+            assert false;
+        }
+    }
+
+    /**
+     * Value object class.
+     */
+    private static class SqlValue {
+        /**
+         * Value.
+         */
+        @QuerySqlField
+        private final int val;
+
+        /**
+         * @param val Value.
+         */
+        SqlValue(int val) {
+            this.val = val;
+        }
+
+        /**
+         * @return Value.
+         */
+        int value() {
+            return val;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override public String toString() {
+            return S.toString(SqlValue.class, this);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/10efad19/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 82c7099..6491765 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
@@ -43,6 +43,7 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
         suite.addTestSuite(GridQueryParsingTest.class);
 
         // Queries tests.
+        suite.addTestSuite(GridCacheQueryIndexDisabledSelfTest.class);
         suite.addTestSuite(IgniteCacheQueryLoadSelfTest.class);
         suite.addTestSuite(IgniteCacheLocalQuerySelfTest.class);
         suite.addTestSuite(IgniteCacheLocalAtomicQuerySelfTest.class);


Mime
View raw message