use of org.apache.phoenix.memory.MemoryManager.MemoryChunk in project phoenix by apache.
the class MemoryManagerTest method testResizeWaitForMemoryAvailable.
@Ignore("See PHOENIX-2840")
@Test
public void testResizeWaitForMemoryAvailable() throws Exception {
final GlobalMemoryManager gmm = spy(new GlobalMemoryManager(100, 80));
final ChildMemoryManager rmm1 = new ChildMemoryManager(gmm, 100);
final ChildMemoryManager rmm2 = new ChildMemoryManager(gmm, 100);
final CountDownLatch latch = new CountDownLatch(2);
Thread t1 = new Thread() {
@Override
public void run() {
MemoryChunk c1 = rmm1.allocate(50);
MemoryChunk c2 = rmm1.allocate(40);
sleepFor(40);
c1.close();
sleepFor(20);
c2.close();
latch.countDown();
}
};
Thread t2 = new Thread() {
@Override
public void run() {
sleepFor(20);
MemoryChunk c3 = rmm2.allocate(10);
// Will require waiting for a bit of time before t1 frees the requested memory
c3.resize(50);
Mockito.verify(gmm, atLeastOnce()).waitForBytesToFree(anyLong(), anyLong());
c3.close();
latch.countDown();
}
};
t1.start();
t2.start();
latch.await(1, TimeUnit.SECONDS);
// Main thread competes with others to get all memory, but should wait
// until both threads are complete (since that's when the memory will
// again be all available.
ChildMemoryManager rmm = new ChildMemoryManager(gmm, 100);
MemoryChunk c = rmm.allocate(100);
c.close();
assertTrue(rmm.getAvailableMemory() == rmm.getMaxMemory());
assertTrue(rmm1.getAvailableMemory() == rmm1.getMaxMemory());
assertTrue(rmm2.getAvailableMemory() == rmm2.getMaxMemory());
}
use of org.apache.phoenix.memory.MemoryManager.MemoryChunk in project phoenix by apache.
the class MemoryManagerTest method testChildDecreaseAllocation.
@Test
public void testChildDecreaseAllocation() throws Exception {
MemoryManager gmm = spy(new GlobalMemoryManager(100, 1));
ChildMemoryManager rmm1 = new ChildMemoryManager(gmm, 100);
ChildMemoryManager rmm2 = new ChildMemoryManager(gmm, 10);
MemoryChunk c1 = rmm1.allocate(50);
MemoryChunk c2 = rmm2.allocate(5, 50);
assertTrue(c2.getSize() == 10);
c1.close();
assertTrue(rmm1.getAvailableMemory() == rmm1.getMaxMemory());
c2.close();
assertTrue(rmm2.getAvailableMemory() == rmm2.getMaxMemory());
assertTrue(gmm.getAvailableMemory() == gmm.getMaxMemory());
}
use of org.apache.phoenix.memory.MemoryManager.MemoryChunk in project phoenix by apache.
the class MemoryManagerTest method testWaitUntilResize.
@Ignore("See PHOENIX-2840")
@Test
public void testWaitUntilResize() throws Exception {
final GlobalMemoryManager gmm = spy(new GlobalMemoryManager(100, 80));
final ChildMemoryManager rmm1 = new ChildMemoryManager(gmm, 100);
final MemoryChunk c1 = rmm1.allocate(70);
final CountDownLatch latch = new CountDownLatch(2);
Thread t1 = new Thread() {
@Override
public void run() {
MemoryChunk c2 = rmm1.allocate(20);
sleepFor(40);
// resize down to test that other thread is notified
c1.resize(20);
sleepFor(20);
c2.close();
c1.close();
assertTrue(rmm1.getAvailableMemory() == rmm1.getMaxMemory());
latch.countDown();
}
};
Thread t2 = new Thread() {
@Override
public void run() {
sleepFor(20);
ChildMemoryManager rmm2 = new ChildMemoryManager(gmm, 100);
MemoryChunk c3 = rmm2.allocate(10);
long startTime = System.currentTimeMillis();
// Test that resize waits if memory not available
c3.resize(60);
// c1 was resized not closed
assertTrue(c1.getSize() == 20);
// we waited some time before the allocate happened
Mockito.verify(gmm, atLeastOnce()).waitForBytesToFree(anyLong(), anyLong());
c3.close();
assertTrue(rmm2.getAvailableMemory() == rmm2.getMaxMemory());
latch.countDown();
}
};
t1.start();
t2.start();
latch.await(1, TimeUnit.SECONDS);
// Main thread competes with others to get all memory, but should wait
// until both threads are complete (since that's when the memory will
// again be all available.
ChildMemoryManager rmm = new ChildMemoryManager(gmm, 100);
MemoryChunk c = rmm.allocate(100);
c.close();
assertTrue(rmm.getAvailableMemory() == rmm.getMaxMemory());
}
Aggregations