Added: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/package-info.java
==============================================================================
--- 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/package-info.java
 (added)
+++ 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/package-info.java
 Tue May 21 21:11:49 2024
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * <p>This package provides high performance primitive and primitive array 
access to direct (native),
+ * off-heap memory and memory-mapped file resources, and consistent views into
+ * {@link java.nio.ByteBuffer}, and on-heap primitive arrays. It can be used 
as a more
+ * comprehensive and flexible replacement for {@link java.nio.ByteBuffer}.
+ * </p>
+ *
+ * <p>In addition, this package provides:</p>
+ *
+ * <ul><li>Two different access APIs: read-only {@link 
org.apache.datasketches.memory.Memory} and
+ * {@link org.apache.datasketches.memory.WritableMemory} for absolute offset 
access,
+ * and read-only {@link org.apache.datasketches.memory.Buffer} and
+ * {@link org.apache.datasketches.memory.WritableBuffer}
+ * for relative positional access (similar to ByteBuffer).</li>
+ *
+ * <li>Clean separation of Read-only API from Writable API, which makes 
writable versus read-only
+ * resources detectable at compile time.</li>
+ *
+ * <li>The conversion from Writable to read-only is just a cast, so no 
unnecessary objects are
+ * created. For example:
+ * <blockquote><pre>
+ *     WritableMemory wMem = ...
+ *     Memory mem = wMem;
+ * </pre></blockquote>
+ * </li>
+ *
+ * <li> {@link java.lang.AutoCloseable} for the external resources that 
require it,
+ * which enables compile-time checks for non-closed resources.</li>
+ *
+ * <li>Immediate invalidation of all downstream references of an AutoCloseable
+ * resource when that resource is closed, either manually or by the JVM.
+ * This virtually eliminates the possibility of accidentally writing into the 
memory space
+ * previously owned by a closed resource.</li>
+ *
+ * <li>Improved performance over the prior Memory implementation.</li>
+ *
+ * <li>Cleaner internal architecture, which will make it easier to extend in 
the future.</li>
+ *
+ * <li>No external dependencies, which makes it simple to install in virtually 
any Java environment.
+ * </li>
+ * </ul>
+ *
+ * <p>More specifically, this package provides access to four different types 
of resources using
+ * two different access APIs. These resources are contiguous blobs of bytes 
that provide at least
+ * byte-level read and write access. The four resources are:</p>
+ *
+ * <ul><li>Direct (a.k.a. Native) off-heap memory allocated by the user.</li>
+ * <li>Memory-mapped files, both writable and read-only.</li>
+ * <li>{@code ByteBuffers}, both heap-based and direct, writable and 
read-only.</li>
+ * <li>Heap-based primitive arrays, which can be accessed as writable or 
read-only.</li>
+ * </ul>
+ *
+ * <p>The two different access APIs are:</p>
+ * <ul><li><i>Memory, WritableMemory</i>: Absolute offset addressing into a 
resource.</li>
+ * <li><i>Buffer, WritableBuffer</i>: Position relative addressing into a 
resource.</li>
+ * </ul>
+ *
+ * <p>In addition, all combinations of access APIs and backing resources can 
be accessed via
+ * multibyte primitive methods (e.g.
+ * <i>getLong(...), getLongArray(...), putLong(...), putLongArray(...)</i>) as 
either
+ * {@link java.nio.ByteOrder#BIG_ENDIAN} or {@link 
java.nio.ByteOrder#LITTLE_ENDIAN}.</p>
+ *
+ * <p>The resources don't know or care about the access APIs, and the access
+ * APIs don't really know or care what resource they are accessing.</p>
+ *
+ * <p>An access API is joined with
+ * a resource either with a static factory method or in combination with a
+ * {@link org.apache.datasketches.memory.Handle}, which is used exclusively 
for resources that are
+ * external to the JVM, such as allocation of direct memory and memory-mapped 
files.</p>
+ *
+ * <p>The role of a Handle is to hold onto the reference of a resource that is 
outside the control
+ * of the JVM. The resource is obtained from the handle with {@code get()}.</p>
+ *
+ * <p>When a handle is extended for an AutoCloseable resource and then joined 
with an access API
+ * it becomes an <i>implementation handle</i>. There are 3 implementation 
handles:</p>
+ *
+ * <ul><li>{@link org.apache.datasketches.memory.MapHandle}
+ * for read-only access to a memory-mapped file</li>
+ * <li>{@link org.apache.datasketches.memory.WritableMapHandle}
+ * for writable access to a memory-mapped file</li>
+ * <li>{@link org.apache.datasketches.memory.WritableHandle}
+ * for writable access to off-heap memory.</li>
+ * </ul>
+ *
+ * <p>As long as the implementation handle is valid the JVM will not attempt 
to close the resource.</p>
+ *
+ * <p>An implementation handle implements {@link java.lang.AutoCloseable},
+ * which also enables compile-time checks for non-closed resources. If a 
Handle is acquired
+ * in a try-with-resources (TWR) block, it's associated resource will be 
automatically closed by
+ * the JVM at the end of the block.
+ * The resource can also be explicitly closed by the user by calling {@code 
Handle.close()}.</p>
+ * <blockquote><pre>
+ *     //Using try-with-resources block:
+ *     try (WritableyMapHandle handle = WritableMemory.map(File file)) {
+ *       WritableMemory wMem = handle.get();
+ *       doWork(wMem) // read and write to memory mapped file.
+ *     }
+ *
+ *     //Using explicit close():
+ *     WritableMapHandle handle = WritableMemory.map(File file);
+ *     WritableMemory wMem = handle.get();
+ *     doWork(wMem) // read and write to memory mapped file.
+ *     handle.close();
+ * </pre></blockquote>
+ *
+ * <p>Where it is desirable to pass ownership of the resource (and the {@code 
close()}
+ * responsibility) one can not use the TWR block. Instead:</p>
+ * <blockquote><pre>
+ *     WritableMapHandle handler = WritableMemory.map(File file);
+ *     doWorkAndClose(handle); //passes the handle to object that closes the 
resource.
+ * </pre></blockquote>
+ *
+ * <p>Whatever part of your process is responsible for allocating a resource 
external
+ * to the JVM must be responsible for closing it or making sure it gets closed.
+ * Since only the implementation Handles implement AutoCloseable, you must not 
let go of the
+ * handle reference until you are done with its associated resource.</p>
+ *
+ * <p>As mentioned above, there are two ways to do this:</p>
+ * <ul><li>Use a try-with-resources block.  At the end of the block, the JVM 
will automatically
+ * close the resource.</li>
+ *
+ * <li>If you need to pass an external resource, pass the implementation 
resource handle, not the
+ * access API. This means you are also passing the responsibility to close the 
resource.
+ * If you have different parts of your code holding references to the same 
handle,
+ * whichever one closes it first will make all the other resources invalid, so 
be careful.
+ * As long as there is at least one reference to the handle that is still 
valid and the resource
+ * has not been closed, the resource will remain valid. If you drop all 
references to all handles,
+ * the JVM will eventually close the resource, making it invalid, but it is 
possible that you might
+ * run out of memory first. Depending on this is a bad idea and a could be a 
serious,
+ * hard-to-find bug.</li>
+ * </ul>
+ *
+ *<p>Moving back and forth between <i>Memory</i> and <i>Buffer</i>:</p>
+ *<blockquote><pre>
+ *    Memory mem = ...
+ *    Buffer buf = mem.asBuffer();
+ *    ...
+ *    Memory mem2 = buf.asMemory();
+ *    ...
+ * </pre></blockquote>
+ *
+ * <p>Hierarchical memory regions can be easily created:</p>
+ * <blockquote><pre>
+ *     WritableMemory wMem = ...
+ *     WritableMemory wReg = wMem.writableRegion(offset, length); //OR
+ *     Memory reg = wMem.region(offset, length);
+ * </pre></blockquote>
+ *
+ * <p>With asserts enabled in the JVM, all methods are checked for bounds and
+ * use-after-close violations.</p>
+ *
+ * @author Lee Rhodes
+ */
+package org.apache.datasketches.memory;

Propchange: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/package-info.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/main/javadoc/overview.html
==============================================================================
--- 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/main/javadoc/overview.html
 (added)
+++ 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/main/javadoc/overview.html
 Tue May 21 21:11:49 2024
@@ -0,0 +1,34 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+   "http://www.w3.org/TR/html4/loose.dtd";>
+
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+
+<html>
+<head>
+</head>
+<body>
+<h2>Memory</h2> 
+<h3>Overview</h3>
+
+<p><b><a href="org/apache/datasketches/memory/package-summary.html">Memory 
Package Overview</a></b></p>
+
+<p>Note: If the requirements or promises of any method's contract are not 
fulfilled (that is, if there is a bug in either the method or its caller), then 
an unchecked exception will be thrown. The precise type of such an unchecked 
exception does not form part of any method's contract.</p>
+</body>
+</html>
\ No newline at end of file

Propchange: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/main/javadoc/overview.html
------------------------------------------------------------------------------
    svn:executable = *

Added: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
==============================================================================
--- 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
 (added)
+++ 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
 Tue May 21 21:11:49 2024
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Note: Lincoln's Gettysburg Address is in the public domain. See LICENSE.
+ */
+
+package org.apache.datasketches.memory.internal;
+
+import static org.apache.datasketches.memory.internal.Util.*;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.io.File;
+import java.nio.ByteOrder;
+
+import org.apache.datasketches.memory.MapHandle;
+import org.apache.datasketches.memory.Memory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class AllocateDirectMapMemoryTest {
+  private static final String LS = System.getProperty("line.separator");
+  MapHandle hand = null;
+
+  @BeforeClass
+  public void setReadOnly() {
+    UtilTest.setGettysburgAddressFileToReadOnly();
+  }
+
+  @Test
+  public void simpleMap() throws Exception {
+    File file = getResourceFile("GettysburgAddress.txt");
+    assertTrue(AllocateDirectMap.isFileReadOnly(file));
+    try (MapHandle rh = Memory.map(file)) {
+      rh.close();
+    }
+  }
+
+  @Test
+  public void testIllegalArguments() throws Exception {
+    File file = getResourceFile("GettysburgAddress.txt");
+    try (MapHandle rh = Memory.map(file, -1, Integer.MAX_VALUE, 
ByteOrder.nativeOrder())) {
+      fail("Failed: testIllegalArgumentException: Position was negative.");
+    } catch (IllegalArgumentException e) {
+      //ok
+    }
+
+    try (MapHandle rh = Memory.map(file, 0, -1, ByteOrder.nativeOrder())) {
+      fail("Failed: testIllegalArgumentException: Size was negative.");
+    } catch (IllegalArgumentException e) {
+      //ok
+    }
+  }
+
+  @Test
+  public void testMapAndMultipleClose() throws Exception {
+    File file = getResourceFile("GettysburgAddress.txt");
+    long memCapacity = file.length();
+    try (MapHandle rh = Memory.map(file, 0, memCapacity, 
ByteOrder.nativeOrder())) {
+      Memory map = rh.get();
+      assertEquals(memCapacity, map.getCapacity());
+      rh.close();
+      rh.close();
+      map.getCapacity(); //throws assertion error
+    } catch (AssertionError e) {
+      //OK
+    }
+  }
+
+  @Test
+  public void testReadFailAfterClose() throws Exception {
+    File file = getResourceFile("GettysburgAddress.txt");
+    long memCapacity = file.length();
+    try (MapHandle rh = Memory.map(file, 0, memCapacity, 
ByteOrder.nativeOrder())) {
+      Memory mmf = rh.get();
+      rh.close();
+      mmf.getByte(0);
+    } catch (AssertionError e) {
+      //OK
+    }
+  }
+
+  @Test
+  public void testLoad() throws Exception {
+    File file = getResourceFile("GettysburgAddress.txt");
+    long memCapacity = file.length();
+    try (MapHandle rh = Memory.map(file, 0, memCapacity, 
ByteOrder.nativeOrder())) {
+      rh.load();
+      assertTrue(rh.isLoaded());
+      rh.close();
+    }
+  }
+
+  @Test
+  public void testHandlerHandoffWithTWR() throws Exception {
+    File file = getResourceFile("GettysburgAddress.txt");
+    long memCapacity = file.length();
+    Memory mem;
+    try (MapHandle rh = Memory.map(file, 0, memCapacity, 
ByteOrder.nativeOrder())) {
+      rh.load();
+      assertTrue(rh.isLoaded());
+      hand = rh;
+      mem = rh.get();
+    } //TWR closes
+    assertFalse(mem.isValid());
+    //println(""+mem.isValid());
+  }
+
+  @Test
+  public void testHandoffWithoutClose() throws Exception {
+    File file = getResourceFile("GettysburgAddress.txt");
+    long memCapacity = file.length();
+    MapHandle rh = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder());
+    rh.load();
+    assertTrue(rh.isLoaded());
+    hand = rh;
+    //The receiver of the handler must close the resource, in this case it is 
the class.
+  }
+
+  @AfterClass
+  public void afterAllTests() throws Exception {
+      if (hand != null) {
+      Memory mem = hand.get();
+      if ((mem != null) && mem.isValid()) {
+        hand.close();
+        assertFalse(mem.isValid());
+      }
+    }
+  }
+
+  @Test
+  public void printlnTest() {
+    println("PRINTING: "+this.getClass().getName());
+  }
+
+  static void println(final Object o) {
+    if (o == null) { print(LS); }
+    else { print(o.toString() + LS); }
+  }
+
+  /**
+   * @param o value to print
+   */
+  static void print(final Object o) {
+    if (o != null) {
+      //System.out.print(o.toString()); //disable here
+    }
+  }
+
+}

