Skip to content

Commit

Permalink
Put helpers after tests, rather than before
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo committed Oct 18, 2021
1 parent 14f1984 commit 2a16334
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ public void testGetPreferredTiersConfiguration() {
assertThat(exception.getMessage(), is("invalid data tier [no_tier]"));
}

public void testDataNodesWithoutAllDataRoles() {
ClusterState clusterState = clusterStateWithoutAllDataRoles();
Set<DiscoveryNode> nodes = DataTier.dataNodesWithoutAllDataRoles(clusterState);
assertEquals(1, nodes.size());
DiscoveryNode node = nodes.iterator().next();
assertEquals("name_3", node.getName());
assertEquals(org.elasticsearch.core.Set.of(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE), node.getRoles());
}

public static ClusterState clusterStateWithoutAllDataRoles() {
Set<DiscoveryNodeRole> allDataRoles = new HashSet<>(DiscoveryNodeRole.BUILT_IN_ROLES).stream()
.filter(role -> ALL_DATA_TIERS.contains(role.roleName())).collect(Collectors.toSet());
Expand All @@ -162,15 +171,6 @@ public static ClusterState clusterStateWithoutAllDataRoles() {
return ClusterState.builder(ClusterState.EMPTY_STATE).nodes(discoBuilder.build()).build();
}

public void testDataNodesWithoutAllDataRoles() {
ClusterState clusterState = clusterStateWithoutAllDataRoles();
Set<DiscoveryNode> nodes = DataTier.dataNodesWithoutAllDataRoles(clusterState);
assertEquals(1, nodes.size());
DiscoveryNode node = nodes.iterator().next();
assertEquals("name_3", node.getName());
assertEquals(org.elasticsearch.core.Set.of(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE), node.getRoles());
}

private static DiscoveryNodes buildDiscoveryNodes() {
int numNodes = randomIntBetween(3, 15);
DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,21 +698,6 @@ public void testFrozenIndex() {
));
}

public static ClusterState clusterStateWithoutAllDataRoles() {
DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder();
List<DiscoveryNode> nodesList = org.elasticsearch.core.List.of(
new DiscoveryNode("name_0", "node_0", buildNewFakeTransportAddress(), org.elasticsearch.core.Map.of(),
org.elasticsearch.core.Set.of(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE), Version.CURRENT)
);
for (DiscoveryNode node : nodesList) {
discoBuilder = discoBuilder.add(node);
}
discoBuilder.localNodeId(randomFrom(nodesList).getId());
discoBuilder.masterNodeId(randomFrom(nodesList).getId());

return ClusterState.builder(ClusterState.EMPTY_STATE).nodes(discoBuilder.build()).build();
}

public void testEmptyDataTierPreference() {
Settings.Builder settings = settings(Version.CURRENT);
settings.put(DataTier.TIER_PREFERENCE_SETTING.getKey(), " ");
Expand All @@ -736,4 +721,19 @@ public void testEmptyDataTierPreference() {
));
}
}

public static ClusterState clusterStateWithoutAllDataRoles() {
DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder();
List<DiscoveryNode> nodesList = org.elasticsearch.core.List.of(
new DiscoveryNode("name_0", "node_0", buildNewFakeTransportAddress(), org.elasticsearch.core.Map.of(),
org.elasticsearch.core.Set.of(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE), Version.CURRENT)
);
for (DiscoveryNode node : nodesList) {
discoBuilder = discoBuilder.add(node);
}
discoBuilder.localNodeId(randomFrom(nodesList).getId());
discoBuilder.masterNodeId(randomFrom(nodesList).getId());

return ClusterState.builder(ClusterState.EMPTY_STATE).nodes(discoBuilder.build()).build();
}
}

0 comments on commit 2a16334

Please sign in to comment.