Search in sources :

Example 21 with LocalMemoryContext

use of io.trino.memory.context.LocalMemoryContext in project trino by trinodb.

the class TestPageProcessor method testProjectEmptyPage.

@Test
public void testProjectEmptyPage() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectAllFilter()), ImmutableList.of(new InputPageProjection(0, BIGINT)));
    Page inputPage = new Page(createLongSequenceBlock(0, 0));
    LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName());
    Iterator<Optional<Page>> output = pageProcessor.process(SESSION, new DriverYieldSignal(), memoryContext, inputPage);
    assertEquals(memoryContext.getBytes(), 0);
    // output should be one page containing no columns (only a count)
    List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
    assertEquals(outputPages.size(), 0);
}
Also used : LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) Optional(java.util.Optional) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 22 with LocalMemoryContext

use of io.trino.memory.context.LocalMemoryContext in project trino by trinodb.

the class TestPageProcessor method testSelectNoneFilter.

@Test
public void testSelectNoneFilter() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectNoneFilter()), ImmutableList.of(new InputPageProjection(0, BIGINT)));
    Page inputPage = new Page(createLongSequenceBlock(0, 100));
    LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName());
    Iterator<Optional<Page>> output = pageProcessor.process(SESSION, new DriverYieldSignal(), memoryContext, inputPage);
    assertEquals(memoryContext.getBytes(), 0);
    List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
    assertEquals(outputPages.size(), 0);
}
Also used : LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) Optional(java.util.Optional) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 23 with LocalMemoryContext

use of io.trino.memory.context.LocalMemoryContext in project trino by trinodb.

the class TestOperatorMemoryRevocation method testOperatorMemoryRevocation.

@Test
public void testOperatorMemoryRevocation() {
    AtomicInteger counter = new AtomicInteger();
    OperatorContext operatorContext = TestingOperatorContext.create(scheduledExecutor);
    LocalMemoryContext revocableMemoryContext = operatorContext.localRevocableMemoryContext();
    revocableMemoryContext.setBytes(1000);
    operatorContext.setMemoryRevocationRequestListener(counter::incrementAndGet);
    operatorContext.requestMemoryRevoking();
    assertTrue(operatorContext.isMemoryRevokingRequested());
    assertEquals(counter.get(), 1);
    // calling resetMemoryRevokingRequested() should clear the memory revoking requested flag
    operatorContext.resetMemoryRevokingRequested();
    assertFalse(operatorContext.isMemoryRevokingRequested());
    operatorContext.requestMemoryRevoking();
    assertEquals(counter.get(), 2);
    assertTrue(operatorContext.isMemoryRevokingRequested());
}
Also used : LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.testng.annotations.Test)

Example 24 with LocalMemoryContext

use of io.trino.memory.context.LocalMemoryContext in project trino by trinodb.

the class TestOperatorMemoryRevocation method testRevocationAlreadyRequested.

@Test
public void testRevocationAlreadyRequested() {
    AtomicInteger counter = new AtomicInteger();
    OperatorContext operatorContext = TestingOperatorContext.create(scheduledExecutor);
    LocalMemoryContext revocableMemoryContext = operatorContext.localRevocableMemoryContext();
    revocableMemoryContext.setBytes(1000);
    // when memory revocation is already requested setting a listener should immediately execute it
    operatorContext.requestMemoryRevoking();
    operatorContext.setMemoryRevocationRequestListener(counter::incrementAndGet);
    assertTrue(operatorContext.isMemoryRevokingRequested());
    assertEquals(counter.get(), 1);
}
Also used : LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.testng.annotations.Test)

Aggregations

LocalMemoryContext (io.trino.memory.context.LocalMemoryContext)24 Test (org.testng.annotations.Test)17 Page (io.trino.spi.Page)7 DriverYieldSignal (io.trino.operator.DriverYieldSignal)5 Optional (java.util.Optional)5 QueryId (io.trino.spi.QueryId)3 LazyBlock (io.trino.spi.block.LazyBlock)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Suppliers (com.google.common.base.Suppliers)1 Futures.immediateVoidFuture (com.google.common.util.concurrent.Futures.immediateVoidFuture)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 Slice (io.airlift.slice.Slice)1 TestingGcMonitor (io.airlift.stats.TestingGcMonitor)1 ExceededMemoryLimitException (io.trino.ExceededMemoryLimitException)1 SqlTask.createSqlTask (io.trino.execution.SqlTask.createSqlTask)1 QueryContext (io.trino.memory.QueryContext)1 MemoryTrackingContext (io.trino.memory.context.MemoryTrackingContext)1