Skip to content

Commit

Permalink
Add assertions that the stats are updated as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveCTurner committed Oct 12, 2017
1 parent e0f3da3 commit a9a2828
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,38 @@ private static MockPublishAction buildPublishClusterStateAction(
discoverySettings);
}

private void assertPublishClusterStateStats(String description,
MockNode node,
long expectedFull,
long expectedDiffs,
long expectedCompatibleDiffs) {
PublishClusterStateStats stats = node.action.stats();
assertThat(description + ": full cluster states", stats.getFullClusterStateReceivedCount(), equalTo(expectedFull));
assertThat(description + ": cluster state diffs", stats.getClusterStateDiffReceivedCount(), equalTo(expectedDiffs));
assertThat(description + ": compatible cluster state diffs", stats.getCompatibleClusterStateDiffReceivedCount(),
equalTo(expectedCompatibleDiffs));
}

public void testSimpleClusterStatePublishing() throws Exception {
MockNode nodeA = createMockNode("nodeA").setAsMaster();
MockNode nodeB = createMockNode("nodeB");

// Initial cluster state
ClusterState clusterState = nodeA.clusterState;

assertPublishClusterStateStats("nodeA: initial state", nodeA, 0, 0, 0);
assertPublishClusterStateStats("nodeB: initial state", nodeB, 0, 0, 0);

// cluster state update - add nodeB
DiscoveryNodes discoveryNodes = DiscoveryNodes.builder(clusterState.nodes()).add(nodeB.discoveryNode).build();
ClusterState previousClusterState = clusterState;
clusterState = ClusterState.builder(clusterState).nodes(discoveryNodes).incrementVersion().build();
publishStateAndWait(nodeA.action, clusterState, previousClusterState);
assertSameStateFromFull(nodeB.clusterState, clusterState);

assertPublishClusterStateStats("nodeA: added nodeB", nodeA, 0, 0, 0);
assertPublishClusterStateStats("nodeB: added nodeB", nodeB, 1, 0, 0);

// cluster state update - add block
previousClusterState = clusterState;
clusterState = ClusterState.builder(clusterState).blocks(ClusterBlocks.builder()
Expand All @@ -306,6 +324,10 @@ public void testSimpleClusterStatePublishing() throws Exception {

MockNode nodeC = createMockNode("nodeC");

assertPublishClusterStateStats("nodeA: adding nodeC", nodeA, 0, 0, 0);
assertPublishClusterStateStats("nodeB: adding nodeC", nodeB, 1, 2, 2);
assertPublishClusterStateStats("nodeC: adding nodeC", nodeC, 0, 0, 0);

// cluster state update 3 - register node C
previousClusterState = clusterState;
discoveryNodes = DiscoveryNodes.builder(discoveryNodes).add(nodeC.discoveryNode).build();
Expand All @@ -315,6 +337,10 @@ public void testSimpleClusterStatePublishing() throws Exception {
// First state
assertSameStateFromFull(nodeC.clusterState, clusterState);

assertPublishClusterStateStats("nodeA: added nodeC", nodeA, 0, 0, 0);
assertPublishClusterStateStats("nodeB: added nodeC", nodeB, 1, 3, 3);
assertPublishClusterStateStats("nodeC: added nodeC", nodeC, 1, 0, 0);

// cluster state update 4 - update settings
previousClusterState = clusterState;
MetaData metaData = MetaData.builder(clusterState.metaData())
Expand All @@ -326,6 +352,10 @@ public void testSimpleClusterStatePublishing() throws Exception {
assertSameStateFromDiff(nodeC.clusterState, clusterState);
assertThat(nodeC.clusterState.blocks().global().size(), equalTo(0));

assertPublishClusterStateStats("nodeA: updated settings", nodeA, 0, 0, 0);
assertPublishClusterStateStats("nodeB: updated settings", nodeB, 1, 4, 4);
assertPublishClusterStateStats("nodeC: updated settings", nodeC, 1, 1, 1);

// cluster state update - skipping one version change - should request full cluster state
previousClusterState = ClusterState.builder(clusterState).incrementVersion().build();
clusterState = ClusterState.builder(clusterState).incrementVersion().build();
Expand All @@ -334,6 +364,10 @@ public void testSimpleClusterStatePublishing() throws Exception {
assertSameStateFromFull(nodeC.clusterState, clusterState);
assertFalse(nodeC.clusterState.wasReadFromDiff());

assertPublishClusterStateStats("nodeA: skipped a version", nodeA, 0, 0, 0);
assertPublishClusterStateStats("nodeB: skipped a version", nodeB, 2, 5, 4);
assertPublishClusterStateStats("nodeC: skipped a version", nodeC, 2, 2, 1);

// node A steps down from being master
nodeA.resetMasterId();
nodeB.resetMasterId();
Expand All @@ -352,6 +386,10 @@ public void testSimpleClusterStatePublishing() throws Exception {
publishStateAndWait(nodeB.action, clusterState, previousClusterState);
assertSameStateFromFull(nodeA.clusterState, clusterState);
assertSameStateFromFull(nodeC.clusterState, clusterState);

assertPublishClusterStateStats("nodeA: B became master", nodeA, 1, 1, 0);
assertPublishClusterStateStats("nodeB: B became master", nodeB, 2, 5, 4);
assertPublishClusterStateStats("nodeC: B became master", nodeC, 3, 3, 1);
}

public void testUnexpectedDiffPublishing() throws Exception {
Expand Down

0 comments on commit a9a2828

Please sign in to comment.