Search in sources :

Example 1 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) {
        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(), false);
        List<IndexMetadata> actualSplitIndex = indexCache.getIndices(table, column, split);
        assertEquals(actualSplitIndex.size(), 0);
        Thread.sleep(loadDelay + 2000);
        actualSplitIndex = indexCache.getIndices(table, column, split);
        assertEquals(actualSplitIndex.size(), numberOfIndexTypes);
        assertEquals(actualSplitIndex.get(0), expectedIndices.get(0));
    }
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) 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 2 with NoOpIndexClient

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

the class TestIndexCacheFetch method testIndexCacheThrowsExecutionException.

@Test
public void testIndexCacheThrowsExecutionException() throws Exception {
    synchronized (this) {
        IndexMetadata indexMetadata = mock(IndexMetadata.class);
        when(indexMetadata.getLastModifiedTime()).then(new Returns(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, new NoOpIndexClient(), false);
        List<IndexMetadata> actualSplitIndex = indexCache.getIndices(table, column, split);
        assertEquals(actualSplitIndex.size(), 0);
        Thread.sleep(loadDelay + 2000);
        actualSplitIndex = indexCache.getIndices(table, column, split);
        assertEquals(actualSplitIndex.size(), 0);
    }
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) IndexMetadata(io.prestosql.spi.heuristicindex.IndexMetadata) NoOpIndexClient(io.prestosql.testing.NoOpIndexClient) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 3 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) {
        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(), false);
        List<IndexMetadata> actualSplitIndex = indexCache.getIndices(table, column, split);
        assertEquals(actualSplitIndex.size(), 0);
        Thread.sleep(loadDelay + 2000);
        actualSplitIndex = indexCache.getIndices(table, column, split);
        assertEquals(actualSplitIndex.size(), numberOfIndexTypes);
        // now the index is in the cache, but changing the lastmodified date of the split should invalidate it
        when(indexMetadata.getLastModifiedTime()).then(new Returns(testLastModifiedTime + 1));
        actualSplitIndex = indexCache.getIndices(table, column, split);
        assertEquals(actualSplitIndex.size(), 0);
    }
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) 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 4 with NoOpIndexClient

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

the class TestIndexCacheRemoval method testIndexCacheEviction.

@Test
public void testIndexCacheEviction() throws Exception {
    synchronized (this) {
        IndexCacheLoader indexCacheLoader = mock(IndexCacheLoader.class);
        IndexCache indexCache = new IndexCache(indexCacheLoader, new NoOpIndexClient(), false);
        // get index for split1
        IndexMetadata indexMetadata1 = mock(IndexMetadata.class);
        when(indexMetadata1.getLastModifiedTime()).thenReturn(testLastModifiedTime);
        Index index1 = mock(Index.class);
        when(indexMetadata1.getIndex()).thenReturn(index1);
        when(index1.getMemoryUsage()).thenReturn(new DataSize(2, KILOBYTE).toBytes());
        List<IndexMetadata> expectedIndices1 = new LinkedList<>();
        expectedIndices1.add(indexMetadata1);
        when(indexCacheLoader.load(any())).then(new Returns(expectedIndices1));
        // each index is has memory usage of 2, and limit is 2*types of idx, so all should be loaded
        List<IndexMetadata> actualSplitIndex = indexCache.getIndices(table, column, split);
        assertEquals(actualSplitIndex.size(), 0);
        Thread.sleep(loadDelay + 2000);
        actualSplitIndex = indexCache.getIndices(table, column, split);
        assertEquals(actualSplitIndex.size(), numberOfIndexTypes);
        assertEquals(actualSplitIndex.get(0), indexMetadata1);
        assertEquals(indexCache.getCacheSize(), numberOfIndexTypes);
        // get index for split2
        when(connectorSplit.getFilePath()).thenReturn(testPath2);
        IndexMetadata indexMetadata2 = mock(IndexMetadata.class);
        when(indexMetadata2.getLastModifiedTime()).thenReturn(testLastModifiedTime);
        Index index2 = mock(Index.class);
        when(indexMetadata2.getIndex()).thenReturn(index2);
        when(index2.getMemoryUsage()).thenReturn(new DataSize(2, KILOBYTE).toBytes());
        // previous indexes should be evicted bc cache was at max weight limit and new ones should be added
        List<IndexMetadata> expectedIndices2 = new LinkedList<>();
        expectedIndices2.add(indexMetadata2);
        when(indexCacheLoader.load(any())).then(new Returns(expectedIndices2));
        actualSplitIndex = indexCache.getIndices(table, column, split);
        assertEquals(actualSplitIndex.size(), 0);
        assertEquals(indexCache.getCacheSize(), numberOfIndexTypes);
        Thread.sleep(loadDelay + 2000);
        actualSplitIndex = indexCache.getIndices(table, column, split);
        assertEquals(actualSplitIndex.size(), numberOfIndexTypes);
        assertEquals(actualSplitIndex.get(0), indexMetadata2);
        assertEquals(indexCache.getCacheSize(), numberOfIndexTypes);
        // get index for split1
        when(connectorSplit.getFilePath()).thenReturn(testPath);
        actualSplitIndex = indexCache.getIndices(table, column, split);
        assertEquals(actualSplitIndex.size(), 0);
        assertEquals(indexCache.getCacheSize(), numberOfIndexTypes);
    }
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) DataSize(io.airlift.units.DataSize) Index(io.prestosql.spi.heuristicindex.Index) NoOpIndexClient(io.prestosql.testing.NoOpIndexClient) IndexMetadata(io.prestosql.spi.heuristicindex.IndexMetadata) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 5 with NoOpIndexClient

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

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)

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