ReverseDictionaryCache extends AbstractDictionaryCache<K, V> { @Override public Dictionary get(DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier) throws CarbonUtilException { return getDictionary(dictionaryColumnUniqueIdentifier); } ReverseDictionaryCache(String carbonStorePath, CarbonLRUCache carbonLRUCache); @Override Dictionary get(DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier); @Override List<Dictionary> getAll(
      List<DictionaryColumnUniqueIdentifier> dictionaryColumnUniqueIdentifiers); @Override Dictionary getIfPresent(
      DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier); @Override void invalidate(
      DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier);  }
@Test public void get() throws Exception { deleteStorePath(); String columnIdentifier = columnIdentifiers[0]; prepareWriterAndWriteData(dataSet1, columnIdentifier); DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier = createDictionaryColumnUniqueIdentifier(columnIdentifier); Dictionary reverseDictionary = (Dictionary) reverseDictionaryCache.get(dictionaryColumnUniqueIdentifier); assertTrue(null != reverseDictionary); compareSurrogateKeyData(dataSet1, reverseDictionary); reverseDictionary.clear(); removeKeyFromLRUCache(reverseDictionaryCache); }
@Test public void testLRUCacheForMaxSize() throws Exception { deleteStorePath(); new MockUp<CarbonDictionaryColumnMetaChunk>() { @Mock public long getEnd_offset() { return 123456789L; } }; String columnIdentifier = columnIdentifiers[0]; prepareWriterAndWriteData(dataSet1, columnIdentifier); DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier = createDictionaryColumnUniqueIdentifier(columnIdentifier); Dictionary reverseDictionary = null; try { reverseDictionary = (Dictionary) reverseDictionaryCache.get(dictionaryColumnUniqueIdentifier); } catch (Exception e) { assertTrue(e instanceof CarbonUtilException); } assertTrue(null == reverseDictionary); }
@Test public void testLRUCacheForKeyDeletionAfterMaxSizeIsReached() throws Exception { deleteStorePath(); String columnIdentifier = columnIdentifiers[0]; prepareWriterAndWriteData(dataSet1, columnIdentifier); DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier = createDictionaryColumnUniqueIdentifier(columnIdentifier); Dictionary reverseDictionary = (Dictionary) reverseDictionaryCache.get(dictionaryColumnUniqueIdentifier); assertTrue(null != reverseDictionary); reverseDictionary.clear(); new MockUp<CarbonDictionaryColumnMetaChunk>() { @Mock public long getEnd_offset() { return 10485755L; } }; columnIdentifier = columnIdentifiers[1]; prepareWriterAndWriteData(dataSet1, columnIdentifier); dictionaryColumnUniqueIdentifier = createDictionaryColumnUniqueIdentifier(columnIdentifier); reverseDictionary = (Dictionary) reverseDictionaryCache.get(dictionaryColumnUniqueIdentifier); assertTrue(null != reverseDictionary); removeKeyFromLRUCache(reverseDictionaryCache); }
@Test public void testMultipleDictionaryChunks() throws Exception { deleteStorePath(); String columnIdentifier = columnIdentifiers[0]; prepareWriterAndWriteData(dataSet1, columnIdentifier); DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier = createDictionaryColumnUniqueIdentifier(columnIdentifier); Dictionary reverseDictionary = (Dictionary) reverseDictionaryCache.get(dictionaryColumnUniqueIdentifier); assertTrue(null != reverseDictionary); prepareWriterAndWriteData(dataSet2, columnIdentifier); reverseDictionary = (Dictionary) reverseDictionaryCache.get(dictionaryColumnUniqueIdentifier); assertTrue(null != reverseDictionary); List<String> expected = new ArrayList<>(2); expected.addAll(dataSet1); expected.addAll(dataSet2); compareSurrogateKeyData(expected, reverseDictionary); reverseDictionary.clear(); removeKeyFromLRUCache(reverseDictionaryCache); }