@Test public void testAddContainer() throws Exception { assumeTrue(!useNewZNodePath); accountService = mockHelixAccountServiceFactory.getAccountService(); assertEquals("The number of account in HelixAccountService is incorrect", 0, accountService.getAllAccounts().size()); boolean res = accountService.updateAccounts(Collections.singletonList(refAccount)); assertTrue("Failed to create account", res); Container brandNewContainer = new ContainerBuilder(refContainer).setId(UNKNOWN_CONTAINER_ID).build(); try { accountService.updateContainers("", null); fail("should fail because input is invalid"); } catch (AccountServiceException e) { assertEquals("Mismatch in error code", AccountServiceErrorCode.BadRequest, e.getErrorCode()); } String fakeAccountName = refAccountName + "fake"; Container containerToAdd1 = new ContainerBuilder(UNKNOWN_CONTAINER_ID, "newContainer", ContainerStatus.ACTIVE, "description", refParentAccountId).build(); try { accountService.updateContainers(fakeAccountName, Collections.singleton(containerToAdd1)); fail("should fail because account is not found"); } catch (AccountServiceException e) { assertEquals("Mismatch in error code", AccountServiceErrorCode.NotFound, e.getErrorCode()); } Container conflictContainer = new ContainerBuilder(brandNewContainer).setBackupEnabled(true).build(); try { accountService.updateContainers(refAccountName, Collections.singleton(conflictContainer)); fail("should fail because there is a conflicting container"); } catch (AccountServiceException e) { assertEquals("Mismatch in error code", AccountServiceErrorCode.ResourceConflict, e.getErrorCode()); } Collection<Container> addedContainers = accountService.updateContainers(refAccountName, Collections.singleton(brandNewContainer)); assertEquals("Mismatch in return count", 1, addedContainers.size()); for (Container container : addedContainers) { assertEquals("Mismatch in account id", refAccountId, container.getParentAccountId()); assertEquals("Mismatch in container id", refContainerId, container.getId()); assertEquals("Mismatch in container name", refContainerName, container.getName()); } MockHelixPropertyStore<ZNRecord> mockHelixStore = mockHelixAccountServiceFactory.getHelixStore(ZK_CONNECT_STRING, storeConfig); mockHelixStore.setExceptionDuringUpdater(true); try { accountService.updateContainers(refAccountName, Collections.singleton(containerToAdd1)); fail("should fail because exception occurs when updating ZK"); } catch (AccountServiceException e) { assertEquals("Mismatch in error code", AccountServiceErrorCode.AccountUpdateError, e.getErrorCode()); } mockHelixStore.setExceptionDuringUpdater(false); Container containerToAdd2 = new ContainerBuilder(UNKNOWN_CONTAINER_ID, "newContainer2", ContainerStatus.ACTIVE, "description", refParentAccountId).build(); addedContainers = accountService.updateContainers(refAccountName, Arrays.asList(containerToAdd1, containerToAdd2)); for (Container container : addedContainers) { assertEquals("Mismatch in account id", refAccountId, container.getParentAccountId()); } }
@Override public boolean updateAccounts(Collection<Account> accounts) { return updateAccountsWithAccountMetadataStore(accounts, accountMetadataStore); }
HelixAccountService extends AbstractAccountService implements AccountService { @Override public boolean updateAccounts(Collection<Account> accounts) { return updateAccountsWithAccountMetadataStore(accounts, accountMetadataStore); } }
HelixAccountService extends AbstractAccountService implements AccountService { @Override public boolean updateAccounts(Collection<Account> accounts) { return updateAccountsWithAccountMetadataStore(accounts, accountMetadataStore); } HelixAccountService(HelixPropertyStore<ZNRecord> helixStore, AccountServiceMetrics accountServiceMetrics,
      Notifier<String> notifier, ScheduledExecutorService scheduler, HelixAccountServiceConfig config); }
HelixAccountService extends AbstractAccountService implements AccountService { @Override public boolean updateAccounts(Collection<Account> accounts) { return updateAccountsWithAccountMetadataStore(accounts, accountMetadataStore); } HelixAccountService(HelixPropertyStore<ZNRecord> helixStore, AccountServiceMetrics accountServiceMetrics,
      Notifier<String> notifier, ScheduledExecutorService scheduler, HelixAccountServiceConfig config); void setupRouter(final Router router); @Override boolean updateAccounts(Collection<Account> accounts); @Override void close(); void selectInactiveContainersAndMarkInZK(StatsSnapshot statsSnapshot); }
HelixAccountService extends AbstractAccountService implements AccountService { @Override public boolean updateAccounts(Collection<Account> accounts) { return updateAccountsWithAccountMetadataStore(accounts, accountMetadataStore); } HelixAccountService(HelixPropertyStore<ZNRecord> helixStore, AccountServiceMetrics accountServiceMetrics,
      Notifier<String> notifier, ScheduledExecutorService scheduler, HelixAccountServiceConfig config); void setupRouter(final Router router); @Override boolean updateAccounts(Collection<Account> accounts); @Override void close(); void selectInactiveContainersAndMarkInZK(StatsSnapshot statsSnapshot);  }