@Test public void getFileSize() throws Exception { Mockito.when(influxDB.query(Mockito.any(), Mockito.any())) .thenReturn(new JsonQueryResult("InfluxHistory_getFileSize").getQueryResult()); assertEquals(12185178L, history.getFileSize()); verify(influxDB, times(1)).query( Mockito.argThat( Matchers.allOf( Matchers.hasProperty("command", Matchers.equalToIgnoringCase("select sum(\"diskBytes\") as \"diskBytes\" from (select last(\"diskBytes\"::field) as \"diskBytes\" from \"shard\" where \"database\"::tag = '" + DATABASE + "' group by * limit 1)")), Matchers.hasProperty("database", Matchers.equalTo("_internal")))), Mockito.eq(TimeUnit.MILLISECONDS) ); verifyNoMoreInteractions(influxDB); }
@Override public long getFileSize() { final QueryResult result = getInfluxDB().query(new Query(String.format("select sum(\"diskBytes\") as \"diskBytes\" from (select last(\"diskBytes\"::field) as \"diskBytes\" from \"shard\" where \"database\"::tag = '%s' group by * limit 1)", getDatabase().replace("'", "\\'")), "_internal"), TimeUnit.MILLISECONDS); throwOnResultError(result); return result.getResults().stream() .filter(r -> !r.hasError()) .filter(r -> r.getSeries() != null) .flatMap(r -> r.getSeries().stream()) .map(s -> getColumnFromSeries(s, "diskBytes")) .filter(Optional::isPresent) .flatMap(Optional::get) .map(Number.class::cast) .mapToLong(Number::longValue) .findAny() .orElse(0); }
InfluxHistory extends InfluxUtil implements CollectHistory, AutoCloseable { @Override public long getFileSize() { final QueryResult result = getInfluxDB().query(new Query(String.format("select sum(\"diskBytes\") as \"diskBytes\" from (select last(\"diskBytes\"::field) as \"diskBytes\" from \"shard\" where \"database\"::tag = '%s' group by * limit 1)", getDatabase().replace("'", "\\'")), "_internal"), TimeUnit.MILLISECONDS); throwOnResultError(result); return result.getResults().stream() .filter(r -> !r.hasError()) .filter(r -> r.getSeries() != null) .flatMap(r -> r.getSeries().stream()) .map(s -> getColumnFromSeries(s, "diskBytes")) .filter(Optional::isPresent) .flatMap(Optional::get) .map(Number.class::cast) .mapToLong(Number::longValue) .findAny() .orElse(0); } }
InfluxHistory extends InfluxUtil implements CollectHistory, AutoCloseable { @Override public long getFileSize() { final QueryResult result = getInfluxDB().query(new Query(String.format("select sum(\"diskBytes\") as \"diskBytes\" from (select last(\"diskBytes\"::field) as \"diskBytes\" from \"shard\" where \"database\"::tag = '%s' group by * limit 1)", getDatabase().replace("'", "\\'")), "_internal"), TimeUnit.MILLISECONDS); throwOnResultError(result); return result.getResults().stream() .filter(r -> !r.hasError()) .filter(r -> r.getSeries() != null) .flatMap(r -> r.getSeries().stream()) .map(s -> getColumnFromSeries(s, "diskBytes")) .filter(Optional::isPresent) .flatMap(Optional::get) .map(Number.class::cast) .mapToLong(Number::longValue) .findAny() .orElse(0); } InfluxHistory(InfluxDB influxDB, String database);  InfluxHistory(InfluxDB influxDB, String database, boolean verifyDatabaseConnection); }
InfluxHistory extends InfluxUtil implements CollectHistory, AutoCloseable { @Override public long getFileSize() { final QueryResult result = getInfluxDB().query(new Query(String.format("select sum(\"diskBytes\") as \"diskBytes\" from (select last(\"diskBytes\"::field) as \"diskBytes\" from \"shard\" where \"database\"::tag = '%s' group by * limit 1)", getDatabase().replace("'", "\\'")), "_internal"), TimeUnit.MILLISECONDS); throwOnResultError(result); return result.getResults().stream() .filter(r -> !r.hasError()) .filter(r -> r.getSeries() != null) .flatMap(r -> r.getSeries().stream()) .map(s -> getColumnFromSeries(s, "diskBytes")) .filter(Optional::isPresent) .flatMap(Optional::get) .map(Number.class::cast) .mapToLong(Number::longValue) .findAny() .orElse(0); } InfluxHistory(InfluxDB influxDB, String database);  InfluxHistory(InfluxDB influxDB, String database, boolean verifyDatabaseConnection); @Override void close(); @Override boolean add(@NonNull TimeSeriesCollection tsdata); @Override boolean addAll(@NonNull Collection<? extends TimeSeriesCollection> c); @Override boolean addAll(@NonNull Iterator<? extends TimeSeriesCollection> i); int getTargetBatchSize(); void setTargetBatchSize(int targetBatchSize); @Override long getFileSize(); @Override DateTime getEnd(); Optional<DateTime> getBegin(); @Override Stream<TimeSeriesCollection> streamReversed(); @Override Stream<TimeSeriesCollection> stream(); Stream<TimeSeriesCollection> stream(@NonNull TimeSeriesMetricFilter filter); Stream<TimeSeriesCollection> stream(@NonNull Duration stepsize, @NonNull TimeSeriesMetricFilter filter); @Override Stream<TimeSeriesCollection> stream(DateTime begin); Stream<TimeSeriesCollection> stream(@NonNull DateTime begin, @NonNull TimeSeriesMetricFilter filter); Stream<TimeSeriesCollection> stream(DateTime begin, Duration stepsize, TimeSeriesMetricFilter filter); @Override Stream<TimeSeriesCollection> stream(DateTime begin, DateTime end); Stream<TimeSeriesCollection> stream(@NonNull DateTime begin, @NonNull DateTime end, @NonNull TimeSeriesMetricFilter filter); Stream<TimeSeriesCollection> stream(DateTime begin, DateTime end, Duration stepsize, TimeSeriesMetricFilter filter); @Override Stream<Context> getContext(Duration stepsize, ExpressionLookBack lookback, TimeSeriesMetricFilter filter); @Override Stream<Context> getContext(DateTime begin, Duration stepsize, ExpressionLookBack lookback, TimeSeriesMetricFilter filter); @Override Stream<Context> getContext(DateTime begin, DateTime end, Duration stepsize, ExpressionLookBack lookback, TimeSeriesMetricFilter filter); }
InfluxHistory extends InfluxUtil implements CollectHistory, AutoCloseable { @Override public long getFileSize() { final QueryResult result = getInfluxDB().query(new Query(String.format("select sum(\"diskBytes\") as \"diskBytes\" from (select last(\"diskBytes\"::field) as \"diskBytes\" from \"shard\" where \"database\"::tag = '%s' group by * limit 1)", getDatabase().replace("'", "\\'")), "_internal"), TimeUnit.MILLISECONDS); throwOnResultError(result); return result.getResults().stream() .filter(r -> !r.hasError()) .filter(r -> r.getSeries() != null) .flatMap(r -> r.getSeries().stream()) .map(s -> getColumnFromSeries(s, "diskBytes")) .filter(Optional::isPresent) .flatMap(Optional::get) .map(Number.class::cast) .mapToLong(Number::longValue) .findAny() .orElse(0); } InfluxHistory(InfluxDB influxDB, String database);  InfluxHistory(InfluxDB influxDB, String database, boolean verifyDatabaseConnection); @Override void close(); @Override boolean add(@NonNull TimeSeriesCollection tsdata); @Override boolean addAll(@NonNull Collection<? extends TimeSeriesCollection> c); @Override boolean addAll(@NonNull Iterator<? extends TimeSeriesCollection> i); int getTargetBatchSize(); void setTargetBatchSize(int targetBatchSize); @Override long getFileSize(); @Override DateTime getEnd(); Optional<DateTime> getBegin(); @Override Stream<TimeSeriesCollection> streamReversed(); @Override Stream<TimeSeriesCollection> stream(); Stream<TimeSeriesCollection> stream(@NonNull TimeSeriesMetricFilter filter); Stream<TimeSeriesCollection> stream(@NonNull Duration stepsize, @NonNull TimeSeriesMetricFilter filter); @Override Stream<TimeSeriesCollection> stream(DateTime begin); Stream<TimeSeriesCollection> stream(@NonNull DateTime begin, @NonNull TimeSeriesMetricFilter filter); Stream<TimeSeriesCollection> stream(DateTime begin, Duration stepsize, TimeSeriesMetricFilter filter); @Override Stream<TimeSeriesCollection> stream(DateTime begin, DateTime end); Stream<TimeSeriesCollection> stream(@NonNull DateTime begin, @NonNull DateTime end, @NonNull TimeSeriesMetricFilter filter); Stream<TimeSeriesCollection> stream(DateTime begin, DateTime end, Duration stepsize, TimeSeriesMetricFilter filter); @Override Stream<Context> getContext(Duration stepsize, ExpressionLookBack lookback, TimeSeriesMetricFilter filter); @Override Stream<Context> getContext(DateTime begin, Duration stepsize, ExpressionLookBack lookback, TimeSeriesMetricFilter filter); @Override Stream<Context> getContext(DateTime begin, DateTime end, Duration stepsize, ExpressionLookBack lookback, TimeSeriesMetricFilter filter);  }