use of org.apache.asterix.common.config.ActiveProperties in project asterixdb by apache.
the class ConcurrentFramePoolUnitTest method testMemoryManager.
@org.junit.Test
public void testMemoryManager() {
ActiveProperties afp = Mockito.mock(ActiveProperties.class);
Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET);
ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE);
int i = 0;
while (fmm.get() != null) {
i++;
}
Assert.assertEquals(i, NUM_FRAMES);
Assert.assertNull(cause);
}
use of org.apache.asterix.common.config.ActiveProperties in project asterixdb by apache.
the class ConcurrentFramePoolUnitTest method testConcurrentVarSizeMemoryManager.
@org.junit.Test
public void testConcurrentVarSizeMemoryManager() {
try {
ActiveProperties afp = Mockito.mock(ActiveProperties.class);
Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET);
ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE);
VarSizeAllocator[] runners = new VarSizeAllocator[NUM_THREADS];
Thread[] threads = new Thread[NUM_THREADS];
Arrays.parallelSetAll(runners, (int i) -> new VarSizeAllocator(fmm));
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(runners[i]);
}
for (int i = 0; i < threads.length; i++) {
threads[i].start();
}
for (int i = 0; i < threads.length; i++) {
threads[i].join();
}
int allocated = 0;
for (int i = 0; i < threads.length; i++) {
if (runners[i].cause() != null) {
runners[i].cause().printStackTrace();
Assert.fail(runners[i].cause().getMessage());
}
allocated += runners[i].getAllocated();
}
Assert.assertEquals(allocated <= NUM_FRAMES, true);
for (int i = 0; i < threads.length; i++) {
Assert.assertEquals(allocated + runners[i].getLastReq() > NUM_FRAMES, true);
}
Assert.assertEquals(allocated + fmm.remaining(), NUM_FRAMES);
} catch (Throwable th) {
th.printStackTrace();
Assert.fail(th.getMessage());
}
Assert.assertNull(cause);
}
use of org.apache.asterix.common.config.ActiveProperties in project asterixdb by apache.
the class ConcurrentFramePoolUnitTest method testAcquireReleaseVarSizeMemoryManager.
@org.junit.Test
public void testAcquireReleaseVarSizeMemoryManager() {
try {
ActiveProperties afp = Mockito.mock(ActiveProperties.class);
Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET);
ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE);
Random random = new Random();
ArrayDeque<ByteBuffer> stack = new ArrayDeque<>();
int i = 0;
int req;
while (true) {
// release
if (random.nextDouble() < RELEASE_PROBABILITY) {
if (!stack.isEmpty()) {
ByteBuffer buffer = stack.pop();
i -= (buffer.capacity() / DEFAULT_FRAME_SIZE);
fmm.release(buffer);
}
} else {
// acquire
req = random.nextInt(MAX_SIZE) + 1;
if (req == 1) {
ByteBuffer buffer = fmm.get();
if (buffer != null) {
stack.push(buffer);
i += 1;
} else {
break;
}
} else {
ByteBuffer buffer = fmm.get(req * DEFAULT_FRAME_SIZE);
if (buffer != null) {
stack.push(buffer);
i += req;
} else {
break;
}
}
}
}
Assert.assertEquals(i <= NUM_FRAMES, true);
Assert.assertEquals(i + req > NUM_FRAMES, true);
Assert.assertEquals(i + fmm.remaining(), NUM_FRAMES);
} catch (Throwable th) {
th.printStackTrace();
Assert.fail(th.getMessage());
} finally {
Assert.assertNull(cause);
}
}
use of org.apache.asterix.common.config.ActiveProperties in project asterixdb by apache.
the class ConcurrentFramePoolUnitTest method testAcquireReleaseMemoryManager.
@org.junit.Test
public void testAcquireReleaseMemoryManager() throws HyracksDataException {
ActiveProperties afp = Mockito.mock(ActiveProperties.class);
Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET);
ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE);
Random random = new Random();
ArrayDeque<ByteBuffer> stack = new ArrayDeque<>();
while (true) {
if (random.nextDouble() < RELEASE_PROBABILITY) {
if (!stack.isEmpty()) {
fmm.release(stack.pop());
}
} else {
ByteBuffer buffer = fmm.get();
if (buffer == null) {
break;
} else {
stack.push(buffer);
}
}
}
Assert.assertEquals(stack.size(), NUM_FRAMES);
Assert.assertEquals(fmm.remaining(), 0);
for (ByteBuffer buffer : stack) {
fmm.release(buffer);
}
stack.clear();
Assert.assertEquals(fmm.remaining(), NUM_FRAMES);
Assert.assertNull(cause);
}
use of org.apache.asterix.common.config.ActiveProperties in project asterixdb by apache.
the class ConcurrentFramePoolUnitTest method testConcurrentAcquireReleaseVarSizeMemoryManager.
@org.junit.Test
public void testConcurrentAcquireReleaseVarSizeMemoryManager() {
try {
ActiveProperties afp = Mockito.mock(ActiveProperties.class);
Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET);
ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE);
VarSizeGoodAllocator[] runners = new VarSizeGoodAllocator[NUM_THREADS];
Thread[] threads = new Thread[NUM_THREADS];
Arrays.parallelSetAll(runners, (int i) -> new VarSizeGoodAllocator(fmm));
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(runners[i]);
}
for (int i = 0; i < threads.length; i++) {
threads[i].start();
}
for (int i = 0; i < threads.length; i++) {
threads[i].join();
}
int i = 0;
for (VarSizeGoodAllocator allocator : runners) {
if (allocator.cause() != null) {
allocator.cause().printStackTrace();
Assert.fail(allocator.cause().getMessage());
}
i += allocator.getAllocated();
}
Assert.assertEquals(NUM_FRAMES, i + fmm.remaining());
} catch (Throwable th) {
th.printStackTrace();
Assert.fail(th.getMessage());
} finally {
Assert.assertNull(cause);
}
}
Aggregations