ElasticsearchDiskSpaceChecker implements DiskSpaceChecker { @Override public boolean isSpaceAvailable() throws DiskSpaceCheckerException { final ElasticsearchClusterStats stats = elasticsearch.getClusterStats(); long free = stats.getFilesystemAvailableBytes(); long max = stats.getFilesystemTotalBytes(); if (max == 0) { LOGGER.warn("ES Cluster Stats reports 0 total bytes - possible issue with ES cluster"); } else if (free == 0) { LOGGER.warn("ES Cluster Stats reports 0 free bytes"); } boolean ret = threshold.withinThreshold(free, max); LOGGER.debug("ES threshold check returned {}", ret); return ret; } ElasticsearchDiskSpaceChecker(ElasticsearchClient client); @Override boolean isSpaceAvailable(); @Override void configure(Map<String, Object> configuration); @Override boolean requiresHttpClient(); @Override void setHttpClient(Client httpClient); @Override void setThreshold(DiskSpaceThreshold threshold); static final String BASE_URL_CONFIG_OPTION; static final String CACHE_MS_CONFIG_OPTION; }
@Test(expected = uk.co.flax.harahachibu.services.DiskSpaceCheckerException.class) public void throwsExceptionWhenESFails() throws Exception { when(elasticsearch.getClusterStats()).thenThrow(new DiskSpaceCheckerException("error")); ElasticsearchDiskSpaceChecker checker = new ElasticsearchDiskSpaceChecker(elasticsearch); checker.isSpaceAvailable(); verify(elasticsearch).getClusterStats(); }