ElasticsearchSituationStore extends AbstractSituationStore implements SituationStore { public List<Situation> getSituations(final SituationsQuery sitQuery) { List<Situation> situations = new java.util.ArrayList<Situation>(); SearchResponse response=_client.getElasticsearchClient().prepareSearch(_client.getIndex()) .setTypes(_client.getType()) .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setTimeout(TimeValue.timeValueMillis(_timeout)) .setSize(_responseSize) .setQuery(getQueryBuilder(sitQuery)) .execute().actionGet(); long num=response.getHits().getTotalHits(); if (num > _responseSize) { num = _responseSize; } for (int i=0; i < num; i++) { SearchHit hit=response.getHits().getAt(i); try { situations.add(SituationUtil.deserializeSituation(hit.getSourceAsString().getBytes())); } catch (Exception e) { LOG.log(Level.SEVERE, java.util.PropertyResourceBundle .getBundle("situation-store-elasticsearch.Messages").getString("SITUATION-STORE-ELASTICSEARCH-2"), e); } } if (LOG.isLoggable(Level.FINEST)) { LOG.finest("Situations="+situations); } return (situations); } ElasticsearchSituationStore(); @ServiceInit void init(); List<Situation> getSituations(final SituationsQuery sitQuery); void assignSituation(final String situationId, final String userName); void unassignSituation(final String situationId); void updateResolutionState(final String situationId, final ResolutionState resolutionState); @Override void recordSuccessfulResubmit(final String situationId, final String userName); @Override void recordResubmitFailure(final String situationId, final String errorMessage, final String userName); @ServiceClose void close();  }
@Test public void deleteSituation() throws Exception { Situation situation = new Situation(); situation.setId("deleteSituation"); situation.setDescription("deleteSituation"); situation.setTimestamp(System.currentTimeMillis()); situation.setSituationProperties(Collections.singletonMap("1", "1")); _elasticsearchSituationStore.store(situation); try { synchronized(this) { wait(2000); } } catch (Exception e) { fail("Failed to wait"); } SituationsQuery situationQuery = new SituationsQuery(); situationQuery.setDescription(situation.getDescription()); _elasticsearchSituationStore.delete(situationQuery); try { synchronized(this) { wait(2000); } } catch (Exception e) { fail("Failed to wait"); } List<Situation> situations = _elasticsearchSituationStore.getSituations(situationQuery); assertTrue(situations.isEmpty()); }