Search in sources :

Example 1 with CompletedBackup

use of com.palantir.atlasdb.backup.api.CompletedBackup 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);
}
Also used : RangesForRepair(com.palantir.atlasdb.cassandra.backup.RangesForRepair) CassandraRepairHelper(com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper) CompleteRestoreResponse(com.palantir.atlasdb.backup.api.CompleteRestoreResponse) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtlasRestoreClient(com.palantir.atlasdb.backup.api.AtlasRestoreClient) RunWith(org.junit.runner.RunWith) AuthHeader(com.palantir.tokens.auth.AuthHeader) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) TimeLockManagementService(com.palantir.atlasdb.timelock.api.management.TimeLockManagementService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) InOrder(org.mockito.InOrder) ImmutableMap(com.google.common.collect.ImmutableMap) KeyedStream(com.palantir.common.streams.KeyedStream) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) RangesForRepair(com.palantir.atlasdb.cassandra.backup.RangesForRepair) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) Optional(java.util.Optional) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 2 with CompletedBackup

use of com.palantir.atlasdb.backup.api.CompletedBackup in project atlasdb by palantir.

the class AtlasBackupResourceTest method completeBackupFiltersOutUnsuccessfulNamespaces.

@Test
public void completeBackupFiltersOutUnsuccessfulNamespaces() {
    when(mockTimelock.getFreshTimestamp()).thenReturn(BACKUP_END_TIMESTAMP);
    InProgressBackupToken validToken = validBackupToken();
    InProgressBackupToken invalidToken = invalidBackupToken(OTHER_NAMESPACE, otherTimelock);
    CompletedBackup expected = completedBackup(validToken);
    assertThat(AtlasFutures.getUnchecked(atlasBackupService.completeBackup(AUTH_HEADER, completeBackupRequest(validToken, invalidToken)))).isEqualTo(completeBackupResponseWith(expected));
}
Also used : CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken) Test(org.junit.Test)

Example 3 with CompletedBackup

use of com.palantir.atlasdb.backup.api.CompletedBackup in project atlasdb by palantir.

the class AtlasBackupResourceTest method completeBackupContainsNamespaceWhenLockIsHeld.

@Test
public void completeBackupContainsNamespaceWhenLockIsHeld() {
    when(mockTimelock.getFreshTimestamp()).thenReturn(BACKUP_END_TIMESTAMP);
    InProgressBackupToken backupToken = validBackupToken();
    CompletedBackup expected = completedBackup(backupToken);
    assertThat(AtlasFutures.getUnchecked(atlasBackupService.completeBackup(AUTH_HEADER, completeBackupRequest(backupToken)))).isEqualTo(completeBackupResponseWith(expected));
    verify(authHeaderValidator).suppliedHeaderMatchesConfig(AUTH_HEADER);
}
Also used : CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken) Test(org.junit.Test)

Example 4 with CompletedBackup

use of com.palantir.atlasdb.backup.api.CompletedBackup in project atlasdb by palantir.

the class AtlasRestoreResourceTest method completesRestoreSuccessfully.

@Test
public void completesRestoreSuccessfully() {
    Namespace newNamespace = Namespace.of("newNamespace");
    CompletedBackup completedBackup = completedBackup();
    CompleteRestoreResponse response = AtlasFutures.getUnchecked(atlasRestoreResource.completeRestore(AUTH_HEADER, CompleteRestoreRequest.of(ImmutableMap.of(newNamespace, completedBackup))));
    assertThat(response.getSuccessfulNamespaces()).containsExactly(newNamespace);
    verify(otherTimelock).fastForwardTimestamp(completedBackup.getBackupEndTimestamp());
}
Also used : CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) CompleteRestoreResponse(com.palantir.atlasdb.backup.api.CompleteRestoreResponse) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 5 with CompletedBackup

use of com.palantir.atlasdb.backup.api.CompletedBackup in project atlasdb by palantir.

the class AtlasRestoreResourceTest method throwsIfWrongAuthHeaderIsProvided.

@Test
public void throwsIfWrongAuthHeaderIsProvided() {
    CompletedBackup completedBackup = completedBackup();
    AuthHeader wrongHeader = AuthHeader.of(BearerToken.valueOf("imposter"));
    CompleteRestoreRequest request = CompleteRestoreRequest.of(ImmutableMap.of(NAMESPACE, completedBackup));
    assertThatServiceExceptionThrownBy(() -> AtlasFutures.getUnchecked(atlasRestoreResource.completeRestore(wrongHeader, request))).hasType(ErrorType.PERMISSION_DENIED);
}
Also used : CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) AuthHeader(com.palantir.tokens.auth.AuthHeader) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) Test(org.junit.Test)

Aggregations

CompletedBackup (com.palantir.atlasdb.backup.api.CompletedBackup)17 Namespace (com.palantir.atlasdb.timelock.api.Namespace)11 Test (org.junit.Test)11 AtlasService (com.palantir.atlasdb.backup.api.AtlasService)9 CompleteRestoreRequest (com.palantir.atlasdb.backup.api.CompleteRestoreRequest)7 ImmutableSet (com.google.common.collect.ImmutableSet)6 Set (java.util.Set)6 InProgressBackupToken (com.palantir.atlasdb.backup.api.InProgressBackupToken)5 AuthHeader (com.palantir.tokens.auth.AuthHeader)5 Optional (java.util.Optional)5 CompleteRestoreResponse (com.palantir.atlasdb.backup.api.CompleteRestoreResponse)4 KeyedStream (com.palantir.common.streams.KeyedStream)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 DisableNamespacesRequest (com.palantir.atlasdb.timelock.api.DisableNamespacesRequest)3 DisableNamespacesResponse (com.palantir.atlasdb.timelock.api.DisableNamespacesResponse)3 ReenableNamespacesRequest (com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest)3 SuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse)3 UnsuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse)3 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)3