|
22 | 22 |
|
23 | 23 | import java.util.ArrayList; |
24 | 24 | import java.util.Arrays; |
| 25 | +import java.util.Collection; |
25 | 26 | import java.util.HashMap; |
26 | 27 | import java.util.HashSet; |
27 | 28 | import java.util.List; |
|
37 | 38 | import static org.elasticsearch.cluster.routing.allocation.DataTier.getPreferredTiersConfiguration; |
38 | 39 | import static org.hamcrest.CoreMatchers.is; |
39 | 40 | import static org.hamcrest.Matchers.arrayContainingInAnyOrder; |
| 41 | +import static org.hamcrest.Matchers.both; |
| 42 | +import static org.hamcrest.Matchers.contains; |
40 | 43 | import static org.hamcrest.Matchers.hasItem; |
| 44 | +import static org.hamcrest.Matchers.hasItems; |
| 45 | +import static org.hamcrest.Matchers.hasProperty; |
| 46 | +import static org.hamcrest.Matchers.hasSize; |
41 | 47 | import static org.hamcrest.Matchers.not; |
42 | 48 |
|
43 | 49 | public class DataTierTests extends ESTestCase { |
@@ -145,22 +151,28 @@ public void testGetPreferredTiersConfiguration() { |
145 | 151 | public void testDataNodesWithoutAllDataRoles() { |
146 | 152 | ClusterState clusterState = clusterStateWithoutAllDataRoles(); |
147 | 153 | Set<DiscoveryNode> nodes = DataTier.dataNodesWithoutAllDataRoles(clusterState); |
148 | | - assertEquals(1, nodes.size()); |
149 | | - DiscoveryNode node = nodes.iterator().next(); |
150 | | - assertEquals("name_3", node.getName()); |
151 | | - assertEquals(org.elasticsearch.core.Set.of(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE), node.getRoles()); |
| 154 | + assertThat(nodes, hasSize(2)); |
| 155 | + assertThat(nodes, hasItem(both(hasProperty("name", is("name_3"))) |
| 156 | + .and(hasProperty("roles", contains(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE))))); |
| 157 | + assertThat(nodes, hasItem(hasProperty("name", is("name_4")))); |
152 | 158 | } |
153 | 159 |
|
154 | 160 | public static ClusterState clusterStateWithoutAllDataRoles() { |
155 | 161 | Set<DiscoveryNodeRole> allDataRoles = new HashSet<>(DiscoveryNodeRole.BUILT_IN_ROLES).stream() |
156 | 162 | .filter(role -> ALL_DATA_TIERS.contains(role.roleName())).collect(Collectors.toSet()); |
157 | 163 |
|
| 164 | + Collection<String> allButOneDataTiers = randomValueOtherThan(ALL_DATA_TIERS, |
| 165 | + () -> randomSubsetOf(randomIntBetween(1, ALL_DATA_TIERS.size() - 1), ALL_DATA_TIERS)); |
| 166 | + Set<DiscoveryNodeRole> allButOneDataRoles = new HashSet<>(DiscoveryNodeRole.BUILT_IN_ROLES).stream() |
| 167 | + .filter(role -> allButOneDataTiers.contains(role.roleName())).collect(Collectors.toSet()); |
| 168 | + |
158 | 169 | DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder(); |
159 | 170 | List<DiscoveryNode> nodesList = org.elasticsearch.core.List.of( |
160 | 171 | newNode(0, org.elasticsearch.core.Map.of(), org.elasticsearch.core.Set.of(DiscoveryNodeRole.MASTER_ROLE)), |
161 | 172 | newNode(1, org.elasticsearch.core.Map.of(), org.elasticsearch.core.Set.of(DiscoveryNodeRole.DATA_ROLE)), |
162 | 173 | newNode(2, org.elasticsearch.core.Map.of(), allDataRoles), |
163 | | - newNode(3, org.elasticsearch.core.Map.of(), org.elasticsearch.core.Set.of(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE)) |
| 174 | + newNode(3, org.elasticsearch.core.Map.of(), org.elasticsearch.core.Set.of(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE)), |
| 175 | + newNode(4, org.elasticsearch.core.Map.of(), allButOneDataRoles) |
164 | 176 | ); |
165 | 177 | for (DiscoveryNode node : nodesList) { |
166 | 178 | discoBuilder = discoBuilder.add(node); |
|
0 commit comments