Skip to content

Commit

Permalink
CDPCP-2435. Add user sync failed state
Browse files Browse the repository at this point in the history
The environment sync state is calculated from the last started
user sync operation. This commit adds a SYNC_FAILED state and
updates the state calculations to explicitly call out when the
sync failed instead of just marking the environment STALE.
  • Loading branch information
handavid authored and lacikaaa committed Jun 23, 2020
1 parent 4d20e49 commit f50f5c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum UserSyncState {
UP_TO_DATE,
STALE,
SYNC_IN_PROGRESS
SYNC_IN_PROGRESS,
SYNC_FAILED
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ private UserSyncState calculateUserSyncState(String accountId, String envCrnStri
throw createExceptionForUnexpectedOperationStatus(envCrnString, userSyncStatus);
case TIMEDOUT:
LOGGER.warn("UserSyncStatus.lastStartedFullSync '{}' is timed out for environment '{}'", lastSync.getOperationId(), envCrnString);
state = UserSyncState.STALE;
state = UserSyncState.SYNC_FAILED;
break;
case FAILED:
state = UserSyncState.SYNC_FAILED;
break;
default:
state = UserSyncState.STALE;
break;
Expand All @@ -93,9 +95,11 @@ private UserSyncState calculateStateForCompletedOperation(String accountId, Stri
UmsEventGenerationIds currentEventGenerationIds = umsEventGenerationIdsProvider.getEventGenerationIds(accountId, MDCUtils.getRequestId());
if (eventGenerationIdsChecker.isInSync(userSyncStatus, currentEventGenerationIds)) {
return UserSyncState.UP_TO_DATE;
} else {
return UserSyncState.STALE;
}
}
return UserSyncState.STALE;
return UserSyncState.SYNC_FAILED;
}

private IllegalStateException createExceptionForUnexpectedOperationStatus(String envCrnString, UserSyncStatus userSyncStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void internalCalculateEnvironmentUserSyncStateLastSyncFailed() {

EnvironmentUserSyncState result = underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, userSyncStatus);

assertEquals(UserSyncState.STALE, result.getState());
assertEquals(UserSyncState.SYNC_FAILED, result.getState());
assertEquals(lastSync.getOperationId(), result.getLastUserSyncOperationId());
}

Expand All @@ -97,7 +97,7 @@ void internalCalculateEnvironmentUserSyncStateLastSyncTimedout() {

EnvironmentUserSyncState result = underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, userSyncStatus);

assertEquals(UserSyncState.STALE, result.getState());
assertEquals(UserSyncState.SYNC_FAILED, result.getState());
assertEquals(lastSync.getOperationId(), result.getLastUserSyncOperationId());
}

Expand Down Expand Up @@ -134,7 +134,7 @@ void internalCalculateEnvironmentUserSyncStateLastSyncCompletedFailure() {

EnvironmentUserSyncState result = underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, userSyncStatus);

assertEquals(UserSyncState.STALE, result.getState());
assertEquals(UserSyncState.SYNC_FAILED, result.getState());
assertEquals(lastSync.getOperationId(), result.getLastUserSyncOperationId());
}

Expand Down

0 comments on commit f50f5c8

Please sign in to comment.