ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [06/50] incubator-ignite git commit: # IGNITE-753 CacheEntryImpl implements Externalizable + test.
Date Mon, 20 Apr 2015 15:14:32 GMT
# IGNITE-753 CacheEntryImpl implements Externalizable + test.


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

Branch: refs/heads/gg-10115
Commit: f2cc14c1ee805f841b41d51d73c2321e9c004226
Parents: 30e318b
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Fri Apr 17 07:09:51 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Fri Apr 17 07:09:51 2015 +0700

----------------------------------------------------------------------
 .../processors/cache/CacheEntryImpl.java        |  29 +++-
 .../GridCacheQuerySerializationSelfTest.java    | 144 +++++++++++++++++++
 .../IgniteCacheQuerySelfTestSuite.java          |   2 +
 3 files changed, 172 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f2cc14c1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryImpl.java
index ebe5f09..3bd7ef4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryImpl.java
@@ -18,16 +18,27 @@
 package org.apache.ignite.internal.processors.cache;
 
 import javax.cache.*;
+import java.io.*;
 
 /**
  *
  */
-public class CacheEntryImpl<K, V> implements Cache.Entry<K, V> {
+public class CacheEntryImpl<K, V> implements Cache.Entry<K, V>, Externalizable
{
     /** */
-    private final K key;
+    private static final long serialVersionUID = 0L;
 
     /** */
-    private final V val;
+    private K key;
+
+    /** */
+    private V val;
+
+    /**
+     * Required by {@link Externalizable}.
+     */
+    public CacheEntryImpl() {
+        // No-op.
+    }
 
     /**
      * @param key Key.
@@ -58,6 +69,18 @@ public class CacheEntryImpl<K, V> implements Cache.Entry<K, V>
{
     }
 
     /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(key);
+        out.writeObject(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
+        key = (K)in.readObject();
+        val = (V)in.readObject();
+    }
+
+    /** {@inheritDoc} */
     public String toString() {
         return "Entry [key=" + key + ", val=" + val + ']';
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f2cc14c1/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQuerySerializationSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQuerySerializationSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQuerySerializationSelfTest.java
new file mode 100644
index 0000000..d42a440
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQuerySerializationSelfTest.java
@@ -0,0 +1,144 @@
+/*
+ * 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.*;
+import org.apache.ignite.cache.query.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import javax.cache.*;
+import java.util.*;
+
+import static org.apache.ignite.cache.CacheMode.*;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
+
+/**
+ * Tests for cache query results serialization.
+ */
+public class GridCacheQuerySerializationSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final int GRID_CNT = 2;
+
+    /** */
+    private static final String CACHE_NAME = "A";
+
+    /** */
+    private static final CacheMode CACHE_MODE = PARTITIONED;
+
+    /** */
+    private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        startGridsMultiThreaded(GRID_CNT);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(ipFinder);
+
+        cfg.setDiscoverySpi(disco);
+
+        CacheConfiguration cacheCfg = defaultCacheConfiguration();
+
+        cacheCfg.setName(CACHE_NAME);
+        cacheCfg.setCacheMode(CACHE_MODE);
+        cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
+        cacheCfg.setIndexedTypes(Integer.class, GridCacheQueryTestValue.class);
+
+        cfg.setCacheConfiguration(cacheCfg);
+
+        return cfg;
+    }
+
+    /**
+     * @return Test value.
+     */
+    private GridCacheQueryTestValue value(String f1, int f2, long f3) {
+        GridCacheQueryTestValue val = new GridCacheQueryTestValue();
+
+        val.setField1(f1);
+        val.setField2(f2);
+        val.setField3(f3);
+
+        return val;
+    }
+
+    /**
+     * Test that query result could be returned from remote node.
+     *
+     * @throws Exception In case of error.
+     */
+    public void testSerialization() throws Exception {
+        IgniteEx g0 = grid(0);
+
+        IgniteCache<Integer, GridCacheQueryTestValue> c0 = g0.cache(CACHE_NAME);
+        c0.put(1, value("A", 1, 1));
+        c0.put(2, value("B", 2, 2));
+
+        IgniteEx g1 = grid(1);
+        IgniteCache<Integer, GridCacheQueryTestValue> c1 = g1.cache(CACHE_NAME);
+        c1.put(3, value("C", 3, 3));
+        c1.put(4, value("D", 4, 4));
+
+        List<Cache.Entry<Integer, GridCacheQueryTestValue>> qryRes =
+            g0.compute(g0.cluster().forNode(g1.localNode())).withNoFailover().call(new QueryCallable());
+
+        assert !qryRes.isEmpty();
+
+        info(">>>> Query result:");
+
+        for (Cache.Entry<Integer, GridCacheQueryTestValue> entry : qryRes)
+            info(">>>>>>>" + entry.getKey() + " " + entry.getValue().getField1());
+    }
+
+    /** */
+    private static class QueryCallable implements IgniteCallable<List<Cache.Entry<Integer,
GridCacheQueryTestValue>>> {
+        /** */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /** {@inheritDoc} */
+        @Override public List<Cache.Entry<Integer, GridCacheQueryTestValue>>
call() throws Exception {
+            IgniteCache<Integer, GridCacheQueryTestValue> c = ignite.cache(CACHE_NAME);
+
+            String sqlStr = "FROM GridCacheQueryTestValue WHERE fieldname = ?";
+            SqlQuery<Integer, GridCacheQueryTestValue> sql = new SqlQuery<>(GridCacheQueryTestValue.class,
sqlStr);
+            sql.setArgs("C");
+
+            return c.query(sql.setSql(sqlStr)).getAll();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f2cc14c1/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 fe70c12..67fb421 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
@@ -67,6 +67,8 @@ public class IgniteCacheQuerySelfTestSuite extends TestSuite {
 //        suite.addTestSuite(IgniteCacheQueryNodeRestartSelfTest.class); TODO IGNITE-484
         suite.addTestSuite(GridCacheReduceQueryMultithreadedSelfTest.class);
         suite.addTestSuite(GridCacheCrossCacheQuerySelfTest.class);
+        suite.addTestSuite(GridCacheQuerySerializationSelfTest.class);
+
 
         // Fields queries.
         suite.addTestSuite(IgniteCacheLocalFieldsQuerySelfTest.class);


Mime
View raw message