Skip to content

Commit

Permalink
Improve LocalIndexStatsTest#testMemoryCostTracking
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarotov committed Feb 2, 2022
1 parent c9c9246 commit ffd32f7
Showing 1 changed file with 9 additions and 5 deletions.
Expand Up @@ -383,29 +383,33 @@ public void testMemoryCostTracking() {
assertTrue(keyEmptyCost > 0);
assertTrue(valueEmptyCost > 0);

for (int i = 0; i < 100; ++i) {
for (int i = 0; i < 10000; ++i) {
map.put(i, i);
}
long keyFullCost = keyStats().getMemoryCost();
long valueFullCost = valueStats().getMemoryCost();
assertTrue(keyFullCost > keyEmptyCost);
assertTrue(valueFullCost > valueEmptyCost);

for (int i = 0; i < 50; ++i) {
for (int i = 0; i < 5000; ++i) {
map.remove(i);
}
long keyHalfFullCost = keyStats().getMemoryCost();
long valueHalfFullCost = valueStats().getMemoryCost();
assertTrue(keyHalfFullCost > keyEmptyCost && keyHalfFullCost < keyFullCost);
// keyHalfFullCost < keyFullCost does not necessarily hold, since
// keys are inlined and b+ tree nodes are deleted only when they become
// fully empty
assertTrue(keyHalfFullCost > keyEmptyCost);
assertTrue(valueHalfFullCost > valueEmptyCost && valueHalfFullCost < valueFullCost);

for (int i = 0; i < 50; ++i) {
// 'force' some extra pages to be allocated
for (int i = 10000; i < 15000; ++i) {
map.put(i, i);
}
assertTrue(keyStats().getMemoryCost() > keyHalfFullCost);
assertTrue(valueStats().getMemoryCost() > valueHalfFullCost);

for (int i = 0; i < 50; ++i) {
for (int i = 0; i < 5000; ++i) {
map.set(i, i * i);
}
assertTrue(keyStats().getMemoryCost() > keyHalfFullCost);
Expand Down

0 comments on commit ffd32f7

Please sign in to comment.