You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2016/09/14 10:53:35 UTC

[30/35] ignite git commit: IGNITE-3172 Review.

IGNITE-3172 Review.


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

Branch: refs/heads/ignite-3199-1
Commit: 563c2765d51c1afafe5fd79b28804b9760d5389f
Parents: 231ead0
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Wed Sep 14 08:38:38 2016 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Wed Sep 14 08:38:38 2016 +0700

----------------------------------------------------------------------
 .../cassandra/serializer/KryoSerializer.java    |   8 +-
 .../apache/ignite/tests/KryoSerializerTest.java |  51 ++++--
 .../java/org/apache/ignite/tests/MyPojo.java    |  54 +++++++
 .../tests/DatasourceSerializationTest.java      | 158 -------------------
 .../tests/DatasourceSerializationTest.java      | 158 +++++++++++++++++++
 5 files changed, 257 insertions(+), 172 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/563c2765/modules/cassandra/serializers/src/main/java/org/apache/ignite/cache/store/cassandra/serializer/KryoSerializer.java
----------------------------------------------------------------------
diff --git a/modules/cassandra/serializers/src/main/java/org/apache/ignite/cache/store/cassandra/serializer/KryoSerializer.java b/modules/cassandra/serializers/src/main/java/org/apache/ignite/cache/store/cassandra/serializer/KryoSerializer.java
index 50cb9a2..775e501 100644
--- a/modules/cassandra/serializers/src/main/java/org/apache/ignite/cache/store/cassandra/serializer/KryoSerializer.java
+++ b/modules/cassandra/serializers/src/main/java/org/apache/ignite/cache/store/cassandra/serializer/KryoSerializer.java
@@ -20,12 +20,13 @@ package org.apache.ignite.cache.store.cassandra.serializer;
 import com.esotericsoftware.kryo.Kryo;
 import com.esotericsoftware.kryo.io.Input;
 import com.esotericsoftware.kryo.io.Output;
-import org.apache.ignite.internal.util.typedef.internal.U;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.nio.ByteBuffer;
 
+import org.apache.ignite.internal.util.typedef.internal.U;
+
 /**
  * Serializer based on Kryo serialization.
  */
