15
15
import org .elasticsearch .common .UUIDs ;
16
16
import org .elasticsearch .common .transport .TransportAddress ;
17
17
import org .elasticsearch .test .ESTestCase ;
18
+ import org .hamcrest .Matcher ;
18
19
19
20
import java .util .Collections ;
20
21
import java .util .concurrent .atomic .AtomicLong ;
@@ -40,48 +41,48 @@ public void testJoinReasonService() {
40
41
41
42
final DiscoveryNodes withNode = DiscoveryNodes .builder (withoutNode ).add (discoveryNode ).build ();
42
43
43
- assertThat (joinReasonService .getJoinReason (discoveryNode , CANDIDATE ), equalTo ("completing election" ));
44
- assertThat (joinReasonService .getJoinReason (discoveryNode , LEADER ), equalTo ("joining" ));
44
+ assertThat (joinReasonService .getJoinReason (discoveryNode , CANDIDATE ), matches ("completing election" ));
45
+ assertThat (joinReasonService .getJoinReason (discoveryNode , LEADER ), matches ("joining" ));
45
46
46
47
joinReasonService .onClusterStateApplied (withoutNode );
47
48
48
- assertThat (joinReasonService .getJoinReason (discoveryNode , CANDIDATE ), equalTo ("completing election" ));
49
- assertThat (joinReasonService .getJoinReason (discoveryNode , LEADER ), equalTo ("joining" ));
49
+ assertThat (joinReasonService .getJoinReason (discoveryNode , CANDIDATE ), matches ("completing election" ));
50
+ assertThat (joinReasonService .getJoinReason (discoveryNode , LEADER ), matches ("joining" ));
50
51
51
52
joinReasonService .onClusterStateApplied (withNode );
52
53
53
- assertThat (joinReasonService .getJoinReason (discoveryNode , CANDIDATE ), equalTo ("completing election" ));
54
- assertThat (joinReasonService .getJoinReason (discoveryNode , LEADER ), equalTo ("rejoining" ));
54
+ assertThat (joinReasonService .getJoinReason (discoveryNode , CANDIDATE ), matches ("completing election" ));
55
+ assertThat (joinReasonService .getJoinReason (discoveryNode , LEADER ), matches ("rejoining" ));
55
56
56
57
joinReasonService .onClusterStateApplied (withoutNode );
57
58
currentTimeMillis .addAndGet (1234L );
58
59
59
60
assertThat (
60
61
joinReasonService .getJoinReason (discoveryNode , LEADER ),
61
- equalTo ("joining, removed [1.2s/1234ms] ago by [" + master .getName () + "]" )
62
+ matches ("joining, removed [1.2s/1234ms] ago by [" + master .getName () + "]" )
62
63
);
63
64
64
65
joinReasonService .onNodeRemoved (discoveryNode , "test removal" );
65
66
currentTimeMillis .addAndGet (4321L );
66
67
67
68
assertThat (
68
69
joinReasonService .getJoinReason (discoveryNode , LEADER ),
69
- equalTo ("joining, removed [5.5s/5555ms] ago with reason [test removal]" )
70
+ matches ("joining, removed [5.5s/5555ms] ago with reason [test removal]" )
70
71
);
71
72
72
73
joinReasonService .onClusterStateApplied (withNode );
73
74
joinReasonService .onClusterStateApplied (withoutNode );
74
75
75
76
assertThat (
76
77
joinReasonService .getJoinReason (discoveryNode , LEADER ),
77
- equalTo ("joining, removed [0ms] ago by [" + master .getName () + "], [2] total removals" )
78
+ matches ("joining, removed [0ms] ago by [" + master .getName () + "], [2] total removals" )
78
79
);
79
80
80
81
joinReasonService .onNodeRemoved (discoveryNode , "second test removal" );
81
82
82
83
assertThat (
83
84
joinReasonService .getJoinReason (discoveryNode , LEADER ),
84
- equalTo ("joining, removed [0ms] ago with reason [second test removal], [2] total removals" )
85
+ matches ("joining, removed [0ms] ago with reason [second test removal], [2] total removals" )
85
86
);
86
87
87
88
final DiscoveryNode rebootedNode = new DiscoveryNode (
@@ -98,7 +99,7 @@ public void testJoinReasonService() {
98
99
99
100
assertThat (
100
101
joinReasonService .getJoinReason (rebootedNode , LEADER ),
101
- equalTo ("joining after restart, removed [0ms] ago with reason [second test removal]" )
102
+ matches ("joining after restart, removed [0ms] ago with reason [second test removal]" )
102
103
);
103
104
104
105
final DiscoveryNodes withRebootedNode = DiscoveryNodes .builder (withoutNode ).add (rebootedNode ).build ();
@@ -108,7 +109,7 @@ public void testJoinReasonService() {
108
109
109
110
assertThat (
110
111
joinReasonService .getJoinReason (rebootedNode , LEADER ),
111
- equalTo ("joining, removed [0ms] ago with reason [third test removal]" )
112
+ matches ("joining, removed [0ms] ago with reason [third test removal]" )
112
113
);
113
114
114
115
joinReasonService .onClusterStateApplied (withRebootedNode );
@@ -117,7 +118,7 @@ public void testJoinReasonService() {
117
118
118
119
assertThat (
119
120
joinReasonService .getJoinReason (rebootedNode , LEADER ),
120
- equalTo ("joining, removed [0ms] ago with reason [fourth test removal], [2] total removals" )
121
+ matches ("joining, removed [0ms] ago with reason [fourth test removal], [2] total removals" )
121
122
);
122
123
123
124
joinReasonService .onClusterStateApplied (withRebootedNode );
@@ -126,12 +127,12 @@ public void testJoinReasonService() {
126
127
127
128
assertThat (
128
129
joinReasonService .getJoinReason (discoveryNode , LEADER ),
129
- equalTo ("joining, removed [0ms] ago by [" + master .getName () + "]" )
130
+ matches ("joining, removed [0ms] ago by [" + master .getName () + "]" )
130
131
);
131
132
132
133
assertThat (
133
134
joinReasonService .getJoinReason (rebootedNode , LEADER ),
134
- equalTo ("joining after restart, removed [0ms] ago by [" + master .getName () + "]" )
135
+ matches ("joining after restart, removed [0ms] ago by [" + master .getName () + "]" )
135
136
);
136
137
}
137
138
@@ -178,11 +179,11 @@ public void testCleanup() {
178
179
179
180
// remove almost enough other nodes and verify that we're still tracking the target node
180
181
joinReasonService .onClusterStateApplied (almostCleanupNodes );
181
- assertThat (joinReasonService .getJoinReason (targetNode , LEADER ), equalTo ("joining, removed [1ms] ago with reason [test]" ));
182
+ assertThat (joinReasonService .getJoinReason (targetNode , LEADER ), matches ("joining, removed [1ms] ago with reason [test]" ));
182
183
183
184
// remove one more node to trigger the cleanup and forget about the target node
184
185
joinReasonService .onClusterStateApplied (cleanupNodes );
185
- assertThat (joinReasonService .getJoinReason (targetNode , LEADER ), equalTo ("joining" ));
186
+ assertThat (joinReasonService .getJoinReason (targetNode , LEADER ), matches ("joining" ));
186
187
}
187
188
188
189
private DiscoveryNode randomDiscoveryNode () {
@@ -199,4 +200,9 @@ private DiscoveryNode randomDiscoveryNode() {
199
200
Version .CURRENT
200
201
);
201
202
}
203
+
204
+ private static Matcher <JoinReason > matches (String message ) {
205
+ return equalTo (new JoinReason (message ));
206
+ }
207
+
202
208
}
0 commit comments