@Test void testDontSyncStackWhenNotCool() { UserSyncStatus userSyncStatus = setupMocks(); when(eventGenerationIdsChecker.isInSync(eq(userSyncStatus), any())).thenReturn(false); when(cooldownChecker.isCooldownExpired(eq(userSyncStatus), any())).thenReturn(false); underTest.syncAllFreeIpaStacks(); verify(userSyncService, times(0)) .synchronizeUsers(any(), any(), any(), any(), any()); }
@VisibleForTesting void syncAllFreeIpaStacks() { try { Optional<String> requestId = Optional.of(UUID.randomUUID().toString()); MDCBuilder.addRequestId(requestId.get()); LOGGER.debug("Setting request id = {} for this poll", requestId); ThreadBasedUserCrnProvider.doAs(INTERNAL_ACTOR_CRN, () -> { LOGGER.debug("Attempting to sync users to FreeIPA stacks"); List<Stack> stackList = stackService.findAllWithStatuses(Status.AVAILABLE_STATUSES); LOGGER.debug("Found {} active stacks", stackList.size()); stackList.stream() .collect(Collectors.groupingBy(Stack::getAccountId)) .entrySet().stream() .forEach(stringListEntry -> { String accountId = stringListEntry.getKey(); if (userSyncPollerEntitlementChecker.isAccountEntitled(accountId)) { LOGGER.debug("Automatic usersync polling is entitled in account {}", accountId); syncFreeIpaStacksInAccount(requestId, accountId, stringListEntry.getValue()); } else { LOGGER.debug("Automatic usersync polling is not entitled in account {}.", accountId); } }); }); } finally { MDCBuilder.cleanupMdc(); } }
UserSyncPoller { @VisibleForTesting void syncAllFreeIpaStacks() { try { Optional<String> requestId = Optional.of(UUID.randomUUID().toString()); MDCBuilder.addRequestId(requestId.get()); LOGGER.debug("Setting request id = {} for this poll", requestId); ThreadBasedUserCrnProvider.doAs(INTERNAL_ACTOR_CRN, () -> { LOGGER.debug("Attempting to sync users to FreeIPA stacks"); List<Stack> stackList = stackService.findAllWithStatuses(Status.AVAILABLE_STATUSES); LOGGER.debug("Found {} active stacks", stackList.size()); stackList.stream() .collect(Collectors.groupingBy(Stack::getAccountId)) .entrySet().stream() .forEach(stringListEntry -> { String accountId = stringListEntry.getKey(); if (userSyncPollerEntitlementChecker.isAccountEntitled(accountId)) { LOGGER.debug("Automatic usersync polling is entitled in account {}", accountId); syncFreeIpaStacksInAccount(requestId, accountId, stringListEntry.getValue()); } else { LOGGER.debug("Automatic usersync polling is not entitled in account {}.", accountId); } }); }); } finally { MDCBuilder.cleanupMdc(); } } }
UserSyncPoller { @VisibleForTesting void syncAllFreeIpaStacks() { try { Optional<String> requestId = Optional.of(UUID.randomUUID().toString()); MDCBuilder.addRequestId(requestId.get()); LOGGER.debug("Setting request id = {} for this poll", requestId); ThreadBasedUserCrnProvider.doAs(INTERNAL_ACTOR_CRN, () -> { LOGGER.debug("Attempting to sync users to FreeIPA stacks"); List<Stack> stackList = stackService.findAllWithStatuses(Status.AVAILABLE_STATUSES); LOGGER.debug("Found {} active stacks", stackList.size()); stackList.stream() .collect(Collectors.groupingBy(Stack::getAccountId)) .entrySet().stream() .forEach(stringListEntry -> { String accountId = stringListEntry.getKey(); if (userSyncPollerEntitlementChecker.isAccountEntitled(accountId)) { LOGGER.debug("Automatic usersync polling is entitled in account {}", accountId); syncFreeIpaStacksInAccount(requestId, accountId, stringListEntry.getValue()); } else { LOGGER.debug("Automatic usersync polling is not entitled in account {}.", accountId); } }); }); } finally { MDCBuilder.cleanupMdc(); } }  }
UserSyncPoller { @VisibleForTesting void syncAllFreeIpaStacks() { try { Optional<String> requestId = Optional.of(UUID.randomUUID().toString()); MDCBuilder.addRequestId(requestId.get()); LOGGER.debug("Setting request id = {} for this poll", requestId); ThreadBasedUserCrnProvider.doAs(INTERNAL_ACTOR_CRN, () -> { LOGGER.debug("Attempting to sync users to FreeIPA stacks"); List<Stack> stackList = stackService.findAllWithStatuses(Status.AVAILABLE_STATUSES); LOGGER.debug("Found {} active stacks", stackList.size()); stackList.stream() .collect(Collectors.groupingBy(Stack::getAccountId)) .entrySet().stream() .forEach(stringListEntry -> { String accountId = stringListEntry.getKey(); if (userSyncPollerEntitlementChecker.isAccountEntitled(accountId)) { LOGGER.debug("Automatic usersync polling is entitled in account {}", accountId); syncFreeIpaStacksInAccount(requestId, accountId, stringListEntry.getValue()); } else { LOGGER.debug("Automatic usersync polling is not entitled in account {}.", accountId); } }); }); } finally { MDCBuilder.cleanupMdc(); } }  @Scheduled(fixedDelayString = "${freeipa.usersync.poller.fixed-delay-millis}", initialDelayString = "${freeipa.usersync.poller.initial-delay-millis}") void automaticUserSyncTask(); }
UserSyncPoller { @VisibleForTesting void syncAllFreeIpaStacks() { try { Optional<String> requestId = Optional.of(UUID.randomUUID().toString()); MDCBuilder.addRequestId(requestId.get()); LOGGER.debug("Setting request id = {} for this poll", requestId); ThreadBasedUserCrnProvider.doAs(INTERNAL_ACTOR_CRN, () -> { LOGGER.debug("Attempting to sync users to FreeIPA stacks"); List<Stack> stackList = stackService.findAllWithStatuses(Status.AVAILABLE_STATUSES); LOGGER.debug("Found {} active stacks", stackList.size()); stackList.stream() .collect(Collectors.groupingBy(Stack::getAccountId)) .entrySet().stream() .forEach(stringListEntry -> { String accountId = stringListEntry.getKey(); if (userSyncPollerEntitlementChecker.isAccountEntitled(accountId)) { LOGGER.debug("Automatic usersync polling is entitled in account {}", accountId); syncFreeIpaStacksInAccount(requestId, accountId, stringListEntry.getValue()); } else { LOGGER.debug("Automatic usersync polling is not entitled in account {}.", accountId); } }); }); } finally { MDCBuilder.cleanupMdc(); } }  @Scheduled(fixedDelayString = "${freeipa.usersync.poller.fixed-delay-millis}", initialDelayString = "${freeipa.usersync.poller.initial-delay-millis}") void automaticUserSyncTask();  }