2021-09-07 19:44:23 +02:00
|
|
|
package it.cavallium.dbengine;
|
|
|
|
|
|
|
|
import static it.cavallium.dbengine.DbTestUtils.destroyAllocator;
|
|
|
|
import static it.cavallium.dbengine.DbTestUtils.ensureNoLeaks;
|
|
|
|
import static it.cavallium.dbengine.DbTestUtils.newAllocator;
|
|
|
|
|
2022-03-16 13:47:56 +01:00
|
|
|
import io.netty5.buffer.api.Buffer;
|
2021-09-07 19:44:23 +02:00
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
public class TestAllocator {
|
|
|
|
|
|
|
|
|
|
|
|
private DbTestUtils.TestAllocator allocator;
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
public void beforeEach() {
|
|
|
|
this.allocator = newAllocator();
|
|
|
|
ensureNoLeaks(allocator.allocator(), false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@AfterEach
|
|
|
|
public void afterEach() {
|
|
|
|
ensureNoLeaks(allocator.allocator(), true, false);
|
|
|
|
destroyAllocator(allocator);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testNoOp() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testShouldPass() {
|
|
|
|
Buffer allocated = allocator.allocator().allocate(5000);
|
|
|
|
allocated.close();
|
|
|
|
ensureNoLeaks(allocator.allocator(), true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testShouldFail() {
|
|
|
|
Buffer allocated = null;
|
|
|
|
try {
|
|
|
|
boolean failed;
|
|
|
|
try {
|
|
|
|
allocated = allocator.allocator().allocate(5000);
|
|
|
|
ensureNoLeaks(allocator.allocator(), true, true);
|
|
|
|
failed = false;
|
|
|
|
} catch (Exception ex) {
|
|
|
|
failed = true;
|
|
|
|
}
|
|
|
|
if (!failed) {
|
|
|
|
Assertions.fail("A leak was not detected!");
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (allocated != null) {
|
|
|
|
allocated.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|