Test JobControl integration
package com.yahoo.vespa.hosted.provision.maintenance;
+import com.yahoo.vespa.hosted.provision.NodeRepository;
import com.yahoo.vespa.hosted.provision.NodeRepositoryTester;
import org.junit.Test;
+import java.time.Duration;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -48,4 +51,41 @@ public class JobControlTest {
assertTrue(jobControl.isActive(job2));
}
+ @Test
+ public void testJobControlMayDeactivateJobs() {
+ NodeRepositoryTester tester = new NodeRepositoryTester();
+ JobControl jobControl = new JobControl(tester.nodeRepository().database());
+ MockMaintainer mockMaintainer = new MockMaintainer(tester.nodeRepository(), jobControl);
+
+ assertTrue(jobControl.jobs().contains("MockMaintainer"));
+
+ assertEquals(0, mockMaintainer.maintenanceInvocations);
+
+ mockMaintainer.run();
+ assertEquals(1, mockMaintainer.maintenanceInvocations);
+
+ jobControl.setActive("MockMaintainer", false);
+ mockMaintainer.run();
+ assertEquals(1, mockMaintainer.maintenanceInvocations);
+
+ jobControl.setActive("MockMaintainer", true);
+ mockMaintainer.run();
+ assertEquals(2, mockMaintainer.maintenanceInvocations);
+ }
+
+ private static class MockMaintainer extends Maintainer {
+
+ int maintenanceInvocations = 0;
+
+ public MockMaintainer(NodeRepository nodeRepository, JobControl jobControl) {
+ super(nodeRepository, Duration.ofHours(1), jobControl);
+ }
+
+ @Override
+ protected void maintain() {
+ maintenanceInvocations++;
+ }
+
+ }
+
}
