geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [geode] branch develop updated: GEODE-4487: Remove singleton calls from offheap package (#1382)
Date Mon, 05 Feb 2018 21:20:08 GMT
This is an automated email from the ASF dual-hosted git repository.

dschneider pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new c36a113  GEODE-4487: Remove singleton calls from offheap package (#1382)
c36a113 is described below

commit c36a11356efac2ca942fac97f27e39d47a496ede
Author: Darrel Schneider <dschneider@pivotal.io>
AuthorDate: Mon Feb 5 13:20:03 2018 -0800

    GEODE-4487: Remove singleton calls from offheap package (#1382)
    
    One test was using the singletons just to confirm the cache had been shutdown. It was
easy to change that test to not confirm the singleton was null but to instead ask if the test's
cache was closed.
    
    The other test was testing DataType which is product code that is only used by tests to
inspect what is stored in offheap memory. The test was mocking the singleton methods because
the product DataType was using the singleton to decode a serialized PDX. I changed DataType
to just do less decoding of pdx. Now it will just say it was a pdx and give you the type number.
---
 .../apache/geode/internal/offheap/DataType.java    |  31 +-----
 .../geode/internal/offheap/DataTypeJUnitTest.java  | 106 +--------------------
 .../offheap/OutOfOffHeapMemoryDUnitTest.java       |   6 +-
 3 files changed, 9 insertions(+), 134 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/offheap/DataType.java b/geode-core/src/main/java/org/apache/geode/internal/offheap/DataType.java
index a6f3e02..8513d23 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/offheap/DataType.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/offheap/DataType.java
@@ -21,15 +21,10 @@ import java.io.IOException;
 
 import org.apache.geode.DataSerializer;
 import org.apache.geode.Instantiator;
-import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.internal.DSCODE;
 import org.apache.geode.internal.DSFIDFactory;
 import org.apache.geode.internal.InternalDataSerializer;
 import org.apache.geode.internal.InternalInstantiator;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
-import org.apache.geode.internal.cache.InternalCache;
-import org.apache.geode.pdx.internal.EnumInfo;
-import org.apache.geode.pdx.internal.PdxType;
 
 /**
  * Determines the data type of the bytes in an off-heap MemoryBlock. This is used by the
tests for
@@ -200,30 +195,12 @@ public class DataType implements DSCODE {
         }
         case PDX: {
           int typeId = in.readInt();
-          try {
-            InternalCache gfc = GemFireCacheImpl
-                .getForPdx("PDX registry is unavailable because the Cache has been closed.");
-            PdxType pdxType = gfc.getPdxRegistry().getType(typeId);
-            if (pdxType == null) { // fix 52164
-              return "org.apache.geode.pdx.PdxInstance: unknown id=" + typeId;
-            }
-            return "org.apache.geode.pdx.PdxInstance:" + pdxType.getClassName();
-          } catch (CacheClosedException e) {
-            return "org.apache.geode.pdx.PdxInstance:PdxRegistryClosed";
-          }
+          return "pdxType:" + typeId;
         }
         case PDX_ENUM: {
-          int dsId = in.readByte();
-          int tmp = InternalDataSerializer.readArrayLength(in);
-          int enumId = (dsId << 24) | (tmp & 0xFFFFFF);
-          try {
-            InternalCache gfc = GemFireCacheImpl
-                .getForPdx("PDX registry is unavailable because the Cache has been closed.");
-            EnumInfo enumInfo = gfc.getPdxRegistry().getEnumInfoById(enumId);
-            return "PdxRegistry/java.lang.Enum:" + enumInfo.getClassName();
-          } catch (CacheClosedException e) {
-            return "PdxRegistry/java.lang.Enum:PdxRegistryClosed";
-          }
+          in.readByte(); // dsId is not needed
+          int enumId = InternalDataSerializer.readArrayLength(in);
+          return "pdxEnum:" + enumId;
         }
         case GEMFIRE_ENUM: {
           String name = DataSerializer.readString(in);
diff --git a/geode-core/src/test/java/org/apache/geode/internal/offheap/DataTypeJUnitTest.java
b/geode-core/src/test/java/org/apache/geode/internal/offheap/DataTypeJUnitTest.java
index b37ce70..913e901 100755
--- a/geode-core/src/test/java/org/apache/geode/internal/offheap/DataTypeJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/offheap/DataTypeJUnitTest.java
@@ -56,7 +56,6 @@ import org.powermock.modules.junit4.PowerMockRunner;
 
 import org.apache.geode.DataSerializer;
 import org.apache.geode.Instantiator;
-import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.distributed.internal.ReplyMessage;
 import org.apache.geode.internal.DSCODE;
 import org.apache.geode.internal.DSFIDFactory;
@@ -65,11 +64,7 @@ import org.apache.geode.internal.DataSerializableJUnitTest.DataSerializableImpl;
 import org.apache.geode.internal.InternalDataSerializer;
 import org.apache.geode.internal.InternalInstantiator;
 import org.apache.geode.internal.admin.remote.ShutdownAllResponse;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.execute.data.CustId;
-import org.apache.geode.pdx.internal.EnumInfo;
-import org.apache.geode.pdx.internal.PdxType;
-import org.apache.geode.pdx.internal.TypeRegistry;
 import org.apache.geode.test.junit.categories.UnitTest;
 
 /**
@@ -79,7 +74,7 @@ import org.apache.geode.test.junit.categories.UnitTest;
 @RunWith(PowerMockRunner.class)
 @PowerMockIgnore("*.UnitTest")
 @PrepareForTest({InternalInstantiator.class, Instantiator.class, DataSerializer.class,
-    GemFireCacheImpl.class, DSFIDFactory.class})
+    DSFIDFactory.class})
 public class DataTypeJUnitTest {
 
   @Test
@@ -816,64 +811,6 @@ public class DataTypeJUnitTest {
   @Test
   public void getDataTypeShouldReturnPDXType() throws IOException {
     int somePdxTypeInt = 1;
-    PdxType somePdxType = mock(PdxType.class);
-    doReturn("PDXType").when(somePdxType).getClassName();
-
-    TypeRegistry mockTypeRegistry = mock(TypeRegistry.class);
-    when(mockTypeRegistry.getType(somePdxTypeInt)).thenReturn(somePdxType);
-
-    GemFireCacheImpl pdxInstance = mock(GemFireCacheImpl.class);
-    when(pdxInstance.getPdxRegistry()).thenReturn(mockTypeRegistry);
-
-    PowerMockito.mockStatic(GemFireCacheImpl.class);
-    when(GemFireCacheImpl.getForPdx(anyString())).thenReturn(pdxInstance);
-
-    ByteArrayOutputStream baos = new ByteArrayOutputStream();
-    DataOutputStream out = new DataOutputStream(baos);
-    out.writeByte(DSCODE.PDX);
-    out.writeInt(somePdxTypeInt);
-    byte[] bytes = baos.toByteArray();
-    String type = DataType.getDataType(bytes);
-
-    assertThat(type).isEqualTo("org.apache.geode.pdx.PdxInstance:PDXType");
-  }
-
-  @Test
-  public void getDataTypeShouldReturnUnknownIfPDXTypeIsNull() throws IOException {
-    int somePdxTypeInt = 1;
-    PdxType somePdxType = null;
-
-    TypeRegistry mockTypeRegistry = mock(TypeRegistry.class);
-    when(mockTypeRegistry.getType(somePdxTypeInt)).thenReturn(somePdxType);
-
-    GemFireCacheImpl pdxInstance = mock(GemFireCacheImpl.class);
-    when(pdxInstance.getPdxRegistry()).thenReturn(mockTypeRegistry);
-
-    PowerMockito.mockStatic(GemFireCacheImpl.class);
-    when(GemFireCacheImpl
-        .getForPdx("PDX registry is unavailable because the Cache has been closed."))
-            .thenReturn(pdxInstance);
-
-    ByteArrayOutputStream baos = new ByteArrayOutputStream();
-    DataOutputStream out = new DataOutputStream(baos);
-    out.writeByte(DSCODE.PDX);
-    out.writeInt(somePdxTypeInt);
-    byte[] bytes = baos.toByteArray();
-    String type = DataType.getDataType(bytes);
-
-    assertThat(type).isEqualTo("org.apache.geode.pdx.PdxInstance: unknown id=" + somePdxTypeInt);
-  }
-
-  @Test
-  public void getDataTypeShouldReturnPDXRegistryClosedForPDXTypeWhenCacheIsClosed()
-      throws IOException {
-    int somePdxTypeInt = 1;
-
-    PowerMockito.mockStatic(GemFireCacheImpl.class);
-    when(GemFireCacheImpl
-        .getForPdx("PDX registry is unavailable because the Cache has been closed."))
-            .thenThrow(CacheClosedException.class);
-
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     DataOutputStream out = new DataOutputStream(baos);
     out.writeByte(DSCODE.PDX);
@@ -881,54 +818,19 @@ public class DataTypeJUnitTest {
     byte[] bytes = baos.toByteArray();
     String type = DataType.getDataType(bytes);
 
-    assertThat(type).isEqualTo("org.apache.geode.pdx.PdxInstance:PdxRegistryClosed");
+    assertThat(type).isEqualTo("pdxType:1");
   }
 
   @Test
   public void getDataTypeShouldReturnPDXEnumType() throws IOException {
     int somePdxEnumId = 1;
-    EnumInfo somePdxEnumInfo = mock(EnumInfo.class);
-    doReturn("PDXENUM").when(somePdxEnumInfo).getClassName();
-
-    TypeRegistry mockTypeRegistry = mock(TypeRegistry.class);
-    when(mockTypeRegistry.getEnumInfoById(0)).thenReturn(somePdxEnumInfo);
-
-    GemFireCacheImpl pdxInstance = mock(GemFireCacheImpl.class);
-    when(pdxInstance.getPdxRegistry()).thenReturn(mockTypeRegistry);
-
-    PowerMockito.mockStatic(GemFireCacheImpl.class);
-    when(GemFireCacheImpl
-        .getForPdx("PDX registry is unavailable because the Cache has been closed."))
-            .thenReturn(pdxInstance);
-
-    ByteArrayOutputStream baos = new ByteArrayOutputStream();
-    DataOutputStream out = new DataOutputStream(baos);
-    out.writeByte(DSCODE.PDX_ENUM);
-    out.writeInt(somePdxEnumId);
-    byte[] bytes = baos.toByteArray();
-    String type = DataType.getDataType(bytes);
-
-    assertThat(type).isEqualTo("PdxRegistry/java.lang.Enum:PDXENUM");
-  }
-
-  @Test
-  public void getDataTypeShouldReturnPDXRegistryClosedForEnumTypeWhenCacheIsClosed()
-      throws IOException {
-    int someArrayLength = 1;
-
-    PowerMockito.mockStatic(GemFireCacheImpl.class);
-    when(GemFireCacheImpl
-        .getForPdx("PDX registry is unavailable because the Cache has been closed."))
-            .thenThrow(CacheClosedException.class);
-
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     DataOutputStream out = new DataOutputStream(baos);
-    out.writeByte(DSCODE.PDX_ENUM);
-    out.writeInt(someArrayLength);
+    InternalDataSerializer.writePdxEnumId(somePdxEnumId, out);
     byte[] bytes = baos.toByteArray();
     String type = DataType.getDataType(bytes);
 
-    assertThat(type).isEqualTo("PdxRegistry/java.lang.Enum:PdxRegistryClosed");
+    assertThat(type).isEqualTo("pdxEnum:1");
   }
 
   @Test
diff --git a/geode-core/src/test/java/org/apache/geode/internal/offheap/OutOfOffHeapMemoryDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/internal/offheap/OutOfOffHeapMemoryDUnitTest.java
index cc2b970..2ca0e45 100755
--- a/geode-core/src/test/java/org/apache/geode/internal/offheap/OutOfOffHeapMemoryDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/offheap/OutOfOffHeapMemoryDUnitTest.java
@@ -37,7 +37,6 @@ import org.apache.geode.distributed.DistributedSystemDisconnectedException;
 import org.apache.geode.distributed.internal.ClusterDistributionManager;
 import org.apache.geode.distributed.internal.InternalDistributedSystem;
 import org.apache.geode.internal.cache.DistributedRegion;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.OffHeapTestUtil;
 import org.apache.geode.internal.util.StopWatch;
 import org.apache.geode.test.dunit.Host;
@@ -146,10 +145,7 @@ public class OutOfOffHeapMemoryDUnitTest extends JUnit4CacheTestCase
{
 
     // wait for cache instance to be nulled out
     with().pollInterval(100, TimeUnit.MILLISECONDS).await().atMost(10, TimeUnit.SECONDS)
-        .until(() -> GemFireCacheImpl.getInstance() == null
-            && InternalDistributedSystem.getAnyInstance() == null);
-
-    assertNull(GemFireCacheImpl.getInstance());
+        .until(() -> cache.isClosed() && !system.isConnected());
 
     // verify system was closed out due to OutOfOffHeapMemoryException
     assertFalse(system.isConnected());

-- 
To stop receiving notification emails like this one, please contact
dschneider@apache.org.

Mime
View raw message