@Test public void search() throws Exception { Mockito.doReturn(EMPTY_SEARCH_RESULT).when(CLIENT).execute(Mockito.any(Search.class)); List<TSDRRecord> result = store.search( ElasticSearchStore.RecordType.METRIC, DataCategory.EXTERNAL.name(), 1L, 0L, 1000); assertThat(result).isEmpty(); result = store.search( ElasticSearchStore.RecordType.METRIC, DataCategory.EXTERNAL.name(), 0L, 0L, 1000); assertThat(result).isEqualTo(Collections.emptyList()); Mockito.verify(CLIENT, Mockito.atLeastOnce()).execute(Mockito.any()); }
@SuppressWarnings("unchecked") <T extends TSDRRecord> List<T> search(RecordType type, String key, long start, long end, int size) { checkNotNull(type); checkNotNull(key); checkState(isRunning(), "The service is not running"); if (end < start) { return Collections.emptyList(); } String query = buildELKQuery(type, key, start, end); SearchResult result = execute(new Search.Builder(query) .addIndex(INDEX) .addType(type.name) .setParameter(Parameters.SIZE, size) .build()); if (result == null || !result.isSucceeded() || result.getTotal() == 0) { return Collections.emptyList(); } return result.getHits(TsdrRecordPayload.class).stream() .map(hit -> (T) hit.source.toRecord(type)) .collect(Collectors.toList()); }
ElasticSearchStore extends AbstractScheduledService implements AutoCloseable { @SuppressWarnings("unchecked") <T extends TSDRRecord> List<T> search(RecordType type, String key, long start, long end, int size) { checkNotNull(type); checkNotNull(key); checkState(isRunning(), "The service is not running"); if (end < start) { return Collections.emptyList(); } String query = buildELKQuery(type, key, start, end); SearchResult result = execute(new Search.Builder(query) .addIndex(INDEX) .addType(type.name) .setParameter(Parameters.SIZE, size) .build()); if (result == null || !result.isSucceeded() || result.getTotal() == 0) { return Collections.emptyList(); } return result.getHits(TsdrRecordPayload.class).stream() .map(hit -> (T) hit.source.toRecord(type)) .collect(Collectors.toList()); } }
ElasticSearchStore extends AbstractScheduledService implements AutoCloseable { @SuppressWarnings("unchecked") <T extends TSDRRecord> List<T> search(RecordType type, String key, long start, long end, int size) { checkNotNull(type); checkNotNull(key); checkState(isRunning(), "The service is not running"); if (end < start) { return Collections.emptyList(); } String query = buildELKQuery(type, key, start, end); SearchResult result = execute(new Search.Builder(query) .addIndex(INDEX) .addType(type.name) .setParameter(Parameters.SIZE, size) .build()); if (result == null || !result.isSucceeded() || result.getTotal() == 0) { return Collections.emptyList(); } return result.getHits(TsdrRecordPayload.class).stream() .map(hit -> (T) hit.source.toRecord(type)) .collect(Collectors.toList()); } @Inject  ElasticSearchStore(); @VisibleForTesting  ElasticSearchStore(Map<String, String> properties, JestClient client); }
ElasticSearchStore extends AbstractScheduledService implements AutoCloseable { @SuppressWarnings("unchecked") <T extends TSDRRecord> List<T> search(RecordType type, String key, long start, long end, int size) { checkNotNull(type); checkNotNull(key); checkState(isRunning(), "The service is not running"); if (end < start) { return Collections.emptyList(); } String query = buildELKQuery(type, key, start, end); SearchResult result = execute(new Search.Builder(query) .addIndex(INDEX) .addType(type.name) .setParameter(Parameters.SIZE, size) .build()); if (result == null || !result.isSucceeded() || result.getTotal() == 0) { return Collections.emptyList(); } return result.getHits(TsdrRecordPayload.class).stream() .map(hit -> (T) hit.source.toRecord(type)) .collect(Collectors.toList()); } @Inject  ElasticSearchStore(); @VisibleForTesting  ElasticSearchStore(Map<String, String> properties, JestClient client); @PostConstruct void init(); @Override @PreDestroy void close(); }
ElasticSearchStore extends AbstractScheduledService implements AutoCloseable { @SuppressWarnings("unchecked") <T extends TSDRRecord> List<T> search(RecordType type, String key, long start, long end, int size) { checkNotNull(type); checkNotNull(key); checkState(isRunning(), "The service is not running"); if (end < start) { return Collections.emptyList(); } String query = buildELKQuery(type, key, start, end); SearchResult result = execute(new Search.Builder(query) .addIndex(INDEX) .addType(type.name) .setParameter(Parameters.SIZE, size) .build()); if (result == null || !result.isSucceeded() || result.getTotal() == 0) { return Collections.emptyList(); } return result.getHits(TsdrRecordPayload.class).stream() .map(hit -> (T) hit.source.toRecord(type)) .collect(Collectors.toList()); } @Inject  ElasticSearchStore(); @VisibleForTesting  ElasticSearchStore(Map<String, String> properties, JestClient client); @PostConstruct void init(); @Override @PreDestroy void close();  }