@Test
  public void testCompareAccountMetadata() throws AccountServiceException {
    Account a1 = testAccount;
    Container c1 = testContainer;
    Container c2 = new ContainerBuilder((short) 2, "c2", Container.ContainerStatus.ACTIVE, "c2", (short) 1).build();
    Container c2Updated = new ContainerBuilder(c2).setStatus(Container.ContainerStatus.INACTIVE).build();
    Container c3 = new ContainerBuilder((short) 3, "c3", Container.ContainerStatus.ACTIVE, "c3", (short) 1).build();

    List<Account> accountsInSecondary =
        Collections.singletonList(new AccountBuilder(a1).addOrUpdateContainer(c2).build());

    List<Account> accountsInPrimary =
        Arrays.asList(new AccountBuilder(a1).addOrUpdateContainer(c2Updated).addOrUpdateContainer(c3).build(),
            new AccountBuilder((short) 2, "a2", Account.AccountStatus.ACTIVE).build());

    when(primaryAccountService.getAllAccounts()).thenReturn(accountsInPrimary);
    when(secondaryAccountService.getAllAccounts()).thenReturn(accountsInSecondary);
    when(secondaryAccountService.getAccountById((short) 1)).thenReturn(accountsInSecondary.iterator().next());
    when(secondaryAccountService.getContainerByName("a1", "c1")).thenReturn(c1);
    when(secondaryAccountService.getContainerByName("a1", "c2")).thenReturn(c2);

    ((CompositeAccountService) compositeAccountService).compareAccountMetadata();
    verify(primaryAccountService, atLeastOnce()).getAllAccounts();
    verify(secondaryAccountService, atLeastOnce()).getAllAccounts();
    // Expects 3 inconsistencies: 1. account a2 missing in secondary, 2. container (a1,c3) missing in secondary, 3. container (a1,c2) different in secondary
    assertEquals("Expected 2 inconsistencies between primary and secondary", 3,
        metrics.accountDataInconsistencyCount.getValue().intValue());
  }
Test composite updateContainers() with either of the sources returning throwing exception.
ambry-account/src/test/java/com/github/ambry/account/CompositeAccountServiceTest.java