use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.
the class UserSyncForEnvServiceTest method testSyncUsersDoesntTimeout.
@Test
public void testSyncUsersDoesntTimeout() {
ReflectionTestUtils.setField(underTest, "operationTimeout", 0L);
Stack stack1 = mock(Stack.class);
when(stack1.getEnvironmentCrn()).thenReturn(ENV_CRN);
UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(Set.of(), Set.of(), Optional.empty());
UserSyncOptions options = new UserSyncOptions(true, true, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED);
doAnswer(inv -> {
inv.getArgument(2, Runnable.class).run();
return null;
}).when(operationService).tryWithOperationCleanup(eq(OPERATION_ID), eq(ACCOUNT_ID), any(Runnable.class));
UmsUsersState umsUsersState1 = mock(UmsUsersState.class);
when(umsUsersStateProviderDispatcher.getEnvToUmsUsersStateMap(eq(ACCOUNT_ID), eq(Set.of(ENV_CRN)), eq(Set.of()), eq(Set.of()), any())).thenReturn(Map.of(ENV_CRN, umsUsersState1));
when(userSyncForStackService.synchronizeStack(stack1, umsUsersState1, options)).thenReturn(new SyncStatusDetail(ENV_CRN, SynchronizationStatus.COMPLETED, "", ImmutableMultimap.of()));
Future<SyncStatusDetail> future = mock(Future.class);
when(asyncTaskExecutor.submit(any(Callable.class))).thenAnswer(inv -> {
SyncStatusDetail result = (SyncStatusDetail) inv.getArgument(0, Callable.class).call();
when(future.get(anyLong(), eq(TimeUnit.MILLISECONDS))).thenReturn(result);
return future;
});
when(umsEventGenerationIdsProvider.getEventGenerationIds(eq(ACCOUNT_ID), any(Optional.class))).thenReturn(new UmsEventGenerationIds());
when(userSyncStatusService.getOrCreateForStack(stack1)).thenReturn(new UserSyncStatus());
when(entitlementService.isUserSyncThreadTimeoutEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
underTest.synchronizeUsers(OPERATION_ID, ACCOUNT_ID, List.of(stack1), userSyncFilter, options, System.currentTimeMillis());
ArgumentCaptor<Collection> successCaptor = ArgumentCaptor.forClass(Collection.class);
ArgumentCaptor<Collection> failureCaptor = ArgumentCaptor.forClass(Collection.class);
verify(operationService).completeOperation(eq(ACCOUNT_ID), eq(OPERATION_ID), successCaptor.capture(), failureCaptor.capture());
verify(future, never()).cancel(true);
verify(future, never()).cancel(false);
assertTrue(failureCaptor.getValue().isEmpty());
assertTrue(successCaptor.getValue().contains(new SuccessDetails(ENV_CRN)));
}
use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.
the class EnvironmentUserSyncStateCalculatorTest method internalCalculateEnvironmentUserSyncStateLastSyncTimedout.
@Test
void internalCalculateEnvironmentUserSyncStateLastSyncTimedout() {
UserSyncStatus userSyncStatus = new UserSyncStatus();
Operation lastSync = new Operation();
lastSync.setOperationId(UUID.randomUUID().toString());
lastSync.setStatus(OperationState.FAILED);
userSyncStatus.setLastStartedFullSync(lastSync);
EnvironmentUserSyncState result = underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, Optional.of(userSyncStatus));
assertEquals(UserSyncState.SYNC_FAILED, result.getState());
assertEquals(lastSync.getOperationId(), result.getLastUserSyncOperationId());
}
use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.
the class EnvironmentUserSyncStateCalculatorTest method internalCalculateEnvironmentUserSyncStateLastSyncRequested.
@Test
void internalCalculateEnvironmentUserSyncStateLastSyncRequested() {
UserSyncStatus userSyncStatus = new UserSyncStatus();
Operation lastSync = new Operation();
lastSync.setOperationId(UUID.randomUUID().toString());
lastSync.setStatus(OperationState.REQUESTED);
userSyncStatus.setLastStartedFullSync(lastSync);
assertThrows(IllegalStateException.class, () -> underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, Optional.of(userSyncStatus)));
}
use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.
the class EnvironmentUserSyncStateCalculatorTest method internalCalculateEnvironmentUserSyncStateLastSyncRejected.
@Test
void internalCalculateEnvironmentUserSyncStateLastSyncRejected() {
UserSyncStatus userSyncStatus = new UserSyncStatus();
Operation lastSync = new Operation();
lastSync.setOperationId(UUID.randomUUID().toString());
lastSync.setStatus(OperationState.REJECTED);
userSyncStatus.setLastStartedFullSync(lastSync);
assertThrows(IllegalStateException.class, () -> underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, Optional.of(userSyncStatus)));
}
use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.
the class EnvironmentUserSyncStateCalculatorTest method internalCalculateEnvironmentUserSyncStateLastSyncCompletedSuccessNotInSync.
@Test
void internalCalculateEnvironmentUserSyncStateLastSyncCompletedSuccessNotInSync() {
UserSyncStatus userSyncStatus = new UserSyncStatus();
Operation lastSync = new Operation();
lastSync.setOperationId(UUID.randomUUID().toString());
lastSync.setStatus(OperationState.COMPLETED);
lastSync.setSuccessList(List.of(new SuccessDetails(ENVIRONMENT_CRN)));
userSyncStatus.setLastStartedFullSync(lastSync);
UmsEventGenerationIds current = new UmsEventGenerationIds();
when(umsEventGenerationIdsProvider.getEventGenerationIds(eq(ACCOUNT_ID), any())).thenReturn(current);
when(eventGenerationIdsChecker.isInSync(userSyncStatus, current)).thenReturn(false);
EnvironmentUserSyncState result = underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, Optional.of(userSyncStatus));
assertEquals(UserSyncState.STALE, result.getState());
assertEquals(lastSync.getOperationId(), result.getLastUserSyncOperationId());
}
Aggregations