From 3dd24358a6c5eaf26e530abccb7f52fcd42f3686 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Thu, 24 May 2018 11:12:08 +0200 Subject: Use absolute path for lock and add test --- .../config/server/maintenance/Maintainer.java | 4 +- .../server/maintenance/TenantsMaintainerTest.java | 52 ++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 configserver/src/test/java/com/yahoo/vespa/config/server/maintenance/TenantsMaintainerTest.java (limited to 'configserver') diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/Maintainer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/Maintainer.java index ce0811184a3..090955ad555 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/Maintainer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/Maintainer.java @@ -20,7 +20,7 @@ public abstract class Maintainer extends AbstractComponent implements Runnable { protected static final Logger log = Logger.getLogger(Maintainer.class.getName()); private static final Path root = Path.fromString("/configserver/v1/"); - private static final com.yahoo.path.Path lockRoot = root.append("locks"); + private static final Path lockRoot = root.append("locks"); private final Duration maintenanceInterval; private final ScheduledExecutorService service; @@ -40,7 +40,7 @@ public abstract class Maintainer extends AbstractComponent implements Runnable { public void run() { try { Path path = lockRoot.append(name()); - try (Lock lock = new Lock(path.toString(), curator)) { + try (Lock lock = new Lock(path.getAbsolute(), curator)) { maintain(); } } catch (UncheckedTimeoutException e) { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/maintenance/TenantsMaintainerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/maintenance/TenantsMaintainerTest.java new file mode 100644 index 00000000000..e8db2af1369 --- /dev/null +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/maintenance/TenantsMaintainerTest.java @@ -0,0 +1,52 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server.maintenance; + +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.ApplicationName; +import com.yahoo.config.provision.InstanceName; +import com.yahoo.config.provision.TenantName; +import com.yahoo.vespa.config.server.ApplicationRepository; +import com.yahoo.vespa.config.server.GlobalComponentRegistry; +import com.yahoo.vespa.config.server.TestComponentRegistry; +import com.yahoo.vespa.config.server.http.SessionHandlerTest; +import com.yahoo.vespa.config.server.session.PrepareParams; +import com.yahoo.vespa.config.server.tenant.TenantRepository; +import com.yahoo.vespa.curator.Curator; +import com.yahoo.vespa.curator.mock.MockCurator; +import org.junit.Test; + +import java.io.File; +import java.time.Clock; +import java.time.Duration; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +public class TenantsMaintainerTest { + + @Test + public void deleteTenantWithNoApplications() { + Curator curator = new MockCurator(); + GlobalComponentRegistry componentRegistry = new TestComponentRegistry.Builder().curator(curator).build(); + TenantRepository tenantRepository = new TenantRepository(componentRegistry, false); + ApplicationRepository applicationRepository = + new ApplicationRepository(tenantRepository, new SessionHandlerTest.MockProvisioner(), Clock.systemUTC()); + TenantName shouldBeDeleted = TenantName.from("to-be-deleted"); + TenantName shouldNotBeDeleted = TenantName.from("should-not-be-deleted"); + + tenantRepository.addTenant(shouldBeDeleted); + tenantRepository.addTenant(shouldNotBeDeleted); + applicationRepository.deploy(new File("src/test/apps/app"), + new PrepareParams.Builder() + .applicationId(ApplicationId.from(shouldNotBeDeleted, ApplicationName.from("foo"), InstanceName.defaultName())) + .build()); + assertNotNull(tenantRepository.getTenant(shouldBeDeleted)); + assertNotNull(tenantRepository.getTenant(shouldNotBeDeleted)); + + new TenantsMaintainer(applicationRepository, curator, Duration.ofMillis(10)); + + try { Thread.sleep(1000); } catch (InterruptedException e) { /* ignore */ } + assertNull(tenantRepository.getTenant(shouldBeDeleted)); + assertNotNull(tenantRepository.getTenant(shouldNotBeDeleted)); + } +} -- cgit v1.2.3