TableMapStore implements MapStore<String, Table> { @Override public void deleteAll(Collection<String> keys) { logger.info(String.format("Delete all called for multiple values: %s", keys)); BulkRequestBuilder bulRequestBuilder = elasticsearchConnection.getClient().prepareBulk().setConsistencyLevel(WriteConsistencyLevel.ALL).setRefresh(true); for (String key : keys) { bulRequestBuilder.add(elasticsearchConnection.getClient() .prepareDelete(TABLE_META_INDEX, TABLE_META_TYPE, key)); } bulRequestBuilder.execute().actionGet(); logger.info(String.format("Deleted multiple values: %s", keys)); } 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 testDeleteAll() throws Exception { Map<String, Table> tables = new HashMap<String, Table>(); for (int i = 0; i < 10; i++) { Table table = new Table(); table.setName(UUID.randomUUID().toString()); table.setTtl(20); tables.put(table.getName(), table); } tableMapStore.storeAll(tables); for (String name : tables.keySet()) { GetResponse response = elasticsearchConnection.getClient().prepareGet() .setIndex(TABLE_META_INDEX) .setType(TABLE_META_TYPE) .setId(name) .execute() .actionGet(); assertTrue(response.isExists()); } tableMapStore.deleteAll(tables.keySet()); for (String name : tables.keySet()) { GetResponse response = elasticsearchConnection.getClient().prepareGet() .setIndex(TABLE_META_INDEX) .setType(TABLE_META_TYPE) .setId(name) .execute() .actionGet(); assertFalse(response.isExists()); } }
@Test(expected = RuntimeException.class) public void testDeleteAllNull() throws Exception { tableMapStore.deleteAll(null); }
@Test(expected = RuntimeException.class) public void testDeleteAllNullKeys() throws Exception { List<String> keys = new ArrayList<String>(); keys.add(null); keys.add(null); tableMapStore.deleteAll(keys); }