@@ -36,9 +37,10 @@ public class KryoSerializer implements Serializer {
     /** */
     private static final int DFLT_BUFFER_SIZE = 4096;
 
-    /** Thread local instance of {@link com.esotericsoftware.kryo.Kryo} */
+    /** Thread local instance of {@link Kryo} */
     private transient ThreadLocal<Kryo> kryos = new ThreadLocal<Kryo>() {
-        protected Kryo initialValue() {
+        /** {@inheritDoc} */
+        @Override protected Kryo initialValue() {
             return new Kryo();
         }
     };

http://git-wip-us.apache.org/repos/asf/ignite/blob/563c2765/modules/cassandra/serializers/src/test/java/org/apache/ignite/tests/KryoSerializerTest.java
----------------------------------------------------------------------
diff --git a/modules/cassandra/serializers/src/test/java/org/apache/ignite/tests/KryoSerializerTest.java b/modules/cassandra/serializers/src/test/java/org/apache/ignite/tests/KryoSerializerTest.java
index 66f6c6a..3053c63 100644
--- a/modules/cassandra/serializers/src/test/java/org/apache/ignite/tests/KryoSerializerTest.java
+++ b/modules/cassandra/serializers/src/test/java/org/apache/ignite/tests/KryoSerializerTest.java
@@ -1,13 +1,40 @@
+/*
+ * 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.tests;
 
+import java.nio.ByteBuffer;
+import java.util.Date;
+
 import org.apache.ignite.cache.store.cassandra.serializer.KryoSerializer;
+
 import org.junit.Test;
 
-import java.nio.ByteBuffer;
-import java.util.Date;
+import static org.junit.Assert.assertEquals;
 
+/**
+ * Simple test for KryoSerializer.
+ */
 public class KryoSerializerTest {
-    @Test public void simpleTest() {
+    /**
+     * Serialize simple object test.
+     */
+    @Test
+    public void simpleTest() {
         MyPojo pojo1 = new MyPojo("123", 1, 123423453467L, new Date(), null);
 
         KryoSerializer ser = new KryoSerializer();
@@ -15,11 +42,14 @@ public class KryoSerializerTest {
         ByteBuffer buff = ser.serialize(pojo1);
         MyPojo pojo2 = (MyPojo)ser.deserialize(buff);
 
-        if (!pojo1.equals(pojo2))
-            throw new RuntimeException("Kryo simple serialization test failed");
+        assertEquals("Kryo simple serialization test failed", pojo1, pojo2);
     }
 
-    @Test public void cyclicStructureTest() {
+    /**
+     * Serialize object with cyclic references test.
+     */
+    @Test
+    public void cyclicStructureTest() {
         MyPojo pojo1 = new MyPojo("123", 1, 123423453467L, new Date(), null);
         MyPojo pojo2 = new MyPojo("321", 2, 123456L, new Date(), pojo1);
         pojo1.setRef(pojo2);
@@ -32,10 +62,9 @@ public class KryoSerializerTest {
         MyPojo pojo3 = (MyPojo)ser.deserialize(buff1);
         MyPojo pojo4 = (MyPojo)ser.deserialize(buff2);
 
-        if (!pojo1.equals(pojo3) || !pojo1.getRef().equals(pojo3.getRef()))
-            throw new RuntimeException("Kryo cyclic structure serialization test failed");
-
-        if (!pojo2.equals(pojo4) || !pojo2.getRef().equals(pojo4.getRef()))
-            throw new RuntimeException("Kryo cyclic structure serialization test failed");
+        assertEquals("Kryo cyclic structure serialization test failed", pojo1, pojo3);
+        assertEquals("Kryo cyclic structure serialization test failed", pojo1.getRef(), pojo3.getRef());
+        assertEquals("Kryo cyclic structure serialization test failed", pojo2, pojo4);
+        assertEquals("Kryo cyclic structure serialization test failed", pojo2.getRef(), pojo4.getRef());
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/563c2765/modules/cassandra/serializers/src/test/java/org/apache/ignite/tests/MyPojo.java
----------------------------------------------------------------------
diff --git a/modules/cassandra/serializers/src/test/java/org/apache/ignite/tests/MyPojo.java b/modules/cassandra/serializers/src/test/java/org/apache/ignite/tests/MyPojo.java
index 2161f25..f901db3 100644
--- a/modules/cassandra/serializers/src/test/java/org/apache/ignite/tests/MyPojo.java
+++ b/modules/cassandra/serializers/src/test/java/org/apache/ignite/tests/MyPojo.java
@@ -1,18 +1,60 @@
+/*
+ * 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.tests;
 
 import java.io.Serializable;
 import java.util.Date;
 
+/**
+ * Sample POJO for tests.
+ */
 public class MyPojo implements Serializable {
+    /** */
     private String field1;
+
+    /** */
     private int field2;
+
+    /** */
     private long field3;
+
+    /** */
     private Date field4;
+
+    /** */
     private MyPojo ref;
 
+    /**
+     * Empty constructor.
+     */
     public MyPojo() {
+        // No-op.
     }
 
+    /**
+     * Full constructor.
+     *
+     * @param field1 Some value.
+     * @param field2 Some value.
+     * @param field3 Some value.
+     * @param field4 Some value.
+     * @param ref Reference to other pojo.
+     */
     public MyPojo(String field1, int field2, long field3, Date field4, MyPojo ref) {
         this.field1 = field1;
         this.field2 = field2;
@@ -21,6 +63,12 @@ public class MyPojo implements Serializable {
         this.ref = ref;
     }
 
+    /**
+     * Compare POJOs.
+     *
+     * @param obj POJO to compare with.
+     * @return {@code true} if equals.
+     */
     public boolean equals(Object obj) {
         if (!(obj instanceof MyPojo))
             return false;
@@ -38,10 +86,16 @@ public class MyPojo implements Serializable {
         return field2 == myObj.field2 && field3 == myObj.field3;
     }
 
+    /**
+     * @param ref New reference.
+     */
     public void setRef(MyPojo ref) {
         this.ref = ref;
     }
 
+    /**
+     * @return Reference to some POJO.
+     */
     public MyPojo getRef() {
         return ref;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/563c2765/modules/cassandra/src/test/java/org/apache/ignite/tests/DatasourceSerializationTest.java
----------------------------------------------------------------------
diff --git a/modules/cassandra/src/test/java/org/apache/ignite/tests/DatasourceSerializationTest.java b/modules/cassandra/src/test/java/org/apache/ignite/tests/DatasourceSerializationTest.java
deleted file mode 100644
index ceb90e0..0000000
--- a/modules/cassandra/src/test/java/org/apache/ignite/tests/DatasourceSerializationTest.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * 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.tests;
-
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.ConsistencyLevel;
-import com.datastax.driver.core.Host;
-import com.datastax.driver.core.HostDistance;
-import com.datastax.driver.core.Statement;
-import com.datastax.driver.core.policies.LoadBalancingPolicy;
-import com.datastax.driver.core.policies.RoundRobinPolicy;
-import com.datastax.driver.core.policies.TokenAwarePolicy;
-
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.net.InetAddress;
-import java.nio.ByteBuffer;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.ignite.cache.store.cassandra.datasource.Credentials;
-import org.apache.ignite.cache.store.cassandra.datasource.DataSource;
-import org.apache.ignite.cache.store.cassandra.serializer.JavaSerializer;
-import org.apache.ignite.tests.utils.CassandraAdminCredentials;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * Test for datasource serialization.
- */
-public class DatasourceSerializationTest {
-    /**
-     * Sample class for serialization test.
-     */
-    private static class MyLoadBalancingPolicy implements LoadBalancingPolicy, Serializable {
-        /** */
-        private transient LoadBalancingPolicy plc = new TokenAwarePolicy(new RoundRobinPolicy());
-
-        /** {@inheritDoc} */
-        @Override public void init(Cluster cluster, Collection<Host> hosts) {
-            plc.init(cluster, hosts);
-        }
-
-        /** {@inheritDoc} */
-        @Override public HostDistance distance(Host host) {
-            return plc.distance(host);
-        }
-
-        /** {@inheritDoc} */
-        @Override public Iterator<Host> newQueryPlan(String loggedKeyspace, Statement statement) {
-            return plc.newQueryPlan(loggedKeyspace, statement);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void onAdd(Host host) {
-            plc.onAdd(host);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void onUp(Host host) {
-            plc.onUp(host);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void onDown(Host host) {
-            plc.onDown(host);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void onRemove(Host host) {
-            plc.onRemove(host);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void close() {
-            plc.close();
-        }
-    }
-
-    /**
-     * Serialization test.
-     */
-    @Test
-    public void serializationTest() {
-        DataSource src = new DataSource();
-
-        Credentials cred = new CassandraAdminCredentials();
-        String[] points = new String[]{"127.0.0.1", "10.0.0.2", "10.0.0.3"};
-        LoadBalancingPolicy plc = new MyLoadBalancingPolicy();
-
-        src.setCredentials(cred);
-        src.setContactPoints(points);
-        src.setReadConsistency("ONE");
-        src.setWriteConsistency("QUORUM");
-        src.setLoadBalancingPolicy(plc);
-
-        JavaSerializer serializer = new JavaSerializer();
-
-        ByteBuffer buff = serializer.serialize(src);
-        DataSource _src = (DataSource)serializer.deserialize(buff);
-
-        Credentials _cred = (Credentials)getFieldValue(_src, "creds");
-        List<InetAddress> _points = (List<InetAddress>)getFieldValue(_src, "contactPoints");
-        ConsistencyLevel _readCons = (ConsistencyLevel)getFieldValue(_src, "readConsistency");
-        ConsistencyLevel _writeCons = (ConsistencyLevel)getFieldValue(_src, "writeConsistency");
-        LoadBalancingPolicy _plc = (LoadBalancingPolicy)getFieldValue(_src, "loadBalancingPlc");
-
-        assertTrue("Incorrectly serialized/deserialized credentials for Cassandra DataSource",
-            cred.getPassword().equals(_cred.getPassword()) && cred.getUser().equals(_cred.getUser()));
-
-        assertTrue("Incorrectly serialized/deserialized contact points for Cassandra DataSource",
-            "/127.0.0.1".equals(_points.get(0).toString()) &&
-            "/10.0.0.2".equals(_points.get(1).toString()) &&
-            "/10.0.0.3".equals(_points.get(2).toString()));
-
-        assertTrue("Incorrectly serialized/deserialized consistency levels for Cassandra DataSource",
-            ConsistencyLevel.ONE == _readCons && ConsistencyLevel.QUORUM == _writeCons);
-
-        assertTrue("Incorrectly serialized/deserialized load balancing policy for Cassandra DataSource",
-            _plc instanceof MyLoadBalancingPolicy);
-    }
-
-    /**
-     * @param obj Object.
-     * @param field Field name.
-     * @return Field value.
-     */
-    private Object getFieldValue(Object obj, String field) {
-        try {
-            Field f = obj.getClass().getDeclaredField(field);
-
-            f.setAccessible(true);
-
-            return f.get(obj);
-        }
-        catch (Throwable e) {
-            throw new RuntimeException("Failed to get field '" + field + "' value", e);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/563c2765/modules/cassandra/store/src/test/java/org/apache/ignite/tests/DatasourceSerializationTest.java
----------------------------------------------------------------------
diff --git a/modules/cassandra/store/src/test/java/org/apache/ignite/tests/DatasourceSerializationTest.java b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/DatasourceSerializationTest.java
new file mode 100644
index 0000000..ceb90e0
--- /dev/null
+++ b/modules/cassandra/store/src/test/java/org/apache/ignite/tests/DatasourceSerializationTest.java
@@ -0,0 +1,158 @@
+/*
+ * 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.tests;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.ConsistencyLevel;
+import com.datastax.driver.core.Host;
+import com.datastax.driver.core.HostDistance;
+import com.datastax.driver.core.Statement;
+import com.datastax.driver.core.policies.LoadBalancingPolicy;
+import com.datastax.driver.core.policies.RoundRobinPolicy;
+import com.datastax.driver.core.policies.TokenAwarePolicy;
+
+import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.ignite.cache.store.cassandra.datasource.Credentials;
+import org.apache.ignite.cache.store.cassandra.datasource.DataSource;
+import org.apache.ignite.cache.store.cassandra.serializer.JavaSerializer;
+import org.apache.ignite.tests.utils.CassandraAdminCredentials;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test for datasource serialization.
+ */
+public class DatasourceSerializationTest {
+    /**
+     * Sample class for serialization test.
+     */
+    private static class MyLoadBalancingPolicy implements LoadBalancingPolicy, Serializable {
+        /** */
+        private transient LoadBalancingPolicy plc = new TokenAwarePolicy(new RoundRobinPolicy());
+
+        /** {@inheritDoc} */
+        @Override public void init(Cluster cluster, Collection<Host> hosts) {
+            plc.init(cluster, hosts);
+        }
+
+        /** {@inheritDoc} */
+        @Override public HostDistance distance(Host host) {
+            return plc.distance(host);
+        }
+
+        /** {@inheritDoc} */
+        @Override public Iterator<Host> newQueryPlan(String loggedKeyspace, Statement statement) {
+            return plc.newQueryPlan(loggedKeyspace, statement);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onAdd(Host host) {
+            plc.onAdd(host);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onUp(Host host) {
+            plc.onUp(host);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onDown(Host host) {
+            plc.onDown(host);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void onRemove(Host host) {
+            plc.onRemove(host);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void close() {
+            plc.close();
+        }
+    }
+
+    /**
+     * Serialization test.
+     */
+    @Test
+    public void serializationTest() {
+        DataSource src = new DataSource();
+
+        Credentials cred = new CassandraAdminCredentials();
+        String[] points = new String[]{"127.0.0.1", "10.0.0.2", "10.0.0.3"};
+        LoadBalancingPolicy plc = new MyLoadBalancingPolicy();
+
+        src.setCredentials(cred);
+        src.setContactPoints(points);
+        src.setReadConsistency("ONE");
+        src.setWriteConsistency("QUORUM");
+        src.setLoadBalancingPolicy(plc);
+
+        JavaSerializer serializer = new JavaSerializer();
+
+        ByteBuffer buff = serializer.serialize(src);
+        DataSource _src = (DataSource)serializer.deserialize(buff);
+
+        Credentials _cred = (Credentials)getFieldValue(_src, "creds");
+        List<InetAddress> _points = (List<InetAddress>)getFieldValue(_src, "contactPoints");
+        ConsistencyLevel _readCons = (ConsistencyLevel)getFieldValue(_src, "readConsistency");
+        ConsistencyLevel _writeCons = (ConsistencyLevel)getFieldValue(_src, "writeConsistency");
+        LoadBalancingPolicy _plc = (LoadBalancingPolicy)getFieldValue(_src, "loadBalancingPlc");
+
+        assertTrue("Incorrectly serialized/deserialized credentials for Cassandra DataSource",
+            cred.getPassword().equals(_cred.getPassword()) && cred.getUser().equals(_cred.getUser()));
+
+        assertTrue("Incorrectly serialized/deserialized contact points for Cassandra DataSource",
+            "/127.0.0.1".equals(_points.get(0).toString()) &&
+            "/10.0.0.2".equals(_points.get(1).toString()) &&
+            "/10.0.0.3".equals(_points.get(2).toString()));
+
+        assertTrue("Incorrectly serialized/deserialized consistency levels for Cassandra DataSource",
+            ConsistencyLevel.ONE == _readCons && ConsistencyLevel.QUORUM == _writeCons);
+
+        assertTrue("Incorrectly serialized/deserialized load balancing policy for Cassandra DataSource",
+            _plc instanceof MyLoadBalancingPolicy);
+    }
+
+    /**
+     * @param obj Object.
+     * @param field Field name.
+     * @return Field value.
+     */
+    private Object getFieldValue(Object obj, String field) {
+        try {
+            Field f = obj.getClass().getDeclaredField(field);
+
+            f.setAccessible(true);
+
+            return f.get(obj);
+        }
+        catch (Throwable e) {
+            throw new RuntimeException("Failed to get field '" + field + "' value", e);
+        }
+    }
+}