Search in sources :

Example 6 with NoOpIndexClient

use of io.prestosql.testing.NoOpIndexClient in project hetu-core by openlookeng.

the class TestIndexCacheRemoval method testExpiredCacheIndices.

@Test
public void testExpiredCacheIndices() throws Exception {
    synchronized (this) {
        HiveSplit testHiveSplit;
        testHiveSplit = mock(HiveSplit.class);
        when(testHiveSplit.getPath()).thenReturn(testPath);
        when(testHiveSplit.getLastModifiedTime()).thenReturn(testLastModifiedTime);
        IndexMetadata indexMetadata = mock(IndexMetadata.class);
        when(indexMetadata.getLastModifiedTime()).thenReturn(testLastModifiedTime);
        Index index = mock(Index.class);
        when(indexMetadata.getIndex()).then(new Returns(index));
        when(index.getMemoryUsage()).thenReturn(new DataSize(1, KILOBYTE).toBytes());
        List<IndexMetadata> expectedIndices = new LinkedList<>();
        expectedIndices.add(indexMetadata);
        IndexCacheLoader indexCacheLoader = mock(IndexCacheLoader.class);
        when(indexCacheLoader.load(any())).then(new Returns(expectedIndices));
        IndexCache indexCache = new IndexCache(indexCacheLoader, loadDelay, new NoOpIndexClient());
        List<IndexMetadata> actualSplitIndex = indexCache.getIndices(catalog, table, testHiveSplit, effectivePredicate, testPartitions);
        assertEquals(actualSplitIndex.size(), 0);
        Thread.sleep(loadDelay + 2000);
        actualSplitIndex = indexCache.getIndices(catalog, table, testHiveSplit, effectivePredicate, testPartitions);
        assertEquals(actualSplitIndex.size(), numberOfIndexTypes);
        // now the index is in the cache, but changing the lastmodified date of the split should invalidate it
        when(testHiveSplit.getLastModifiedTime()).thenReturn(testLastModifiedTime + 1);
        actualSplitIndex = indexCache.getIndices(catalog, table, testHiveSplit, effectivePredicate, testPartitions);
        assertEquals(actualSplitIndex.size(), 0);
    }
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) HiveSplit(io.prestosql.plugin.hive.HiveSplit) DataSize(io.airlift.units.DataSize) Index(io.prestosql.spi.heuristicindex.Index) IndexMetadata(io.prestosql.spi.heuristicindex.IndexMetadata) NoOpIndexClient(io.prestosql.testing.NoOpIndexClient) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 7 with NoOpIndexClient

use of io.prestosql.testing.NoOpIndexClient in project boostkit-bigdata by kunpengcompute.

the class TestIndexCacheFetch method testIndexCacheThrowsExecutionException.

@Test
public void testIndexCacheThrowsExecutionException() throws Exception {
    synchronized (this) {
        HiveSplit testHiveSplit;
        testHiveSplit = mock(HiveSplit.class);
        when(testHiveSplit.getPath()).thenReturn(testPath);
        when(testHiveSplit.getLastModifiedTime()).thenReturn(testLastModifiedTime);
        IndexMetadata indexMetadata = mock(IndexMetadata.class);
        when(indexMetadata.getLastModifiedTime()).thenReturn(testLastModifiedTime);
        List<IndexMetadata> expectedIndices = new LinkedList<>();
        expectedIndices.add(indexMetadata);
        IndexCacheLoader indexCacheLoader = mock(IndexCacheLoader.class);
        when(indexCacheLoader.load(any())).thenThrow(ExecutionException.class);
        IndexCache indexCache = new IndexCache(indexCacheLoader, loadDelay, new NoOpIndexClient());
        List<IndexMetadata> actualSplitIndex = indexCache.getIndices(catalog, table, testHiveSplit, effectivePredicate, testPartitions);
        assertEquals(actualSplitIndex.size(), 0);
        Thread.sleep(loadDelay + 2000);
        actualSplitIndex = indexCache.getIndices(catalog, table, testHiveSplit, effectivePredicate, testPartitions);
        assertEquals(actualSplitIndex.size(), 0);
    }
}
Also used : HiveSplit(io.prestosql.plugin.hive.HiveSplit) IndexMetadata(io.prestosql.spi.heuristicindex.IndexMetadata) NoOpIndexClient(io.prestosql.testing.NoOpIndexClient) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 8 with NoOpIndexClient

