ClusterFacade { public static CompactionStats parseCompactionStats(String json) throws IOException { try { return parseJson(json, new TypeReference<CompactionStats>(){}); } catch (IOException e) { List<Compaction> compactions = parseJson(json, new TypeReference<List<Compaction>>() {}); return CompactionStats.builder() .withPendingCompactions(-1) .withActiveCompactions(compactions) .build(); } } private  ClusterFacade(AppContext context); static ClusterFacade create(AppContext context); JmxProxy preHeatJmxConnections(Cluster cluster, Collection<String> endpoints); String getClusterName(Cluster cluster, Collection<String> endpoints); String getClusterName(Node node); String getPartitioner(Cluster cluster, Collection<String> endpoints); List<String> getLiveNodes(Cluster cluster); List<String> getLiveNodes(Cluster cluster, Collection<String> endpoints); NodesStatus getNodesStatus(Cluster cluster, Collection<String> endpoints); String getCassandraVersion(Cluster cluster); String getCassandraVersion(Cluster cluster, Collection<String> endpoints); List<BigInteger> getTokens(Cluster cluster); Map<List<String>, List<String>> getRangeToEndpointMap(
      Cluster cluster,
      String keyspace); Set<Table> getTablesForKeyspace(Cluster cluster, String keyspaceName); Map<String, List<String>> listTablesByKeyspace(Cluster cluster); List<String> getKeyspaces(Cluster cluster); Map<String, String> getEndpointToHostId(Cluster cluster); List<String> tokenRangeToEndpoint(Cluster cluster, String keyspace, Segment segment); List<RingRange> getRangesForLocalEndpoint(Cluster cluster, String keyspace); String getDatacenter(Cluster cluster, String endpoint); String getDatacenter(Node node); String getLocalEndpoint(Node node); Map<String, List<String>> getTokensByNode(Cluster cluster); CompactionStats listActiveCompactions(Node node); CompactionStats listCompactionStatsDirect(Node node); boolean nodeIsAccessibleThroughJmx(String nodeDc, String node); Map<String, List<JmxStat>> collectMetrics(Node node, String[] collectedMetrics); List<MetricsHistogram> getClientRequestLatencies(Node node); List<DroppedMessages> getDroppedMessages(Node node); @VisibleForTesting List<DroppedMessages> convertToDroppedMessages(List<GenericMetric> metrics); List<ThreadPoolStat> getTpStats(Node node); @VisibleForTesting List<ThreadPoolStat> convertToThreadPoolStats(List<GenericMetric> metrics); @VisibleForTesting List<MetricsHistogram> convertToMetricsHistogram(List<GenericMetric> metrics); Pair<Node, String> takeSnapshot(String snapshotName, Node host, String... keyspaces); List<Snapshot> listSnapshots(Node host); void clearSnapshot(String snapshotName, Node host); List<StreamSession> listActiveStreams(Node node); List<StreamSession> listStreamsDirect(Node node); static List<StreamSession> parseStreamSessionJson(String json); static CompactionStats parseCompactionStats(String json); JmxProxy connect(Cluster cluster); JmxProxy connect(Cluster cluster, Collection<String> endpoints); JmxProxy connect(Node node); JmxProxy connect(Node node, Collection<String> endpoints);  }
@Test public void parseListCompactionTest() throws IOException { final ObjectMapper objectMapper = new ObjectMapper(); Compaction compaction = Compaction.builder() .withId("foo") .withKeyspace("ks") .withTable("t") .withProgress(64L) .withTotal(128L) .withType("Validation") .withUnit("unit") .build(); String compactionsJson = objectMapper.writeValueAsString(ImmutableList.of(compaction)); CompactionStats compactionStats = ClusterFacade.parseCompactionStats(compactionsJson); assertEquals(-1L, compactionStats.getPendingCompactions().longValue()); }
@Test public void parseCompactionStatsTest() throws IOException { final ObjectMapper objectMapper = new ObjectMapper(); Compaction compaction = Compaction.builder() .withId("foo") .withKeyspace("ks") .withTable("t") .withProgress(64L) .withTotal(128L) .withType("Validation") .withUnit("unit") .build(); CompactionStats originalCompactionStats = CompactionStats.builder() .withActiveCompactions(ImmutableList.of(compaction)) .withPendingCompactions(42) .build(); String compactionJson = objectMapper.writeValueAsString(originalCompactionStats); CompactionStats compactionStats = ClusterFacade.parseCompactionStats(compactionJson); assertEquals(42L, compactionStats.getPendingCompactions().longValue()); }
@Test(expected = IOException.class) public void parseCompactionStatsErrorTest() throws IOException { String compactionJson = "{\"json\": \"thats_not_compactionstats\"}"; ClusterFacade.parseCompactionStats(compactionJson); }