use of com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest in project atlasdb by palantir.
the class AtlasRestoreServiceTest method restoresToNewNamespaceCorrectly.
@Test
public void restoresToNewNamespaceCorrectly() {
RestoreRequest restoreRequest = RestoreRequest.builder().oldNamespace(WITH_BACKUP).newNamespace(NO_BACKUP).build();
// prepare
DisableNamespacesResponse successfulDisable = DisableNamespacesResponse.successful(SuccessfulDisableNamespacesResponse.of(BACKUP_ID));
DisableNamespacesRequest request = DisableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP), BACKUP_ID);
when(timeLockManagementService.disableTimelock(authHeader, request)).thenReturn(successfulDisable);
Set<Namespace> disabledNamespaces = atlasRestoreService.prepareRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
assertThat(disabledNamespaces).containsExactly(NO_BACKUP);
// repair
BiConsumer<String, RangesForRepair> doNothingConsumer = (_unused1, _unused2) -> {
};
Set<Namespace> repairedNamespaces = atlasRestoreService.repairInternalTables(ImmutableSet.of(restoreRequest), doNothingConsumer);
assertThat(repairedNamespaces).containsExactly(NO_BACKUP);
verify(cassandraRepairHelper).repairInternalTables(NO_BACKUP, doNothingConsumer);
verify(cassandraRepairHelper).repairTransactionsTables(eq(NO_BACKUP), anyList(), eq(doNothingConsumer));
verify(cassandraRepairHelper).cleanTransactionsTables(eq(NO_BACKUP), eq(BACKUP_START_TIMESTAMP), anyList());
verifyNoMoreInteractions(cassandraRepairHelper);
// complete
CompletedBackup completedBackup = backupPersister.getCompletedBackup(WITH_BACKUP).orElseThrow();
CompleteRestoreRequest completeRestoreRequest = CompleteRestoreRequest.of(ImmutableMap.of(NO_BACKUP, completedBackup));
when(atlasRestoreClient.completeRestore(authHeader, completeRestoreRequest)).thenReturn(CompleteRestoreResponse.of(ImmutableSet.of(NO_BACKUP)));
ReenableNamespacesRequest reenableRequest = ReenableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP), BACKUP_ID);
Set<Namespace> completedNamespaces = atlasRestoreService.completeRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
assertThat(completedNamespaces).containsExactly(NO_BACKUP);
verify(atlasRestoreClient).completeRestore(authHeader, completeRestoreRequest);
verify(timeLockManagementService).reenableTimelock(authHeader, reenableRequest);
}
use of com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest in project atlasdb by palantir.
the class AllNodesDisabledNamespacesUpdaterTest method rollsBackIfLocalUpdateFails.
@Test
public void rollsBackIfLocalUpdateFails() {
when(remote1.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
when(remote2.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
Set<Namespace> failedNamespaces = ImmutableSet.of(OTHER_NAMESPACE);
when(localUpdater.disable(DisableNamespacesRequest.of(BOTH_NAMESPACES, LOCK_ID))).thenReturn(singleNodeUpdateFailure(failedNamespaces));
DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(BOTH_NAMESPACES));
assertThat(response).isEqualTo(partiallyDisabled(BOTH_NAMESPACES));
ReenableNamespacesRequest rollbackRequest = ReenableNamespacesRequest.of(BOTH_NAMESPACES, LOCK_ID);
verify(remote1).reenable(AUTH_HEADER, rollbackRequest);
verify(remote2).reenable(AUTH_HEADER, rollbackRequest);
// local update failed, so no need to roll back
verify(localUpdater, never()).reEnable(any());
}
use of com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest in project atlasdb by palantir.
the class AllNodesDisabledNamespacesUpdaterTest method canReEnableSingleNamespace.
@Test
public void canReEnableSingleNamespace() {
ReenableNamespacesRequest request = ReenableNamespacesRequest.of(ImmutableSet.of(NAMESPACE), LOCK_ID);
when(remote1.reenable(AUTH_HEADER, request)).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
when(remote2.reenable(AUTH_HEADER, request)).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
when(localUpdater.reEnable(request)).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
ReenableNamespacesResponse response = updater.reEnableOnAllNodes(AUTH_HEADER, request);
assertThat(response).isEqualTo(REENABLED_SUCCESSFULLY);
}
use of com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest in project atlasdb by palantir.
the class AllNodesDisabledNamespacesUpdaterTest method reEnableCanPartiallyFail.
// Case A: Start with one disabled namespace, re-enable fails on some node, we should re-disable
@Test
public void reEnableCanPartiallyFail() {
ImmutableSet<Namespace> oneNamespace = ImmutableSet.of(NAMESPACE);
ReenableNamespacesRequest request = ReenableNamespacesRequest.of(oneNamespace, LOCK_ID);
when(remote1.reenable(AUTH_HEADER, request)).thenReturn(SingleNodeUpdateResponse.successful());
when(remote2.reenable(AUTH_HEADER, request)).thenReturn(singleNodeUpdateFailure(oneNamespace));
when(localUpdater.reEnable(request)).thenReturn(SingleNodeUpdateResponse.successful());
ReenableNamespacesResponse response = updater.reEnableOnAllNodes(AUTH_HEADER, request);
assertThat(response).isEqualTo(partiallyLocked(oneNamespace));
// verify we still unlocked locally
verify(localUpdater).reEnable(request);
}
use of com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest in project atlasdb by palantir.
the class TimeLockManagementResourceTest method reEnableTimeLockThrowsIfAuthHeaderIsWrong.
@Test
public void reEnableTimeLockThrowsIfAuthHeaderIsWrong() {
ReenableNamespacesRequest request = ReenableNamespacesRequest.of(NAMESPACES, LOCK_ID);
assertThatServiceExceptionThrownBy(() -> AtlasFutures.getUnchecked(timeLockManagementResource.reenableTimelock(WRONG_AUTH_HEADER, request))).hasType(ErrorType.PERMISSION_DENIED);
verifyNoInteractions(allNodesDisabledNamespacesUpdater);
}
Aggregations