use of com.yahoo.test.ManualClock in project vespa by vespa-engine.
the class ActiveContainerDeactivationWatchdogTest method watchdog_counts_deactivated_containers.
@Test
public void watchdog_counts_deactivated_containers() {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ManualClock clock = new ManualClock(Instant.now());
ActiveContainerDeactivationWatchdog watchdog = new ActiveContainerDeactivationWatchdog(clock, Executors.newScheduledThreadPool(1));
MockMetric metric = new MockMetric();
ActiveContainer containerWithoutRetainedResources = new ActiveContainer(driver.newContainerBuilder());
watchdog.onContainerActivation(containerWithoutRetainedResources);
watchdog.emitMetrics(metric);
assertEquals(0, metric.totalCount);
assertEquals(0, metric.withRetainedReferencesCount);
watchdog.onContainerActivation(null);
containerWithoutRetainedResources.release();
clock.advance(ActiveContainerDeactivationWatchdog.REPORTING_GRACE_PERIOD);
watchdog.emitMetrics(metric);
assertEquals(0, metric.totalCount);
assertEquals(0, metric.withRetainedReferencesCount);
clock.advance(Duration.ofSeconds(1));
watchdog.emitMetrics(metric);
assertEquals(1, metric.totalCount);
assertEquals(0, metric.withRetainedReferencesCount);
ActiveContainer containerWithRetainedResources = new ActiveContainer(driver.newContainerBuilder());
try (ResourceReference ignoredRef = containerWithRetainedResources.refer()) {
watchdog.onContainerActivation(containerWithRetainedResources);
containerWithRetainedResources.release();
watchdog.onContainerActivation(null);
clock.advance(ActiveContainerDeactivationWatchdog.REPORTING_GRACE_PERIOD.plusSeconds(1));
watchdog.emitMetrics(metric);
assertEquals(2, metric.totalCount);
assertEquals(1, metric.withRetainedReferencesCount);
}
}
use of com.yahoo.test.ManualClock in project vespa by vespa-engine.
the class ActiveContainerDeactivationWatchdogTest method deactivated_container_destructed_if_its_reference_counter_is_nonzero.
@Test
@Ignore("Ignored as it assumes phantom references are enqueued right after first GC have cleared the weak reference. " + "This is the case on most JVMs.")
public void deactivated_container_destructed_if_its_reference_counter_is_nonzero() {
ExecutorMock executor = new ExecutorMock();
ManualClock clock = new ManualClock(Instant.now());
ActiveContainerDeactivationWatchdog watchdog = new ActiveContainerDeactivationWatchdog(clock, executor);
ActiveContainer container = new ActiveContainer(TestDriver.newSimpleApplicationInstanceWithoutOsgi().newContainerBuilder());
AtomicBoolean destructed = new AtomicBoolean(false);
container.shutdown().notifyTermination(() -> destructed.set(true));
// increase reference counter to simulate a leaking resource
container.refer();
watchdog.onContainerActivation(container);
// release resource
container.release();
// deactivate container
watchdog.onContainerActivation(null);
WeakReference<ActiveContainer> containerWeakReference = new WeakReference<>(container);
// make container instance collectable by GC
container = null;
clock.advance(ActiveContainerDeactivationWatchdog.GC_GRACE_PERIOD.plusSeconds(1));
executor.triggerGcCommand.run();
assertNull("Container is not GCed - probably because the watchdog has a concrete reference to it", containerWeakReference.get());
executor.enforceDestructionOfGarbageCollectedContainersCommand.run();
assertTrue("Destructor is not called on deactivated container", destructed.get());
}
use of com.yahoo.test.ManualClock in project vespa by vespa-engine.
the class OperatorChangeApplicationMaintainerTest method test_application_maintenance.
@Test
public void test_application_maintenance() throws InterruptedException {
ManualClock clock = new ManualClock();
Curator curator = new MockCurator();
Zone zone = new Zone(Environment.prod, RegionName.from("us-east"));
this.nodeRepository = new NodeRepository(nodeFlavors, curator, clock, zone, new MockNameResolver().mockAnyLookup(), new DockerImage("docker-registry.domain.tld:8080/dist/vespa"), true);
this.fixture = new Fixture(zone, nodeRepository, nodeFlavors, curator);
createReadyNodes(15, nodeRepository, nodeFlavors);
createHostNodes(2, nodeRepository, nodeFlavors);
// Create applications
fixture.activate();
OperatorChangeApplicationMaintainer maintainer = new OperatorChangeApplicationMaintainer(fixture.deployer, nodeRepository, clock, Duration.ofMinutes(1), new JobControl(nodeRepository.database()));
clock.advance(Duration.ofMinutes(2));
maintainer.maintain();
assertEquals("No changes -> no redeployments", 0, fixture.deployer.redeployments);
nodeRepository.fail(nodeRepository.getNodes(fixture.app1).get(3).hostname(), Agent.system, "Failing to unit test");
clock.advance(Duration.ofMinutes(2));
maintainer.maintain();
assertEquals("System change -> no redeployments", 0, fixture.deployer.redeployments);
clock.advance(Duration.ofSeconds(1));
nodeRepository.fail(nodeRepository.getNodes(fixture.app2).get(4).hostname(), Agent.operator, "Manual node failing");
clock.advance(Duration.ofMinutes(2));
maintainer.maintain();
assertEquals("Operator change -> redeployment", 1, fixture.deployer.redeployments);
clock.advance(Duration.ofMinutes(2));
maintainer.maintain();
assertEquals("No further operator changes -> no (new) redeployments", 1, fixture.deployer.redeployments);
}
Aggregations