jmalkin commented on code in PR #576:
URL: https://github.com/apache/datasketches-java/pull/576#discussion_r1718886981
##########
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:
I think in order to call it a test and pretend it means anything we should
assert that the size is larger than the initial size.
--
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]