maedhroz commented on PR #4900:
URL: https://github.com/apache/cassandra/pull/4900#issuecomment-4791824207

   For finding 1 above, this test does appear to fail, but I could still just 
be testing the wrong thing...
   
   ```
   /**
    * Verifies that re-inserting every key that already exists reports a net 
heap delta of exactly zero,
    * and that {@code onAllocatedOnHeap} is actually invoked (not silently 
skipped by an {@code allocated > 0}
    * guard). The call must happen so that callers accumulating signed deltas 
see the confirmation, and so
    * that a negative allocated value cannot permanently disable accounting by 
crossing the -1 sentinel.
    */
   @Test
   public void netZeroDeltaOnAllocatedOnHeapIsInvoked()
   {
       int numKeys = BTree.MAX_KEYS * BTree.MAX_KEYS;
       Integer[] keys = new Integer[numKeys];
       for (int i = 0; i < numKeys; i++)
           keys[i] = i;
   
       Object[] tree = BTree.build(BulkIterator.of(keys), numKeys, 
UpdateFunction.noOp());
       Object[] insert = BTree.build(BulkIterator.of(keys), numKeys, 
UpdateFunction.noOp());
   
       // Use a counting variant that records invocation count separately from 
the accumulated total
       final long[] invocations = { 0 };
       final long[] total = { 0 };
   
       UpdateFunction<Integer, Integer> fn = new UpdateFunction<Integer, 
Integer>()
       {
           @Override public Integer insert(Integer i) { return i; }
           @Override public Integer merge(Integer existing, Integer update) { 
return update; }
           @Override public void onAllocatedOnHeap(long delta)
           {
               invocations[0]++;
               total[0] += delta;
           }
       };
   
       Object[] result = BTree.update(tree, insert, CMP, fn);
   
       assertSame("full re-insert of identical keys must reuse the existing 
tree root", tree, result);
   
       assertEquals("reported net delta must be zero for a full re-insert of 
identical keys",
                    0L, total[0]);
   
       // This is the assertion that catches the bug:
       // with `if (allocated > 0)`, invocations[0] == 0 (call skipped entirely)
       // with `if (allocated != 0)` or unconditional, invocations[0] == 1
       assertTrue("onAllocatedOnHeap must be invoked even for a net-zero 
update; " +
                  "skipping it conflates 'tracking disabled' (-1 sentinel) with 
'net zero result' (0)",
                  invocations[0] >= 1);
   }
   
   ```


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