TenantRepository { public synchronized void deleteTenant(TenantName name) { if (name.equals(DEFAULT_TENANT)) throw new IllegalArgumentException("Deleting 'default' tenant is not allowed"); if ( ! tenants.containsKey(name)) throw new IllegalArgumentException("Deleting '" + name + "' failed, tenant does not exist"); log.log(Level.INFO, "Deleting tenant '" + name + "'"); curator.delete(tenants.get(name).getPath()); } @Inject  TenantRepository(GlobalComponentRegistry componentRegistry); synchronized Tenant addTenant(TenantName tenantName); void createAndWriteTenantMetaData(Tenant tenant); Transaction createWriteTenantMetaDataTransaction(TenantMetaData tenantMetaData); TenantMetaData getTenantMetaData(Tenant tenant); synchronized void updateTenants(); Instant readCreatedTimeFromZooKeeper(TenantName tenantName); synchronized Tenant defaultTenant(); synchronized void deleteTenant(TenantName name); static String logPre(ApplicationId app); static String logPre(TenantName tenant); void close(); boolean checkThatTenantExists(TenantName tenant); Tenant getTenant(TenantName tenantName); Set<TenantName> getAllTenantNames(); Collection<Tenant> getAllTenants(); static Path getTenantPath(TenantName tenantName); static Path getSessionsPath(TenantName tenantName); static Path getApplicationsPath(TenantName tenantName); static Path getLocksPath(TenantName tenantName); Curator getCurator(); static final TenantName HOSTED_VESPA_TENANT; }
@Test public void testDeleteTenant() throws Exception { assertZooKeeperTenantPathExists(tenant1); tenantRepository.deleteTenant(tenant1); assertFalse(tenantRepository.getAllTenantNames().contains(tenant1)); try { tenantRepository.deleteTenant(TenantName.from("non-existing")); fail("deletion of non-existing tenant should fail"); } catch (IllegalArgumentException e) { } }
@Test(expected = IllegalArgumentException.class) public void testDeletingDefaultTenant() { try { assertZooKeeperTenantPathExists(TenantName.defaultName()); } catch (Exception e) { fail("default tenant does not exist"); } tenantRepository.deleteTenant(TenantName.defaultName()); }