Search in sources :

Example 1 with NO_WAIT

use of com.facebook.presto.execution.buffer.BufferTestUtils.NO_WAIT in project presto by prestodb.

the class TestClientBuffer method testReferenceCount.

@Test
public void testReferenceCount() {
    AtomicInteger releasedPages = new AtomicInteger(0);
    PagesReleasedListener onPagesReleased = (lifespan, releasedPagesCount, releasedSizeInBytes) -> {
        releasedPages.addAndGet(releasedPagesCount);
    };
    ClientBuffer buffer = new ClientBuffer(TASK_INSTANCE_ID, BUFFER_ID, onPagesReleased);
    // add 2 pages and verify they are referenced
    addPage(buffer, createPage(0));
    addPage(buffer, createPage(1));
    assertEquals(releasedPages.get(), 0);
    assertBufferInfo(buffer, 2, 0);
    // read one page
    assertBufferResultEquals(TYPES, getBufferResult(buffer, 0, sizeOfPages(0), NO_WAIT), bufferResult(0, createPage(0)));
    assertEquals(releasedPages.get(), 0);
    assertBufferInfo(buffer, 2, 0);
    // acknowledge first page
    assertBufferResultEquals(TYPES, getBufferResult(buffer, 1, sizeOfPages(1), NO_WAIT), bufferResult(1, createPage(1)));
    assertEquals(releasedPages.get(), 1);
    assertBufferInfo(buffer, 1, 1);
    // destroy the buffer
    buffer.destroy();
    assertEquals(releasedPages.get(), 2);
    assertBufferDestroyed(buffer, 1);
}
Also used : Page(com.facebook.presto.common.Page) PagesReleasedListener(com.facebook.presto.execution.buffer.SerializedPageReference.PagesReleasedListener) PAGES_SERDE(com.facebook.presto.execution.buffer.BufferTestUtils.PAGES_SERDE) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SerializedPageReference.dereferencePages(com.facebook.presto.execution.buffer.SerializedPageReference.dereferencePages) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) NO_WAIT(com.facebook.presto.execution.buffer.BufferTestUtils.NO_WAIT) BufferTestUtils.sizeOfPages(com.facebook.presto.execution.buffer.BufferTestUtils.sizeOfPages) OutputBufferId(com.facebook.presto.execution.buffer.OutputBuffers.OutputBufferId) Deque(java.util.Deque) BufferTestUtils.createPage(com.facebook.presto.execution.buffer.BufferTestUtils.createPage) Duration(io.airlift.units.Duration) ArrayList(java.util.ArrayList) BufferTestUtils.getFuture(com.facebook.presto.execution.buffer.BufferTestUtils.getFuture) PagesSupplier(com.facebook.presto.execution.buffer.ClientBuffer.PagesSupplier) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Objects.requireNonNull(java.util.Objects.requireNonNull) Assert.assertFalse(org.testng.Assert.assertFalse) BufferTestUtils.createBufferResult(com.facebook.presto.execution.buffer.BufferTestUtils.createBufferResult) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) BufferResult.emptyResults(com.facebook.presto.execution.buffer.BufferResult.emptyResults) Lifespan(com.facebook.presto.execution.Lifespan) BigintType(com.facebook.presto.common.type.BigintType) Assert.fail(org.testng.Assert.fail) ThreadSafe(javax.annotation.concurrent.ThreadSafe) GuardedBy(javax.annotation.concurrent.GuardedBy) Preconditions.checkState(com.google.common.base.Preconditions.checkState) BufferTestUtils.assertBufferResultEquals(com.facebook.presto.execution.buffer.BufferTestUtils.assertBufferResultEquals) DataSize(io.airlift.units.DataSize) List(java.util.List) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) ArrayDeque(java.util.ArrayDeque) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PagesReleasedListener(com.facebook.presto.execution.buffer.SerializedPageReference.PagesReleasedListener) Test(org.testng.annotations.Test)

Aggregations

Page (com.facebook.presto.common.Page)1 BigintType (com.facebook.presto.common.type.BigintType)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 Lifespan (com.facebook.presto.execution.Lifespan)1 BufferResult.emptyResults (com.facebook.presto.execution.buffer.BufferResult.emptyResults)1 NO_WAIT (com.facebook.presto.execution.buffer.BufferTestUtils.NO_WAIT)1 PAGES_SERDE (com.facebook.presto.execution.buffer.BufferTestUtils.PAGES_SERDE)1 BufferTestUtils.assertBufferResultEquals (com.facebook.presto.execution.buffer.BufferTestUtils.assertBufferResultEquals)1 BufferTestUtils.createBufferResult (com.facebook.presto.execution.buffer.BufferTestUtils.createBufferResult)1 BufferTestUtils.createPage (com.facebook.presto.execution.buffer.BufferTestUtils.createPage)1 BufferTestUtils.getFuture (com.facebook.presto.execution.buffer.BufferTestUtils.getFuture)1 BufferTestUtils.sizeOfPages (com.facebook.presto.execution.buffer.BufferTestUtils.sizeOfPages)1 PagesSupplier (com.facebook.presto.execution.buffer.ClientBuffer.PagesSupplier)1 OutputBufferId (com.facebook.presto.execution.buffer.OutputBuffers.OutputBufferId)1 PagesReleasedListener (com.facebook.presto.execution.buffer.SerializedPageReference.PagesReleasedListener)1 SerializedPageReference.dereferencePages (com.facebook.presto.execution.buffer.SerializedPageReference.dereferencePages)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 DataSize (io.airlift.units.DataSize)1