Skip to content
Permalink
Browse files
Merge pull request #137 from apache/CleanUp
Clean up
  • Loading branch information
leerho committed Aug 10, 2021
2 parents 8cb5f39 + 52592d4 commit e3a0c37abcbc56290470a7588d68f217b83a8d74
Show file tree
Hide file tree
Showing 36 changed files with 197 additions and 192 deletions.
@@ -34,7 +34,7 @@

@SuppressWarnings("javadoc")
public class AllocateDirectMemoryTest {

@Test
public void simpleAllocateDirect() throws Exception {
int longs = 32;
@@ -48,7 +48,7 @@ public void simpleAllocateDirect() throws Exception {
//inside the TWR block the memory should be valid
ReflectUtil.checkValid(wMem);
//OK
}
}
//The TWR block has exited, so the memory should be invalid
try {
ReflectUtil.checkValid(wMem);
@@ -100,7 +100,7 @@ public void checkNonNativeDirect() throws Exception {
WritableMemory wmem = h.getWritable();
wmem.putChar(0, (char) 1);
assertEquals(wmem.getByte(1), (byte) 1);
}
}
}

@Test
@@ -55,20 +55,20 @@ public class AllocateDirectWritableMapMemoryTest {
private static final String LS = System.getProperty("line.separator");

static final Method IS_FILE_READ_ONLY;

static {
IS_FILE_READ_ONLY =
ReflectUtil.getMethod(ReflectUtil.ALLOCATE_DIRECT_MAP, "isFileReadOnly", File.class);
}

private static boolean isFileReadOnly(final File file) {
try {
return (boolean) IS_FILE_READ_ONLY.invoke(null, file);
} catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new RuntimeException(e);
} catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}

@BeforeClass
public void setReadOnly() {
UtilTest.setGettysburgAddressFileToReadOnly();
@@ -247,7 +247,7 @@ public void checkDirectCounter() {
println(""+count);
fail();
}
}
}

