ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [39/50] [abbrv] ignite git commit: IGNITE-3399 - Added a test for the Jira ticket.
Date Mon, 04 Jul 2016 19:03:15 GMT
IGNITE-3399 - Added a test for the Jira ticket.


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

Branch: refs/heads/ignite-2949
Commit: 140fe1933542594ef85e8b08e1dee1a0a109cd9f
Parents: a0d373e
Author: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Authored: Wed Jun 29 16:05:36 2016 -0700
Committer: Alexey Goncharuk <alexey.goncharuk@gmail.com>
Committed: Wed Jun 29 16:05:36 2016 -0700

----------------------------------------------------------------------
 .../org/apache/ignite/cache/QueryEntity.java    |  18 +++
 ...IgniteCachePrimitiveFieldsQuerySelfTest.java | 134 +++++++++++++++++++
 2 files changed, 152 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/140fe193/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
index 7901bec..9758cfc 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
@@ -49,6 +49,24 @@ public class QueryEntity implements Serializable {
     private Map<String, QueryIndex> idxs = new HashMap<>();
 
     /**
+     * Creates an empty query entity.
+     */
+    public QueryEntity() {
+        // No-op constructor.
+    }
+
+    /**
+     * Creates a query entity with the given key and value types.
+     *
+     * @param keyType Key type.
+     * @param valType Value type.
+     */
+    public QueryEntity(String keyType, String valType) {
+        this.keyType = keyType;
+        this.valType = valType;
+    }
+
+    /**
      * Gets key type for this query pair.
      *
      * @return Key type.

http://git-wip-us.apache.org/repos/asf/ignite/blob/140fe193/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePrimitiveFieldsQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePrimitiveFieldsQuerySelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePrimitiveFieldsQuerySelfTest.java
new file mode 100644
index 0000000..19ce3f0
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePrimitiveFieldsQuerySelfTest.java
@@ -0,0 +1,134 @@
+/*
+ * 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.IgniteCache;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+
+/**
+ *
+ */
+public class IgniteCachePrimitiveFieldsQuerySelfTest extends GridCommonAbstractTest {
+    /** IP finder. */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** Cache name. */
+    private static final String CACHE_NAME = "cache";
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        cfg.setCacheConfiguration(cacheConfiguration(CACHE_NAME));
+
+        // Force BinaryMarshaller.
+        cfg.setMarshaller(null);
+
+        return cfg;
+    }
+
+    /**
+     * @param cacheName Cache name.
+     * @return Cache configuration.
+     */
+    private CacheConfiguration<Integer, IndexedType> cacheConfiguration(String cacheName)
{
+        CacheConfiguration<Integer, IndexedType> ccfg = new CacheConfiguration<>(cacheName);
+
+        QueryEntity entity = new QueryEntity(Integer.class.getName(), IndexedType.class.getName());
+
+        LinkedHashMap<String, String> fields = new LinkedHashMap<>();
+
+        // Test will pass if we use java.lang.Integer instead of int.
+        fields.put("iVal", "int");
+
+        entity.setFields(fields);
+
+        entity.setIndexes(F.asList(
+            new QueryIndex("iVal")
+        ));
+
+        ccfg.setQueryEntities(F.asList(entity));
+
+        return ccfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(3);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception if failed.
+     */
+    public void testStaticCache() throws Exception {
+        checkCache(ignite(0).<Integer, IndexedType>cache(CACHE_NAME));
+    }
+
+    /**
+     * @throws Exception if failed.
+     */
+    private void checkCache(IgniteCache<Integer, IndexedType> cache) throws Exception
{
+        for (int i = 0; i < 1000; i++)
+            cache.put(i, new IndexedType(i));
+
+        List<List<?>> res = cache.query(new SqlFieldsQuery("select avg(iVal)
from IndexedType where iVal > ?")
+            .setArgs(499)).getAll();
+
+        assertEquals(1, res.size());
+        assertEquals(1, res.get(0).size());
+    }
+
+    /**
+     * 
+     */
+    @SuppressWarnings("unused")
+    private static class IndexedType {
+        /** */
+        private int iVal;
+
+        /**
+         * @param iVal Value.
+         */
+        private IndexedType(int iVal) {
+            this.iVal = iVal;
+        }
+    }
+}


Mime
View raw message