### Question:
AWSGlueMetastoreCacheDecorator extends AWSGlueMetastoreBaseDecorator { @Override public Table getTable(String dbName, String tableName) { Table result; if(tableCacheEnabled) { TableIdentifier key = new TableIdentifier(dbName, tableName); Table valueFromCache = tableCache.getIfPresent(key); if(valueFromCache != null) { logger.info("Cache hit for operation [getTable] on key [" + key + "]"); result = valueFromCache; } else { logger.info("Cache miss for operation [getTable] on key [" + key + "]"); result = super.getTable(dbName, tableName); tableCache.put(key, result); } } else { result = super.getTable(dbName, tableName); } return result; } AWSGlueMetastoreCacheDecorator(HiveConf conf, AWSGlueMetastore awsGlueMetastore); @Override Database getDatabase(String dbName); @Override void updateDatabase(String dbName, DatabaseInput databaseInput); @Override void deleteDatabase(String dbName); @Override Table getTable(String dbName, String tableName); @Override void updateTable(String dbName, TableInput tableInput); @Override void deleteTable(String dbName, String tableName);  }### Answer:
@Test public void testGetTableWhenCacheDisabled() { when(hiveConf.getBoolean(AWS_GLUE_TABLE_CACHE_ENABLE, false)).thenReturn(false); Table table = new Table(); AWSGlueMetastoreCacheDecorator cacheDecorator = new AWSGlueMetastoreCacheDecorator(hiveConf, glueMetastore); when(glueMetastore.getTable(DB_NAME, TABLE_NAME)).thenReturn(table); assertEquals(table, cacheDecorator.getTable(DB_NAME, TABLE_NAME)); assertNull(cacheDecorator.tableCache); verify(glueMetastore, times(1)).getTable(DB_NAME, TABLE_NAME); }
@Test public void testGetTableWhenCacheEnabledAndCacheMiss() { Table table = new Table(); AWSGlueMetastoreCacheDecorator cacheDecorator = new AWSGlueMetastoreCacheDecorator(hiveConf, glueMetastore); assertNotNull(cacheDecorator.tableCache); Cache tableCache = mock(Cache.class); cacheDecorator.tableCache = tableCache; when(tableCache.getIfPresent(TABLE_IDENTIFIER)).thenReturn(null); when(glueMetastore.getTable(DB_NAME, TABLE_NAME)).thenReturn(table); doNothing().when(tableCache).put(TABLE_IDENTIFIER, table); assertEquals(table, cacheDecorator.getTable(DB_NAME, TABLE_NAME)); verify(glueMetastore, times(1)).getTable(DB_NAME, TABLE_NAME); verify(tableCache, times(1)).getIfPresent(TABLE_IDENTIFIER); verify(tableCache, times(1)).put(TABLE_IDENTIFIER, table); }
@Test public void testGetTableWhenCacheEnabledAndCacheHit() { Table table = new Table(); AWSGlueMetastoreCacheDecorator cacheDecorator = new AWSGlueMetastoreCacheDecorator(hiveConf, glueMetastore); assertNotNull(cacheDecorator.tableCache); Cache tableCache = mock(Cache.class); cacheDecorator.tableCache = tableCache; when(tableCache.getIfPresent(TABLE_IDENTIFIER)).thenReturn(table); assertEquals(table, cacheDecorator.getTable(DB_NAME, TABLE_NAME)); verify(tableCache, times(1)).getIfPresent(TABLE_IDENTIFIER); }