Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrinot committed Mar 22, 2024
1 parent 616272f commit 9f07233
Showing 1 changed file with 33 additions and 0 deletions.
Expand Up @@ -29,6 +29,7 @@
import io.questdb.griffin.engine.groupby.StableAwareStringHolder;
import io.questdb.std.Chars;
import io.questdb.std.Numbers;
import io.questdb.std.Rnd;
import io.questdb.std.str.DirectUtf16Sink;
import io.questdb.std.str.StableDirectString;
import io.questdb.test.AbstractCairoTest;
Expand Down Expand Up @@ -93,6 +94,38 @@ public void testClearAndSetDirect() throws Exception {
});
}

@Test
public void testClearAndSetDirect_fuzzed() throws Exception {
assertMemoryLeak(() -> {
try (GroupByAllocator allocator = new GroupByAllocatorArena(64, Numbers.SIZE_1GB);
DirectUtf16Sink directCharSequence = new DirectUtf16Sink(16);
) {
StableAwareStringHolder holder = new StableAwareStringHolder();
holder.setAllocator(allocator);
Rnd rnd = TestUtils.generateRandom(null);
StableDirectString stableDirectString = new StableDirectString();
for (int i = 0; i < 1_000; i++) {
boolean useDirect = rnd.nextBoolean();
int len = rnd.nextPositiveInt() % 100;
if (len == 99) {
holder.clearAndSet(null);
Assert.assertEquals(0, holder.length());
} else if (useDirect) {
directCharSequence.clear();
rnd.nextChars(directCharSequence, len);
stableDirectString.of(directCharSequence.lo(), directCharSequence.hi());
holder.clearAndSet(stableDirectString);
TestUtils.assertEquals(stableDirectString, holder);
} else {
CharSequence cs = rnd.nextChars(len);
holder.clearAndSet(cs);
TestUtils.assertEquals(cs, holder);
}
}
}
});
}

@Test
public void testPutCharSequence() throws Exception {
final int N = 1000;
Expand Down

0 comments on commit 9f07233

Please sign in to comment.