@Test
public void printlnTest() {
@@ -56,7 +56,7 @@ public void checkExampleMemoryRequestServer1() {
* by the MemoryClient when it is done with the new memory allocations.
* The initial allocation stays open until the end where it is closed at the end of the
* TWR scope.
* @throws Exception
* @throws Exception
*/
@Test
public void checkExampleMemoryRequestServer2() throws Exception {
@@ -101,15 +101,15 @@ void process() {
WritableMemory bigMem = svr.request(2 * cap1); //get bigger mem
long cap2 = bigMem.getCapacity();
smallMem.copyTo(0, bigMem, 0, cap1); //copy data from small to big
svr.requestClose(smallMem, bigMem); //done with smallMem, release it
svr.requestClose(smallMem, bigMem); //done with smallMem, release it

bigMem.fill(cap1, cap1, (byte) 2); //fill the rest of bigMem, still not big enough
println(bigMem.toHexString("Big", 0, (int)cap2));

WritableMemory giantMem = svr.request(2 * cap2); //get giant mem
long cap3 = giantMem.getCapacity();
bigMem.copyTo(0, giantMem, 0, cap2); //copy data from small to big
svr.requestClose(bigMem, giantMem); //done with bigMem, release it
svr.requestClose(bigMem, giantMem); //done with bigMem, release it

giantMem.fill(cap2, cap2, (byte) 3); //fill the rest of giantMem
println(giantMem.toHexString("Giant", 0, (int)cap3));
@@ -47,16 +47,16 @@ public class LeafImplTest {
private static final ByteOrder NO = nativeByteOrder;
private static final ByteOrder NNO = nonNativeByteOrder;
private static final MemoryRequestServer dummyMemReqSvr = new DummyMemoryRequestServer();
private static ByteOrder otherOrder(ByteOrder order) { return (order == NO) ? NNO : NO; }

private static ByteOrder otherOrder(ByteOrder order) { return (order == NO) ? NNO : NO; }

static class DummyMemoryRequestServer implements MemoryRequestServer {
@Override
public WritableMemory request(long capacityBytes) { return null; }
@Override
public void requestClose(WritableMemory memToClose, WritableMemory newMemory) { }
}

@Test
public void checkDirectLeafs() throws Exception {
long off = 0;
@@ -78,7 +78,7 @@ public void checkDirectLeafs() throws Exception {
checkCombinations(memNNO, off, cap, memNNO.isDirect(), NNO, false, true);
}
}

@Test
public void checkByteBufferLeafs() {
long off = 0;
@@ -90,8 +90,8 @@ public void checkByteBufferLeafs() {
WritableMemory mem = WritableMemory.writableWrap(bb, NO, dummyMemReqSvr);
assertEquals(bb.isDirect(), mem.isDirect());
assertNotNull(ReflectUtil.getUnsafeObject(mem));
checkCombinations(mem, off, cap, mem.isDirect(), mem.getTypeByteOrder(), true, true);
checkCombinations(mem, off, cap, mem.isDirect(), mem.getTypeByteOrder(), true, true);

//BB off heap, native order, has ByteBuffer, has MemReqSvr
ByteBuffer dbb = ByteBuffer.allocateDirect((int)cap);
dbb.order(NO);
@@ -100,7 +100,7 @@ public void checkByteBufferLeafs() {
assertEquals(dbb.isDirect(), mem.isDirect());
assertNull(ReflectUtil.getUnsafeObject(mem));
checkCombinations(mem, off, cap, mem.isDirect(), mem.getTypeByteOrder(), true, true);

//BB on heap, non native order, has ByteBuffer, has MemReqSvr
bb = ByteBuffer.allocate((int)cap);
bb.order(NNO);
@@ -109,7 +109,7 @@ public void checkByteBufferLeafs() {
assertEquals(bb.isDirect(), mem.isDirect());
assertNotNull(ReflectUtil.getUnsafeObject(mem));
checkCombinations(mem, off, cap, mem.isDirect(), mem.getTypeByteOrder(), true, true);

//BB off heap, non native order, has ByteBuffer, has MemReqSvr
dbb = ByteBuffer.allocateDirect((int)cap);
dbb.order(NNO);
@@ -153,7 +153,7 @@ public void checkMapLeafs() throws Exception {
checkCombinations(memNNO, off, cap, memNNO.isDirect(), NNO, false, false);
}
}

@Test
public void checkHeapLeafs() {
long off = 0;
@@ -172,23 +172,23 @@ public void checkHeapLeafs() {
checkCombinations(memNNO, off, cap, memNNO.isDirect(), NNO, false, false);
}

private static void checkCombinations(WritableMemory mem, long off, long cap,
private static void checkCombinations(WritableMemory mem, long off, long cap,
boolean direct, ByteOrder bo, boolean hasByteBuffer, boolean hasMemReqSvr) {
ByteOrder oo = otherOrder(bo);

assertEquals(mem.writableRegion(off, cap, bo).getShort(0), 1);
assertEquals(mem.writableRegion(off, cap, oo).getShort(0), 256);

assertEquals(mem.asWritableBuffer(bo).getShort(0), 1);
assertEquals(mem.asWritableBuffer(oo).getShort(0), 256);

ByteBuffer bb = mem.getByteBuffer();
assertTrue( hasByteBuffer ? bb != null : bb == null);

assertTrue(mem.getTypeByteOrder() == bo);

if (hasMemReqSvr) { assertTrue(mem.getMemoryRequestServer() instanceof DummyMemoryRequestServer); }

Object obj = ReflectUtil.getUnsafeObject(mem);
if (direct) {
assertTrue(mem.isDirect());
@@ -197,7 +197,7 @@ private static void checkCombinations(WritableMemory mem, long off, long cap,
assertFalse(mem.isDirect());
assertNotNull(obj);
}

assertTrue(mem.isValid() == true);

WritableBuffer buf = mem.asWritableBuffer();
@@ -209,9 +209,9 @@ private static void checkCombinations(WritableMemory mem, long off, long cap,

bb = buf.getByteBuffer();
assertTrue(hasByteBuffer ? bb != null : bb == null);

assertTrue(buf.getTypeByteOrder() == bo);

if (hasMemReqSvr) { assertTrue(buf.getMemoryRequestServer() instanceof DummyMemoryRequestServer); }

obj = ReflectUtil.getUnsafeObject(buf);
@@ -222,7 +222,7 @@ private static void checkCombinations(WritableMemory mem, long off, long cap,
assertFalse(buf.isDirect());
assertNotNull(obj);
}

assertTrue(buf.isValid() == true);

WritableMemory nnMem = mem.writableRegion(off, cap, oo);
@@ -234,11 +234,11 @@ private static void checkCombinations(WritableMemory mem, long off, long cap,

bb = nnMem.getByteBuffer();
assertTrue( hasByteBuffer ? bb != null : bb == null);

assertTrue(nnMem.getTypeByteOrder() == oo);

if (hasMemReqSvr) { assertTrue(nnMem.getMemoryRequestServer() instanceof DummyMemoryRequestServer); }

obj = ReflectUtil.getUnsafeObject(nnMem);
if (direct) {
assertTrue(nnMem.isDirect());
@@ -247,7 +247,7 @@ private static void checkCombinations(WritableMemory mem, long off, long cap,
assertFalse(nnMem.isDirect());
assertNotNull(obj);
}

assertTrue(nnMem.isValid() == true);

WritableBuffer nnBuf = mem.asWritableBuffer(oo);
@@ -259,9 +259,9 @@ private static void checkCombinations(WritableMemory mem, long off, long cap,

bb = nnBuf.getByteBuffer();
assertTrue( hasByteBuffer ? bb != null : bb == null);

assertTrue(nnBuf.getTypeByteOrder() == oo);

if (hasMemReqSvr) { assertTrue(nnBuf.getMemoryRequestServer() instanceof DummyMemoryRequestServer); }

obj = ReflectUtil.getUnsafeObject(nnBuf);
@@ -272,8 +272,8 @@ private static void checkCombinations(WritableMemory mem, long off, long cap,
assertFalse(nnBuf.isDirect());
assertNotNull(obj);
}

assertTrue(nnBuf.isValid() == true);
}

}
@@ -23,7 +23,7 @@

package org.apache.datasketches.memory.test;

import static org.apache.datasketches.memory.internal.Util.*;
import static org.apache.datasketches.memory.internal.Util.getResourceFile;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
@@ -37,10 +37,10 @@

import org.apache.datasketches.memory.BaseState;
import org.apache.datasketches.memory.MapHandle;
import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.internal.Util;
import org.apache.datasketches.memory.WritableHandle;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.memory.internal.Util;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -49,7 +49,7 @@
@SuppressWarnings("javadoc")
public class MemoryTest {
private static final String LS = System.getProperty("line.separator");

@BeforeClass
public void setReadOnly() {
UtilTest.setGettysburgAddressFileToReadOnly();
@@ -411,7 +411,7 @@ public void checkMonitorDirectMapStats() throws Exception {

MapHandle mmh1 = Memory.map(file);
MapHandle mmh2 = Memory.map(file);

assertEquals(BaseState.getCurrentDirectMemoryMapAllocations(), 2L);
assertEquals(BaseState.getCurrentDirectMemoryMapAllocated(), 2 * bytes);

@@ -35,7 +35,7 @@ public void checkVMParams() {
println("Page Aligned: " + ReflectUtil.isPageAligned());
println("Page Size: " + ReflectUtil.pageSize());
}

@Test
public void checkGetAtomicFields() {
//testing this beyond 2GB may not work on JVMs < 8GB.

0 comments on commit e3a0c37

Please sign in to comment.