Skip to content
Permalink
Browse files
Merge pull request #136 from apache/DS-javaIssue358
Ds java issue358
  • Loading branch information
leerho committed Aug 10, 2021
2 parents bdbb636 + 25a4d7c commit e97d072f582b2b093884d2f1c63a8178621e6f26
Show file tree
Hide file tree
Showing 30 changed files with 418 additions and 444 deletions.
@@ -87,17 +87,16 @@ public void checkDefaultMemoryRequestServer() throws Exception {

@Test
public void checkNullMemoryRequestServer() throws Exception {
try (WritableHandle wh = WritableMemory.allocateDirect(128, null)) {
try (WritableHandle wh = WritableMemory.allocateDirect(128, Util.nativeByteOrder, null)) {
WritableMemory wmem = wh.getWritable();
assertNotNull(wmem.getMemoryRequestServer());
}
}


@Test
public void checkNonNativeDirect() throws Exception { //not allowed in public API
try (WritableHandle h = ReflectUtil.wrapDirect(8, Util.nonNativeByteOrder, null)) {
//BaseWritableMemory.wrapDirect(8, Util.nonNativeByteOrder, null)) {
public void checkNonNativeDirect() throws Exception {
try (WritableHandle h = WritableMemory.allocateDirect(128, Util.nonNativeByteOrder, null)) {
WritableMemory wmem = h.getWritable();
wmem.putChar(0, (char) 1);
assertEquals(wmem.getByte(1), (byte) 1);
@@ -21,6 +21,7 @@

import static org.testng.Assert.assertFalse;

import java.nio.ByteOrder;
import java.util.IdentityHashMap;

import org.apache.datasketches.memory.MemoryRequestServer;
@@ -61,7 +62,7 @@ public void checkExampleMemoryRequestServer1() {
public void checkExampleMemoryRequestServer2() throws Exception {
int bytes = 8;
ExampleMemoryRequestServer svr = new ExampleMemoryRequestServer();
try (WritableHandle handle = WritableMemory.allocateDirect(bytes, svr)) {
try (WritableHandle handle = WritableMemory.allocateDirect(bytes, ByteOrder.nativeOrder(), svr)) {
WritableMemory wMem = handle.getWritable();
MemoryClient client = new MemoryClient(wMem);
client.process();
@@ -73,7 +74,7 @@ public void checkExampleMemoryRequestServer2() throws Exception {
@Test(expectedExceptions = IllegalArgumentException.class)
public void checkZeroCapacity() {
ExampleMemoryRequestServer svr = new ExampleMemoryRequestServer();
WritableMemory.allocateDirect(0, svr);
WritableMemory.allocateDirect(0, ByteOrder.nativeOrder(), svr);
}

/**
@@ -126,7 +127,7 @@ public static class ExampleMemoryRequestServer implements MemoryRequestServer {
@SuppressWarnings("resource")
@Override
public WritableMemory request(long capacityBytes) {
WritableHandle handle = WritableMemory.allocateDirect(capacityBytes, this);
WritableHandle handle = WritableMemory.allocateDirect(capacityBytes, ByteOrder.nativeOrder(), this);
WritableMemory wmem = handle.getWritable();
map.put(wmem, handle); //We track the newly allocated memory and its handle.
return wmem;

0 comments on commit e97d072

Please sign in to comment.