use of io.prestosql.testing.NoOpIndexClient in project boostkit-bigdata by kunpengcompute.

the class TestIndexCachePartition method testIndexCacheWithPartitions.

@Test
public void testIndexCacheWithPartitions() throws Exception {
    synchronized (this) {
        HiveSplit testHiveSplit;
        testHiveSplit = mock(HiveSplit.class);
        when(testHiveSplit.getPath()).thenReturn(testPath);
        when(testHiveSplit.getLastModifiedTime()).thenReturn(testLastModifiedTime);
        HiveColumnHandle partitionColumnHandle;
        TupleDomain<HiveColumnHandle> effectivePredicateForPartition;
        partitionColumnHandle = mock(HiveColumnHandle.class);
        // partition column should be filtered out this should never get called
        when(partitionColumnHandle.getName()).thenThrow(Exception.class);
        effectivePredicateForPartition = TupleDomain.withColumnDomains(ImmutableMap.of(testColumnHandle, domain, partitionColumnHandle, domain));
        List<HiveColumnHandle> partitionColumns = ImmutableList.of(partitionColumnHandle);
        IndexMetadata indexMetadata = mock(IndexMetadata.class);
        when(indexMetadata.getLastModifiedTime()).thenReturn(testLastModifiedTime);
        Index index = mock(Index.class);
        when(indexMetadata.getIndex()).then(new Returns(index));
        when(index.getMemoryUsage()).thenReturn(new DataSize(1, KILOBYTE).toBytes());
        List<IndexMetadata> expectedIndices = new LinkedList<>();
        expectedIndices.add(indexMetadata);
        IndexCacheLoader indexCacheLoader = mock(IndexCacheLoader.class);
        when(indexCacheLoader.load(any())).then(new Returns(expectedIndices));
        IndexCache indexCache = new IndexCache(indexCacheLoader, loadDelay, new NoOpIndexClient());
        List<IndexMetadata> actualSplitIndex = indexCache.getIndices(catalog, table, testHiveSplit, effectivePredicateForPartition, partitionColumns);
        assertEquals(actualSplitIndex.size(), 0);
        Thread.sleep(loadDelay + 2000);
        actualSplitIndex = indexCache.getIndices(catalog, table, testHiveSplit, effectivePredicateForPartition, partitionColumns);
        assertEquals(actualSplitIndex.size(), numberOfIndexTypes);
    }
}
Also used : Index(io.prestosql.spi.heuristicindex.Index) LinkedList(java.util.LinkedList) Returns(org.mockito.internal.stubbing.answers.Returns) HiveSplit(io.prestosql.plugin.hive.HiveSplit) DataSize(io.airlift.units.DataSize) IndexMetadata(io.prestosql.spi.heuristicindex.IndexMetadata) NoOpIndexClient(io.prestosql.testing.NoOpIndexClient) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle) Test(org.testng.annotations.Test)

Example 9 with NoOpIndexClient

use of io.prestosql.testing.NoOpIndexClient in project hetu-core by openlookeng.

the class TestIndexCacheFetch method testIndexCacheGetIndices.

@Test
public void testIndexCacheGetIndices() throws Exception {
    synchronized (this) {
        HiveSplit testHiveSplit;
        testHiveSplit = mock(HiveSplit.class);
        when(testHiveSplit.getPath()).thenReturn(testPath);
        when(testHiveSplit.getLastModifiedTime()).thenReturn(testLastModifiedTime);
        IndexMetadata indexMetadata = mock(IndexMetadata.class);
        when(indexMetadata.getLastModifiedTime()).thenReturn(testLastModifiedTime);
        Index index = mock(Index.class);
        when(indexMetadata.getIndex()).then(new Returns(index));
        when(index.getMemoryUsage()).thenReturn(new DataSize(1, KILOBYTE).toBytes());
        List<IndexMetadata> expectedIndices = new LinkedList<>();
        expectedIndices.add(indexMetadata);
        IndexCacheLoader indexCacheLoader = mock(IndexCacheLoader.class);
        when(indexCacheLoader.load(any())).then(new Returns(expectedIndices));
        IndexCache indexCache = new IndexCache(indexCacheLoader, new NoOpIndexClient());
        List<IndexMetadata> actualSplitIndex = indexCache.getIndices(catalog, table, testHiveSplit, effectivePredicate, testPartitions);
        assertEquals(actualSplitIndex.size(), 0);
        Thread.sleep(loadDelay + 2000);
        actualSplitIndex = indexCache.getIndices(catalog, table, testHiveSplit, effectivePredicate, testPartitions);
        assertEquals(actualSplitIndex.size(), numberOfIndexTypes);
        assertEquals(actualSplitIndex.get(0), expectedIndices.get(0));
    }
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) HiveSplit(io.prestosql.plugin.hive.HiveSplit) DataSize(io.airlift.units.DataSize) Index(io.prestosql.spi.heuristicindex.Index) IndexMetadata(io.prestosql.spi.heuristicindex.IndexMetadata) NoOpIndexClient(io.prestosql.testing.NoOpIndexClient) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 10 with NoOpIndexClient

