diff options
author | Harald Musum <musum@yahoo-inc.com> | 2016-12-22 13:37:56 +0100 |
---|---|---|
committer | Harald Musum <musum@yahoo-inc.com> | 2016-12-22 13:37:56 +0100 |
commit | fcaa8264cb9f34b81ad951675ba7004a98496928 (patch) | |
tree | 11543cf22396b99f7b34aefcdbb33fa9c605b27e /configserver | |
parent | 127cef5ab3b75b1a9026f4eff13e36f507eb6f47 (diff) |
Get rid of tenantsCopy()
* Use ImmutableSet where needed instead
Diffstat (limited to 'configserver')
8 files changed, 68 insertions, 83 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java index df49ce9ed43..f78a52e5db4 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java @@ -83,7 +83,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye */ @Override public Optional<com.yahoo.config.provision.Deployment> deployFromLocalActive(ApplicationId application, Duration timeout) { - Tenant tenant = tenants.tenantsCopy().get(application.tenant()); + Tenant tenant = tenants.getTenant(application.tenant()); LocalSession activeSession = tenant.getLocalSessionRepo().getActiveSession(application); if (activeSession == null) return Optional.empty(); TimeoutBudget timeoutBudget = new TimeoutBudget(clock, timeout); @@ -114,7 +114,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye * @throws RuntimeException if the remove transaction fails. This method is exception safe. */ public boolean remove(ApplicationId applicationId) { - Optional<Tenant> owner = Optional.ofNullable(tenants.tenantsCopy().get(applicationId.tenant())); + Optional<Tenant> owner = Optional.ofNullable(tenants.getTenant(applicationId.tenant())); if ( ! owner.isPresent()) return false; TenantApplications tenantApplications = owner.get().getApplicationRepo(); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpConfigRequests.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpConfigRequests.java index ca0fceef5e7..4c03f656fce 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpConfigRequests.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpConfigRequests.java @@ -46,7 +46,7 @@ public class HttpConfigRequests { static RequestHandler getRequestHandler(Tenants tenants, TenantRequest request) { - Tenant tenant = tenants.tenantsCopy().get(request.getApplicationId().tenant()); + Tenant tenant = tenants.getTenant(request.getApplicationId().tenant()); if (tenant==null) throw new NotFoundException("No such tenant: "+request.getApplicationId().tenant()); return tenant.getRequestHandler(); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListTenantsHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListTenantsHandler.java index c2065249ad1..84df1834712 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListTenantsHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ListTenantsHandler.java @@ -11,9 +11,8 @@ import com.yahoo.vespa.config.server.tenant.Tenants; /** * Handler to list tenants in the configserver - * - * @author vegardh * + * @author vegardh */ public class ListTenantsHandler extends HttpHandler { @@ -25,12 +24,10 @@ public class ListTenantsHandler extends HttpHandler { this.tenants = tenants; } - + @Override protected HttpResponse handleGET(HttpRequest request) { - return new ListTenantsResponse(tenants.tenantsCopy().keySet()); + return new ListTenantsResponse(tenants.getAllTenants()); } - - - + } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenants.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenants.java index 478bf957fe8..e28c353e532 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenants.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/Tenants.java @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.tenant; +import com.google.common.collect.ImmutableSet; import com.google.inject.Inject; import com.yahoo.concurrent.ThreadFactoryFactory; import com.yahoo.config.provision.ApplicationId; @@ -194,17 +195,6 @@ public class Tenants implements ConnectionStateListener, PathChildrenCacheListen } /** - * The registered tenants. Creates a copy of the map to avoid it being modified outside, since it can - * change after this method has been called. - * - * @return tenant list - */ - // TODO: Replace by something idiomatic - public synchronized Map<TenantName, Tenant> tenantsCopy() { - return new LinkedHashMap<>(tenants); - } - - /** * Returns a default (compatibility with single tenant config requests) tenant * * @return default tenant @@ -295,7 +285,7 @@ public class Tenants implements ConnectionStateListener, PathChildrenCacheListen public static String logPre(TenantName tenant) { if (DEFAULT_TENANT.equals(tenant)) return ""; StringBuilder ret = new StringBuilder() - .append("tenant:"+tenant.value()) + .append("tenant:" + tenant.value()) .append(" "); return ret.toString(); } @@ -337,21 +327,26 @@ public class Tenants implements ConnectionStateListener, PathChildrenCacheListen } public void redeployApplications(Deployer deployer) { - int totalNumberOfApplications = tenantsCopy().values().stream() + Set<Tenant> allTenants = ImmutableSet.copyOf(tenants.values()); + int totalNumberOfApplications = allTenants.stream() .mapToInt(tenant -> tenant.getApplicationRepo().listApplications().size()).sum(); int applicationsRedeployed = 0; - for (Tenant tenant : tenantsCopy().values()) { + for (Tenant tenant : allTenants) { tenant.redeployApplications(deployer); applicationsRedeployed += redeployProgress(tenant, applicationsRedeployed, totalNumberOfApplications); } } public boolean checkThatTenantExists(TenantName tenant) { - return tenantsCopy().containsKey(tenant); + return tenants.containsKey(tenant); } public Tenant getTenant(TenantName tenantName) { - return tenantsCopy().get(tenantName); + return tenants.get(tenantName); + } + + public Set<TenantName> getAllTenants() { + return ImmutableSet.copyOf(tenants.keySet()); } private static int redeployProgress(Tenant tenant, int applicationsRedeployed, int totalNumberOfApplications) { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java index c4090c96f04..4e730728ae3 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java @@ -128,7 +128,7 @@ public class ApplicationHandlerTest { // as login is moved from the HTTP layer into ApplicationRepository Tenants tenants = addApplication(defaultId, sessionId); ApplicationHandler handler = createApplicationHandler(tenants); - Tenant mytenant = tenants.tenantsCopy().get(defaultId.tenant()); + Tenant mytenant = tenants.getTenant(defaultId.tenant()); LocalSession applicationData = mytenant.getLocalSessionRepo().getSession(sessionId); assertNotNull(applicationData); assertNotNull(applicationData.getApplicationId()); @@ -145,7 +145,7 @@ public class ApplicationHandlerTest { sessionId++; { - addMockApplication(tenants.tenantsCopy().get(mytenantName), defaultId, sessionId); + addMockApplication(tenants.getTenant(mytenantName), defaultId, sessionId); deleteAndAssertOKResponseMocked(defaultId, true); ApplicationId fooId = new ApplicationId.Builder() @@ -154,8 +154,8 @@ public class ApplicationHandlerTest { sessionId++; - addMockApplication(tenants.tenantsCopy().get(mytenantName), fooId, sessionId); - addMockApplication(tenants.tenantsCopy().get(foobar), fooId, sessionId); + addMockApplication(tenants.getTenant(mytenantName), fooId, sessionId); + addMockApplication(tenants.getTenant(foobar), fooId, sessionId); assertApplicationExists(mytenantName, fooId, Zone.defaultZone()); assertApplicationExists(foobar, fooId, Zone.defaultZone()); deleteAndAssertOKResponseMocked(fooId, true); @@ -170,7 +170,7 @@ public class ApplicationHandlerTest { ApplicationId baliId = new ApplicationId.Builder() .tenant(mytenantName) .applicationName("bali").instanceName("quux").build(); - addMockApplication(tenants.tenantsCopy().get(mytenantName), baliId, sessionId); + addMockApplication(tenants.getTenant(mytenantName), baliId, sessionId); deleteAndAssertOKResponseMocked(baliId, true); assertApplicationExists(mytenantName, null, Zone.defaultZone()); } @@ -180,7 +180,7 @@ public class ApplicationHandlerTest { public void testGet() throws Exception { long sessionId = 1; ApplicationId defaultId = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build(); - addMockApplication(tenants.tenantsCopy().get(mytenantName), defaultId, sessionId); + addMockApplication(tenants.getTenant(mytenantName), defaultId, sessionId); assertApplicationGeneration(defaultId, Zone.defaultZone(), 1, true); assertApplicationGeneration(defaultId, Zone.defaultZone(), 1, false); } @@ -189,7 +189,7 @@ public class ApplicationHandlerTest { public void testRestart() throws Exception { long sessionId = 1; ApplicationId application = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build(); - addMockApplication(tenants.tenantsCopy().get(mytenantName), application, sessionId); + addMockApplication(tenants.getTenant(mytenantName), application, sessionId); assertFalse(provisioner.restarted); restart(application, Zone.defaultZone()); assertTrue(provisioner.restarted); @@ -200,7 +200,7 @@ public class ApplicationHandlerTest { public void testConverge() throws Exception { long sessionId = 1; ApplicationId application = new ApplicationId.Builder().applicationName(ApplicationName.defaultName()).tenant(mytenantName).build(); - addMockApplication(tenants.tenantsCopy().get(mytenantName), application, sessionId); + addMockApplication(tenants.getTenant(mytenantName), application, sessionId); assertFalse(stateApiFactory.createdApi); converge(application, Zone.defaultZone()); assertTrue(stateApiFactory.createdApi); @@ -218,7 +218,7 @@ public class ApplicationHandlerTest { mockHandler = createMockApplicationHandler( provisioner, new ApplicationConvergenceChecker(stateApiFactory), new LogServerLogGrabber()); final ApplicationId applicationId = ApplicationId.defaultId(); - addMockApplication(tenants.tenantsCopy().get(mytenantName), applicationId, 1); + addMockApplication(tenants.getTenant(mytenantName), applicationId, 1); assertApplicationExists(mytenantName, applicationId, Zone.defaultZone()); provisioner.activated = true; @@ -292,9 +292,9 @@ public class ApplicationHandlerTest { } private void deleteAndAssertOKResponseMocked(ApplicationId applicationId, boolean fullAppIdInUrl) throws IOException { - long sessionId = tenants.tenantsCopy().get(applicationId.tenant()).getApplicationRepo().getSessionIdForApplication(applicationId); + long sessionId = tenants.getTenant(applicationId.tenant()).getApplicationRepo().getSessionIdForApplication(applicationId); deleteAndAssertResponse(mockHandler, applicationId, Zone.defaultZone(), Response.Status.OK, null, fullAppIdInUrl); - assertNull(tenants.tenantsCopy().get(applicationId.tenant()).getLocalSessionRepo().getSession(sessionId)); + assertNull(tenants.getTenant(applicationId.tenant()).getLocalSessionRepo().getSession(sessionId)); } private void deleteAndAssertOKResponse(ApplicationHandler handler, Tenant tenant, ApplicationId applicationId) throws IOException { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java index 4ed87dd5d81..8e2b5da814b 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java @@ -62,14 +62,14 @@ public class HostHandlerTest { assertThat(hostRegistries, is(hostHandler.hostRegistries)); long sessionId = 1; ApplicationId id = ApplicationId.from(mytenant, ApplicationName.defaultName(), InstanceName.defaultName()); - ApplicationHandlerTest.addMockApplication(tenants.tenantsCopy().get(mytenant), id, sessionId); + ApplicationHandlerTest.addMockApplication(tenants.getTenant(mytenant), id, sessionId); assertApplicationForHost(hostname, mytenant, id, Zone.defaultZone()); } @Test public void require_that_handler_gives_error_for_unknown_hostname() throws Exception { long sessionId = 1; - ApplicationHandlerTest.addMockApplication(tenants.tenantsCopy().get(mytenant), ApplicationId.defaultId(), sessionId); + ApplicationHandlerTest.addMockApplication(tenants.getTenant(mytenant), ApplicationId.defaultId(), sessionId); final String hostname = "unknown"; assertErrorForHost(hostname, Response.Status.NOT_FOUND, diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java index 2eb27c6d51c..41521a7c43f 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java @@ -32,7 +32,7 @@ public class TenantHandlerTest extends TenantTest { @Test public void testTenantCreate() throws Exception { - assertFalse(tenants.tenantsCopy().containsKey(a)); + assertNull(tenants.getTenant(a)); TenantCreateResponse response = (TenantCreateResponse) putSync( HttpRequest.createTestRequest("http://deploy.example.yahoo.com:80/application/v2/tenant/a", Method.PUT)); assertResponseEquals(response, "{\"message\":\"Tenant a created.\"}"); @@ -41,7 +41,7 @@ public class TenantHandlerTest extends TenantTest { @Test public void testTenantCreateWithAllPossibleCharactersInName() throws Exception { TenantName tenantName = TenantName.from("aB-9999_foo"); - assertFalse(tenants.tenantsCopy().containsKey(tenantName)); + assertNull(tenants.getTenant(tenantName)); TenantCreateResponse response = (TenantCreateResponse) putSync( HttpRequest.createTestRequest("http://deploy.example.yahoo.com:80/application/v2/tenant/" + tenantName, Method.PUT)); assertResponseEquals(response, "{\"message\":\"Tenant " + tenantName + " created.\"}"); @@ -65,29 +65,28 @@ public class TenantHandlerTest extends TenantTest { @Test(expected=BadRequestException.class) public void testCreateExisting() throws Exception { - assertFalse(tenants.tenantsCopy().containsKey(a)); + assertNull(tenants.getTenant(a)); TenantCreateResponse response = (TenantCreateResponse) putSync(HttpRequest.createTestRequest("http://deploy.example.yahoo.com:80/application/v2/tenant/a", Method.PUT)); assertResponseEquals(response, "{\"message\":\"Tenant a created.\"}"); - Tenant ta = tenants.tenantsCopy().get(a); - assertEquals(ta.getName(), a); + assertEquals(tenants.getTenant(a).getName(), a); handler.handlePUT(HttpRequest.createTestRequest("http://deploy.example.yahoo.com:80/application/v2/tenant/a", Method.PUT)); } @Test public void testDelete() throws IOException, InterruptedException { putSync(HttpRequest.createTestRequest("http://deploy.example.yahoo.com:80/application/v2/tenant/a", Method.PUT)); - assertEquals(tenants.tenantsCopy().get(a).getName(), a); + assertEquals(tenants.getTenant(a).getName(), a); TenantDeleteResponse delResp = (TenantDeleteResponse) handler.handleDELETE(HttpRequest.createTestRequest("http://deploy.example.yahoo.com:80/application/v2/tenant/a", Method.DELETE)); assertResponseEquals(delResp, "{\"message\":\"Tenant a deleted.\"}"); - assertFalse(tenants.tenantsCopy().containsKey(a)); + assertNull(tenants.getTenant(a)); } @Test public void testDeleteTenantWithActiveApplications() throws Exception { putSync(HttpRequest.createTestRequest("http://deploy.example.yahoo.com:80/application/v2/tenant/" + a, Method.PUT)); - assertEquals(tenants.tenantsCopy().get(a).getName(), a); + final Tenant tenant = tenants.getTenant(a); + assertEquals(a, tenant.getName()); - final Tenant tenant = tenants.tenantsCopy().get(a); final int sessionId = 1; ApplicationId app = ApplicationId.from(a, ApplicationName.from("foo"), InstanceName.defaultName()); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantsTestCase.java b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantsTestCase.java index 767956d7dd3..31e8d545b7a 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantsTestCase.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantsTestCase.java @@ -25,14 +25,12 @@ import java.io.IOException; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; import java.util.Set; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -65,13 +63,13 @@ public class TenantsTestCase extends TestWithCurator { @Test public void testStartUp() { - assertEquals(tenants.tenantsCopy().get(tenant1).getName(), tenant1); - assertEquals(tenants.tenantsCopy().get(tenant2).getName(), tenant2); + assertEquals(tenants.getTenant(tenant1).getName(), tenant1); + assertEquals(tenants.getTenant(tenant2).getName(), tenant2); } @Test public void testListenersAdded() throws IOException, SAXException { - tenants.tenantsCopy().get(tenant1).getReloadHandler().reloadConfig(ApplicationSet.fromSingle(new Application(new VespaModel(MockApplicationPackage.createEmpty()), new ServerCache(), 4l, Version.fromIntValues(1, 2, 3), MetricUpdater.createTestUpdater(), ApplicationId.defaultId()))); + tenants.getTenant(tenant1).getReloadHandler().reloadConfig(ApplicationSet.fromSingle(new Application(new VespaModel(MockApplicationPackage.createEmpty()), new ServerCache(), 4l, Version.fromIntValues(1, 2, 3), MetricUpdater.createTestUpdater(), ApplicationId.defaultId()))); assertThat(listener.reloaded.get(), is(1)); } @@ -82,22 +80,22 @@ public class TenantsTestCase extends TestWithCurator { @Test public void testTenantListenersNotified() throws Exception { tenants.writeTenantPath(tenant3); - assertThat("tenant3 not the last created tenant. Tenants: " + tenants.tenantsCopy().keySet() + ", /config/v2/tenants: " + readZKChildren("/config/v2/tenants"), tenantListener.tenantCreatedName, is(tenant3)); + assertThat("tenant3 not the last created tenant. Tenants: " + tenants.getAllTenants() + ", /config/v2/tenants: " + readZKChildren("/config/v2/tenants"), tenantListener.tenantCreatedName, is(tenant3)); tenants.deleteTenant(tenant2); - assertFalse(tenants.tenantsCopy().containsKey(tenant2)); + assertFalse(tenants.getAllTenants().contains(tenant2)); assertThat(tenantListener.tenantDeletedName, is(tenant2)); } @Test public void testAddTenant() throws Exception { - Map<TenantName, Tenant> tenantsCopy = tenants.tenantsCopy(); - assertEquals(tenantsCopy.get(tenant1).getName(), tenant1); - assertEquals(tenantsCopy.get(tenant2).getName(), tenant2); + Set<TenantName> allTenants = tenants.getAllTenants(); + assertTrue(allTenants.contains(tenant1)); + assertTrue(allTenants.contains(tenant2)); tenants.writeTenantPath(tenant3); - tenantsCopy = tenants.tenantsCopy(); - assertEquals(tenantsCopy.get(tenant1).getName(), tenant1); - assertEquals(tenantsCopy.get(tenant2).getName(), tenant2); - assertEquals(tenantsCopy.get(tenant3).getName(), tenant3); + allTenants = tenants.getAllTenants(); + assertTrue(allTenants.contains(tenant1)); + assertTrue(allTenants.contains(tenant2)); + assertTrue(allTenants.contains(tenant3)); } @Test @@ -110,7 +108,7 @@ public class TenantsTestCase extends TestWithCurator { public void testRemove() throws Exception { assertNotNull(globalComponentRegistry.getCurator().framework().checkExists().forPath(tenants.tenantZkPath(tenant1))); tenants.deleteTenant(tenant1); - assertFalse(tenants.tenantsCopy().containsKey(tenant1)); + assertFalse(tenants.getAllTenants().contains(tenant1)); } @Test @@ -122,16 +120,17 @@ public class TenantsTestCase extends TestWithCurator { newTenants.add(tenant2); newTenants.add(defaultTenant); tenants.tenantsChanged(newTenants); - Map<TenantName, Tenant> tenantsCopy = tenants.tenantsCopy(); - assertEquals(tenantsCopy.get(tenant2).getName(), tenant2); - assertEquals(tenantsCopy.get(defaultTenant).getName().value(), "default"); - assertNull(tenantsCopy.get(tenant1)); + Set<TenantName> allTenants = tenants.getAllTenants(); + assertTrue(allTenants.contains(tenant2)); + assertEquals("default", defaultTenant.value()); + assertTrue(allTenants.contains(defaultTenant)); + assertFalse(allTenants.contains(tenant1)); newTenants.clear(); tenants.tenantsChanged(newTenants); - tenantsCopy = tenants.tenantsCopy(); - assertNull(tenantsCopy.get(tenant1)); - assertNull(tenantsCopy.get(tenant2)); - assertNull(tenantsCopy.get(defaultTenant)); + allTenants = tenants.getAllTenants(); + assertFalse(allTenants.contains(tenant1)); + assertFalse(allTenants.contains(tenant2)); + assertFalse(allTenants.contains(defaultTenant)); newTenants.clear(); TenantName foo = TenantName.from("foo"); TenantName bar = TenantName.from("bar"); @@ -139,13 +138,10 @@ public class TenantsTestCase extends TestWithCurator { newTenants.add(foo); newTenants.add(bar); tenants.tenantsChanged(newTenants); - tenantsCopy = tenants.tenantsCopy(); - assertNotNull(tenantsCopy.get(tenant2)); - assertNotNull(tenantsCopy.get(foo)); - assertNotNull(tenantsCopy.get(bar)); - assertEquals(tenantsCopy.get(tenant2).getName(), tenant2); - assertEquals(tenantsCopy.get(foo).getName(), foo); - assertEquals(tenantsCopy.get(bar).getName(), bar); + allTenants = tenants.getAllTenants(); + assertTrue(allTenants.contains(tenant2)); + assertTrue(allTenants.contains(foo)); + assertTrue(allTenants.contains(bar)); } @Test @@ -153,15 +149,13 @@ public class TenantsTestCase extends TestWithCurator { TestComponentRegistry reg = new TestComponentRegistry.Builder().curator(curator).build(); Tenants t = new Tenants(reg, Metrics.createTestMetrics()); try { - assertEquals(t.tenantsCopy().get(TenantName.defaultName()).getName(), TenantName.defaultName()); + assertTrue(t.getAllTenants().contains(TenantName.defaultName())); reg.getCurator().framework().create().forPath(tenants.tenantZkPath(TenantName.from("newTenant"))); // Poll for the watcher to pick up the tenant from zk, and add it int tries=0; while(true) { if (tries > 500) fail("Didn't react on watch"); - Tenant nt = t.tenantsCopy().get(TenantName.from("newTenant")); - if (nt != null) { - assertEquals(nt.getName().value(), "newTenant"); + if (t.getAllTenants().contains(TenantName.from("newTenant"))) { return; } tries++; @@ -175,7 +169,7 @@ public class TenantsTestCase extends TestWithCurator { @Test public void testTenantRedeployment() throws Exception { MockDeployer deployer = new MockDeployer(); - Tenant tenant = tenants.tenantsCopy().get(tenant1); + Tenant tenant = tenants.getTenant(tenant1); ApplicationId id = ApplicationId.from(tenant1, ApplicationName.defaultName(), InstanceName.defaultName()); tenant.getApplicationRepo().createPutApplicationTransaction(id, 3).commit(); tenants.redeployApplications(deployer); |