18
18
import org .elasticsearch .common .settings .ClusterSettings ;
19
19
import org .elasticsearch .common .settings .Settings ;
20
20
import org .elasticsearch .common .settings .SettingsModule ;
21
+ import org .elasticsearch .common .util .set .Sets ;
21
22
import org .elasticsearch .persistent .PersistentTasksCustomMetadata .Assignment ;
22
23
import org .elasticsearch .test .ESTestCase ;
24
+ import org .elasticsearch .test .VersionUtils ;
23
25
import org .elasticsearch .threadpool .ThreadPool ;
24
26
import org .elasticsearch .xpack .ccr .CcrSettings ;
25
27
@@ -38,9 +40,13 @@ public class ShardFollowTasksExecutorAssignmentTests extends ESTestCase {
38
40
39
41
public void testAssignmentToNodeWithDataAndRemoteClusterClientRoles () {
40
42
runAssignmentTest (
41
- new HashSet <>(Arrays .asList (DiscoveryNodeRole .DATA_ROLE , DiscoveryNodeRole .REMOTE_CLUSTER_CLIENT_ROLE )),
42
- randomIntBetween (0 , 8 ),
43
- () -> new HashSet <>(randomSubsetOf (new HashSet <>(Arrays .asList (DiscoveryNodeRole .DATA_ROLE , DiscoveryNodeRole .INGEST_ROLE )))),
43
+ newNode (
44
+ Sets .newHashSet (DiscoveryNodeRole .DATA_ROLE , DiscoveryNodeRole .REMOTE_CLUSTER_CLIENT_ROLE ),
45
+ VersionUtils .randomVersion (random ())),
46
+ newNodes (
47
+ between (0 , 8 ),
48
+ () -> Sets .newHashSet (randomSubsetOf (Arrays .asList (DiscoveryNodeRole .DATA_ROLE , DiscoveryNodeRole .INGEST_ROLE ))),
49
+ Version .CURRENT ),
44
50
(theSpecial , assignment ) -> {
45
51
assertTrue (assignment .isAssigned ());
46
52
assertThat (assignment .getExecutorNode (), equalTo (theSpecial .getId ()));
@@ -56,11 +62,26 @@ public void testRemoteClusterClientRoleWithoutDataRole() {
56
62
runNoAssignmentTest (Collections .singleton (DiscoveryNodeRole .REMOTE_CLUSTER_CLIENT_ROLE ));
57
63
}
58
64
65
+ public void testNodeWithLegacyRolesOnly () {
66
+ final Version oldVersion = VersionUtils .randomVersionBetween (random (),
67
+ Version .V_6_0_0 , VersionUtils .getPreviousVersion (DiscoveryNodeRole .REMOTE_CLUSTER_CLIENT_ROLE_VERSION ));
68
+ runAssignmentTest (
69
+ newNode (Sets .newHashSet (DiscoveryNodeRole .DATA_ROLE ), oldVersion ),
70
+ newNodes (
71
+ between (0 , 8 ),
72
+ () -> Sets .newHashSet (randomSubsetOf (Arrays .asList (DiscoveryNodeRole .DATA_ROLE , DiscoveryNodeRole .INGEST_ROLE ))),
73
+ Version .CURRENT ),
74
+ (theSpecial , assignment ) -> {
75
+ assertTrue (assignment .isAssigned ());
76
+ assertThat (assignment .getExecutorNode (), equalTo (theSpecial .getId ()));
77
+ }
78
+ );
79
+ }
80
+
59
81
private void runNoAssignmentTest (final Set <DiscoveryNodeRole > roles ) {
60
82
runAssignmentTest (
61
- roles ,
62
- 0 ,
63
- Collections ::emptySet ,
83
+ newNode (roles , Version .CURRENT ),
84
+ Collections .emptySet (),
64
85
(theSpecial , assignment ) -> {
65
86
assertFalse (assignment .isAssigned ());
66
87
assertThat (assignment .getExplanation (), equalTo ("no nodes found with data and remote cluster client roles" ));
@@ -69,9 +90,8 @@ private void runNoAssignmentTest(final Set<DiscoveryNodeRole> roles) {
69
90
}
70
91
71
92
private void runAssignmentTest (
72
- final Set <DiscoveryNodeRole > theSpecialRoles ,
73
- final int numberOfOtherNodes ,
74
- final Supplier <Set <DiscoveryNodeRole >> otherNodesRolesSupplier ,
93
+ final DiscoveryNode targetNode ,
94
+ final Set <DiscoveryNode > otherNodes ,
75
95
final BiConsumer <DiscoveryNode , Assignment > consumer
76
96
) {
77
97
final ClusterService clusterService = mock (ClusterService .class );
@@ -82,25 +102,30 @@ private void runAssignmentTest(
82
102
final ShardFollowTasksExecutor executor =
83
103
new ShardFollowTasksExecutor (mock (Client .class ), mock (ThreadPool .class ), clusterService , settingsModule );
84
104
final ClusterState .Builder clusterStateBuilder = ClusterState .builder (new ClusterName ("test" ));
85
- final DiscoveryNodes .Builder nodesBuilder = DiscoveryNodes .builder ();
86
- final DiscoveryNode theSpecial = newNode (theSpecialRoles );
87
- nodesBuilder .add (theSpecial );
88
- for (int i = 0 ; i < numberOfOtherNodes ; i ++) {
89
- nodesBuilder .add (newNode (otherNodesRolesSupplier .get ()));
105
+ final DiscoveryNodes .Builder nodesBuilder = DiscoveryNodes .builder ().add (targetNode );
106
+ for (DiscoveryNode node : otherNodes ) {
107
+ nodesBuilder .add (node );
90
108
}
91
109
clusterStateBuilder .nodes (nodesBuilder );
92
110
final Assignment assignment = executor .getAssignment (mock (ShardFollowTask .class ), clusterStateBuilder .build ());
93
- consumer .accept (theSpecial , assignment );
111
+ consumer .accept (targetNode , assignment );
94
112
}
95
113
96
- private static DiscoveryNode newNode (final Set <DiscoveryNodeRole > roles ) {
114
+ private static DiscoveryNode newNode (final Set <DiscoveryNodeRole > roles , final Version version ) {
97
115
return new DiscoveryNode (
98
116
"node_" + UUIDs .randomBase64UUID (random ()),
99
117
buildNewFakeTransportAddress (),
100
118
Collections .emptyMap (),
101
119
roles ,
102
- Version . CURRENT
120
+ version
103
121
);
104
122
}
105
123
124
+ private static Set <DiscoveryNode > newNodes (int numberOfNodes , Supplier <Set <DiscoveryNodeRole >> rolesSupplier , Version version ) {
125
+ Set <DiscoveryNode > nodes = new HashSet <>();
126
+ for (int i = 0 ; i < numberOfNodes ; i ++) {
127
+ nodes .add (newNode (rolesSupplier .get (), version ));
128
+ }
129
+ return nodes ;
130
+ }
106
131
}
0 commit comments