@Test public void testRangeOnlySearch() throws Exception { Map<String, List<String>> query = new HashMap<>(); final int eventCountToCapture = TENANT_RANGE_EVENTS_NUM / 2; final int secondsDelta = 10; DateTime fromDateTime = new DateTime().minusSeconds(RANGE_STEP_IN_SECONDS * eventCountToCapture - secondsDelta); query.put(Event.fromParameterName, Arrays.asList(Long.toString(fromDateTime.getMillis()))); List<Map<String, Object>> results = searchIO.search(TENANT_RANGE, query); Assert.assertEquals(eventCountToCapture, results.size()); DateTime untilDateTime = new DateTime().minusSeconds(RANGE_STEP_IN_SECONDS * eventCountToCapture - secondsDelta); query.clear(); query.put(Event.untilParameterName, Arrays.asList(Long.toString(untilDateTime.getMillis()))); results = searchIO.search(TENANT_RANGE, query); Assert.assertEquals(eventCountToCapture, results.size()); query.clear(); fromDateTime = new DateTime().minusSeconds(RANGE_STEP_IN_SECONDS * 2 - secondsDelta); untilDateTime = new DateTime().minusSeconds(RANGE_STEP_IN_SECONDS - secondsDelta); query.put(Event.fromParameterName, Arrays.asList(Long.toString(fromDateTime.getMillis()))); query.put(Event.untilParameterName, Arrays.asList(Long.toString(untilDateTime.getMillis()))); results = searchIO.search(TENANT_RANGE, query); Assert.assertEquals(1, results.size()); }
@Override public List<Map<String, Object>> search(String tenant, Map<String, List<String>> query) { ArrayList<Map<String, Object>> searchResults = new ArrayList<>(); Timer.Context eventSearchTimerContext = eventSearchTimer.time(); try { String result = elasticsearchRestHelper.fetchEvents(tenant, query); searchResults.addAll(getEventResults(result)); } catch(IOException e){ String format = "Query for given event in elasticsearch failed. Exception message: %s"; log.error(String.format(format, e.getMessage())); throw new RuntimeException(String.format(format, e.getMessage()), e); } finally{ eventSearchTimerContext.stop(); } return searchResults; }
EventElasticSearchIO implements EventsIO { @Override public List<Map<String, Object>> search(String tenant, Map<String, List<String>> query) { ArrayList<Map<String, Object>> searchResults = new ArrayList<>(); Timer.Context eventSearchTimerContext = eventSearchTimer.time(); try { String result = elasticsearchRestHelper.fetchEvents(tenant, query); searchResults.addAll(getEventResults(result)); } catch(IOException e){ String format = "Query for given event in elasticsearch failed. Exception message: %s"; log.error(String.format(format, e.getMessage())); throw new RuntimeException(String.format(format, e.getMessage()), e); } finally{ eventSearchTimerContext.stop(); } return searchResults; } }
EventElasticSearchIO implements EventsIO { @Override public List<Map<String, Object>> search(String tenant, Map<String, List<String>> query) { ArrayList<Map<String, Object>> searchResults = new ArrayList<>(); Timer.Context eventSearchTimerContext = eventSearchTimer.time(); try { String result = elasticsearchRestHelper.fetchEvents(tenant, query); searchResults.addAll(getEventResults(result)); } catch(IOException e){ String format = "Query for given event in elasticsearch failed. Exception message: %s"; log.error(String.format(format, e.getMessage())); throw new RuntimeException(String.format(format, e.getMessage()), e); } finally{ eventSearchTimerContext.stop(); } return searchResults; } EventElasticSearchIO(); }
EventElasticSearchIO implements EventsIO { @Override public List<Map<String, Object>> search(String tenant, Map<String, List<String>> query) { ArrayList<Map<String, Object>> searchResults = new ArrayList<>(); Timer.Context eventSearchTimerContext = eventSearchTimer.time(); try { String result = elasticsearchRestHelper.fetchEvents(tenant, query); searchResults.addAll(getEventResults(result)); } catch(IOException e){ String format = "Query for given event in elasticsearch failed. Exception message: %s"; log.error(String.format(format, e.getMessage())); throw new RuntimeException(String.format(format, e.getMessage()), e); } finally{ eventSearchTimerContext.stop(); } return searchResults; } EventElasticSearchIO(); @Override void insert(String tenantId, Map<String, Object> event); @Override List<Map<String, Object>> search(String tenant, Map<String, List<String>> query); }
EventElasticSearchIO implements EventsIO { @Override public List<Map<String, Object>> search(String tenant, Map<String, List<String>> query) { ArrayList<Map<String, Object>> searchResults = new ArrayList<>(); Timer.Context eventSearchTimerContext = eventSearchTimer.time(); try { String result = elasticsearchRestHelper.fetchEvents(tenant, query); searchResults.addAll(getEventResults(result)); } catch(IOException e){ String format = "Query for given event in elasticsearch failed. Exception message: %s"; log.error(String.format(format, e.getMessage())); throw new RuntimeException(String.format(format, e.getMessage()), e); } finally{ eventSearchTimerContext.stop(); } return searchResults; } EventElasticSearchIO(); @Override void insert(String tenantId, Map<String, Object> event); @Override List<Map<String, Object>> search(String tenant, Map<String, List<String>> query); static final String EVENT_INDEX; static final String ES_TYPE; public ElasticsearchRestHelper elasticsearchRestHelper; }