16
16
import org .elasticsearch .test .ESTestCase ;
17
17
import org .elasticsearch .threadpool .TestThreadPool ;
18
18
import org .elasticsearch .threadpool .ThreadPool ;
19
+ import org .elasticsearch .xpack .core .ml .MlMetadata ;
19
20
import org .elasticsearch .xpack .core .ml .action .DeleteExpiredDataAction ;
20
21
import org .junit .After ;
21
22
import org .junit .Before ;
28
29
import static org .mockito .Matchers .any ;
29
30
import static org .mockito .Matchers .same ;
30
31
import static org .mockito .Mockito .mock ;
32
+ import static org .mockito .Mockito .times ;
33
+ import static org .mockito .Mockito .verifyNoMoreInteractions ;
31
34
import static org .mockito .Mockito .when ;
32
35
33
36
public class MlDailyMaintenanceServiceTests extends ESTestCase {
@@ -43,11 +46,6 @@ public void setUpTests() {
43
46
client = mock (Client .class );
44
47
when (client .threadPool ()).thenReturn (threadPool );
45
48
clusterService = mock (ClusterService .class );
46
- ClusterState state = ClusterState .builder (new ClusterName ("MlDailyMaintenanceServiceTests" ))
47
- .metadata (Metadata .builder ().putCustom (PersistentTasksCustomMetadata .TYPE , PersistentTasksCustomMetadata .builder ().build ()))
48
- .nodes (DiscoveryNodes .builder ().build ())
49
- .build ();
50
- when (clusterService .state ()).thenReturn (state );
51
49
mlAssignmentNotifier = mock (MlAssignmentNotifier .class );
52
50
}
53
51
@@ -57,6 +55,8 @@ public void stop() {
57
55
}
58
56
59
57
public void testScheduledTriggering () throws InterruptedException {
58
+ when (clusterService .state ()).thenReturn (createClusterState (false ));
59
+
60
60
int triggerCount = randomIntBetween (2 , 4 );
61
61
CountDownLatch latch = new CountDownLatch (triggerCount );
62
62
try (MlDailyMaintenanceService service = createService (latch , client )) {
@@ -68,10 +68,33 @@ public void testScheduledTriggering() throws InterruptedException {
68
68
verify (mlAssignmentNotifier , Mockito .atLeast (triggerCount - 1 )).auditUnassignedMlTasks (any (), any ());
69
69
}
70
70
71
+ public void testScheduledTriggeringWhileUpgradeModeIsEnabled () throws InterruptedException {
72
+ when (clusterService .state ()).thenReturn (createClusterState (true ));
73
+
74
+ int triggerCount = randomIntBetween (2 , 4 );
75
+ CountDownLatch latch = new CountDownLatch (triggerCount );
76
+ try (MlDailyMaintenanceService service = createService (latch , client )) {
77
+ service .start ();
78
+ latch .await (5 , TimeUnit .SECONDS );
79
+ }
80
+
81
+ verify (clusterService , times (triggerCount - 1 )).state ();
82
+ verifyNoMoreInteractions (client , clusterService , mlAssignmentNotifier );
83
+ }
84
+
71
85
private MlDailyMaintenanceService createService (CountDownLatch latch , Client client ) {
72
86
return new MlDailyMaintenanceService (threadPool , client , clusterService , mlAssignmentNotifier , () -> {
73
87
latch .countDown ();
74
88
return TimeValue .timeValueMillis (100 );
75
89
});
76
90
}
91
+
92
+ private static ClusterState createClusterState (boolean isUpgradeMode ) {
93
+ return ClusterState .builder (new ClusterName ("MlDailyMaintenanceServiceTests" ))
94
+ .metadata (Metadata .builder ()
95
+ .putCustom (PersistentTasksCustomMetadata .TYPE , PersistentTasksCustomMetadata .builder ().build ())
96
+ .putCustom (MlMetadata .TYPE , new MlMetadata .Builder ().isUpgradeMode (isUpgradeMode ).build ()))
97
+ .nodes (DiscoveryNodes .builder ().build ())
98
+ .build ();
99
+ }
77
100
}
0 commit comments