ClusterStatsChangeTracker { public boolean statsHaveChanged() { if (!aggregatedStats.hasUpdatesFromAllDistributors()) { return false; } for (Iterator<ContentNodeStats> itr = aggregatedStats.getStats().iterator(); itr.hasNext(); ) { int nodeIndex = itr.next().getNodeIndex(); boolean currValue = mayHaveMergesPendingInGlobalSpace(nodeIndex); Boolean prevValue = prevMayHaveMergesPendingInGlobalSpace(nodeIndex); if (prevValue != null) { if (prevValue != currValue) { return true; } } else { return true; } } return false; } ClusterStatsChangeTracker(AggregatedClusterStats aggregatedStats,
                                     double minMergeCompletionRatio); void syncAggregatedStats(); void updateAggregatedStats(AggregatedClusterStats newAggregatedStats,
                                      double minMergeCompletionRatio); boolean statsHaveChanged();  }
@Test public void stats_have_not_changed_if_not_all_distributors_are_updated() { Fixture f = Fixture.empty(); assertFalse(f.statsHaveChanged()); }
@Test public void stats_have_changed_if_in_sync_node_not_found_in_previous_stats() { Fixture f = Fixture.fromStats(stats().inSync(0)); assertTrue(f.statsHaveChanged()); }
@Test public void stats_have_changed_if_buckets_pending_node_not_found_in_previous_stats() { Fixture f = Fixture.fromStats(stats().bucketsPending(0)); assertTrue(f.statsHaveChanged()); }
@Test public void stats_have_changed_if_one_node_has_in_sync_to_buckets_pending_transition() { Fixture f = Fixture.fromStats(stats().bucketsPending(0).inSync(1)); f.newAggregatedStats(stats().bucketsPending(0).bucketsPending(1)); assertTrue(f.statsHaveChanged()); }
@Test public void stats_have_changed_if_one_node_has_buckets_pending_to_in_sync_transition() { Fixture f = Fixture.fromStats(stats().bucketsPending(0).bucketsPending(1)); f.newAggregatedStats(stats().bucketsPending(0).inSync(1)); assertTrue(f.statsHaveChanged()); }
@Test public void stats_have_not_changed_if_no_nodes_have_changed_state() { Fixture f = Fixture.fromStats(stats().bucketsPending(0).bucketsPending(1)); f.newAggregatedStats(stats().bucketsPending(0).bucketsPending(1)); assertFalse(f.statsHaveChanged()); }