Propchange: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
==============================================================================
--- 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
 (added)
+++ 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
 Tue May 21 21:11:49 2024
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.memory.internal;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.fail;
+
+import org.apache.datasketches.memory.BaseState;
+import org.apache.datasketches.memory.DefaultMemoryRequestServer;
+import org.apache.datasketches.memory.MemoryRequestServer;
+import org.apache.datasketches.memory.WritableHandle;
+import org.apache.datasketches.memory.WritableMemory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.Test;
+
+public class AllocateDirectMemoryTest {
+
+  @Test
+  public void simpleAllocateDirect() throws Exception {
+    int longs = 32;
+    WritableMemory wMem;
+    try (WritableHandle wh = WritableMemory.allocateDirect(longs << 3)) {
+      wMem = wh.getWritable();
+      for (int i = 0; i<longs; i++) {
+        wMem.putLong(i << 3, i);
+        assertEquals(wMem.getLong(i << 3), i);
+      }
+      //inside the TWR block the memory should be valid
+      ((BaseStateImpl)wMem).checkValid();
+      //OK
+    }
+    //The TWR block has exited, so the memory should be invalid
+    try {
+      ((BaseStateImpl)wMem).checkValid();
+      fail();
+    } catch (final RuntimeException e) {
+      //OK
+    }
+  }
+
+  @Test
+  public void checkDefaultMemoryRequestServer() throws Exception {
+    int longs1 = 32;
+    int bytes1 = longs1 << 3;
+    try (WritableHandle wh = WritableMemory.allocateDirect(bytes1)) {
+      WritableMemory origWmem = wh.getWritable();
+      for (int i = 0; i<longs1; i++) { //puts data in wMem1
+        origWmem.putLong(i << 3, i);
+        assertEquals(origWmem.getLong(i << 3), i);
+      }
+      println(origWmem.toHexString("Test", 0, 32 * 8));
+
+      int longs2 = 64;
+      int bytes2 = longs2 << 3;
+      MemoryRequestServer memReqSvr;
+      if (BaseState.defaultMemReqSvr == null) {
+        memReqSvr = new DefaultMemoryRequestServer();
+      } else {
+        memReqSvr = origWmem.getMemoryRequestServer();
+      }
+      WritableMemory newWmem = memReqSvr.request(origWmem, bytes2);
+      assertFalse(newWmem.isDirect()); //on heap by default
+      for (int i = 0; i < longs2; i++) {
+          newWmem.putLong(i << 3, i);
+          assertEquals(newWmem.getLong(i << 3), i);
+      }
+      memReqSvr.requestClose(origWmem, newWmem);
+      //The default MRS doesn't actually release because it could be easily 
misused.
+      // So we let the TWR release it.
+    }
+  }
+
+  @Test
+  public void checkNonNativeDirect() throws Exception {
+    try (WritableHandle h = WritableMemory.allocateDirect(128, 
Util.NON_NATIVE_BYTE_ORDER, null)) {
+      WritableMemory wmem = h.getWritable();
+      wmem.putChar(0, (char) 1);
+      assertEquals(wmem.getByte(1), (byte) 1);
+    }
+  }
+
+  @Test
+  public void checkExplicitClose() throws Exception {
+    final long cap = 128;
+    try (WritableHandle wdh = WritableMemory.allocateDirect(cap)) {
+      wdh.close(); //explicit close. Does the work of closing
+    } //end of scope call to Cleaner/Deallocator also will be redundant
+  }
+
+
+  @AfterClass
+  public void checkDirectCounter() {
+    WritableMemory.writableWrap(new byte[8]);
+    long count = BaseState.getCurrentDirectMemoryAllocations();
+    if (count != 0) {
+      println(""+count);
+      fail();
+    }
+  }
+
+  @Test
+  public void printlnTest() {
+    println("PRINTING: "+this.getClass().getName());
+  }
+
+  /**
+   * @param s value to print
+   */
+  static void println(String s) {
+    //System.out.println(s); //disable here
+  }
+}

