TableMapStore implements MapStore<String, Table> { @Override public void delete(String key) { logger.info("Delete called for value: " + key); elasticsearchConnection.getClient().prepareDelete() .setConsistencyLevel(WriteConsistencyLevel.ALL) .setRefresh(true) .setIndex(TABLE_META_INDEX) .setType(TABLE_META_TYPE) .setId(key) .execute() .actionGet(); logger.info("Deleted value: " + key); } TableMapStore(ElasticsearchConnection elasticsearchConnection); static Factory factory(ElasticsearchConnection elasticsearchConnection); @Override void store(String key, Table value); @Override void storeAll(Map<String, Table> map); @Override void delete(String key); @Override void deleteAll(Collection<String> keys); @Override Table load(String key); @Override Map<String, Table> loadAll(Collection<String> keys); @Override Set<String> loadAllKeys(); static final String TABLE_META_INDEX; static final String TABLE_META_TYPE; }
@Test public void testDelete() throws Exception { Table table = new Table(); table.setName(TEST_TABLE); table.setTtl(30); tableMapStore.store(table.getName(), table); GetResponse response = elasticsearchConnection.getClient().prepareGet() .setIndex(TABLE_META_INDEX) .setType(TABLE_META_TYPE) .setId(table.getName()) .execute() .actionGet(); assertTrue(response.isExists()); tableMapStore.delete(table.getName()); response = elasticsearchConnection.getClient().prepareGet() .setIndex(TABLE_META_INDEX) .setType(TABLE_META_TYPE) .setId(table.getName()) .execute() .actionGet(); assertFalse(response.isExists()); }
@Test(expected = RuntimeException.class) public void testDeleteNullKey() throws Exception { tableMapStore.delete(null); }
@Test public void testDeleteMissingKey() throws Exception { tableMapStore.delete("HELLO"); }