use of io.prestosql.testing.NoOpIndexClient in project hetu-core by openlookeng.

the class TestIndexCachePartition method testIndexCacheWithPartitions.

@Test
public void testIndexCacheWithPartitions() throws Exception {
    synchronized (this) {
        HiveSplit testHiveSplit;
        testHiveSplit = mock(HiveSplit.class);
        when(testHiveSplit.getPath()).thenReturn(testPath);
        when(testHiveSplit.getLastModifiedTime()).thenReturn(testLastModifiedTime);
        HiveColumnHandle partitionColumnHandle;
        TupleDomain<HiveColumnHandle> effectivePredicateForPartition;
        partitionColumnHandle = mock(HiveColumnHandle.class);
        // partition column should be filtered out this should never get called
        when(partitionColumnHandle.getName()).thenThrow(Exception.class);
        effectivePredicateForPartition = TupleDomain.withColumnDomains(ImmutableMap.of(testColumnHandle, domain, partitionColumnHandle, domain));
        List<HiveColumnHandle> partitionColumns = ImmutableList.of(partitionColumnHandle);
        IndexMetadata indexMetadata = mock(IndexMetadata.class);
        when(indexMetadata.getLastModifiedTime()).thenReturn(testLastModifiedTime);
        Index index = mock(Index.class);
        when(indexMetadata.getIndex()).then(new Returns(index));
        when(index.getMemoryUsage()).thenReturn(new DataSize(1, KILOBYTE).toBytes());
        List<IndexMetadata> expectedIndices = new LinkedList<>();
        expectedIndices.add(indexMetadata);
        IndexCacheLoader indexCacheLoader = mock(IndexCacheLoader.class);
        when(indexCacheLoader.load(any())).then(new Returns(expectedIndices));
        IndexCache indexCache = new IndexCache(indexCacheLoader, loadDelay, new NoOpIndexClient());
        List<IndexMetadata> actualSplitIndex = indexCache.getIndices(catalog, table, testHiveSplit, effectivePredicateForPartition, partitionColumns);
        assertEquals(actualSplitIndex.size(), 0);
        Thread.sleep(loadDelay + 2000);
        actualSplitIndex = indexCache.getIndices(catalog, table, testHiveSplit, effectivePredicateForPartition, partitionColumns);
        assertEquals(actualSplitIndex.size(), numberOfIndexTypes);
    }
}
Also used : Index(io.prestosql.spi.heuristicindex.Index) LinkedList(java.util.LinkedList) Returns(org.mockito.internal.stubbing.answers.Returns) HiveSplit(io.prestosql.plugin.hive.HiveSplit) DataSize(io.airlift.units.DataSize) IndexMetadata(io.prestosql.spi.heuristicindex.IndexMetadata) NoOpIndexClient(io.prestosql.testing.NoOpIndexClient) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle) Test(org.testng.annotations.Test)

Aggregations

IndexMetadata (io.prestosql.spi.heuristicindex.IndexMetadata)14 NoOpIndexClient (io.prestosql.testing.NoOpIndexClient)14 LinkedList (java.util.LinkedList)14 Test (org.testng.annotations.Test)14 Returns (org.mockito.internal.stubbing.answers.Returns)12 DataSize (io.airlift.units.DataSize)11 Index (io.prestosql.spi.heuristicindex.Index)11 HiveSplit (io.prestosql.plugin.hive.HiveSplit)10 HiveColumnHandle (io.prestosql.plugin.hive.HiveColumnHandle)2