Propchange: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
==============================================================================
--- 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
 (added)
+++ 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
 Tue May 21 21:11:49 2024
@@ -0,0 +1,253 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Note: Lincoln's Gettysburg Address is in the public domain. See LICENSE.
+ */
+
+package org.apache.datasketches.memory.internal;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.datasketches.memory.internal.Util.getResourceFile;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteOrder;
+
+import org.apache.datasketches.memory.BaseState;
+import org.apache.datasketches.memory.MapHandle;
+import org.apache.datasketches.memory.Memory;
+import org.apache.datasketches.memory.ReadOnlyException;
+import org.apache.datasketches.memory.WritableHandle;
+import org.apache.datasketches.memory.WritableMapHandle;
+import org.apache.datasketches.memory.WritableMemory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class AllocateDirectWritableMapMemoryTest {
+  private static final String LS = System.getProperty("line.separator");
+
+  @BeforeClass
+  public void setReadOnly() {
+    UtilTest.setGettysburgAddressFileToReadOnly();
+  }
+
+  @Test
+  public void simpleMap() throws Exception {
+    File file = getResourceFile("GettysburgAddress.txt");
+    try (MapHandle h = Memory.map(file); WritableMapHandle wh = 
(WritableMapHandle) h) {
+      Memory mem = h.get();
+      byte[] bytes = new byte[(int)mem.getCapacity()];
+      mem.getByteArray(0, bytes, 0, bytes.length);
+      String text = new String(bytes, UTF_8);
+      println(text);
+      try {
+        wh.force();
+        fail();
+      } catch (ReadOnlyException e) {
+        //OK
+      }
+    }
+  }
+
+  @Test
+  public void copyOffHeapToMemoryMappedFile() throws Exception {
+    long bytes = 1L << 10; //small for unit tests.  Make it larger than 2GB if 
you like.
+    long longs = bytes >>> 3;
+
+    File file = new File("TestFile.bin");
+    if (file.exists()) {
+      try {
+        java.nio.file.Files.delete(file.toPath());
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+    }
+    assertTrue(file.createNewFile());
+    assertTrue (file.setWritable(true, false)); //writable=true, 
ownerOnly=false
+    assertTrue (file.isFile());
+    file.deleteOnExit();  //comment out if you want to examine the file.
+
+    try (
+        WritableMapHandle dstHandle
+          = WritableMemory.writableMap(file, 0, bytes, 
ByteOrder.nativeOrder());
+        WritableHandle srcHandle = WritableMemory.allocateDirect(bytes)) {
+
+      WritableMemory dstMem = dstHandle.getWritable();
+      WritableMemory srcMem = srcHandle.getWritable();
+
+      for (long i = 0; i < longs; i++) {
+        srcMem.putLong(i << 3, i); //load source with consecutive longs
+      }
+
+      srcMem.copyTo(0, dstMem, 0, srcMem.getCapacity()); //off-heap to 
off-heap copy
+
+      dstHandle.force(); //push any remaining to the file
+
+      //check end value
+      assertEquals(dstMem.getLong(longs - 1L << 3), longs - 1L);
+    }
+  }
+
+  @Test
+  public void checkNonNativeFile() throws Exception {
+    File file = new File("TestFile2.bin");
+    if (file.exists()) {
+      try {
+        java.nio.file.Files.delete(file.toPath());
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+    }
+    assertTrue(file.createNewFile());
+    assertTrue(file.setWritable(true, false)); //writable=true, ownerOnly=false
+    assertTrue(file.isFile());
+    file.deleteOnExit();  //comment out if you want to examine the file.
+
+    final long bytes = 8;
+    try (WritableMapHandle h = WritableMemory.writableMap(file, 0L, bytes, 
Util.NON_NATIVE_BYTE_ORDER)) {
+      WritableMemory wmem = h.getWritable();
+      wmem.putChar(0, (char) 1);
+      assertEquals(wmem.getByte(1), (byte) 1);
+    }
+  }
+
+  @Test(expectedExceptions = RuntimeException.class)
+  public void testMapException() throws IOException {
+    File dummy = createFile("dummy.txt", ""); //zero length
+    //throws java.lang.reflect.InvocationTargetException
+    Memory.map(dummy, 0, dummy.length(), ByteOrder.nativeOrder());
+  }
+
+  @Test(expectedExceptions = ReadOnlyException.class)
+  public void simpleMap2() throws Exception {
+    File file = getResourceFile("GettysburgAddress.txt");
+    assertTrue(file.canRead() && !file.canWrite());
+    try (WritableMapHandle rh =
+        WritableMemory.writableMap(file)) { //throws
+      //
+    }
+  }
+
+  @Test(expectedExceptions = ReadOnlyException.class)
+  public void checkOverLength() throws Exception  {
+    File file = getResourceFile("GettysburgAddress.txt");
+    try (WritableMapHandle rh =
+        WritableMemory.writableMap(file, 0, 1 << 20, ByteOrder.nativeOrder())) 
{
+      //
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  @Test
+  public void testForce() throws Exception {
+    String origStr = "Corectng spellng mistks";
+    File origFile = createFile("force_original.txt", origStr); //23
+    assertTrue(origFile.setWritable(true, false));
+    long origBytes = origFile.length();
+    String correctStr = "Correcting spelling mistakes"; //28
+    byte[] correctByteArr = correctStr.getBytes(UTF_8);
+    long corrBytes = correctByteArr.length;
+
+    try (MapHandle rh = Memory.map(origFile, 0, origBytes, 
ByteOrder.nativeOrder())) {
+      Memory map = rh.get();
+      rh.load();
+      assertTrue(rh.isLoaded());
+      //confirm orig string
+      byte[] buf = new byte[(int)origBytes];
+      map.getByteArray(0, buf, 0, (int)origBytes);
+      String bufStr = new String(buf, UTF_8);
+      assertEquals(bufStr, origStr);
+    }
+
+    try (WritableMapHandle wrh = WritableMemory.writableMap(origFile, 0, 
corrBytes,
+        ByteOrder.nativeOrder())) {
+      WritableMemory wMap = wrh.getWritable();
+      wrh.load();
+      assertTrue(wrh.isLoaded());
+      // over write content
+      wMap.putByteArray(0, correctByteArr, 0, (int)corrBytes);
+      wrh.force();
+      //confirm correct string
+      byte[] buf = new byte[(int)corrBytes];
+      wMap.getByteArray(0, buf, 0, (int)corrBytes);
+      String bufStr = new String(buf, UTF_8);
+      assertEquals(bufStr, correctStr);
+    }
+  }
+
+  private static File createFile(String fileName, String text) throws 
FileNotFoundException {
+    File file = new File(fileName);
+    file.deleteOnExit();
+    PrintWriter writer;
+    try {
+      writer = new PrintWriter(file, UTF_8.name());
+      writer.print(text);
+      writer.close();
+    } catch (UnsupportedEncodingException e) {
+      e.printStackTrace();
+    }
+    return file;
+  }
+
+  @Test
+  public void checkExplicitClose() throws Exception {
+    File file = getResourceFile("GettysburgAddress.txt");
+    try (MapHandle wmh = Memory.map(file)) {
+      wmh.close(); //explicit close.
+    } //end of scope call to Cleaner/Deallocator also will be redundant
+  }
+
+  @AfterClass
+  public void checkDirectCounter() {
+    long count =  BaseState.getCurrentDirectMemoryMapAllocations();
+      if (count != 0) {
+        println(""+count);
+        fail();
+      }
+    }
+
+  @Test
+  public void printlnTest() {
+    println("PRINTING: "+this.getClass().getName());
+  }
+
+  static void println(final Object o) {
+    if (o == null) { print(LS); }
+    else { print(o.toString() + LS); }
+  }
+
+  /**
+   * @param o value to print
+   */
+  static void print(final Object o) {
+    if (o != null) {
+      //System.out.print(o.toString()); //disable here
+    }
+  }
+
+}

Propchange: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectWritableMapMemoryTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java
==============================================================================
--- 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java
 (added)
+++ 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java
 Tue May 21 21:11:49 2024
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.memory.internal;
+
+import static org.testng.Assert.fail;
+
+import org.apache.datasketches.memory.Buffer;
+import org.apache.datasketches.memory.Memory;
+import org.apache.datasketches.memory.WritableHandle;
+import org.apache.datasketches.memory.WritableMemory;
+import org.testng.annotations.Test;
+
+/**
+ * @author Lee Rhodes
+ */
+public class BaseBufferTest {
+
+  @Test
+  public void checkLimits() {
+    Buffer buf = Memory.wrap(new byte[100]).asBuffer();
+    buf.setStartPositionEnd(40, 45, 50);
+    buf.setStartPositionEnd(0, 0, 100);
+    try {
+      buf.setStartPositionEnd(0, 0, 101);
+      fail();
+    } catch (AssertionError e) {
+      //ok
+    }
+  }
+
+  @Test
+  public void checkLimitsAndCheck() {
+    Buffer buf = Memory.wrap(new byte[100]).asBuffer();
+    buf.setAndCheckStartPositionEnd(40, 45, 50);
+    buf.setAndCheckStartPositionEnd(0, 0, 100);
+    try {
+      buf.setAndCheckStartPositionEnd(0, 0, 101);
+      fail();
+    } catch (IllegalArgumentException e) {
+      //ok
+    }
+    buf.setAndCheckPosition(100);
+    try {
+      buf.setAndCheckPosition(101);
+      fail();
+    } catch (IllegalArgumentException e) {
+      //ok
+    }
+    buf.setPosition(99);
+    buf.incrementAndCheckPosition(1L);
+    try {
+      buf.incrementAndCheckPosition(1L);
+      fail();
+    } catch (IllegalArgumentException e) {
+      //ok
+    }
+  }
+
+  @Test
+  public void checkCheckValid() throws Exception {
+    WritableMemory wmem;
+    Buffer buf;
+    try (WritableHandle hand = WritableMemory.allocateDirect(100)) {
+      wmem = hand.getWritable();
+      buf = wmem.asBuffer();
+    }
+    try {
+      @SuppressWarnings("unused")
+      Memory mem = buf.asMemory();
+    } catch (AssertionError ae) { }
+  }
+}

Propchange: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseBufferTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
==============================================================================
--- 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
 (added)
+++ 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
 Tue May 21 21:11:49 2024
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.memory.internal;
+
+import static 
org.apache.datasketches.memory.internal.UnsafeUtil.ARRAY_DOUBLE_INDEX_SCALE;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.nio.ByteOrder;
+
+import org.apache.datasketches.memory.Buffer;
+import org.apache.datasketches.memory.Memory;
+import org.apache.datasketches.memory.WritableBuffer;
+import org.apache.datasketches.memory.WritableMemory;
+import org.testng.annotations.Test;
+
+public class BaseStateTest {
+
+  @Test
+  public void checkPrimOffset() {
+    int off = (int)Prim.BYTE.off();
+    assertTrue(off > 0);
+  }
+
+  @Test
+  public void checkIsSameResource() {
+    WritableMemory wmem = WritableMemory.allocate(16);
+    Memory mem = wmem;
+    assertFalse(wmem.isSameResource(null));
+    assertTrue(wmem.isSameResource(mem));
+
+    WritableBuffer wbuf = wmem.asWritableBuffer();
+    Buffer buf = wbuf;
+    assertFalse(wbuf.isSameResource(null));
+    assertTrue(wbuf.isSameResource(buf));
+  }
+
+  @Test
+  public void checkNotEqualTo() {
+    byte[] arr = new byte[8];
+    Memory mem = Memory.wrap(arr);
+    assertFalse(mem.equalTo(0, arr, 0, 8));
+  }
+
+  //StepBoolean checks
+  @Test
+  public void checkStepBoolean() {
+    checkStepBoolean(true);
+    checkStepBoolean(false);
+  }
+
+  private static void checkStepBoolean(boolean initialState) {
+    StepBoolean step = new StepBoolean(initialState);
+    assertTrue(step.get() == initialState); //confirm initialState
+    step.change();
+    assertTrue(step.hasChanged());      //1st change was successful
+    assertTrue(step.get() != initialState); //confirm it is different from 
initialState
+    step.change();
+    assertTrue(step.get() != initialState); //Still different from initialState
+    assertTrue(step.hasChanged());  //confirm it was changed from initialState 
value
+  }
+
+  @Test
+  public void checkPrim() {
+    assertEquals(Prim.DOUBLE.scale(), ARRAY_DOUBLE_INDEX_SCALE);
+  }
+
+  @Test
+  public void checkGetNativeBaseOffset_Heap() throws Exception {
+    WritableMemory wmem = WritableMemory.allocate(8); //heap
+    final long offset = ((BaseStateImpl)wmem).getNativeBaseOffset();
+    assertEquals(offset, 0L);
+  }
+
+  @Test
+  public void checkIsByteOrderCompatible() {
+    WritableMemory wmem = WritableMemory.allocate(8);
+    assertTrue(wmem.isByteOrderCompatible(ByteOrder.nativeOrder()));
+  }
+
+  @Test(expectedExceptions = IllegalArgumentException.class)
+  public void checkByteOrderNull() {
+    Util.isNativeByteOrder(null);
+    fail();
+  }
+
+  @Test
+  public void checkIsNativeByteOrder() {
+    assertTrue(BaseStateImpl.isNativeByteOrder(ByteOrder.nativeOrder()));
+    try {
+      BaseStateImpl.isNativeByteOrder(null);
+      fail();
+    } catch (final IllegalArgumentException e) {}
+  }
+
+  @Test
+  public void checkXxHash64() {
+    WritableMemory mem = WritableMemory.allocate(8);
+    long out = mem.xxHash64(mem.getLong(0), 1L);
+    assertTrue(out != 0);
+  }
+
+  @Test
+  public void checkTypeDecode() {
+    for (int i = 0; i < 128; i++) {
+      BaseStateImpl.typeDecode(i);
+    }
+  }
+
+  /********************/
+  @Test
+  public void printlnTest() {
+    println("PRINTING: "+this.getClass().getName());
+  }
+
+  /**
+   * @param s value to print
+   */
+  static void println(String s) {
+    //System.out.println(s); //disable here
+  }
+
+}

Propchange: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BaseStateTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
==============================================================================
--- 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
 (added)
+++ 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
 Tue May 21 21:11:49 2024
@@ -0,0 +1,462 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.memory.internal;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.datasketches.memory.Buffer;
+import org.apache.datasketches.memory.DefaultMemoryRequestServer;
+import org.apache.datasketches.memory.Memory;
+import org.apache.datasketches.memory.ReadOnlyException;
+import org.apache.datasketches.memory.WritableBuffer;
+import org.apache.datasketches.memory.WritableMemory;
+import org.testng.annotations.Test;
+
+public class Buffer2Test {
+
+  @Test
+  public void testWrapByteBuf() {
+    ByteBuffer bb = ByteBuffer.allocate(64).order(ByteOrder.nativeOrder());
+
+    Byte b = 0;
+    while (bb.hasRemaining()) {
+      bb.put(b);
+      b++;
+    }
+    bb.position(0);
+
+    Buffer buffer = 
Buffer.wrap(bb.asReadOnlyBuffer().order(ByteOrder.nativeOrder()));
+    while (buffer.hasRemaining()) {
+      assertEquals(bb.get(), buffer.getByte());
+    }
+
+    assertEquals(true, buffer.hasArray());
+    assertEquals(true, buffer.hasByteBuffer());
+  }
+
+  @Test
+  public void testWrapDirectBB() {
+    ByteBuffer bb = 
ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder());
+
+    Byte b = 0;
+    while (bb.hasRemaining()) {
+      bb.put(b);
+      b++;
+    }
+    bb.position(0);
+
+    Buffer buffer = Buffer.wrap(bb);
+    while (buffer.hasRemaining()) {
+      assertEquals(bb.get(), buffer.getByte());
+    }
+
+    assertEquals(false, buffer.hasArray());
+    assertEquals(true, buffer.hasByteBuffer());
+  }
+
+  @Test
+  public void testWrapByteArray() {
+    byte[] byteArray = new byte[64];
+
+    for (byte i = 0; i < 64; i++) {
+      byteArray[i] = i;
+    }
+
+    Buffer buffer = Memory.wrap(byteArray).asBuffer();
+    int i = 0;
+    while (buffer.hasRemaining()) {
+      assertEquals(byteArray[i++], buffer.getByte());
+    }
+
+    buffer.setPosition(0);
+    byte[] copyByteArray = new byte[64];
+    buffer.getByteArray(copyByteArray, 0, 64);
+    assertEquals(byteArray, copyByteArray);
+
+    assertEquals(true, buffer.hasArray());
+    assertEquals(false, buffer.hasByteBuffer());
+  }
+
+  @Test
+  public void testWrapCharArray() {
+    char[] charArray = new char[64];
+
+    for (char i = 0; i < 64; i++) {
+      charArray[i] = i;
+    }
+
+    Buffer buffer = Memory.wrap(charArray).asBuffer();
+    int i = 0;
+    while (buffer.hasRemaining()) {
+      assertEquals(charArray[i++], buffer.getChar());
+    }
+
+    buffer.setPosition(0);
+    char[] copyCharArray = new char[64];
+    buffer.getCharArray(copyCharArray, 0, 64);
+    assertEquals(charArray, copyCharArray);
+  }
+
+  @Test
+  public void testWrapShortArray() {
+    short[] shortArray = new short[64];
+
+    for (short i = 0; i < 64; i++) {
+      shortArray[i] = i;
+    }
+
+    Buffer buffer = Memory.wrap(shortArray).asBuffer();
+    int i = 0;
+    while (buffer.hasRemaining()) {
+      assertEquals(shortArray[i++], buffer.getShort());
+    }
+
+    buffer.setPosition(0);
+    short[] copyShortArray = new short[64];
+    buffer.getShortArray(copyShortArray, 0, 64);
+    assertEquals(shortArray, copyShortArray);
+  }
+
+  @Test
+  public void testWrapIntArray() {
+    int[] intArray = new int[64];
+
+    for (int i = 0; i < 64; i++) {
+      intArray[i] = i;
+    }
+
+    Buffer buffer = Memory.wrap(intArray).asBuffer();
+    int i = 0;
+    while (buffer.hasRemaining()) {
+      assertEquals(intArray[i++], buffer.getInt());
+    }
+
+    buffer.setPosition(0);
+    int[] copyIntArray = new int[64];
+    buffer.getIntArray(copyIntArray, 0, 64);
+    assertEquals(intArray, copyIntArray);
+  }
+
+  @Test
+  public void testWrapLongArray() {
+    long[] longArray = new long[64];
+
+    for (int i = 0; i < 64; i++) {
+      longArray[i] = i;
+    }
+
+    Buffer buffer = Memory.wrap(longArray).asBuffer();
+    int i = 0;
+    while (buffer.hasRemaining()) {
+      assertEquals(longArray[i++], buffer.getLong());
+    }
+
+    buffer.setPosition(0);
+    long[] copyLongArray = new long[64];
+    buffer.getLongArray(copyLongArray, 0, 64);
+    assertEquals(longArray, copyLongArray);
+  }
+
+  @Test
+  public void testWrapFloatArray() {
+    float[] floatArray = new float[64];
+
+    for (int i = 0; i < 64; i++) {
+      floatArray[i] = i;
+    }
+
+    Buffer buffer = Memory.wrap(floatArray).asBuffer();
+    int i = 0;
+    while (buffer.hasRemaining()) {
+      assertEquals(floatArray[i++], buffer.getFloat());
+    }
+
+    buffer.setPosition(0);
+    float[] copyFloatArray = new float[64];
+    buffer.getFloatArray(copyFloatArray, 0, 64);
+    assertEquals(floatArray, copyFloatArray);
+  }
+
+  @Test
+  public void testWrapDoubleArray() {
+    double[] doubleArray = new double[64];
+
+    for (int i = 0; i < 64; i++) {
+      doubleArray[i] = i;
+    }
+
+    Buffer buffer = Memory.wrap(doubleArray).asBuffer();
+    int i = 0;
+    while (buffer.hasRemaining()) {
+      assertEquals(doubleArray[i++], buffer.getDouble());
+    }
+
+    buffer.setPosition(0);
+    double[] copyDoubleArray = new double[64];
+    buffer.getDoubleArray(copyDoubleArray, 0, 64);
+    assertEquals(doubleArray, copyDoubleArray);
+  }
+
+  @Test
+  public void testWrapBooleanArray() {
+    boolean[] booleanArray = new boolean[64];
+
+    for (int i = 0; i < 64; i++) {
+      if ((i % 3) == 0) {
+        booleanArray[i] = true;
+      }
+    }
+
+    Buffer buffer = Memory.wrap(booleanArray).asBuffer();
+    int i = 0;
+    while (buffer.hasRemaining()) {
+      assertEquals(booleanArray[i++], buffer.getBoolean());
+    }
+
+    buffer.setPosition(0);
+    boolean[] copyBooleanArray = new boolean[64];
+    buffer.getBooleanArray(copyBooleanArray, 0, 64);
+    for (int j = 0; j < copyBooleanArray.length; j++) {
+      assertEquals(booleanArray[j], copyBooleanArray[j]);
+    }
+  }
+
+  @Test
+  public void testByteBufferPositionPreservation() {
+    ByteBuffer bb = ByteBuffer.allocate(64).order(ByteOrder.nativeOrder());
+
+    Byte b = 0;
+    while (bb.hasRemaining()) {
+      bb.put(b);
+      b++;
+    }
+    bb.position(10);
+
+    Buffer buffer = Buffer.wrap(bb);
+    while (buffer.hasRemaining()) {
+      assertEquals(bb.get(), buffer.getByte());
+    }
+  }
+
+  @Test
+  public void testGetAndHasRemaining() {
+    ByteBuffer bb = ByteBuffer.allocate(64).order(ByteOrder.nativeOrder());
+
+    Byte b = 0;
+    while (bb.hasRemaining()) {
+      bb.put(b);
+      b++;
+    }
+    bb.position(10);
+
+    Buffer buffer = Buffer.wrap(bb);
+    assertEquals(bb.hasRemaining(), buffer.hasRemaining());
+    assertEquals(bb.remaining(), buffer.getRemaining());
+  }
+
+  @Test
+  public void testGetSetIncResetPosition() {
+    ByteBuffer bb = ByteBuffer.allocate(64).order(ByteOrder.nativeOrder());
+
+    Byte b = 0;
+    while (bb.hasRemaining()) {
+      bb.put(b);
+      b++;
+    }
+    bb.position(10);
+
+    Buffer buffer = Buffer.wrap(bb);
+    assertEquals(bb.position(), buffer.getPosition());
+    assertEquals(30, buffer.setPosition(30).getPosition());
+    assertEquals(40, buffer.incrementPosition(10).getPosition());
+    assertEquals(0, buffer.resetPosition().getPosition());
+  }
+
+  @Test
+  public void testByteBufferSlice() {
+    ByteBuffer bb = ByteBuffer.allocate(64).order(ByteOrder.nativeOrder());
+
+    Byte b = 0;
+    while (bb.hasRemaining()) {
+      bb.put(b);
+      b++;
+    }
+    bb.position(10);
+
+    Buffer buffer = Buffer.wrap(bb.slice().order(ByteOrder.nativeOrder()));
+    while (buffer.hasRemaining()) {
+      assertEquals(bb.get(), buffer.getByte());
+    }
+
+    assertEquals(bb.position(), buffer.getPosition() + 10);
+    assertEquals(30, buffer.setPosition(30).getPosition());
+    assertEquals(40, buffer.incrementPosition(10).getPosition());
+    assertEquals(0, buffer.resetPosition().getPosition());
+  }
+
+  @Test
+  public void testDuplicateAndRegion() {
+    ByteBuffer bb = ByteBuffer.allocate(64).order(ByteOrder.nativeOrder());
+
+    Byte b = 0;
+    while (bb.hasRemaining()) {
+      bb.put(b);
+      b++;
+    }
+    bb.position(10);
+
+    Buffer buffer = Buffer.wrap(bb.slice().order(ByteOrder.nativeOrder())); 
//slice = 54
+    buffer.setPosition(30);//remaining = 24
+    Buffer dupBuffer = buffer.duplicate(); //all 54
+    Buffer regionBuffer = buffer.region(); //24
+
+    assertEquals(dupBuffer.getStart(), buffer.getStart());
+    assertEquals(regionBuffer.getStart(), buffer.getStart());
+    assertEquals(dupBuffer.getEnd(), buffer.getEnd());
+    assertEquals(regionBuffer.getEnd(), buffer.getRemaining());
+    assertEquals(dupBuffer.getPosition(), buffer.getPosition());
+    assertEquals(regionBuffer.getPosition(), 0);
+    assertEquals(dupBuffer.getCapacity(), buffer.getCapacity());
+    assertEquals(regionBuffer.getCapacity(), buffer.getCapacity() - 30);
+  }
+
+  @Test
+  public void checkRORegions() {
+    int n = 16;
+    int n2 = n / 2;
+    long[] arr = new long[n];
+    for (int i = 0; i < n; i++) { arr[i] = i; }
+    Memory mem = Memory.wrap(arr);
+    Buffer buf = mem.asBuffer();
+    Buffer reg = buf.region(n2 * 8, n2 * 8, buf.getTypeByteOrder()); //top half
+    for (int i = 0; i < n2; i++) {
+      long v = reg.getLong(i * 8);
+      long e = i + n2;
+      assertEquals(v, e);
+    }
+  }
+
+  @Test
+  public void testAsMemory() {
+    ByteBuffer bb = ByteBuffer.allocate(64).order(ByteOrder.nativeOrder());
+
+    Byte b = 0;
+    while (bb.hasRemaining()) {
+      bb.put(b);
+      b++;
+    }
+    bb.position(10);
+
+    Buffer buffer = Buffer.wrap(bb);
+    Memory memory = buffer.asMemory();
+
+    assertEquals(buffer.getCapacity(), memory.getCapacity());
+
+    while(buffer.hasRemaining()){
+      assertEquals(memory.getByte(buffer.getPosition()), buffer.getByte());
+    }
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testROByteBuffer() {
+    byte[] arr = new byte[64];
+    ByteBuffer roBB = ByteBuffer.wrap(arr).asReadOnlyBuffer();
+    Buffer buf = Buffer.wrap(roBB);
+    WritableBuffer wbuf = (WritableBuffer) buf;
+    wbuf.putByte(0, (byte) 1);
+  }
+
+  @Test(expectedExceptions = ReadOnlyException.class)
+  public void testROByteBuffer2() {
+    byte[] arr = new byte[64];
+    ByteBuffer roBB = ByteBuffer.wrap(arr).asReadOnlyBuffer();
+    Buffer buf = Buffer.wrap(roBB);
+    WritableBuffer wbuf = (WritableBuffer) buf;
+    wbuf.putByteArray(arr, 0, 64);
+  }
+
+  @Test(expectedExceptions = ReadOnlyException.class)
+  public void testIllegalFill() {
+    byte[] arr = new byte[64];
+    ByteBuffer roBB = ByteBuffer.wrap(arr).asReadOnlyBuffer();
+    Buffer buf = Buffer.wrap(roBB);
+    WritableBuffer wbuf = (WritableBuffer) buf;
+    wbuf.fill((byte)0);
+  }
+
+  @Test
+  public void checkWritableWrap() {
+    ByteBuffer bb = ByteBuffer.allocate(16);
+    WritableBuffer buf = WritableBuffer.writableWrap(bb, 
ByteOrder.nativeOrder(), null);
+    assertNotNull(buf);
+    buf = WritableBuffer.writableWrap(bb, ByteOrder.nativeOrder(), new 
DefaultMemoryRequestServer());
+    assertNotNull(buf);
+  }
+
+  @Test
+  public void testWritableDuplicate() {
+    WritableMemory wmem = WritableMemory.writableWrap(new byte[1]);
+    WritableBuffer wbuf = wmem.asWritableBuffer();
+    WritableBuffer wbuf2 = wbuf.writableDuplicate();
+    assertEquals(wbuf2.getCapacity(), 1);
+    Buffer buf = wmem.asBuffer();
+    assertEquals(buf.getCapacity(), 1);
+  }
+
+  @Test
+  public void checkIndependence() {
+    int cap = 64;
+    WritableMemory wmem = WritableMemory.allocate(cap);
+    WritableBuffer wbuf1 = wmem.asWritableBuffer();
+    WritableBuffer wbuf2 = wmem.asWritableBuffer();
+    assertFalse(wbuf1 == wbuf2);
+    assertTrue(wbuf1.isSameResource(wbuf2));
+
+    WritableMemory reg1 = wmem.writableRegion(0, cap);
+    WritableMemory reg2 = wmem.writableRegion(0, cap);
+    assertFalse(reg1 == reg2);
+    assertTrue(reg1.isSameResource(reg2));
+
+
+    WritableBuffer wbuf3 = wbuf1.writableRegion();
+    WritableBuffer wbuf4 = wbuf1.writableRegion();
+    assertFalse(wbuf3 == wbuf4);
+    assertTrue(wbuf3.isSameResource(wbuf4));
+  }
+
+  @Test
+  public void printlnTest() {
+    println("PRINTING: "+this.getClass().getName());
+  }
+
+  /**
+   * @param s value to print
+   */
+  static void println(String s) {
+    //System.out.println(s); //disable here
+  }
+
+}

Propchange: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Buffer2Test.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferBoundaryCheckTest.java
==============================================================================
--- 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferBoundaryCheckTest.java
 (added)
+++ 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferBoundaryCheckTest.java
 Tue May 21 21:11:49 2024
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.memory.internal;
+
+import org.apache.datasketches.memory.WritableMemory;
+import org.testng.annotations.Test;
+
+public class BufferBoundaryCheckTest {
+
+  private final WritableMemory writableMemory = WritableMemory.allocate(8);
+
+  @Test
+  public void testGetBoolean() {
+    writableMemory.getBoolean(7);
+    try {
+      writableMemory.getBoolean(8);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testPutBoolean() {
+    writableMemory.putBoolean(7, true);
+    try {
+      writableMemory.putBoolean(8, true);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testGetByte() {
+    writableMemory.getByte(7);
+    try {
+      writableMemory.getByte(8);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testPutByte() {
+    writableMemory.putByte(7, (byte) 1);
+    try {
+      writableMemory.putByte(8, (byte) 1);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testGetChar() {
+    writableMemory.getChar(6);
+    try {
+      writableMemory.getChar(7);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testPutChar() {
+    writableMemory.putChar(6, 'a');
+    try {
+      writableMemory.putChar(7, 'a');
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testGetShort() {
+    writableMemory.getShort(6);
+    try {
+      writableMemory.getShort(7);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testPutShort() {
+    writableMemory.putShort(6, (short) 1);
+    try {
+      writableMemory.putShort(7, (short) 1);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testGetInt() {
+    writableMemory.getInt(4);
+    try {
+      writableMemory.getInt(5);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testPutInt() {
+    writableMemory.putInt(4, 1);
+    try {
+      writableMemory.putInt(5, 1);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testGetFloat() {
+    writableMemory.getFloat(4);
+    try {
+      writableMemory.getFloat(5);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testPutFloat() {
+    writableMemory.putFloat(4, 1f);
+    try {
+      writableMemory.putFloat(5, 1f);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testGetLong() {
+    writableMemory.getLong(0);
+    try {
+      writableMemory.getLong(1);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testPutLong() {
+    writableMemory.putLong(0, 1L);
+    try {
+      writableMemory.putLong(1, 1L);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testGetDouble() {
+    writableMemory.getDouble(0);
+    try {
+      writableMemory.getDouble(1);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testPutDouble() {
+    writableMemory.putDouble(0, 1d);
+    try {
+      writableMemory.putDouble(1, 1d);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testGetAndAddLong() {
+    writableMemory.getAndAddLong(0, 1L);
+    try {
+      writableMemory.getAndAddLong(1, 1L);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testGetAndSetLong() {
+    writableMemory.getAndSetLong(0, 1L);
+    try {
+      writableMemory.getAndSetLong(1, 1L);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+
+  @Test
+  public void testCompareAndSwapLong() {
+    writableMemory.compareAndSwapLong(0, 0L, 1L);
+    try {
+      writableMemory.compareAndSwapLong(1, 0L, 1L);
+      throw new RuntimeException("Expected AssertionError");
+    } catch (final AssertionError expected) {
+      // ignore
+    }
+  }
+}

Propchange: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferBoundaryCheckTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
==============================================================================
--- 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
 (added)
+++ 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
 Tue May 21 21:11:49 2024
@@ -0,0 +1,341 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.memory.internal;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.fail;
+
+import java.nio.ByteBuffer;
+
+import org.apache.datasketches.memory.Buffer;
+import org.apache.datasketches.memory.WritableBuffer;
+import org.apache.datasketches.memory.WritableHandle;
+import org.apache.datasketches.memory.WritableMemory;
+import org.testng.annotations.Test;
+
+/**
+ * @author Lee Rhodes
+ */
+public class BufferInvariantsTest {
+
+  @Test
+  public void testRegion() {
+    ByteBuffer byteBuffer = ByteBuffer.allocate(10);
+    byteBuffer.limit(7);
+    Buffer buff = Buffer.wrap(byteBuffer); //assuming buff has cap of 8
+    assertEquals(buff.getCapacity(), 10); //wrong should be 8
+    buff.getByte(); //pos moves to 1
+    Buffer copyBuff = buff.region(); //pos: 0, start: 0, end: 6: cap: 7
+    assertEquals(copyBuff.getEnd(), 6);
+    assertEquals(copyBuff.getCapacity(), 6);
+    assertEquals(copyBuff.getStart(), 0);
+    assertEquals(copyBuff.getPosition(), 0);
+
+    buff.setStartPositionEnd(1, 1, 5);
+    buff.getByte();
+    Buffer copyBuff2 = buff.region();
+    assertEquals(copyBuff2.getEnd(), 3);
+    assertEquals(copyBuff2.getCapacity(), 3);
+    assertEquals(copyBuff2.getStart(), 0);
+    assertEquals(copyBuff2.getPosition(), 0);
+  }
+
+  @Test
+  public void testBB() {
+    int n = 25;
+    ByteBuffer bb = ByteBuffer.allocate(n);
+    for (byte i = 0; i < n; i++) { bb.put(i, i); }
+    assertEquals(bb.position(), 0);
+    assertEquals(bb.limit(), n);
+    assertEquals(bb.get(0), 0);
+//    print("Orig : ");
+//    printbb(bb);
+
+    bb.limit(20);
+    bb.position(5);
+    assertEquals(bb.remaining(), 15);
+//    print("Set  : ");
+//    printbb(bb);
+
+    ByteBuffer dup = bb.duplicate();
+    assertEquals(dup.position(), 5);
+    assertEquals(dup.limit(), 20);
+    assertEquals(dup.capacity(), 25);
+//    print("Dup  : ");
+//    printbb(dup);
+
+    ByteBuffer sl = bb.slice();
+    assertEquals(sl.position(), 0);
+    assertEquals(sl.limit(), 15);
+    assertEquals(sl.capacity(), 15);
+//    print("Slice: ");
+//    printbb(sl);
+  }
+
+  @Test
+  public void testBuf() {
+    int n = 25;
+    WritableBuffer buf = WritableMemory.allocate(n).asWritableBuffer();
+    for (byte i = 0; i < n; i++) { buf.putByte(i); }
+    buf.setPosition(0);
+    assertEquals(buf.getPosition(), 0);
+    assertEquals(buf.getEnd(), 25);
+    assertEquals(buf.getCapacity(), 25);
+//    print("Orig  : ");
+//    printbuf(buf);
+
+    buf.setStartPositionEnd(0, 5, 20);
+    assertEquals(buf.getRemaining(), 15);
+    assertEquals(buf.getCapacity(), 25);
+    assertEquals(buf.getByte(), 5);
+    buf.setPosition(5);
+//    print("Set   : ");
+//    printbuf(buf);
+
+    Buffer dup = buf.duplicate();
+    assertEquals(dup.getRemaining(), 15);
+    assertEquals(dup.getCapacity(), 25);
+    assertEquals(dup.getByte(), 5);
+    dup.setPosition(5);
+//    print("Dup   : ");
+//    printbuf(dup);
+
+
+    Buffer reg = buf.region();
+    assertEquals(reg.getPosition(), 0);
+    assertEquals(reg.getEnd(), 15);
+    assertEquals(reg.getRemaining(), 15);
+    assertEquals(reg.getCapacity(), 15);
+    assertEquals(reg.getByte(), 5);
+    reg.setPosition(0);
+//    print("Region: ");
+//    printbuf(reg);
+  }
+
+  @Test
+  public void testBufWrap() {
+    int n = 25;
+    ByteBuffer bb = ByteBuffer.allocate(n);
+    for (byte i = 0; i < n; i++) { bb.put(i, i); }
+
+    bb.position(5);
+    bb.limit(20);
+
+    Buffer buf = Buffer.wrap(bb);
+    assertEquals(buf.getPosition(), 5);
+    assertEquals(buf.getEnd(), 20);
+    assertEquals(buf.getRemaining(), 15);
+    assertEquals(buf.getCapacity(), 25);
+    assertEquals(buf.getByte(), 5);
+    buf.setPosition(5);
+//    print("Buf.wrap: ");
+//    printbuf(buf);
+
+    Buffer reg = buf.region();
+    assertEquals(reg.getPosition(), 0);
+    assertEquals(reg.getEnd(), 15);
+    assertEquals(reg.getRemaining(), 15);
+    assertEquals(reg.getCapacity(), 15);
+    assertEquals(reg.getByte(), 5);
+    reg.setPosition(0);
+//    print("Buf.region: ");
+//    printbuf(reg);
+  }
+
+  @Test
+  public void checkLimitsDirect() throws Exception {
+    try (WritableHandle hand = WritableMemory.allocateDirect(100)) {
+      WritableMemory wmem = hand.getWritable();
+      Buffer buf = wmem.asBuffer();
+      buf.setStartPositionEnd(40, 45, 50);
+      buf.setStartPositionEnd(0, 0, 100);
+      try {
+        buf.setStartPositionEnd(0, 0, 101);
+        fail();
+      } catch (AssertionError e) {
+        //ok
+      }
+    }
+  }
+
+  @Test
+  public void testRegionDirect() {
+    ByteBuffer byteBuffer = ByteBuffer.allocate(10);
+    byteBuffer.limit(7);
+    Buffer buff = Buffer.wrap(byteBuffer); //assuming buff has cap of 8
+    assertEquals(buff.getCapacity(), 10); //wrong should be 8
+    buff.getByte(); //pos moves to 1
+    Buffer copyBuff = buff.region(); //pos: 0, start: 0, end: 6: cap: 7
+    assertEquals(copyBuff.getEnd(), 6);
+    assertEquals(copyBuff.getCapacity(), 6);
+    assertEquals(copyBuff.getStart(), 0);
+    assertEquals(copyBuff.getPosition(), 0);
+
+    buff.setStartPositionEnd(1, 1, 5);
+    buff.getByte();
+    Buffer copyBuff2 = buff.region();
+    assertEquals(copyBuff2.getEnd(), 3);
+    assertEquals(copyBuff2.getCapacity(), 3);
+    assertEquals(copyBuff2.getStart(), 0);
+    assertEquals(copyBuff2.getPosition(), 0);
+  }
+
+  @Test
+  public void testBBDirect() {
+    int n = 25;
+    ByteBuffer bb = ByteBuffer.allocateDirect(n);
+    for (byte i = 0; i < n; i++) { bb.put(i, i); }
+    assertEquals(bb.position(), 0);
+    assertEquals(bb.limit(), n);
+    assertEquals(bb.get(0), 0);
+//    print("Orig : ");
+//    printbb(bb);
+
+    bb.limit(20);
+    bb.position(5);
+    assertEquals(bb.remaining(), 15);
+//    print("Set  : ");
+//    printbb(bb);
+
+    ByteBuffer dup = bb.duplicate();
+    assertEquals(dup.position(), 5);
+    assertEquals(dup.limit(), 20);
+    assertEquals(dup.capacity(), 25);
+//    print("Dup  : ");
+//    printbb(dup);
+
+    ByteBuffer sl = bb.slice();
+    assertEquals(sl.position(), 0);
+    assertEquals(sl.limit(), 15);
+    assertEquals(sl.capacity(), 15);
+//    print("Slice: ");
+//    printbb(sl);
+  }
+
+  @Test
+  public void testBufDirect() throws Exception {
+    int n = 25;
+    try (WritableHandle whand = WritableMemory.allocateDirect(n)) {
+    WritableMemory wmem = whand.getWritable();
+    WritableBuffer buf = wmem.asWritableBuffer();
+    for (byte i = 0; i < n; i++) { buf.putByte(i); }
+    buf.setPosition(0);
+    assertEquals(buf.getPosition(), 0);
+    assertEquals(buf.getEnd(), 25);
+    assertEquals(buf.getCapacity(), 25);
+//    print("Orig  : ");
+//    printbuf(buf);
+
+    buf.setStartPositionEnd(0, 5, 20);
+    assertEquals(buf.getRemaining(), 15);
+    assertEquals(buf.getCapacity(), 25);
+    assertEquals(buf.getByte(), 5);
+    buf.setPosition(5);
+//    print("Set   : ");
+//    printbuf(buf);
+
+    Buffer dup = buf.duplicate();
+    assertEquals(dup.getRemaining(), 15);
+    assertEquals(dup.getCapacity(), 25);
+    assertEquals(dup.getByte(), 5);
+    dup.setPosition(5);
+//    print("Dup   : ");
+//    printbuf(dup);
+
+
+    Buffer reg = buf.region();
+    assertEquals(reg.getPosition(), 0);
+    assertEquals(reg.getEnd(), 15);
+    assertEquals(reg.getRemaining(), 15);
+    assertEquals(reg.getCapacity(), 15);
+    assertEquals(reg.getByte(), 5);
+    reg.setPosition(0);
+//    print("Region: ");
+//    printbuf(reg);
+    }
+  }
+
+  @Test
+  public void testBufWrapDirect() {
+    int n = 25;
+    ByteBuffer bb = ByteBuffer.allocateDirect(n);
+    for (byte i = 0; i < n; i++) { bb.put(i, i); }
+
+    bb.position(5);
+    bb.limit(20);
+
+    Buffer buf = Buffer.wrap(bb);
+    assertEquals(buf.getPosition(), 5);
+    assertEquals(buf.getEnd(), 20);
+    assertEquals(buf.getRemaining(), 15);
+    assertEquals(buf.getCapacity(), 25);
+    assertEquals(buf.getByte(), 5);
+    buf.setPosition(5);
+//    print("Buf.wrap: ");
+//    printbuf(buf);
+
+    Buffer reg = buf.region();
+    assertEquals(reg.getPosition(), 0);
+    assertEquals(reg.getEnd(), 15);
+    assertEquals(reg.getRemaining(), 15);
+    assertEquals(reg.getCapacity(), 15);
+    assertEquals(reg.getByte(), 5);
+    reg.setPosition(0);
+//    print("Buf.region: ");
+//    printbuf(reg);
+  }
+
+
+  static void printbb(ByteBuffer bb) {
+    println("pos: " + bb.position() + ", lim: " + bb.limit() + ", cap: " + 
bb.capacity());
+    int rem = bb.remaining();
+    int pos = bb.position();
+    int i;
+    for (i = 0; i < (rem-1); i++) {
+      print(bb.get(i+ pos) + ", ");
+    }
+    println(bb.get(i + pos) + "\n");
+  }
+
+  static void printbuf(Buffer buf) {
+    println("pos: " + buf.getPosition() + ", end: " + buf.getEnd() + ", cap: " 
+ buf.getCapacity());
+    long rem = buf.getRemaining();
+    long pos = buf.getPosition();
+    int i;
+    for (i = 0; i < (rem-1); i++) {
+      print(buf.getByte(i+ pos) + ", ");
+    }
+    println(buf.getByte(i + pos) + "\n");
+  }
+
+  /**
+   * @param s value to print
+   */
+  static void println(String s) {
+    //System.out.println(s); //disable here
+  }
+
+  /**
+   * @param s value to print
+   */
+  static void print(String s) {
+    //System.out.print(s); //disable here
+  }
+}

Propchange: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferInvariantsTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferReadWriteSafetyTest.java
==============================================================================
--- 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferReadWriteSafetyTest.java
 (added)
+++ 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferReadWriteSafetyTest.java
 Tue May 21 21:11:49 2024
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.memory.internal;
+
+import java.nio.ByteBuffer;
+
+import org.apache.datasketches.memory.Buffer;
+import org.apache.datasketches.memory.ReadOnlyException;
+import org.apache.datasketches.memory.WritableBuffer;
+import org.apache.datasketches.memory.WritableMemory;
+import org.testng.annotations.Test;
+
+public class BufferReadWriteSafetyTest {
+
+  // Test various operations with read-only Buffer
+
+  private final WritableBuffer buf = (WritableBuffer) 
Buffer.wrap(ByteBuffer.allocate(8));
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutByte() {
+    buf.putByte(0, (byte) 1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutBytePositional() {
+    buf.putByte((byte) 1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutBoolean() {
+    buf.putBoolean(0, true);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutBooleanPositional() {
+    buf.putBoolean(true);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutShort() {
+    buf.putShort(0, (short) 1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutShortPositional() {
+    buf.putShort((short) 1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutChar() {
+    buf.putChar(0, (char) 1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutCharPositional() {
+    buf.putChar((char) 1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutInt() {
+    buf.putInt(0, 1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutIntPositional() {
+    buf.putInt(1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutLong() {
+    buf.putLong(0, 1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutLongPositional() {
+    buf.putLong(1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutFloat() {
+    buf.putFloat(0, 1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutFloatPositional() {
+    buf.putFloat(1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutDouble() {
+    buf.putDouble(0, 1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPutDoublePositional() {
+    buf.putDouble(1);
+  }
+
+  @Test(expectedExceptions = ReadOnlyException.class)
+  public void testPutByteArray() {
+    buf.putByteArray(new byte[] {1}, 0, 1);
+  }
+
+  @Test(expectedExceptions = ReadOnlyException.class)
+  public void testPutBooleanArray() {
+    buf.putBooleanArray(new boolean[] {true}, 0, 1);
+  }
+
+  @Test(expectedExceptions = ReadOnlyException.class)
+  public void testPutShortArray() {
+    buf.putShortArray(new short[] {1}, 0, 1);
+  }
+
+  @Test(expectedExceptions = ReadOnlyException.class)
+  public void testPutCharArray() {
+    buf.putCharArray(new char[] {1}, 0, 1);
+  }
+
+  @Test(expectedExceptions = ReadOnlyException.class)
+  public void testPutIntArray() {
+    buf.putIntArray(new int[] {1}, 0, 1);
+  }
+
+  @Test(expectedExceptions = ReadOnlyException.class)
+  public void testPutLongArray() {
+    buf.putLongArray(new long[] {1}, 0, 1);
+  }
+
+  @Test(expectedExceptions = ReadOnlyException.class)
+  public void testPutFloatArray() {
+    buf.putFloatArray(new float[] {1}, 0, 1);
+  }
+
+  @Test(expectedExceptions = ReadOnlyException.class)
+  public void testDoubleByteArray() {
+    buf.putDoubleArray(new double[] {1}, 0, 1);
+  }
+
+  // Now, test that various ways to obtain a read-only buffer produce a 
read-only buffer indeed
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testWritableMemoryAsBuffer() {
+    WritableBuffer buf1 = (WritableBuffer) 
WritableMemory.allocate(8).asBuffer();
+    buf1.putInt(1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testWritableBufferRegion() {
+    WritableBuffer buf1 = (WritableBuffer) 
WritableMemory.allocate(8).asWritableBuffer().region();
+    buf1.putInt(1);
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testWritableBufferDuplicate() {
+    WritableBuffer buf1 = (WritableBuffer) 
WritableMemory.allocate(8).asWritableBuffer().duplicate();
+    buf1.putInt(1);
+  }
+}

Propchange: 
dev/datasketches/memory/2.2.0-RC1/apache-datasketches-memory-2.2.0-src/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/BufferReadWriteSafetyTest.java
------------------------------------------------------------------------------
    svn:executable = *



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to