geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [50/50] incubator-geode git commit: added test coverage for GetOperationContextImpl
Date Fri, 24 Jul 2015 23:16:13 GMT
added test coverage for GetOperationContextImpl


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

Branch: refs/heads/feature/GEODE-86
Commit: 11dfc07a16e698d24354351c7841a61d7b7338de
Parents: 98c31fa
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Fri Jul 24 16:14:22 2015 -0700
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Fri Jul 24 16:14:22 2015 -0700

----------------------------------------------------------------------
 .../cache/operations/GetOperationContext.java   |   1 +
 .../GetOperationContextImplJUnitTest.java       | 275 +++++++++++++++++++
 2 files changed, 276 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/11dfc07a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/operations/GetOperationContext.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/operations/GetOperationContext.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/operations/GetOperationContext.java
index ae1d034..ceb95b6 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/operations/GetOperationContext.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/operations/GetOperationContext.java
@@ -55,6 +55,7 @@ public class GetOperationContext extends KeyValueOperationContext {
    * 
    * @return the result of get operation; null when the result is a serialized
    *         value in which case user should invoke {@link #getSerializedValue()}
+   *         or {@link #getDeserializedValue()}.
    */
   public Object getObject() {
     if (super.getSerializedValue() != null) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/11dfc07a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/operations/internal/GetOperationContextImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/operations/internal/GetOperationContextImplJUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/operations/internal/GetOperationContextImplJUnitTest.java
new file mode 100644
index 0000000..8607468
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/operations/internal/GetOperationContextImplJUnitTest.java
@@ -0,0 +1,275 @@
+package com.gemstone.gemfire.cache.operations.internal;
+
+import static org.junit.Assert.*;
+import static org.junit.matchers.JUnitMatchers.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.matchers.JUnitMatchers;
+import org.junit.rules.ExpectedException;
+
+import com.gemstone.gemfire.DataSerializer;
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.cache.operations.PutOperationContextJUnitTest;
+import com.gemstone.gemfire.pdx.PdxInstance;
+import com.gemstone.gemfire.pdx.PdxReader;
+import com.gemstone.gemfire.pdx.PdxSerializable;
+import com.gemstone.gemfire.pdx.PdxWriter;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class GetOperationContextImplJUnitTest {
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+  
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+  }
+
+  @AfterClass
+  public static void tearDownAfterClass() throws Exception {
+  }
+
+  @Before
+  public void setUp() throws Exception {
+  }
+
+  @After
+  public void tearDown() throws Exception {
+  }
+
+  @Test
+  public void testGetSerializedValue() throws IOException {
+    {
+      byte[] byteArrayValue = new byte[]{1,2,3,4};
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject(byteArrayValue, false);
+      Assert.assertFalse(poc.isObject());
+      Assert.assertNull("value is an actual byte array which is not a serialized blob", poc.getSerializedValue());
+    }
+
+    {
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject(null, true);
+      Assert.assertTrue(poc.isObject());
+      Assert.assertNull("value is null which is not a serialized blob", poc.getSerializedValue());
+    }
+
+    {
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject("value", true);
+      Assert.assertTrue(poc.isObject());
+      Assert.assertNull("value is a String which is not a serialized blob", poc.getSerializedValue());
+    }
+
+    {
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      DataOutputStream dos = new DataOutputStream(baos);
+      DataSerializer.writeObject("value", dos);
+      dos.close();
+      byte[] blob = baos.toByteArray();
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject(blob, true);
+      Assert.assertTrue(poc.isObject());
+      Assert.assertArrayEquals(blob, poc.getSerializedValue());
+    }
+
+    {
+      // create a loner cache so that pdx serialization will work
+      Cache c = (new CacheFactory()).set("locators", "").set("mcast-port", "0").setPdxReadSerialized(true).create();
+      try {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DataOutputStream dos = new DataOutputStream(baos);
+        DataSerializer.writeObject(new PutOperationContextJUnitTest.PdxValue("value"), dos);
+        dos.close();
+        byte[] blob = baos.toByteArray();
+        GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+        poc.setObject(blob, true);
+        Assert.assertTrue(poc.isObject());
+        Assert.assertArrayEquals(blob, poc.getSerializedValue());
+      } finally {
+        c.close();
+      }
+    }
+  }
+
+  @Test
+  public void testGetDeserializedValue() throws IOException {
+    {
+      byte[] byteArrayValue = new byte[]{1,2,3,4};
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject(byteArrayValue, false);
+      Assert.assertFalse(poc.isObject());
+      Assert.assertArrayEquals(byteArrayValue, (byte[]) poc.getDeserializedValue());
+    }
+
+    {
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject(null, true);
+      Assert.assertTrue(poc.isObject());
+      Assert.assertEquals(null, poc.getDeserializedValue());
+    }
+
+    {
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject("value", true);
+      Assert.assertTrue(poc.isObject());
+      Assert.assertEquals("value", poc.getDeserializedValue());
+    }
+
+    {
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      DataOutputStream dos = new DataOutputStream(baos);
+      DataSerializer.writeObject("value", dos);
+      dos.close();
+      byte[] blob = baos.toByteArray();
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject(blob, true);
+      Assert.assertTrue(poc.isObject());
+      Assert.assertEquals("value", poc.getDeserializedValue());
+    }
+
+    {
+      // create a loner cache so that pdx serialization will work
+      Cache c = (new CacheFactory()).set("locators", "").set("mcast-port", "0").setPdxReadSerialized(true).create();
+      try {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DataOutputStream dos = new DataOutputStream(baos);
+        DataSerializer.writeObject(new PutOperationContextJUnitTest.PdxValue("value"), dos);
+        dos.close();
+        byte[] blob = baos.toByteArray();
+        GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+        poc.setObject(blob, true);
+        Assert.assertTrue(poc.isObject());
+        PdxInstance pi = (PdxInstance) poc.getDeserializedValue();
+        Assert.assertEquals("value", pi.getField("v"));
+      } finally {
+        c.close();
+      }
+    }
+  }
+
+  @Test
+  public void testGetValue() throws IOException {
+    {
+      byte[] byteArrayValue = new byte[]{1,2,3,4};
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject(byteArrayValue, false);
+      Assert.assertFalse(poc.isObject());
+      Assert.assertArrayEquals(byteArrayValue, (byte[]) poc.getValue());
+    }
+
+    {
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject(null, true);
+      Assert.assertTrue(poc.isObject());
+      Assert.assertEquals(null, poc.getValue());
+    }
+
+    {
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject("value", true);
+      Assert.assertTrue(poc.isObject());
+      Assert.assertEquals("value", poc.getValue());
+    }
+
+    {
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      DataOutputStream dos = new DataOutputStream(baos);
+      DataSerializer.writeObject("value", dos);
+      dos.close();
+      byte[] blob = baos.toByteArray();
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject(blob, true);
+      Assert.assertTrue(poc.isObject());
+      Assert.assertArrayEquals(blob, (byte[]) poc.getValue());
+    }
+
+    {
+      // create a loner cache so that pdx serialization will work
+      Cache c = (new CacheFactory()).set("locators", "").set("mcast-port", "0").setPdxReadSerialized(true).create();
+      try {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DataOutputStream dos = new DataOutputStream(baos);
+        DataSerializer.writeObject(new PutOperationContextJUnitTest.PdxValue("value"), dos);
+        dos.close();
+        byte[] blob = baos.toByteArray();
+        GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+        poc.setObject(blob, true);
+        Assert.assertTrue(poc.isObject());
+        Assert.assertArrayEquals(blob, (byte[]) poc.getValue());
+      } finally {
+        c.close();
+      }
+    }
+  }
+
+  @Test
+  public void testGetObject() throws IOException {
+    {
+      byte[] byteArrayValue = new byte[]{1,2,3,4};
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject(byteArrayValue, false);
+      Assert.assertFalse(poc.isObject());
+      Assert.assertArrayEquals(byteArrayValue, (byte[]) poc.getObject());
+    }
+
+    {
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject(null, true);
+      Assert.assertTrue(poc.isObject());
+      Assert.assertEquals(null, poc.getObject());
+    }
+
+    {
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject("value", true);
+      Assert.assertTrue(poc.isObject());
+      Assert.assertEquals("value", poc.getObject());
+    }
+
+    {
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      DataOutputStream dos = new DataOutputStream(baos);
+      DataSerializer.writeObject("value", dos);
+      dos.close();
+      byte[] blob = baos.toByteArray();
+      GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+      poc.setObject(blob, true);
+      Assert.assertTrue(poc.isObject());
+      Assert.assertNull("value is a serialized blob which is not an Object", poc.getObject());
+    }
+
+    {
+      // create a loner cache so that pdx serialization will work
+      Cache c = (new CacheFactory()).set("locators", "").set("mcast-port", "0").setPdxReadSerialized(true).create();
+      try {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        DataOutputStream dos = new DataOutputStream(baos);
+        DataSerializer.writeObject(new PutOperationContextJUnitTest.PdxValue("value"), dos);
+        dos.close();
+        byte[] blob = baos.toByteArray();
+        GetOperationContextImpl poc = new GetOperationContextImpl("key", true);
+        poc.setObject(blob, true);
+        Assert.assertTrue(poc.isObject());
+        Assert.assertNull("value is a serialized blob which is not an Object", poc.getObject());
+      } finally {
+        c.close();
+      }
+    }
+  }
+  // @TODO OFFHEAP: add coverage of "release" and the gettors methods with StoreObject and
off-heap Chunk values
+}


Mime
View raw message