leerho commented on code in PR #675:
URL: https://github.com/apache/datasketches-java/pull/675#discussion_r2244076523


##########
src/test/java/org/apache/datasketches/quantiles/ReadOnlyMemoryTest.java:
##########
@@ -184,92 +185,92 @@ public void wrapEmptyUpdateSketch() {
   @Test
   public void wrapEmptyCompactSketch() {
     final UpdateDoublesSketch s1 = DoublesSketch.builder().build();
-    final Memory mem = Memory.wrap(s1.compact().toByteArray());
-    DoublesSketch s2 = DoublesSketch.wrap(mem); // compact, so this is ok
+    final MemorySegment seg = 
MemorySegment.ofArray(s1.compact().toByteArray());
+    final DoublesSketch s2 = DoublesSketch.wrap(seg); // compact, so this is ok
     Assert.assertTrue(s2.isEmpty());
   }
 
   @Test
   public void heapifyUnionFromSparse() {
-    UpdateDoublesSketch s1 = DoublesSketch.builder().build();
+    final UpdateDoublesSketch s1 = DoublesSketch.builder().build();
     s1.update(1);
     s1.update(2);
-    Memory mem = Memory.wrap(s1.toByteArray(false));
-    DoublesUnion u = DoublesUnion.heapify(mem);
+    final MemorySegment seg = MemorySegment.ofArray(s1.toByteArray(false));
+    final DoublesUnion u = DoublesUnion.heapify(seg);
     u.update(3);
-    DoublesSketch s2 = u.getResult();
+    final DoublesSketch s2 = u.getResult();
     Assert.assertEquals(s2.getMinItem(), 1.0);
     Assert.assertEquals(s2.getMaxItem(), 3.0);
   }
 
   @Test
   public void heapifyUnionFromCompact() {
-    UpdateDoublesSketch s1 = DoublesSketch.builder().build();
+    final UpdateDoublesSketch s1 = DoublesSketch.builder().build();
     s1.update(1);
     s1.update(2);
-    Memory mem = Memory.wrap(s1.toByteArray(true));
-    DoublesUnion u = DoublesUnion.heapify(mem);
+    final MemorySegment seg = MemorySegment.ofArray(s1.toByteArray(true));
+    final DoublesUnion u = DoublesUnion.heapify(seg);
     u.update(3);
-    DoublesSketch s2 = u.getResult();
+    final DoublesSketch s2 = u.getResult();
     Assert.assertEquals(s2.getMinItem(), 1.0);
     Assert.assertEquals(s2.getMaxItem(), 3.0);
   }
 
   @Test
   public void wrapUnionFromSparse() {
-    UpdateDoublesSketch s1 = DoublesSketch.builder().build();
+    final UpdateDoublesSketch s1 = DoublesSketch.builder().build();
     s1.update(1);
     s1.update(2);
-    Memory mem = Memory.wrap(s1.toByteArray(false));
-    DoublesUnion u = DoublesUnion.wrap(mem);
-    DoublesSketch s2 = u.getResult();
+    final MemorySegment seg = 
MemorySegment.ofArray(s1.toByteArray(false)).asReadOnly();
+    final DoublesUnion u = DoublesUnion.wrap(seg);
+    final DoublesSketch s2 = u.getResult();
     Assert.assertEquals(s2.getMinItem(), 1.0);
     Assert.assertEquals(s2.getMaxItem(), 2.0);
 
     // ensure update and reset methods fail
     try {
       u.update(3);
       fail();
-    } catch (SketchesReadOnlyException e) {
+    } catch (final IllegalArgumentException e) {
       // expected
     }
 
     try {
       u.union(s2);
       fail();
-    } catch (SketchesReadOnlyException e) {
+    } catch (final IllegalArgumentException e) {
       // expected
     }
 
     try {
-      u.union(mem);
+      u.union(seg);
       fail();
-    } catch (SketchesReadOnlyException e) {
+    } catch (final IllegalArgumentException e) {
       // expected
     }
 
     try {
       u.reset();
       fail();
-    } catch (SketchesReadOnlyException e) {
+    } catch (final IllegalArgumentException e) {
       // expected
     }
 
     try {
       u.getResultAndReset();
       fail();
-    } catch (SketchesReadOnlyException e) {
+    } catch (final AssertionError e) { //null

Review Comment:
   This is more complex than what Copilot sees.  Although what is implemented 
works it is not really the right way to do it.  What is missing is a _copy()_ 
method so that the gadget result can be copied for the user and then the 
original one can be reset.  Adding a copy() method is a bit more involved and I 
will do that in a subsequent PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@datasketches.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@datasketches.apache.org
For additional commands, e-mail: dev-h...@datasketches.apache.org

Reply via email to