You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by sa...@apache.org on 2016/05/24 18:53:46 UTC
[05/55] [abbrv] incubator-geode git commit: GEODE-1276: Change
UnitTests file system to IntegrationTest category GEODE-1307: Rename
HeterogenousLuceneSerializer to HeterogeneousLuceneSerializer GEODE-1279:
Tests for old TRAC bugs should be renamed to use
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectSliceJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectSliceJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectSliceJUnitTest.java
index 1b5bf26..09c0f59 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectSliceJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectSliceJUnitTest.java
@@ -14,11 +14,9 @@
* 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.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.experimental.categories.Category;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectWithHeapFormJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectWithHeapFormJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectWithHeapFormJUnitTest.java
index a763e76..8193b15 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectWithHeapFormJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapStoredObjectWithHeapFormJUnitTest.java
@@ -14,14 +14,9 @@
* 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.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
+import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.experimental.categories.Category;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
index 5d79192..7498670 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
@@ -19,7 +19,6 @@ package com.gemstone.gemfire.internal.offheap;
import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
-import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
@@ -31,11 +30,6 @@ import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.DataSerializer;
import com.gemstone.gemfire.internal.HeapDataOutputStream;
import com.gemstone.gemfire.internal.cache.EntryEventImpl;
-import com.gemstone.gemfire.internal.offheap.NullOffHeapMemoryStats;
-import com.gemstone.gemfire.internal.offheap.NullOutOfOffHeapMemoryListener;
-import com.gemstone.gemfire.internal.offheap.MemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.StoredObject;
-import com.gemstone.gemfire.internal.offheap.SlabImpl;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
@Category(UnitTest.class)
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfoJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfoJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfoJUnitTest.java
index 99f4ed8..d02717a 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfoJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/RefCountChangeInfoJUnitTest.java
@@ -18,8 +18,6 @@ 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;
@@ -28,14 +26,6 @@ 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() {
@@ -192,7 +182,7 @@ public class RefCountChangeInfoJUnitTest {
}
- class SameHashDifferentTrace {
+ private static class SameHashDifferentTrace {
public int hashCode() {
return 1;
@@ -202,6 +192,4 @@ public class RefCountChangeInfoJUnitTest {
return false;
}
}
-
-
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/TinyMemoryBlockJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/TinyMemoryBlockJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/TinyMemoryBlockJUnitTest.java
index 681bec0..2e1bd6a 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/TinyMemoryBlockJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/TinyMemoryBlockJUnitTest.java
@@ -14,7 +14,6 @@
* 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.*;
@@ -42,18 +41,7 @@ public class TinyMemoryBlockJUnitTest {
private MemoryAllocatorImpl ma;
private OutOfOffHeapMemoryListener ooohml;
private OffHeapMemoryStats stats;
-
- private Slab[] slabs = {
- new SlabImpl((int)OffHeapStorage.MIN_SLAB_SIZE),
- new SlabImpl((int)OffHeapStorage.MIN_SLAB_SIZE),
- new SlabImpl((int)OffHeapStorage.MIN_SLAB_SIZE)
- };
-
- private static class TestableFreeListManager extends FreeListManager {
- TestableFreeListManager(MemoryAllocatorImpl ma, final Slab[] slabs) {
- super (ma, slabs);
- }
- }
+ private Slab[] slabs;
@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -61,16 +49,13 @@ public class TinyMemoryBlockJUnitTest {
@Rule
public JUnitSoftAssertions softly = new JUnitSoftAssertions();
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- }
-
@Before
public void setUp() throws Exception {
+ slabs = new Slab[] {
+ new SlabImpl((int)OffHeapStorage.MIN_SLAB_SIZE),
+ new SlabImpl((int)OffHeapStorage.MIN_SLAB_SIZE),
+ new SlabImpl((int)OffHeapStorage.MIN_SLAB_SIZE)
+ };
ooohml = mock(OutOfOffHeapMemoryListener.class);
stats = mock(OffHeapMemoryStats.class);
ma = (MemoryAllocatorImpl) MemoryAllocatorImpl.createForUnitTest(ooohml, stats, slabs);
@@ -241,4 +226,10 @@ public class TinyMemoryBlockJUnitTest {
softly.assertThat(mb.hashCode()).isEqualTo(new OffHeapStoredObject(slabs[0].getMemoryAddress(), slabs[0].getSize()).hashCode());
}
+ private static class TestableFreeListManager extends FreeListManager {
+ TestableFreeListManager(MemoryAllocatorImpl ma, final Slab[] slabs) {
+ super (ma, slabs);
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/TinyStoredObjectJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/TinyStoredObjectJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/TinyStoredObjectJUnitTest.java
index 94559d6..56a93db 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/TinyStoredObjectJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/offheap/TinyStoredObjectJUnitTest.java
@@ -14,340 +14,334 @@
* 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 static org.mockito.Mockito.*;
+
+import java.nio.ByteBuffer;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
import com.gemstone.gemfire.compression.Compressor;
import com.gemstone.gemfire.internal.cache.BytesAndBitsForCompactor;
import com.gemstone.gemfire.internal.cache.CachePerfStats;
import com.gemstone.gemfire.internal.cache.EntryEventImpl;
import com.gemstone.gemfire.internal.cache.RegionEntryContext;
-import com.gemstone.gemfire.internal.offheap.TinyStoredObject;
-
-import com.gemstone.gemfire.internal.offheap.OffHeapRegionEntryHelper;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.mockito.Mock;
-
-import java.nio.ByteBuffer;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.*;
@Category(UnitTest.class)
public class TinyStoredObjectJUnitTest extends AbstractStoredObjectTestBase {
- @Override
- public Object getValue() {
- return Integer.valueOf(123456789);
+ @Override
+ public Object getValue() {
+ return Integer.valueOf(123456789);
+ }
+
+ @Override
+ public byte[] getValueAsByteArray() {
+ return convertValueToByteArray(getValue());
+ }
+
+ private byte[] convertValueToByteArray(Object value) {
+ return ByteBuffer.allocate(Integer.SIZE / Byte.SIZE).putInt((Integer) value).array();
+ }
+
+ @Override
+ public Object convertByteArrayToObject(byte[] valueInByteArray) {
+ return ByteBuffer.wrap(valueInByteArray).getInt();
+ }
+
+ @Override
+ public Object convertSerializedByteArrayToObject(byte[] valueInSerializedByteArray) {
+ return EntryEventImpl.deserialize(valueInSerializedByteArray);
+ }
+
+ @Override
+ public TinyStoredObject createValueAsUnserializedStoredObject(Object value) {
+ byte[] valueInByteArray;
+ if (value instanceof Integer) {
+ valueInByteArray = convertValueToByteArray(value);
+ } else {
+ valueInByteArray = (byte[]) value;
}
+ //encode a non-serialized entry value to address
+ long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(valueInByteArray, false, false);
+ return new TinyStoredObject(encodedAddress);
+ }
+
+ @Override
+ public TinyStoredObject createValueAsSerializedStoredObject(Object value) {
+ byte[] valueInSerializedByteArray = EntryEventImpl.serialize(value);
+ //encode a serialized entry value to address
+ long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(valueInSerializedByteArray, true, false);
+ return new TinyStoredObject(encodedAddress);
+ }
+
+ public TinyStoredObject createValueAsCompressedStoredObject(Object value) {
+ byte[] valueInSerializedByteArray = EntryEventImpl.serialize(value);
+ //encode a serialized, compressed entry value to address
+ long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(valueInSerializedByteArray, true, true);
+ return new TinyStoredObject(encodedAddress);
+ }
+
+ public TinyStoredObject createValueAsUncompressedStoredObject(Object value) {
+ byte[] valueInSerializedByteArray = EntryEventImpl.serialize(value);
+ //encode a serialized, uncompressed entry value to address
+ long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(valueInSerializedByteArray, true, false);
+ return new TinyStoredObject(encodedAddress);
+ }
+
+ @Test
+ public void shouldReturnCorrectEncodingAddress() {
+
+ TinyStoredObject address1 = new TinyStoredObject(10001L);
+ assertNotNull(address1);
+ assertEquals("Encoding address should be:", 10001, address1.getAddress());
+
+ TinyStoredObject address2 = new TinyStoredObject(10002L);
+ assertNotNull(address2);
+ assertEquals("Returning always 10001 expected 10002", 10002, address2.getAddress());
+ }
- @Override
- public byte[] getValueAsByteArray() {
- return convertValueToByteArray(getValue());
- }
+ @Test
+ public void twoAddressesShouldBeEqualIfEncodingAddressIsSame() {
+ TinyStoredObject address1 = new TinyStoredObject(10001L);
+ TinyStoredObject address2 = new TinyStoredObject(10001L);
+
+ assertEquals("Two addresses are equal if encoding address is same", true, address1.equals(address2));
+ }
- private byte[] convertValueToByteArray(Object value) {
- return ByteBuffer.allocate(Integer.SIZE / Byte.SIZE).putInt((Integer) value).array();
- }
+ @Test
+ public void twoAddressesShouldNotBeEqualIfEncodingAddressIsNotSame() {
+ TinyStoredObject address1 = new TinyStoredObject(10001L);
+ TinyStoredObject address2 = new TinyStoredObject(10002L);
+
+ assertEquals("Two addresses are not equal if encoding address is not same", false, address1.equals(address2));
+ }
- @Override
- public Object convertByteArrayToObject(byte[] valueInByteArray) {
- return ByteBuffer.wrap(valueInByteArray).getInt();
- }
+ @Test
+ public void twoAddressesAreNotEqualIfTheyAreNotTypeDataAsAddress() {
+ TinyStoredObject address1 = new TinyStoredObject(10001L);
+ Long address2 = new Long(10002L);
+
+ assertEquals("Two addresses are not equal if encoding address is not same", false, address1.equals(address2));
+ }
- @Override
- public Object convertSerializedByteArrayToObject(byte[] valueInSerializedByteArray) {
- return EntryEventImpl.deserialize(valueInSerializedByteArray);
- }
+ @Test
+ public void addressHashCodeShouldBe() {
+ TinyStoredObject address1 = new TinyStoredObject(10001L);
+ assertEquals("", 10001, address1.hashCode());
+ }
- @Override
- public TinyStoredObject createValueAsUnserializedStoredObject(Object value) {
- byte[] valueInByteArray;
- if(value instanceof Integer) {
- valueInByteArray = convertValueToByteArray(value);
- } else {
- valueInByteArray = (byte[]) value;
- }
- //encode a non-serialized entry value to address
- long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(valueInByteArray, false, false);
- return new TinyStoredObject(encodedAddress);
- }
+ @Test
+ public void getSizeInBytesAlwaysReturnsZero() {
+ TinyStoredObject address1 = new TinyStoredObject(10001L);
+ TinyStoredObject address2 = new TinyStoredObject(10002L);
- @Override
- public TinyStoredObject createValueAsSerializedStoredObject(Object value) {
- byte[] valueInSerializedByteArray = EntryEventImpl.serialize(value);
- //encode a serialized entry value to address
- long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(valueInSerializedByteArray, true, false);
- return new TinyStoredObject(encodedAddress);
- }
+ assertEquals("getSizeInBytes", 0, address1.getSizeInBytes());
+ assertEquals("getSizeInBytes", 0, address2.getSizeInBytes());
+ }
- public TinyStoredObject createValueAsCompressedStoredObject(Object value) {
- byte[] valueInSerializedByteArray = EntryEventImpl.serialize(value);
- //encode a serialized, compressed entry value to address
- long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(valueInSerializedByteArray, true, true);
- return new TinyStoredObject(encodedAddress);
- }
+ @Test
+ public void getValueSizeInBytesAlwaysReturnsZero() {
+ TinyStoredObject address1 = new TinyStoredObject(10001L);
+ TinyStoredObject address2 = new TinyStoredObject(10002L);
- public TinyStoredObject createValueAsUncompressedStoredObject(Object value) {
- byte[] valueInSerializedByteArray = EntryEventImpl.serialize(value);
- //encode a serialized, uncompressed entry value to address
- long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(valueInSerializedByteArray, true, false);
- return new TinyStoredObject(encodedAddress);
- }
+ assertEquals("getSizeInBytes", 0, address1.getValueSizeInBytes());
+ assertEquals("getSizeInBytes", 0, address2.getValueSizeInBytes());
+ }
- @Test
- public void shouldReturnCorrectEncodingAddress() {
+ @Test
+ public void isCompressedShouldReturnTrueIfCompressed() {
+ Object regionEntryValue = getValue();
- TinyStoredObject address1 = new TinyStoredObject(10001L);
- assertNotNull(address1);
- assertEquals("Encoding address should be:", 10001, address1.getAddress());
+ TinyStoredObject offheapAddress = createValueAsCompressedStoredObject(regionEntryValue);
- TinyStoredObject address2 = new TinyStoredObject(10002L);
- assertNotNull(address2);
- assertEquals("Returning always 10001 expected 10002", 10002, address2.getAddress());
- }
+ assertEquals("Should return true as it is compressed", true, offheapAddress.isCompressed());
+ }
- @Test
- public void twoAddressesShouldBeEqualIfEncodingAddressIsSame() {
- TinyStoredObject address1 = new TinyStoredObject(10001L);
- TinyStoredObject address2 = new TinyStoredObject(10001L);
+ @Test
+ public void isCompressedShouldReturnFalseIfNotCompressed() {
+ Object regionEntryValue = getValue();
- assertEquals("Two addresses are equal if encoding address is same", true, address1.equals(address2));
- }
+ TinyStoredObject offheapAddress = createValueAsUncompressedStoredObject(regionEntryValue);
- @Test
- public void twoAddressesShouldNotBeEqualIfEncodingAddressIsNotSame() {
- TinyStoredObject address1 = new TinyStoredObject(10001L);
- TinyStoredObject address2 = new TinyStoredObject(10002L);
+ assertEquals("Should return false as it is compressed", false, offheapAddress.isCompressed());
+ }
- assertEquals("Two addresses are not equal if encoding address is not same", false, address1.equals(address2));
- }
+ @Test
+ public void isSerializedShouldReturnTrueIfSeriazlied() {
+ Object regionEntryValue = getValue();
- @Test
- public void twoAddressesAreNotEqualIfTheyAreNotTypeDataAsAddress() {
- TinyStoredObject address1 = new TinyStoredObject(10001L);
- Long address2 = new Long(10002L);
+ TinyStoredObject offheapAddress = createValueAsSerializedStoredObject(regionEntryValue);
- assertEquals("Two addresses are not equal if encoding address is not same", false, address1.equals(address2));
- }
+ assertEquals("Should return true as it is serialized", true, offheapAddress.isSerialized());
+ }
- @Test
- public void addressHashCodeShouldBe() {
- TinyStoredObject address1 = new TinyStoredObject(10001L);
- assertEquals("", 10001, address1.hashCode());
- }
+ @Test
+ public void isSerializedShouldReturnFalseIfNotSeriazlied() {
+ Object regionEntryValue = getValue();
- @Test
- public void getSizeInBytesAlwaysReturnsZero() {
- TinyStoredObject address1 = new TinyStoredObject(10001L);
- TinyStoredObject address2 = new TinyStoredObject(10002L);
+ TinyStoredObject offheapAddress = createValueAsUnserializedStoredObject(regionEntryValue);
- assertEquals("getSizeInBytes", 0, address1.getSizeInBytes());
- assertEquals("getSizeInBytes", 0, address2.getSizeInBytes());
- }
+ assertEquals("Should return false as it is serialized", false, offheapAddress.isSerialized());
+ }
- @Test
- public void getValueSizeInBytesAlwaysReturnsZero() {
- TinyStoredObject address1 = new TinyStoredObject(10001L);
- TinyStoredObject address2 = new TinyStoredObject(10002L);
+ @Test
+ public void getDecompressedBytesShouldReturnDecompressedBytesIfCompressed() {
+ Object regionEntryValue = getValue();
+ byte[] regionEntryValueAsBytes = convertValueToByteArray(regionEntryValue);
- assertEquals("getSizeInBytes", 0, address1.getValueSizeInBytes());
- assertEquals("getSizeInBytes", 0, address2.getValueSizeInBytes());
- }
-
- @Test
- public void isCompressedShouldReturnTrueIfCompressed() {
- Object regionEntryValue = getValue();
-
- TinyStoredObject offheapAddress = createValueAsCompressedStoredObject(regionEntryValue);
-
- assertEquals("Should return true as it is compressed", true, offheapAddress.isCompressed());
- }
-
- @Test
- public void isCompressedShouldReturnFalseIfNotCompressed() {
- Object regionEntryValue = getValue();
-
- TinyStoredObject offheapAddress = createValueAsUncompressedStoredObject(regionEntryValue);
-
- assertEquals("Should return false as it is compressed", false, offheapAddress.isCompressed());
- }
-
- @Test
- public void isSerializedShouldReturnTrueIfSeriazlied() {
- Object regionEntryValue = getValue();
-
- TinyStoredObject offheapAddress = createValueAsSerializedStoredObject(regionEntryValue);
-
- assertEquals("Should return true as it is serialized", true, offheapAddress.isSerialized());
- }
-
- @Test
- public void isSerializedShouldReturnFalseIfNotSeriazlied() {
- Object regionEntryValue = getValue();
+ //encode a non-serialized and compressed entry value to address - last argument is to let that it is compressed
+ long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(regionEntryValueAsBytes, false, true);
+ TinyStoredObject offheapAddress = new TinyStoredObject(encodedAddress);
- TinyStoredObject offheapAddress = createValueAsUnserializedStoredObject(regionEntryValue);
+ RegionEntryContext regionContext = mock(RegionEntryContext.class);
+ CachePerfStats cacheStats = mock(CachePerfStats.class);
+ Compressor compressor = mock(Compressor.class);
- assertEquals("Should return false as it is serialized", false, offheapAddress.isSerialized());
- }
-
- @Test
- public void getDecompressedBytesShouldReturnDecompressedBytesIfCompressed() {
- Object regionEntryValue = getValue();
- byte[] regionEntryValueAsBytes = convertValueToByteArray(regionEntryValue);
+ long startTime = 10000L;
- //encode a non-serialized and compressed entry value to address - last argument is to let that it is compressed
- long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(regionEntryValueAsBytes, false, true);
- TinyStoredObject offheapAddress = new TinyStoredObject(encodedAddress);
+ //mock required things
+ when(regionContext.getCompressor()).thenReturn(compressor);
+ when(compressor.decompress(regionEntryValueAsBytes)).thenReturn(regionEntryValueAsBytes);
+ when(regionContext.getCachePerfStats()).thenReturn(cacheStats);
+ when(cacheStats.startDecompression()).thenReturn(startTime);
- RegionEntryContext regionContext = mock(RegionEntryContext.class);
- CachePerfStats cacheStats = mock(CachePerfStats.class);
- Compressor compressor = mock(Compressor.class);
+ //invoke the thing
+ byte[] bytes = offheapAddress.getDecompressedBytes(regionContext);
- long startTime = 10000L;
+ //verify the thing happened
+ verify(cacheStats, atLeastOnce()).startDecompression();
+ verify(compressor, times(1)).decompress(regionEntryValueAsBytes);
+ verify(cacheStats, atLeastOnce()).endDecompression(startTime);
- //mock required things
- when(regionContext.getCompressor()).thenReturn(compressor);
- when(compressor.decompress(regionEntryValueAsBytes)).thenReturn(regionEntryValueAsBytes);
- when(regionContext.getCachePerfStats()).thenReturn(cacheStats);
- when(cacheStats.startDecompression()).thenReturn(startTime);
+ assertArrayEquals(regionEntryValueAsBytes, bytes);
+ }
- //invoke the thing
- byte[] bytes = offheapAddress.getDecompressedBytes(regionContext);
+ @Test
+ public void getDecompressedBytesShouldNotTryToDecompressIfNotCompressed() {
+ Object regionEntryValue = getValue();
- //verify the thing happened
- verify(cacheStats, atLeastOnce()).startDecompression();
- verify(compressor, times(1)).decompress(regionEntryValueAsBytes);
- verify(cacheStats, atLeastOnce()).endDecompression(startTime);
-
- assertArrayEquals(regionEntryValueAsBytes, bytes);
- }
+ TinyStoredObject offheapAddress = createValueAsUncompressedStoredObject(regionEntryValue);
- @Test
- public void getDecompressedBytesShouldNotTryToDecompressIfNotCompressed() {
- Object regionEntryValue = getValue();
+ //mock the thing
+ RegionEntryContext regionContext = mock(RegionEntryContext.class);
+ Compressor compressor = mock(Compressor.class);
+ when(regionContext.getCompressor()).thenReturn(compressor);
- TinyStoredObject offheapAddress = createValueAsUncompressedStoredObject(regionEntryValue);
+ //invoke the thing
+ byte[] actualValueInBytes = offheapAddress.getDecompressedBytes(regionContext);
- //mock the thing
- RegionEntryContext regionContext = mock(RegionEntryContext.class);
- Compressor compressor = mock(Compressor.class);
- when(regionContext.getCompressor()).thenReturn(compressor);
+ //createValueAsUncompressedStoredObject does uses a serialized value - so convert it to object
+ Object actualRegionValue = convertSerializedByteArrayToObject(actualValueInBytes);
- //invoke the thing
- byte[] actualValueInBytes = offheapAddress.getDecompressedBytes(regionContext);
-
- //createValueAsUncompressedStoredObject does uses a serialized value - so convert it to object
- Object actualRegionValue = convertSerializedByteArrayToObject(actualValueInBytes);
-
- //verify the thing happened
- verify(regionContext, never()).getCompressor();
- assertEquals(regionEntryValue, actualRegionValue);
- }
+ //verify the thing happened
+ verify(regionContext, never()).getCompressor();
+ assertEquals(regionEntryValue, actualRegionValue);
+ }
- @Test
- public void getRawBytesShouldReturnAByteArray() {
- byte[] regionEntryValueAsBytes = getValueAsByteArray();
+ @Test
+ public void getRawBytesShouldReturnAByteArray() {
+ byte[] regionEntryValueAsBytes = getValueAsByteArray();
- TinyStoredObject offheapAddress = createValueAsUnserializedStoredObject(regionEntryValueAsBytes);
- byte[] actual = offheapAddress.getRawBytes();
+ TinyStoredObject offheapAddress = createValueAsUnserializedStoredObject(regionEntryValueAsBytes);
+ byte[] actual = offheapAddress.getRawBytes();
- assertArrayEquals(regionEntryValueAsBytes, actual);
- }
+ assertArrayEquals(regionEntryValueAsBytes, actual);
+ }
- @Test
- public void getSerializedValueShouldReturnASerializedByteArray() {
- Object regionEntryValue = getValue();
+ @Test
+ public void getSerializedValueShouldReturnASerializedByteArray() {
+ Object regionEntryValue = getValue();
- TinyStoredObject offheapAddress = createValueAsSerializedStoredObject(regionEntryValue);
+ TinyStoredObject offheapAddress = createValueAsSerializedStoredObject(regionEntryValue);
- byte[] actualSerializedValue = offheapAddress.getSerializedValue();
+ byte[] actualSerializedValue = offheapAddress.getSerializedValue();
- Object actualRegionEntryValue = convertSerializedByteArrayToObject(actualSerializedValue);
+ Object actualRegionEntryValue = convertSerializedByteArrayToObject(actualSerializedValue);
- assertEquals(regionEntryValue, actualRegionEntryValue);
- }
+ assertEquals(regionEntryValue, actualRegionEntryValue);
+ }
- @Test
- public void getDeserializedObjectShouldReturnADeserializedObject() {
- Object regionEntryValue = getValue();
+ @Test
+ public void getDeserializedObjectShouldReturnADeserializedObject() {
+ Object regionEntryValue = getValue();
- TinyStoredObject offheapAddress = createValueAsSerializedStoredObject(regionEntryValue);
+ TinyStoredObject offheapAddress = createValueAsSerializedStoredObject(regionEntryValue);
- Integer actualRegionEntryValue = (Integer) offheapAddress.getDeserializedValue(null, null);
+ Integer actualRegionEntryValue = (Integer) offheapAddress.getDeserializedValue(null, null);
- assertEquals(regionEntryValue, actualRegionEntryValue);
- }
+ assertEquals(regionEntryValue, actualRegionEntryValue);
+ }
- @Test
- public void getDeserializedObjectShouldReturnAByteArrayAsIsIfNotSerialized() {
- byte[] regionEntryValueAsBytes = getValueAsByteArray();
+ @Test
+ public void getDeserializedObjectShouldReturnAByteArrayAsIsIfNotSerialized() {
+ byte[] regionEntryValueAsBytes = getValueAsByteArray();
- TinyStoredObject offheapAddress = createValueAsUnserializedStoredObject(regionEntryValueAsBytes);
+ TinyStoredObject offheapAddress = createValueAsUnserializedStoredObject(regionEntryValueAsBytes);
- byte[] deserializeValue = (byte[]) offheapAddress.getDeserializedValue(null, null);
+ byte[] deserializeValue = (byte[]) offheapAddress.getDeserializedValue(null, null);
- assertArrayEquals(regionEntryValueAsBytes, deserializeValue);
- }
+ assertArrayEquals(regionEntryValueAsBytes, deserializeValue);
+ }
- @Test
- public void fillSerializedValueShouldFillWrapperWithSerializedValueIfValueIsSerialized() {
- Object regionEntryValue = getValue();
- byte[] serializedRegionEntryValue = EntryEventImpl.serialize(regionEntryValue);
+ @Test
+ public void fillSerializedValueShouldFillWrapperWithSerializedValueIfValueIsSerialized() {
+ Object regionEntryValue = getValue();
+ byte[] serializedRegionEntryValue = EntryEventImpl.serialize(regionEntryValue);
- //encode a serialized entry value to address
- long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(serializedRegionEntryValue, true, false);
+ //encode a serialized entry value to address
+ long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(serializedRegionEntryValue, true, false);
- TinyStoredObject offheapAddress = new TinyStoredObject(encodedAddress);
+ TinyStoredObject offheapAddress = new TinyStoredObject(encodedAddress);
- //mock the things
- BytesAndBitsForCompactor wrapper = mock(BytesAndBitsForCompactor.class);
+ //mock the things
+ BytesAndBitsForCompactor wrapper = mock(BytesAndBitsForCompactor.class);
- byte userBits = 1;
- offheapAddress.fillSerializedValue(wrapper, userBits);
+ byte userBits = 1;
+ offheapAddress.fillSerializedValue(wrapper, userBits);
- verify(wrapper, times(1)).setData(serializedRegionEntryValue, userBits, serializedRegionEntryValue.length, true);
- }
+ verify(wrapper, times(1)).setData(serializedRegionEntryValue, userBits, serializedRegionEntryValue.length, true);
+ }
- @Test
- public void fillSerializedValueShouldFillWrapperWithDeserializedValueIfValueIsNotSerialized() {
- Object regionEntryValue = getValue();
- byte[] regionEntryValueAsBytes = convertValueToByteArray(regionEntryValue);
+ @Test
+ public void fillSerializedValueShouldFillWrapperWithDeserializedValueIfValueIsNotSerialized() {
+ Object regionEntryValue = getValue();
+ byte[] regionEntryValueAsBytes = convertValueToByteArray(regionEntryValue);
- //encode a un serialized entry value to address
- long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(regionEntryValueAsBytes, false, false);
+ //encode a un serialized entry value to address
+ long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(regionEntryValueAsBytes, false, false);
- TinyStoredObject offheapAddress = new TinyStoredObject(encodedAddress);
+ TinyStoredObject offheapAddress = new TinyStoredObject(encodedAddress);
- //mock the things
- BytesAndBitsForCompactor wrapper = mock(BytesAndBitsForCompactor.class);
+ //mock the things
+ BytesAndBitsForCompactor wrapper = mock(BytesAndBitsForCompactor.class);
- byte userBits = 1;
- offheapAddress.fillSerializedValue(wrapper, userBits);
+ byte userBits = 1;
+ offheapAddress.fillSerializedValue(wrapper, userBits);
- verify(wrapper, times(1)).setData(regionEntryValueAsBytes, userBits, regionEntryValueAsBytes.length, true);
- }
+ verify(wrapper, times(1)).setData(regionEntryValueAsBytes, userBits, regionEntryValueAsBytes.length, true);
+ }
- @Test
- public void getStringFormShouldCatchExceptionAndReturnErrorMessageAsString() {
- Object regionEntryValueAsBytes = getValue();
+ @Test
+ public void getStringFormShouldCatchExceptionAndReturnErrorMessageAsString() {
+ Object regionEntryValueAsBytes = getValue();
- byte[] serializedValue = EntryEventImpl.serialize(regionEntryValueAsBytes);
+ byte[] serializedValue = EntryEventImpl.serialize(regionEntryValueAsBytes);
- //store -127 (DSCODE.ILLEGAL) - in order the deserialize to throw exception
- serializedValue[0] = -127;
+ //store -127 (DSCODE.ILLEGAL) - in order the deserialize to throw exception
+ serializedValue[0] = -127;
- //encode a un serialized entry value to address
- long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(serializedValue, true, false);
+ //encode a un serialized entry value to address
+ long encodedAddress = OffHeapRegionEntryHelper.encodeDataAsAddress(serializedValue, true, false);
- TinyStoredObject offheapAddress = new TinyStoredObject(encodedAddress);
+ TinyStoredObject offheapAddress = new TinyStoredObject(encodedAddress);
- String errorMessage = offheapAddress.getStringForm();
+ String errorMessage = offheapAddress.getStringForm();
- assertEquals(true, errorMessage.contains("Could not convert object to string because "));
- }
+ assertEquals(true, errorMessage.contains("Could not convert object to string because "));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessControllerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessControllerJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessControllerJUnitTest.java
index da811b5..db5f823 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessControllerJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessControllerJUnitTest.java
@@ -31,9 +31,13 @@ import javax.management.Query;
import javax.management.QueryExp;
import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+import com.gemstone.gemfire.internal.process.mbean.Process;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
/**
@@ -45,25 +49,31 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest;
public class LocalProcessControllerJUnitTest {
private MBeanServer server;
- private ObjectName objectName;
-
+ private ObjectName objectName;
+ private int pid;
+
+ @Rule
+ public TestName testName = new TestName();
+
+ @Before
+ public void setUp() throws Exception {
+ pid = ProcessUtils.identifyPid();
+ final Process process = new Process(pid, true);
+
+ this.objectName = ObjectName.getInstance(getClass().getSimpleName() + ":testName=" + testName.getMethodName());
+ this.server = ManagementFactory.getPlatformMBeanServer();
+
+ final ObjectInstance instance = this.server.registerMBean(process, objectName);
+ assertNotNull(instance);
+ }
+
@After
- public void unregisterMBean() throws Exception {
+ public void tearDown() throws Exception {
this.server.unregisterMBean(objectName);
}
@Test
public void testProcessMBean() throws Exception {
- final String testName = "testProcessMBean";
- final int pid = ProcessUtils.identifyPid();
- final com.gemstone.gemfire.internal.process.mbean.Process process = new com.gemstone.gemfire.internal.process.mbean.Process(pid, true);
-
- this.objectName = ObjectName.getInstance(getClass().getSimpleName() + ":testName=" + testName);
- this.server = ManagementFactory.getPlatformMBeanServer();
-
- final ObjectInstance instance = this.server.registerMBean(process, objectName);
- assertNotNull(instance);
-
// validate basics of the ProcessMBean
Set<ObjectName> mbeanNames = this.server.queryNames(objectName, null);
assertFalse("Zero matching mbeans", mbeanNames.isEmpty());
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessLauncherDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessLauncherDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessLauncherDUnitTest.java
index a20871b..0bbab35 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessLauncherDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessLauncherDUnitTest.java
@@ -22,13 +22,9 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.internal.process.LocalProcessLauncher;
import com.gemstone.gemfire.test.dunit.DistributedTestCase;
import com.gemstone.gemfire.test.dunit.Host;
import com.gemstone.gemfire.test.dunit.SerializableRunnable;
-import com.gemstone.gemfire.test.junit.categories.UnitTest;
/**
* Multi-process tests for ProcessLauncher.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessLauncherJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessLauncherJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessLauncherJUnitTest.java
index 78dc6bb..3ff9936 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessLauncherJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/LocalProcessLauncherJUnitTest.java
@@ -24,26 +24,36 @@ import java.io.FileReader;
import java.io.FileWriter;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
import com.gemstone.gemfire.internal.OSProcess;
-import com.gemstone.gemfire.internal.process.LocalProcessLauncher;
-import com.gemstone.gemfire.test.junit.categories.UnitTest;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
/**
* Unit tests for ProcessLauncher.
*
* @since 7.0
*/
-@Category(UnitTest.class)
+@Category(IntegrationTest.class)
public class LocalProcessLauncherJUnitTest {
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Rule
+ public TestName testName = new TestName();
+
+ private File pidFile;
+
@Before
- public void createDirectory() throws Exception {
- new File(getClass().getSimpleName()).mkdir();
+ public void setUp() throws Exception {
+ this.pidFile = new File(this.temporaryFolder.getRoot(), testName.getMethodName() + ".pid");
}
-
+
@Test
public void testPidAccuracy() throws PidUnavailableException {
int pid = ProcessUtils.identifyPid();
@@ -58,8 +68,6 @@ public class LocalProcessLauncherJUnitTest {
@Test
public void testPidFileIsCreated() throws Exception {
- final File pidFile = new File(getClass().getSimpleName()
- + File.separator + "testPidFileIsCreated.pid");
assertFalse(pidFile.exists());
new LocalProcessLauncher(pidFile, false);
assertTrue(pidFile.exists());
@@ -67,8 +75,6 @@ public class LocalProcessLauncherJUnitTest {
@Test
public void testPidFileContainsPid() throws Exception {
- final File pidFile = new File(getClass().getSimpleName()
- + File.separator + "testPidFileContainsPid.pid");
final LocalProcessLauncher launcher = new LocalProcessLauncher(pidFile, false);
assertNotNull(launcher);
assertTrue(pidFile.exists());
@@ -85,8 +91,6 @@ public class LocalProcessLauncherJUnitTest {
@Test
public void testPidFileIsCleanedUp() throws Exception {
- final File pidFile = new File(getClass().getSimpleName()
- + File.separator + "testPidFileIsCleanedUp.pid");
final LocalProcessLauncher launcher = new LocalProcessLauncher(pidFile, false);
assertTrue(pidFile.exists());
launcher.close(); // TODO: launch an external JVM and then close it nicely
@@ -95,8 +99,6 @@ public class LocalProcessLauncherJUnitTest {
@Test
public void testExistingPidFileThrows() throws Exception {
- final File pidFile = new File(getClass().getSimpleName()
- + File.separator + "testExistingPidFileThrows.pid");
assertTrue(pidFile.createNewFile());
assertTrue(pidFile.exists());
@@ -115,8 +117,6 @@ public class LocalProcessLauncherJUnitTest {
@Test
public void testStalePidFileIsReplaced() throws Exception {
- final File pidFile = new File(getClass().getSimpleName()
- + File.separator + "testStalePidFileIsReplaced.pid");
assertTrue(pidFile.createNewFile());
assertTrue(pidFile.exists());
@@ -143,9 +143,7 @@ public class LocalProcessLauncherJUnitTest {
public void testForceReplacesExistingPidFile() throws Exception {
assertTrue("testForceReplacesExistingPidFile is broken if PID == Integer.MAX_VALUE",
ProcessUtils.identifyPid() != Integer.MAX_VALUE);
-
- final File pidFile = new File(getClass().getSimpleName()
- + File.separator + "testForceReplacesExistingPidFile.pid");
+
assertTrue(pidFile.createNewFile());
assertTrue(pidFile.exists());
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/process/PidFileJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/PidFileJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/PidFileJUnitTest.java
index e74365e..bd9bf62 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/PidFileJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/PidFileJUnitTest.java
@@ -41,7 +41,7 @@ import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import com.gemstone.gemfire.internal.util.StopWatch;
-import com.gemstone.gemfire.test.junit.categories.UnitTest;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
import com.gemstone.gemfire.test.junit.rules.ExpectedTimeoutRule;
/**
@@ -49,7 +49,7 @@ import com.gemstone.gemfire.test.junit.rules.ExpectedTimeoutRule;
*
* @since 8.2
*/
-@Category(UnitTest.class)
+@Category(IntegrationTest.class)
public class PidFileJUnitTest {
@Rule
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/process/signal/AbstractSignalNotificationHandlerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/signal/AbstractSignalNotificationHandlerJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/signal/AbstractSignalNotificationHandlerJUnitTest.java
index 243f8d3..488957d 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/process/signal/AbstractSignalNotificationHandlerJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/process/signal/AbstractSignalNotificationHandlerJUnitTest.java
@@ -20,9 +20,6 @@ import static org.junit.Assert.*;
import java.util.Set;
-import com.gemstone.gemfire.internal.util.CollectionUtils;
-import com.gemstone.gemfire.test.junit.categories.UnitTest;
-
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
@@ -31,6 +28,9 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import com.gemstone.gemfire.internal.util.CollectionUtils;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
/**
* The AbstractSignalNotificationHandlerJUnitTest class is a test suite of test cases testing the contract
* and functionality of the AbstractSignalNotificationHandler.
@@ -63,7 +63,7 @@ public class AbstractSignalNotificationHandlerJUnitTest {
mockContext = null;
}
- protected AbstractSignalNotificationHandler createSignalNotificationHandler() {
+ private AbstractSignalNotificationHandler createSignalNotificationHandler() {
return new TestSignalNotificationHandler();
}
@@ -453,7 +453,7 @@ public class AbstractSignalNotificationHandlerJUnitTest {
// notification verification handled by mockContext.assertIsSatisfied in tearDown()
}
- protected static final class TestSignalNotificationHandler extends AbstractSignalNotificationHandler {
+ private static final class TestSignalNotificationHandler extends AbstractSignalNotificationHandler {
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ObjectSizerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ObjectSizerJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ObjectSizerJUnitTest.java
index 91af22c..0852c9d 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ObjectSizerJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ObjectSizerJUnitTest.java
@@ -16,26 +16,19 @@
*/
package com.gemstone.gemfire.internal.size;
+import static com.gemstone.gemfire.internal.size.SizeTestUtil.*;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import junit.framework.TestCase;
-import static com.gemstone.gemfire.internal.size.SizeTestUtil.*;
-
@Category(UnitTest.class)
-public class ObjectSizerJUnitTest extends TestCase {
-
-
- public ObjectSizerJUnitTest() {
- super();
- }
-
- public ObjectSizerJUnitTest(String name) {
- super(name);
- }
+public class ObjectSizerJUnitTest {
- public void test() throws IllegalArgumentException, IllegalAccessException {
+ @Test
+ public void test() throws Exception {
assertEquals(roundup(OBJECT_SIZE), ObjectGraphSizer.size(new Object()));
assertEquals(roundup(OBJECT_SIZE + 4), ObjectGraphSizer.size(new TestObject1()));
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ObjectTraverserJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ObjectTraverserJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ObjectTraverserJUnitTest.java
index bd0bf9d..87ca34f 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ObjectTraverserJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ObjectTraverserJUnitTest.java
@@ -16,24 +16,25 @@
*/
package com.gemstone.gemfire.internal.size;
+import static org.junit.Assert.*;
+
import java.util.ArrayList;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
+import org.junit.Ignore;
+import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
@Category(UnitTest.class)
-public class ObjectTraverserJUnitTest extends TestCase {
-
- public void testBasic() throws IllegalArgumentException, IllegalAccessException {
-
+public class ObjectTraverserJUnitTest {
+
+ @Test
+ public void testBasic() throws Exception {
Set testData = new HashSet();
Object one = new Object();
testData.add(one);
@@ -46,36 +47,35 @@ public class ObjectTraverserJUnitTest extends TestCase {
TestVisitor visitor = new TestVisitor();
ObjectTraverser.breadthFirstSearch(testData, visitor, false);
- Assert.assertNotNull(visitor.visited.remove(testData));
- Assert.assertNotNull(visitor.visited.remove(one));
- Assert.assertNotNull(visitor.visited.remove(two));
- Assert.assertNotNull(visitor.visited.remove(three));
+ assertNotNull(visitor.visited.remove(testData));
+ assertNotNull(visitor.visited.remove(one));
+ assertNotNull(visitor.visited.remove(two));
+ assertNotNull(visitor.visited.remove(three));
}
-
- public void testStatics() throws IllegalArgumentException, IllegalAccessException {
-
+
+ @Test
+ public void testStatics() throws Exception {
final Object staticObject = new Object();
TestObject1.test2 = staticObject;
TestObject1 test1 = new TestObject1();
TestVisitor visitor = new TestVisitor();
ObjectTraverser.breadthFirstSearch(test1, visitor, false);
- Assert.assertNull(visitor.visited.get(staticObject));
+ assertNull(visitor.visited.get(staticObject));
visitor = new TestVisitor();
ObjectTraverser.breadthFirstSearch(test1, visitor, true);
- Assert.assertNotNull(visitor.visited.get(staticObject));
+ assertNotNull(visitor.visited.get(staticObject));
}
-
- public void testStop() throws IllegalArgumentException, IllegalAccessException {
+
+ @Test
+ public void testStop() throws Exception {
Set set1 = new HashSet();
final Set set2 = new HashSet();
Object object3 = new Object();
set1.add(set2);
set2.add(object3);
-
-
TestVisitor visitor = new TestVisitor();
visitor = new TestVisitor() {
public boolean visit(Object parent, Object object) {
@@ -86,14 +86,15 @@ public class ObjectTraverserJUnitTest extends TestCase {
ObjectTraverser.breadthFirstSearch(set1, visitor, true);
- Assert.assertNotNull(visitor.visited.get(set1));
- Assert.assertNotNull(visitor.visited.get(set2));
- Assert.assertNull(visitor.visited.get(object3));
+ assertNotNull(visitor.visited.get(set1));
+ assertNotNull(visitor.visited.get(set2));
+ assertNull(visitor.visited.get(object3));
}
/** This test is commented out because it needs to be verified manually */
- public void z_testHistogram() throws IllegalArgumentException, IllegalAccessException {
-
+ @Ignore("commented out because it needs to be verified manually")
+ @Test
+ public void testHistogram() throws Exception {
Set set1 = new HashSet();
final Set set2 = new HashSet();
Object object3 = new Object();
@@ -110,7 +111,7 @@ public class ObjectTraverserJUnitTest extends TestCase {
public Map visited = new IdentityHashMap();
public boolean visit(Object parent, Object object) {
- Assert.assertNull(visited.put(object, VALUE));
+ assertNull(visited.put(object, VALUE));
return true;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizerJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizerJUnitTest.java
index 4489433..7618e36 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizerJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/size/ReflectionObjectSizerJUnitTest.java
@@ -17,29 +17,26 @@
package com.gemstone.gemfire.internal.size;
import static org.junit.Assert.*;
-
-import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-import com.gemstone.gemfire.internal.logging.LogService;
-import com.gemstone.gemfire.test.junit.categories.UnitTest;
+import static org.mockito.Mockito.*;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import io.codearte.catchexception.shade.mockito.Mockito;
+import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
+import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
@Category(UnitTest.class)
public class ReflectionObjectSizerJUnitTest {
@Test
public void skipsSizingDistributedSystem() {
-
- Object referenceObject = Mockito.mock(InternalDistributedSystem.class);
+ Object referenceObject = mock(InternalDistributedSystem.class);
checkSizeDoesNotChange(referenceObject);
}
@Test
public void skipsSizingClassLoader() {
-
checkSizeDoesNotChange(Thread.currentThread().getContextClassLoader());
}
@@ -59,7 +56,7 @@ public class ReflectionObjectSizerJUnitTest {
assertNotEquals(sizeWithoutReference, sizer.sizeof(stringReference));
}
- public class TestObject {
+ private static class TestObject {
public TestObject(final Object reference) {
this.reference = reference;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/size/SizeClassOnceObjectSizerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/size/SizeClassOnceObjectSizerJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/size/SizeClassOnceObjectSizerJUnitTest.java
index 8f41b21..5f7bb1b 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/size/SizeClassOnceObjectSizerJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/size/SizeClassOnceObjectSizerJUnitTest.java
@@ -16,20 +16,19 @@
*/
package com.gemstone.gemfire.internal.size;
-import org.junit.experimental.categories.Category;
-
-import junit.framework.TestCase;
import static com.gemstone.gemfire.internal.size.SizeTestUtil.*;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.cache.util.ObjectSizer;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-/**
- *
- */
@Category(UnitTest.class)
-public class SizeClassOnceObjectSizerJUnitTest extends TestCase{
-
+public class SizeClassOnceObjectSizerJUnitTest {
+
+ @Test
public void test() {
byte[] b1 = new byte[5];
byte[] b2 = new byte[15];
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/size/WellKnownClassSizerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/size/WellKnownClassSizerJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/size/WellKnownClassSizerJUnitTest.java
index 76655fb..e25ae4c 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/size/WellKnownClassSizerJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/size/WellKnownClassSizerJUnitTest.java
@@ -16,20 +16,19 @@
*/
package com.gemstone.gemfire.internal.size;
+import static com.gemstone.gemfire.internal.size.SizeTestUtil.*;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.cache.util.ObjectSizer;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import junit.framework.TestCase;
-import static com.gemstone.gemfire.internal.size.SizeTestUtil.*;
-
-/**
- *
- */
@Category(UnitTest.class)
-public class WellKnownClassSizerJUnitTest extends TestCase {
-
+public class WellKnownClassSizerJUnitTest {
+
+ @Test
public void testByteArrays() {
byte[] test1 = new byte[5];
byte[] test2 = new byte[8];
@@ -41,7 +40,8 @@ public class WellKnownClassSizerJUnitTest extends TestCase {
assertEquals(0, WellKnownClassSizer.sizeof(new Object()));
}
-
+
+ @Test
public void testStrings() {
String test1 = "123";
String test2 = "012345678";
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/SampleCollectorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/SampleCollectorJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/SampleCollectorJUnitTest.java
index dcf9420..37b75a4 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/SampleCollectorJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/SampleCollectorJUnitTest.java
@@ -16,18 +16,12 @@
*/
package com.gemstone.gemfire.internal.statistics;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
import java.io.File;
import java.util.List;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -44,47 +38,31 @@ import com.gemstone.gemfire.internal.statistics.TestSampleHandler.SampledInfo;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
/**
- * Unit tests for the SampleCollector class.
+ * Unit tests for the SampleCollector class. No disk IO.
*
* @since 7.0
*/
@Category(UnitTest.class)
public class SampleCollectorJUnitTest {
- private static final String dir = "SampleCollectorJUnitTest";
-
- private Mockery mockContext;
- private TestStatisticsManager manager;
+ private TestStatisticsManager manager;
private SampleCollector sampleCollector;
@Before
public void setUp() throws Exception {
- new File(dir).mkdir();
- this.mockContext = new Mockery() {{
- setImposteriser(ClassImposteriser.INSTANCE);
- }};
final long startTime = System.currentTimeMillis();
- this.manager = new TestStatisticsManager(1, "SampleCollectorJUnitTest", startTime);
-
- final StatArchiveHandlerConfig mockStatArchiveHandlerConfig = this.mockContext.mock(StatArchiveHandlerConfig.class, "SampleCollectorJUnitTest$StatArchiveHandlerConfig");
- this.mockContext.checking(new Expectations() {{
- allowing(mockStatArchiveHandlerConfig).getArchiveFileName();
- will(returnValue(new File("")));
- allowing(mockStatArchiveHandlerConfig).getArchiveFileSizeLimit();
- will(returnValue(0));
- allowing(mockStatArchiveHandlerConfig).getArchiveDiskSpaceLimit();
- will(returnValue(0));
- allowing(mockStatArchiveHandlerConfig).getSystemId();
- will(returnValue(1));
- allowing(mockStatArchiveHandlerConfig).getSystemStartTime();
- will(returnValue(startTime));
- allowing(mockStatArchiveHandlerConfig).getSystemDirectoryPath();
- will(returnValue(""));
- allowing(mockStatArchiveHandlerConfig).getProductDescription();
- will(returnValue("SampleCollectorJUnitTest"));
- }});
+ this.manager = new TestStatisticsManager(1, getClass().getSimpleName(), startTime);
+
+ final StatArchiveHandlerConfig mockStatArchiveHandlerConfig = mock(StatArchiveHandlerConfig.class, getClass().getSimpleName() + "$" + StatArchiveHandlerConfig.class.getSimpleName());
+ when(mockStatArchiveHandlerConfig.getArchiveFileName()).thenReturn(new File(""));
+ when(mockStatArchiveHandlerConfig.getArchiveFileSizeLimit()).thenReturn(0L);
+ when(mockStatArchiveHandlerConfig.getArchiveDiskSpaceLimit()).thenReturn(0L);
+ when(mockStatArchiveHandlerConfig.getSystemId()).thenReturn(0L);
+ when(mockStatArchiveHandlerConfig.getSystemStartTime()).thenReturn(startTime);
+ when(mockStatArchiveHandlerConfig.getSystemDirectoryPath()).thenReturn("");
+ when(mockStatArchiveHandlerConfig.getProductDescription()).thenReturn(getClass().getSimpleName());
- StatisticsSampler sampler = new TestStatisticsSampler(manager);
+ final StatisticsSampler sampler = new TestStatisticsSampler(manager);
this.sampleCollector = new SampleCollector(sampler);
this.sampleCollector.initialize(mockStatArchiveHandlerConfig, NanoTimer.getTime());
}
@@ -95,8 +73,6 @@ public class SampleCollectorJUnitTest {
this.sampleCollector.close();
this.sampleCollector = null;
}
- this.mockContext.assertIsSatisfied();
- this.mockContext = null;
this.manager = null;
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/StatMonitorHandlerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/StatMonitorHandlerJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/StatMonitorHandlerJUnitTest.java
index 6c88fd4..c4370e5 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/StatMonitorHandlerJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/StatMonitorHandlerJUnitTest.java
@@ -27,29 +27,19 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import com.gemstone.gemfire.i18n.LogWriterI18n;
import com.gemstone.gemfire.internal.NanoTimer;
-import com.gemstone.gemfire.internal.logging.LogWriterImpl;
-import com.gemstone.gemfire.internal.logging.PureLogWriter;
import com.gemstone.gemfire.internal.statistics.StatMonitorHandler.StatMonitorNotifier;
import com.gemstone.gemfire.internal.util.StopWatch;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
/**
- * Unit test for the StatMonitorHandler and its inner classes.
+ * Unit tests for the StatMonitorHandler and its inner classes.
*
* @since 7.0
*/
@Category(UnitTest.class)
public class StatMonitorHandlerJUnitTest {
- private LogWriterI18n log = null;
-
- @Before
- public void setUp() throws Exception {
- this.log = new PureLogWriter(LogWriterImpl.levelNameToCode("config"));
- }
-
@Test
public void testAddNewMonitor() throws Exception {
StatMonitorHandler handler = new StatMonitorHandler();
@@ -100,7 +90,7 @@ public class StatMonitorHandlerJUnitTest {
}
@Test
- public void testNotificationSampleFrequencyDefault() {
+ public void testNotificationSampleFrequencyDefault() throws Exception {
final int sampleFrequency = 1;
StatMonitorHandler handler = new StatMonitorHandler();
TestStatisticsMonitor monitor = new TestStatisticsMonitor();
@@ -114,7 +104,7 @@ public class StatMonitorHandlerJUnitTest {
}
@Test
- public void testNotificationSampleTimeMillis() {
+ public void testNotificationSampleTimeMillis() throws Exception {
final long currentTime = System.currentTimeMillis();
StatMonitorHandler handler = new StatMonitorHandler();
TestStatisticsMonitor monitor = new TestStatisticsMonitor();
@@ -127,7 +117,7 @@ public class StatMonitorHandlerJUnitTest {
}
@Test
- public void testNotificationResourceInstances() {
+ public void testNotificationResourceInstances() throws Exception {
final int resourceInstanceCount = 100;
final List<ResourceInstance> resourceInstances = new ArrayList<ResourceInstance>();
for (int i = 0; i < resourceInstanceCount; i++) {
@@ -194,26 +184,18 @@ public class StatMonitorHandlerJUnitTest {
waitUntilWaiting(notifier);
}
- private static void waitUntilWaiting(StatMonitorNotifier notifier) {
+ private static void waitUntilWaiting(StatMonitorNotifier notifier) throws InterruptedException {
boolean done = false;
- try {
- for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 2000; done = (notifier.isWaiting())) {
- Thread.sleep(10);
- }
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
+ for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 2000; done = (notifier.isWaiting())) {
+ Thread.sleep(10);
}
- assertTrue("waiting for notifier to be waiting", done);
+ assertTrue("waiting for notifier to be waiting", done);
}
- private static void waitForNotificationCount(final TestStatisticsMonitor monitor, final int expected, long ms, long interval, boolean throwOnTimeout) {
+ private static void waitForNotificationCount(final TestStatisticsMonitor monitor, final int expected, long ms, long interval, boolean throwOnTimeout) throws InterruptedException {
boolean done = false;
- try {
- for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < ms; done = (monitor.getNotificationCount() >= expected)) {
- Thread.sleep(interval);
- }
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
+ for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < ms; done = (monitor.getNotificationCount() >= expected)) {
+ Thread.sleep(interval);
}
if (throwOnTimeout) {
assertTrue("waiting for notification count to be " + expected, done);
@@ -223,7 +205,7 @@ public class StatMonitorHandlerJUnitTest {
/**
* @since 7.0
*/
- static class TestStatisticsMonitor extends StatisticsMonitor {
+ private static class TestStatisticsMonitor extends StatisticsMonitor {
private volatile long timeStamp;
private volatile List<ResourceInstance> resourceInstances;
private volatile int notificationCount;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/StatisticsMonitorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/StatisticsMonitorJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/StatisticsMonitorJUnitTest.java
index f8cf043..4ee8995 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/StatisticsMonitorJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/StatisticsMonitorJUnitTest.java
@@ -17,68 +17,43 @@
package com.gemstone.gemfire.internal.statistics;
import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
import java.io.File;
import java.util.List;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.internal.NanoTimer;
-import com.gemstone.gemfire.internal.logging.InternalLogWriter;
-import com.gemstone.gemfire.internal.logging.LogWriterImpl;
-import com.gemstone.gemfire.internal.logging.PureLogWriter;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
/**
- * Unit and integration tests for the StatisticsMonitor.
+ * Unit tests for the StatisticsMonitor class. No disk IO.
*
* @since 7.0
*/
@Category(UnitTest.class)
public class StatisticsMonitorJUnitTest {
- private Mockery mockContext;
- private InternalLogWriter log;
- private TestStatisticsManager manager;
+ private TestStatisticsManager manager;
private SampleCollector sampleCollector;
@Before
public void setUp() throws Exception {
- this.mockContext = new Mockery() {{
- setImposteriser(ClassImposteriser.INSTANCE);
- }};
-
- this.log = new PureLogWriter(LogWriterImpl.levelNameToCode("config"));
-
final long startTime = System.currentTimeMillis();
- this.manager = new TestStatisticsManager(
- 1,
- "StatisticsMonitorJUnitTest",
- startTime);
+ this.manager = new TestStatisticsManager(1, getClass().getSimpleName(), startTime);
- final StatArchiveHandlerConfig mockStatArchiveHandlerConfig = this.mockContext.mock(StatArchiveHandlerConfig.class, "StatisticsMonitorJUnitTest$StatArchiveHandlerConfig");
- this.mockContext.checking(new Expectations() {{
- allowing(mockStatArchiveHandlerConfig).getArchiveFileName();
- will(returnValue(new File("")));
- allowing(mockStatArchiveHandlerConfig).getArchiveFileSizeLimit();
- will(returnValue(0));
- allowing(mockStatArchiveHandlerConfig).getArchiveDiskSpaceLimit();
- will(returnValue(0));
- allowing(mockStatArchiveHandlerConfig).getSystemId();
- will(returnValue(1));
- allowing(mockStatArchiveHandlerConfig).getSystemStartTime();
- will(returnValue(startTime));
- allowing(mockStatArchiveHandlerConfig).getSystemDirectoryPath();
- will(returnValue(""));
- allowing(mockStatArchiveHandlerConfig).getProductDescription();
- will(returnValue("StatisticsMonitorJUnitTest"));
- }});
+ final StatArchiveHandlerConfig mockStatArchiveHandlerConfig = mock(StatArchiveHandlerConfig.class, getClass().getSimpleName() + "$" + StatArchiveHandlerConfig.class.getSimpleName());
+ when(mockStatArchiveHandlerConfig.getArchiveFileName()).thenReturn(new File(""));
+ when(mockStatArchiveHandlerConfig.getArchiveFileSizeLimit()).thenReturn(0L);
+ when(mockStatArchiveHandlerConfig.getArchiveDiskSpaceLimit()).thenReturn(0L);
+ when(mockStatArchiveHandlerConfig.getSystemId()).thenReturn(0L);
+ when(mockStatArchiveHandlerConfig.getSystemStartTime()).thenReturn(0L);
+ when(mockStatArchiveHandlerConfig.getSystemDirectoryPath()).thenReturn("");
+ when(mockStatArchiveHandlerConfig.getProductDescription()).thenReturn(getClass().getSimpleName());
StatisticsSampler sampler = new TestStatisticsSampler(manager);
this.sampleCollector = new SampleCollector(sampler);
@@ -91,8 +66,6 @@ public class StatisticsMonitorJUnitTest {
this.sampleCollector.close();
this.sampleCollector = null;
}
- this.mockContext.assertIsSatisfied();
- this.mockContext = null;
this.manager = null;
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/tcp/ConnectionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/tcp/ConnectionJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/tcp/ConnectionJUnitTest.java
index ffd5092..3a88707 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/tcp/ConnectionJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/tcp/ConnectionJUnitTest.java
@@ -16,10 +16,7 @@
*/
package com.gemstone.gemfire.internal.tcp;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.*;
import java.io.InputStream;
import java.net.InetSocketAddress;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/util/AbortableTaskServiceJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/AbortableTaskServiceJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/AbortableTaskServiceJUnitTest.java
index 4378180..77098ca 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/AbortableTaskServiceJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/AbortableTaskServiceJUnitTest.java
@@ -165,7 +165,6 @@ public class AbortableTaskServiceJUnitTest {
* Proxy handler which invokes methodName asynchronously AND delays the
* invocation to the underlying methodName until after CountDownLatch is
* opened.
- *
*/
private class DelayedExecutorHandler implements InvocationHandler {
private final Executor executor;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/util/ArrayUtilsJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/ArrayUtilsJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/ArrayUtilsJUnitTest.java
index 0a78a19..1fd759a 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/ArrayUtilsJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/ArrayUtilsJUnitTest.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package com.gemstone.gemfire.internal.util;
import static org.junit.Assert.*;
@@ -25,7 +24,7 @@ import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
/**
- * The ArrayUtilsJUnitTest class... </p>
+ * Unit tests for {@link ArrayUtils}.
*
* @since 7.x
*/
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/util/BytesJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/BytesJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/BytesJUnitTest.java
index e5a7f4d..50f3280 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/BytesJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/BytesJUnitTest.java
@@ -16,18 +16,27 @@
*/
package com.gemstone.gemfire.internal.util;
+import static org.junit.Assert.*;
+
import java.nio.ByteBuffer;
+import org.junit.Before;
+import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import junit.framework.TestCase;
-
@Category(UnitTest.class)
-public class BytesJUnitTest extends TestCase {
- private ByteBuffer buf = ByteBuffer.allocate(8);
-
+public class BytesJUnitTest {
+
+ private ByteBuffer buf;
+
+ @Before
+ public void setUp() throws Exception {
+ buf = ByteBuffer.allocate(8);
+ }
+
+ @Test
public void testShort() {
short[] val = { 666, -1, Short.MIN_VALUE, 0, 12, Short.MAX_VALUE };
for (int i = 0; i < val.length; i++) {
@@ -37,7 +46,8 @@ public class BytesJUnitTest extends TestCase {
buf.rewind();
}
}
-
+
+ @Test
public void testChar() {
char[] val = { 'a', 'b', 'c' };
for (int i = 0; i < val.length; i++) {
@@ -47,7 +57,8 @@ public class BytesJUnitTest extends TestCase {
buf.rewind();
}
}
-
+
+ @Test
public void testUnsignedShort() {
int[] val = { 0, 1, Short.MAX_VALUE + 1, 2 * Short.MAX_VALUE };
for (int i = 0; i < val.length; i++) {
@@ -57,7 +68,8 @@ public class BytesJUnitTest extends TestCase {
buf.rewind();
}
}
-
+
+ @Test
public void testInt() {
int[] val = { 666, -1, Integer.MIN_VALUE, 0, 1, Integer.MAX_VALUE };
for (int i = 0; i < val.length; i++) {
@@ -71,7 +83,8 @@ public class BytesJUnitTest extends TestCase {
assertEquals(val[i], Bytes.toInt(bytes[0], bytes[1], bytes[2], bytes[3]));
}
}
-
+
+ @Test
public void testLong() {
long[] val = { 666, -1, Long.MIN_VALUE, 0, 1, Long.MAX_VALUE };
for (int i = 0; i < val.length; i++) {
@@ -82,8 +95,8 @@ public class BytesJUnitTest extends TestCase {
buf.rewind();
}
}
-
-
+
+ @Test
public void testVarint() {
ByteBuffer buf = ByteBuffer.allocate(5);
checkVarint(0, buf);
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/util/CollectionUtilsJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/CollectionUtilsJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/CollectionUtilsJUnitTest.java
index 0748055..242d2f2 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/CollectionUtilsJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/CollectionUtilsJUnitTest.java
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package com.gemstone.gemfire.internal.util;
import static org.junit.Assert.*;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/util/DelayedActionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/DelayedActionJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/DelayedActionJUnitTest.java
index c6aa1a3..3a2d660 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/DelayedActionJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/DelayedActionJUnitTest.java
@@ -16,19 +16,22 @@
*/
package com.gemstone.gemfire.internal.util;
+import static org.junit.Assert.*;
+
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.junit.Test;
import org.junit.experimental.categories.Category;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import junit.framework.TestCase;
-
@Category(UnitTest.class)
-public class DelayedActionJUnitTest extends TestCase {
+public class DelayedActionJUnitTest {
+
+ @Test
public void testDelay() throws InterruptedException {
final AtomicBoolean hit = new AtomicBoolean(false);
final CountDownLatch complete = new CountDownLatch(1);
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/util/IOUtilsJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/IOUtilsJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/IOUtilsJUnitTest.java
index 0a36780..fe68196 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/IOUtilsJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/IOUtilsJUnitTest.java
@@ -70,7 +70,7 @@ public class IOUtilsJUnitTest {
* @param pathElements a String array containing the elements of the path.
* @return a fully-qualified pathname as a String value.
*/
- protected String toPathname(final String... pathElements) {
+ private String toPathname(final String... pathElements) {
if (pathElements != null) {
final StringBuilder buffer = new StringBuilder();
for (String pathElement : pathElements) {
@@ -274,7 +274,7 @@ public class IOUtilsJUnitTest {
}
}
- protected static final class MockFile extends File {
+ private static final class MockFile extends File {
private boolean isGetAbsoluteFileCalled = false;
private boolean isGetCanonicalFileCalled = false;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/util/concurrent/CompactConcurrentHashSetJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/concurrent/CompactConcurrentHashSetJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/concurrent/CompactConcurrentHashSetJUnitTest.java
index 216a85c..e053d38 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/concurrent/CompactConcurrentHashSetJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/concurrent/CompactConcurrentHashSetJUnitTest.java
@@ -16,14 +16,14 @@
*/
package com.gemstone.gemfire.internal.util.concurrent;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Random;
import java.util.Set;
+import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -32,17 +32,23 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest;
@Category(UnitTest.class)
public class CompactConcurrentHashSetJUnitTest {
- static int RANGE = 100000;
- static int SET_SIZE = 1000;
- Random ran = new Random();
-
+
+ private static final int RANGE = 100000;
+
+ private Random random;
+
+ @Before
+ public void setUp() throws Exception {
+ random = new Random();
+ }
+
@Test
- public void testEquals() {
+ public void testEquals() { // TODO: reduce test runtime
Set s1, s2;
s1 = new CompactConcurrentHashSet2();
s2 = new HashSet();
for (int i=0; i<10000; i++) {
- int nexti = ran.nextInt(RANGE);
+ int nexti = random.nextInt(RANGE);
s1.add(nexti);
s2.add(nexti);
assertTrue("expected s1 and s2 to be equal", s1.equals(s2));
@@ -60,7 +66,7 @@ public class CompactConcurrentHashSetJUnitTest {
Set<Integer> s1;
s1 = new CompactConcurrentHashSet2<Integer>();
for (int i=0; i<10000; i++) {
- int nexti = ran.nextInt(RANGE);
+ int nexti = random.nextInt(RANGE);
s1.add(nexti);
}
for (Iterator<Integer> it=s1.iterator(); it.hasNext(); ) {
@@ -80,7 +86,7 @@ public class CompactConcurrentHashSetJUnitTest {
s1 = new CompactConcurrentHashSet2<Integer>();
s2 = new HashSet<Integer>();
for (int i=0; i<10000; i++) {
- int nexti = ran.nextInt(RANGE);
+ int nexti = random.nextInt(RANGE);
s1.add(nexti);
s2.add(nexti);
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bf258f62/geode-core/src/test/java/com/gemstone/gemfire/internal/util/concurrent/ReentrantSemaphoreJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/concurrent/ReentrantSemaphoreJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/concurrent/ReentrantSemaphoreJUnitTest.java
index d24d067..0fe7301 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/util/concurrent/ReentrantSemaphoreJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/util/concurrent/ReentrantSemaphoreJUnitTest.java
@@ -16,45 +16,69 @@
*/
package com.gemstone.gemfire.internal.util.concurrent;
+import static org.junit.Assert.*;
+
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.junit.rules.Timeout;
import com.gemstone.gemfire.test.junit.categories.UnitTest;
-import junit.framework.TestCase;
-
-/**
- *
- */
@Category(UnitTest.class)
-public class ReentrantSemaphoreJUnitTest extends TestCase {
-
- public void test() throws Throwable {
+public class ReentrantSemaphoreJUnitTest {
+
+ private static final long OPERATION_TIMEOUT_MILLIS = 10 * 1000;
+
+ private CountDownLatch done;
+ private CountDownLatch acquired;
+
+ @Rule
+ public Timeout timeout = new Timeout(30, TimeUnit.SECONDS);
+
+ @Before
+ public void setUp() throws Exception {
+ done = new CountDownLatch(1);
+ acquired = new CountDownLatch(2);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ acquired.countDown();
+ done.countDown();
+ }
+
+ @Test
+ public void testOneThread() throws Exception {
+ final ReentrantSemaphore semaphore = new ReentrantSemaphore(2);
+ semaphore.acquire();
+ semaphore.acquire();
+ assertEquals(1, semaphore.availablePermits());
+ semaphore.release();
+ semaphore.release();
+ assertEquals(2, semaphore.availablePermits());
+ }
+
+ @Test
+ public void testMultipleThreads() throws Exception {
final ReentrantSemaphore sem = new ReentrantSemaphore(2);
-
- sem.acquire();
- sem.acquire();
- assertEquals(1, sem.availablePermits());
- sem.release();
- sem.release();
- assertEquals(2, sem.availablePermits());
-
- final CountDownLatch testDone = new CountDownLatch(1);
- final CountDownLatch semsAquired = new CountDownLatch(2);
-
- final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
-
+
+ final AtomicReference<Throwable> failure = new AtomicReference<>();
+
Thread t1 = new Thread() {
public void run() {
- try {
+ try {
sem.acquire();
sem.acquire();
sem.acquire();
- semsAquired.countDown();
- testDone.await();
+ acquired.countDown();
+ assertTrue(done.await(OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
sem.release();
sem.release();
sem.release();
@@ -71,8 +95,8 @@ public class ReentrantSemaphoreJUnitTest extends TestCase {
sem.acquire();
sem.acquire();
sem.acquire();
- semsAquired.countDown();
- testDone.await();
+ acquired.countDown();
+ assertTrue(done.await(OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
sem.release();
sem.release();
sem.release();
@@ -86,7 +110,7 @@ public class ReentrantSemaphoreJUnitTest extends TestCase {
Thread t3 = new Thread() {
public void run() {
try {
- semsAquired.await();
+ assertTrue(acquired.await(OPERATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
assertEquals(0, sem.availablePermits());
assertFalse(sem.tryAcquire(1, TimeUnit.SECONDS));
} catch(Exception e) {
@@ -96,13 +120,19 @@ public class ReentrantSemaphoreJUnitTest extends TestCase {
};
t3.start();
- t3.join();
- testDone.countDown();
- t2.join();
- t1.join();
-
- if(failure.get() != null) {
- throw failure.get();
+ t3.join(OPERATION_TIMEOUT_MILLIS);
+ assertFalse(t3.isAlive());
+
+ done.countDown();
+
+ t2.join(OPERATION_TIMEOUT_MILLIS);
+ assertFalse(t3.isAlive());
+
+ t1.join(OPERATION_TIMEOUT_MILLIS);
+ assertFalse(t1.isAlive());
+
+ if (failure.get() != null) {
+ throw new AssertionError(failure.get());
}
assertEquals(2, sem.availablePermits());