geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject incubator-geode git commit: GEODE-623: add unit test for RefCountChangeInfo
Date Tue, 08 Dec 2015 23:47:07 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/develop 476c6cd3b -> 68dfcab10


GEODE-623: add unit test for RefCountChangeInfo


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

Branch: refs/heads/develop
Commit: 68dfcab10d68b1babb2035bc4c87c93acf52077c
Parents: 476c6cd
Author: Scott Jewell <sjewell@pivotal.io>
Authored: Fri Dec 4 13:06:58 2015 -0800
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Tue Dec 8 15:45:57 2015 -0800

----------------------------------------------------------------------
 .../internal/offheap/RefCountChangeInfo.java    |  43 +++--
 .../offheap/RefCountChangeInfoJUnitTest.java    | 159 +++++++++++++++++++
 2 files changed, 185 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/68dfcab1/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfo.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfo.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfo.java
index 56cab97..67688ed 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfo.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfo.java
@@ -68,20 +68,11 @@ public class RefCountChangeInfo extends Throwable {
       ps.print("@");
       ps.print(System.identityHashCode(this.owner));
     }
+    
     ps.println(": ");
-    StackTraceElement[] trace = getStackTrace();
-    // skip the initial elements from SimpleMemoryAllocatorImpl
-    int skip=0;
-    for (int i=0; i < trace.length; i++) {
-      if (!trace[i].getClassName().contains("SimpleMemoryAllocatorImpl")) {
-        skip = i;
-        break;
-      }
-    }
-    for (int i=skip; i < trace.length; i++) {
-      ps.println("\tat " + trace[i]);
-    }
+    cleanStackTrace(ps); 
     ps.flush();
+    
     return baos.toString();
   }
   
@@ -99,14 +90,32 @@ public class RefCountChangeInfo extends Throwable {
   }
 
   private String stackTraceString;
