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


##########
src/test/java/org/apache/datasketches/quantiles/DirectQuantilesMemoryRequestTest.java:
##########
@@ -47,35 +46,30 @@ public void checkLimitedMemoryScenarios() { //Requesting 
application
     final int initBytes = ((2 * k) + 4) << 3; //just the BB
 
     //########## Owning Implementation
-    // This part would actually be part of the Memory owning implemention so 
it is faked here
-    try (WritableHandle wdh = WritableMemory.allocateDirect(initBytes,
-            ByteOrder.nativeOrder(), new DefaultMemoryRequestServer())) {
-      final WritableMemory wmem = wdh.getWritable();
-      println("Initial mem size: " + wmem.getCapacity());
-
-      //########## Receiving Application
-      // The receiving application has been given wmem to use for a sketch,
-      // but alas, it is not ultimately large enough.
-      final UpdateDoublesSketch usk1 = 
DoublesSketch.builder().setK(k).build(wmem);
-      assertTrue(usk1.isEmpty());
-
-      //Load the sketch
-      for (int i = 0; i < u; i++) {
-        // The sketch uses The MemoryRequest, acquired from wmem, to acquire 
more memory as
-        // needed, and requests via the MemoryRequest to free the old 
allocations.
-        usk1.update(i);
-      }
-      final double result = usk1.getQuantile(0.5);
-      println("Result: " + result);
-      assertEquals(result, u / 2.0, 0.05 * u); //Success
-
-      //########## Owning Implementation
-      //The actual Memory has been re-allocated several times,
-      // so the above wmem reference is invalid.
-      println("\nFinal mem size: " + wmem.getCapacity());
-    } catch (Exception e) {
-      throw new RuntimeException(e);
+    // This part would actually be part of the Memory owning implementation so 
it is faked here
+    WritableMemory wmem = WritableMemory.allocateDirect(initBytes, 
ByteOrder.nativeOrder(), new DefaultMemoryRequestServer());
+    println("Initial mem size: " + wmem.getCapacity());
+
+    //########## Receiving Application
+    // The receiving application has been given wmem to use for a sketch,
+    // but alas, it is not ultimately large enough.
+    final UpdateDoublesSketch usk1 = 
DoublesSketch.builder().setK(k).build(wmem);
+    assertTrue(usk1.isEmpty());
+
+    //Load the sketch
+    for (int i = 0; i < u; i++) {
+      // The sketch uses The MemoryRequest, acquired from wmem, to acquire 
more memory as
+      // needed, and requests via the MemoryRequest to free the old 
allocations.
+      usk1.update(i);
     }
+    final double result = usk1.getQuantile(0.5);
+    println("Result: " + result);
+    assertEquals(result, u / 2.0, 0.05 * u); //Success
+
+    //The actual Memory has been re-allocated several times,
+    // so the the wmem reference is invalid. Use the sketch to get the last 
memory reference.
+    WritableMemory lastMem = usk1.getMemory();

Review Comment:
   The real objective of this test is to be an example for the user on how the 
MemoryRequestServer can be used to help with limited memory scenarios where the 
sketch needs to expand beyond what was allocated.  This is why there are 
extensive code comments in this test method.
   
   The actual test that the expansion of memory occurred (several times) and 
the test that the sketch continued successfully is on line 67.   After that, 
the actual capacity of the last memory allocated is printed out just for the 
user.  There is no reason to test it, we know that it was big enough. 
   
   No change is necessary.



-- 
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]

Reply via email to