Search in sources :

Example 1 with FrameAction

use of org.apache.asterix.common.memory.FrameAction in project asterixdb by apache.

the class ConcurrentFramePoolUnitTest method testFixedSizeSubscribtion.

@org.junit.Test
public void testFixedSizeSubscribtion() {
    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);
        int i = 0;
        ByteBuffer buffer = ByteBuffer.allocate(DEFAULT_FRAME_SIZE);
        LinkedBlockingDeque<ByteBuffer> buffers = new LinkedBlockingDeque<>();
        FrameAction frameAction = new FrameAction();
        frameAction.setFrame(buffer);
        while (!fmm.subscribe(frameAction)) {
            buffers.put(frameAction.retrieve());
            i++;
        }
        // One subscriber.
        // Check that all frames have been consumed
        Assert.assertEquals(i, NUM_FRAMES);
        // Release a frame (That will be handed out to the subscriber)
        fmm.release(buffers.take());
        // Check that all frames have been consumed (since the released frame have been handed to the consumer)
        Assert.assertEquals(0, fmm.remaining());
    } catch (Throwable th) {
        th.printStackTrace();
        Assert.fail(th.getMessage());
    } finally {
        Assert.assertNull(cause);
    }
}
Also used : ConcurrentFramePool(org.apache.asterix.common.memory.ConcurrentFramePool) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ActiveProperties(org.apache.asterix.common.config.ActiveProperties) FrameAction(org.apache.asterix.common.memory.FrameAction) ByteBuffer(java.nio.ByteBuffer)

Example 2 with FrameAction

use of org.apache.asterix.common.memory.FrameAction in project asterixdb by apache.

the class ConcurrentFramePoolUnitTest method testgetWhileSubscribersExist.

@org.junit.Test
public void testgetWhileSubscribersExist() {
    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);
        int i = 0;
        ByteBuffer buffer = ByteBuffer.allocate(DEFAULT_FRAME_SIZE);
        LinkedBlockingDeque<ByteBuffer> buffers = new LinkedBlockingDeque<>();
        FrameAction frameAction = new FrameAction();
        frameAction.setFrame(buffer);
        while (!fmm.subscribe(frameAction)) {
            buffers.put(frameAction.retrieve());
            i++;
        }
        // One subscriber.
        // Check that all frames have been consumed
        Assert.assertEquals(i, NUM_FRAMES);
        // Release a frame (That will be handed out to the subscriber)
        fmm.release(buffers.take());
        // Check that all frames have been consumed (since the released frame have been handed to the consumer)
        Assert.assertEquals(fmm.remaining(), 0);
        buffers.put(frameAction.retrieve());
        // Create another subscriber that takes frames of double the size
        ByteBuffer bufferTimes2 = ByteBuffer.allocate(DEFAULT_FRAME_SIZE * 2);
        LinkedBlockingDeque<ByteBuffer> buffersTimes2 = new LinkedBlockingDeque<>();
        FrameAction frameActionTimes2 = new FrameAction();
        frameActionTimes2.setFrame(bufferTimes2);
        Assert.assertEquals(true, fmm.subscribe(frameActionTimes2));
        // release a small one
        fmm.release(buffers.take());
        Assert.assertEquals(fmm.remaining(), 1);
        // Check that a small get fails
        Assert.assertEquals(null, fmm.get());
        // release another small one
        fmm.release(buffers.take());
        // Check that no small frames exists in the pool since subscriber request was satisfied
        Assert.assertEquals(fmm.remaining(), 0);
        buffersTimes2.add(frameActionTimes2.retrieve());
        fmm.release(buffers);
        fmm.release(bufferTimes2);
        Assert.assertEquals(fmm.remaining(), NUM_FRAMES);
    } catch (Throwable th) {
        th.printStackTrace();
        Assert.fail(th.getMessage());
    } finally {
        Assert.assertNull(cause);
    }
}
Also used : ConcurrentFramePool(org.apache.asterix.common.memory.ConcurrentFramePool) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ActiveProperties(org.apache.asterix.common.config.ActiveProperties) FrameAction(org.apache.asterix.common.memory.FrameAction) ByteBuffer(java.nio.ByteBuffer)

Example 3 with FrameAction

use of org.apache.asterix.common.memory.FrameAction in project asterixdb by apache.

the class ConcurrentFramePoolUnitTest method testLargerThanBudgetSubscribe.

@org.junit.Test
public void testLargerThanBudgetSubscribe() {
    HyracksDataException hde = null;
    try {
        ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", DEFAULT_FRAME_SIZE * 16, DEFAULT_FRAME_SIZE);
        ByteBuffer buffer = ByteBuffer.allocate(DEFAULT_FRAME_SIZE * 32);
        FrameAction frameAction = new FrameAction();
        frameAction.setFrame(buffer);
        fmm.subscribe(frameAction);
    } catch (HyracksDataException e) {
        hde = e;
    } catch (Throwable th) {
        th.printStackTrace();
        Assert.fail(th.getMessage());
    }
    Assert.assertNotNull(hde);
    Assert.assertNull(cause);
}
Also used : ConcurrentFramePool(org.apache.asterix.common.memory.ConcurrentFramePool) FrameAction(org.apache.asterix.common.memory.FrameAction) ByteBuffer(java.nio.ByteBuffer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

ByteBuffer (java.nio.ByteBuffer)3 ConcurrentFramePool (org.apache.asterix.common.memory.ConcurrentFramePool)3 FrameAction (org.apache.asterix.common.memory.FrameAction)3 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)2 ActiveProperties (org.apache.asterix.common.config.ActiveProperties)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1