-  private String getStackTraceString() {
+  String getStackTraceString() {
     String result = this.stackTraceString;
     if (result == null) {
-      StringPrintWriter spr = new StringPrintWriter();
-      printStackTrace(spr);
-      result = spr.getBuilder().toString();
-      this.stackTraceString = result;
+	ByteArrayOutputStream baos = new ByteArrayOutputStream(64*1024);
+	PrintStream spr = new PrintStream(baos);
+
+	cleanStackTrace(spr);
+	result = baos.toString();
+	this.stackTraceString = result;
     }
     return result;
   }
+  
+  private void cleanStackTrace(PrintStream ps) {
+      StackTraceElement[] trace = getStackTrace();
+      // skip the initial elements from the offheap package
+      int skip=0;
+      for (int i=0; i < trace.length; i++) {
+	if (!trace[i].getClassName().contains("com.gemstone.gemfire.internal.offheap")) {
+          skip = i;
+          break;
+        }
+      }
+      for (int i=skip; i < trace.length; i++) {
+        ps.println("\tat " + trace[i]);
+      }   
+  }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/68dfcab1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfoJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfoJUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfoJUnitTest.java
new file mode 100644
index 0000000..fc726ce
--- /dev/null
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfoJUnitTest.java
@@ -0,0 +1,159 @@
+/*
+ * 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 com.gemstone.gemfire.internal.offheap;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class RefCountChangeInfoJUnitTest {
+
+  @Before
+  public void setUp() throws Exception {
+  }
+
+  @After
+  public void tearDown() throws Exception {
+  }
+
+  @Test
+  public void testGetOwner() {
+
+    String owner1 = new String("Info1");
+    String notOwner1 = new String("notInfo1");
+
+    RefCountChangeInfo refInfo1 = new RefCountChangeInfo(true, 1, owner1);
+
+    assertEquals(owner1, refInfo1.getOwner());
+
+    try {
+      assertEquals(owner1, notOwner1);
+      fail("Expected owner1 != notOwner1");
+    } catch (AssertionError e) {
+      // Ignore expected error
+    }
+
+  }
+
+  @Test
+  public void testGetDupCount() {
+
+    String owner1 = new String("Info1");
+    String owner2 = new String("Info2");
+
+    RefCountChangeInfo refInfo1 = new RefCountChangeInfo(true, 1, owner1);
+    assertEquals(0, refInfo1.getDupCount());
+
+    RefCountChangeInfo refInfo2 = new RefCountChangeInfo(true, 1, owner1);
+    assertTrue(refInfo1.isDuplicate(refInfo2));
+    assertEquals(1, refInfo1.getDupCount());
+
+    // owner not used in isDup
+    RefCountChangeInfo refInfo3 = new RefCountChangeInfo(true, 1, owner2);
+    assertTrue(refInfo1.isDuplicate(refInfo3));
+    assertEquals(2, refInfo1.getDupCount());
+
+    RefCountChangeInfo refInfo4 = new RefCountChangeInfo(false, 1, owner2);
+    assertFalse(refInfo1.isDuplicate(refInfo4));
+    assertEquals(2, refInfo1.getDupCount());
+
+  }
+
+  @Test
+  public void testDecDupCount() {
+
+    String owner1 = new String("Info1");
+    String owner2 = new String("Info2");
+
+    RefCountChangeInfo refInfo1 = new RefCountChangeInfo(true, 1, owner1);
+    assertEquals(0, refInfo1.getDupCount());
+
+    RefCountChangeInfo refInfo2 = new RefCountChangeInfo(true, 1, owner1);
+    assertTrue(refInfo1.isDuplicate(refInfo2));
+    assertEquals(1, refInfo1.getDupCount());
+
+    // owner not used in isDuplicate check
+    RefCountChangeInfo refInfo3 = new RefCountChangeInfo(true, 1, owner2);
+    assertTrue(refInfo1.isDuplicate(refInfo3));
+    assertEquals(2, refInfo1.getDupCount());
+
+    refInfo1.decDupCount();
+    assertEquals(1, refInfo1.getDupCount());
+
+    refInfo1.decDupCount();
+    assertEquals(0, refInfo1.getDupCount());
+
+  }
+
+  @Test
+  public void testToString() {
+
+    String owner1 = new String("Info1");
+
+    RefCountChangeInfo refInfo1 = new RefCountChangeInfo(true, 1, owner1);
+
+    RefCountChangeInfo refInfo2 = new RefCountChangeInfo(true, 1, owner1);
+    assertEquals(refInfo1.toString(), refInfo2.toString());
+
+    RefCountChangeInfo refInfo3 = new RefCountChangeInfo(false, 1, owner1);
+    try {
+      assertEquals(refInfo1.toString(), refInfo3.toString());
+      fail("expected refInfo1.toString() != refInfo3.toString()");
+    } catch (AssertionError e) {
+      // ignore expected IllegalArgumentException
+    }
+
+    RefCountChangeInfo refInfo4 = new RefCountChangeInfo(true, 2, owner1);
+    try {
+      assertEquals(refInfo1.toString(), refInfo4.toString());
+      fail("expected refInfo1.toString() != refInfo4.toString()");
+    } catch (AssertionError e) {
+      // ignore expected IllegalArgumentException
+    }
+
+  }
+
+  @Test
+  public void testIsDuplicate() {
+
+    String owner1 = new String("Info1");
+    String owner2 = new String("Info2");
+
+    RefCountChangeInfo refInfo1 = new RefCountChangeInfo(true, 1, owner1);
+    assertEquals(0, refInfo1.getDupCount());
+
+    RefCountChangeInfo refInfo2 = new RefCountChangeInfo(true, 1, owner1);
+    assertTrue(refInfo1.isDuplicate(refInfo2));
+    assertEquals(1, refInfo1.getDupCount());
+
+    RefCountChangeInfo refInfo3 = new RefCountChangeInfo(false, 1, owner1);
+    assertFalse(refInfo1.isDuplicate(refInfo3));
+    assertEquals(1, refInfo1.getDupCount());
+
+    RefCountChangeInfo refInfo4 = new RefCountChangeInfo(true, 1, owner2);
+    assertTrue(refInfo1.isDuplicate(refInfo4));
+    assertEquals(2, refInfo1.getDupCount());
+
+  }
+
+}


Mime
View raw message