leerho commented on code in PR #576:
URL: https://github.com/apache/datasketches-java/pull/576#discussion_r1718807733
##########
src/test/java/org/apache/datasketches/theta/UnionImplTest.java:
##########
@@ -192,24 +191,20 @@ public void checkMoveAndResize() {
final int k = 1 << 12;
final int u = 2 * k;
final int bytes = Sketches.getMaxUpdateSketchBytes(k);
- try (WritableHandle wh = WritableMemory.allocateDirect(bytes/2);
- WritableHandle wh2 = WritableMemory.allocateDirect(bytes/2) ) {
- final WritableMemory wmem = wh.getWritable();
- final UpdateSketch sketch =
Sketches.updateSketchBuilder().setNominalEntries(k).build(wmem);
- assertTrue(sketch.isSameResource(wmem));
-
- final WritableMemory wmem2 = wh2.getWritable();
- final Union union = SetOperation.builder().buildUnion(wmem2);
- assertTrue(union.isSameResource(wmem2));
-
- for (int i = 0; i < u; i++) { union.update(i); }
- assertFalse(union.isSameResource(wmem));
-
- final Union union2 = SetOperation.builder().buildUnion(); //on-heap union
- assertFalse(union2.isSameResource(wmem2)); //obviously not
- } catch (final Exception e) {
- throw new RuntimeException(e);
- }
+ WritableMemory wmem = WritableMemory.allocateDirect(bytes / 2);
+ WritableMemory wmem2 = WritableMemory.allocateDirect(bytes / 2);
+ final UpdateSketch sketch =
Sketches.updateSketchBuilder().setNominalEntries(k).build(wmem);
+ assertTrue(sketch.isSameResource(wmem));
+
+ final Union union = SetOperation.builder().buildUnion(wmem2);
+ assertTrue(union.isSameResource(wmem2));
+
+ for (int i = 0; i < u; i++) { union.update(i); }
+ assertFalse(union.isSameResource(wmem));
+
+ final Union union2 = SetOperation.builder().buildUnion(); //on-heap union
+ assertFalse(union2.isSameResource(wmem2)); //obviously not
+ wmem.close();
Review Comment:
Because it has already been closed. In fact, if you try to close wmem2, it
will throw an error.
The purpose of this test is to check the **move** and **resize** behavior
when a sketch is off-heap.
- Note on line 193 we get sufficient bytes to hold the sketch, but on line
195 we under allocate space by half. This will force the sketch to request more
memory.
- The default MemoryRequestServer will allocate new memory on the heap, and
the sketch itself will **move** the data from wmem2 to the new heap allocation,
and then **resize** the internal hash table into the new memory. Then the
sketch will request the MRS to close wmem2, which it does.
I will add some more comments to make this test a little clearer
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]