Search in sources :

Example 16 with ManualClock

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);
    }
}
Also used : ManualClock(com.yahoo.test.ManualClock) ResourceReference(com.yahoo.jdisc.ResourceReference) TestDriver(com.yahoo.jdisc.test.TestDriver) Test(org.junit.Test)

Example 17 with ManualClock

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());
}
Also used : ManualClock(com.yahoo.test.ManualClock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WeakReference(java.lang.ref.WeakReference) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with ManualClock

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);
}
Also used : ManualClock(com.yahoo.test.ManualClock) MockNameResolver(com.yahoo.vespa.hosted.provision.testutils.MockNameResolver) Zone(com.yahoo.config.provision.Zone) NodeRepository(com.yahoo.vespa.hosted.provision.NodeRepository) Curator(com.yahoo.vespa.curator.Curator) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) DockerImage(com.yahoo.config.provision.DockerImage) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Test(org.junit.Test)

Aggregations

ManualClock (com.yahoo.test.ManualClock)18 Test (org.junit.Test)16 Version (com.yahoo.component.Version)4 Application (com.yahoo.vespa.hosted.controller.Application)4 ControllerTester (com.yahoo.vespa.hosted.controller.ControllerTester)4 ApplicationPackage (com.yahoo.vespa.hosted.controller.application.ApplicationPackage)4 JobType.stagingTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.stagingTest)4 JobType.systemTest (com.yahoo.vespa.hosted.controller.application.DeploymentJobs.JobType.systemTest)4 DockerImage (com.yahoo.config.provision.DockerImage)3 ApplicationPackageBuilder (com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder)3 DeploymentTester (com.yahoo.vespa.hosted.controller.deployment.DeploymentTester)3 VespaVersion (com.yahoo.vespa.hosted.controller.versions.VespaVersion)3 NodeRepository (com.yahoo.vespa.hosted.provision.NodeRepository)3 MockNameResolver (com.yahoo.vespa.hosted.provision.testutils.MockNameResolver)3 ArrayList (java.util.ArrayList)3 ModelFactory (com.yahoo.config.model.api.ModelFactory)2 ApplicationId (com.yahoo.config.provision.ApplicationId)2 Zone (com.yahoo.config.provision.Zone)2 Metric (com.yahoo.jdisc.Metric)2 Curator (com.yahoo.vespa.curator.Curator)2