Search in sources :

Example 6 with SingleNodeUpdateResponse

use of com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse in project atlasdb by palantir.

the class AllNodesDisabledNamespacesUpdaterTest method rollsBackDisableIfInconsistentStateIsFound.

// Case C: If we start with an inconsistent state, we roll back our request
@Test
public void rollsBackDisableIfInconsistentStateIsFound() {
    Set<Namespace> disabledNamespaces = ImmutableSet.of(OTHER_NAMESPACE);
    SingleNodeUpdateResponse unsuccessfulResponse = singleNodeUpdateFailure(disabledNamespaces);
    when(remote1.disable(any(), any())).thenReturn(unsuccessfulResponse);
    when(remote2.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote2.reenable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(localUpdater.getNamespacesLockedWithDifferentLockId(any(), any())).thenReturn(ImmutableMap.of());
    DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(ImmutableSet.of(NAMESPACE, OTHER_NAMESPACE)));
    ReenableNamespacesRequest rollbackRequest = ReenableNamespacesRequest.of(BOTH_NAMESPACES, LOCK_ID);
    verify(remote1, never()).reenable(any(), any());
    verify(remote2).reenable(AUTH_HEADER, rollbackRequest);
    verify(localUpdater, never()).reEnable(any());
    assertThat(response).isEqualTo(partiallyDisabled(BOTH_NAMESPACES));
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) SingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse) ImmutableSingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.ImmutableSingleNodeUpdateResponse) Test(org.junit.Test)

Example 7 with SingleNodeUpdateResponse

use of com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse in project atlasdb by palantir.

the class AllNodesDisabledNamespacesUpdaterTest method reEnableDoesNotReportConsistentStateWhenNamespacesAreLockedWithDifferentIds.

@Test
public void reEnableDoesNotReportConsistentStateWhenNamespacesAreLockedWithDifferentIds() {
    Set<Namespace> namespaces = ImmutableSet.of(NAMESPACE);
    String otherLockId = "otherLockId";
    String yetAnotherLockId = "yetAnotherLockId";
    SingleNodeUpdateResponse lockedWithOtherLock = ImmutableSingleNodeUpdateResponse.builder().isSuccessful(false).putLockedNamespaces(NAMESPACE, otherLockId).build();
    SingleNodeUpdateResponse lockedWithYetAnotherLock = ImmutableSingleNodeUpdateResponse.builder().isSuccessful(false).putLockedNamespaces(NAMESPACE, yetAnotherLockId).build();
    when(remote1.reenable(any(), any())).thenReturn(lockedWithOtherLock);
    when(remote2.reenable(any(), any())).thenReturn(SingleNodeUpdateResponse.successful());
    when(localUpdater.reEnable(any())).thenReturn(lockedWithYetAnotherLock);
    ReenableNamespacesResponse reenableResponse = updater.reEnableOnAllNodes(AUTH_HEADER, ReenableNamespacesRequest.of(namespaces, LOCK_ID));
    assertThat(reenableResponse).isEqualTo(partiallyLocked(namespaces));
    verify(remote1, never()).disable(any(), any());
    verify(remote2, never()).disable(any(), any());
}
Also used : UnsuccessfulReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulReenableNamespacesResponse) SuccessfulReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulReenableNamespacesResponse) ReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.ReenableNamespacesResponse) Namespace(com.palantir.atlasdb.timelock.api.Namespace) SingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse) ImmutableSingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.ImmutableSingleNodeUpdateResponse) Test(org.junit.Test)

Example 8 with SingleNodeUpdateResponse

use of com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse in project atlasdb by palantir.

the class AllNodesDisabledNamespacesUpdaterTest method doesNotReEnableIfSomeNamespaceDisabledWithOtherLock.

// Case B: re-enable with wrong lock -> don't re-enable anywhere
@Test
public void doesNotReEnableIfSomeNamespaceDisabledWithOtherLock() {
    Set<Namespace> disabledNamespaces = ImmutableSet.of(OTHER_NAMESPACE);
    SingleNodeUpdateResponse unsuccessfulResponse = singleNodeUpdateFailure(disabledNamespaces);
    when(remote1.reenable(any(), any())).thenReturn(unsuccessfulResponse);
    when(remote2.reenable(any(), any())).thenReturn(unsuccessfulResponse);
    when(localUpdater.reEnable(any())).thenReturn(unsuccessfulResponse);
    ReenableNamespacesResponse response = updater.reEnableOnAllNodes(AUTH_HEADER, ReenableNamespacesRequest.of(BOTH_NAMESPACES, LOCK_ID));
    assertThat(response).isEqualTo(consistentlyLocked(disabledNamespaces));
}
Also used : UnsuccessfulReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulReenableNamespacesResponse) SuccessfulReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulReenableNamespacesResponse) ReenableNamespacesResponse(com.palantir.atlasdb.timelock.api.ReenableNamespacesResponse) Namespace(com.palantir.atlasdb.timelock.api.Namespace) SingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse) ImmutableSingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.ImmutableSingleNodeUpdateResponse) Test(org.junit.Test)

Example 9 with SingleNodeUpdateResponse

use of com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse in project atlasdb by palantir.

the class DisabledNamespacesTest method enableFailsIfDisabledWithWrongLock.

@Test
public void enableFailsIfDisabledWithWrongLock() {
    disabledNamespaces.disable(disableNamespacesRequest(FIRST));
    DisableNamespacesRequest wrongLockId = DisableNamespacesRequest.of(ImmutableSet.of(SECOND), OTHER_LOCK_ID);
    disabledNamespaces.disable(wrongLockId);
    SingleNodeUpdateResponse response = disabledNamespaces.reEnable(ReenableNamespacesRequest.of(ImmutableSet.of(FIRST, SECOND), LOCK_ID));
    assertThat(response).isEqualTo(SingleNodeUpdateResponse.failed(ImmutableMap.of(SECOND, OTHER_LOCK_ID)));
    // non-conflicting namespaces should still be re-enabled
    assertThat(disabledNamespaces.isDisabled(FIRST)).isFalse();
    assertThat(disabledNamespaces.isDisabled(SECOND)).isTrue();
}
Also used : DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) SingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse) Test(org.junit.Test)

Example 10 with SingleNodeUpdateResponse

use of com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse in project atlasdb by palantir.

the class DisabledNamespacesTest method disableSucceedsIfAlreadyDisabledWithTheSameId.

@Test
public void disableSucceedsIfAlreadyDisabledWithTheSameId() {
    SingleNodeUpdateResponse firstResponse = disabledNamespaces.disable(disableNamespacesRequest(FIRST));
    assertThat(firstResponse).isEqualTo(successfulResponse());
    SingleNodeUpdateResponse secondResponse = disabledNamespaces.disable(disableNamespacesRequest(FIRST));
    assertThat(secondResponse).isEqualTo(successfulResponse());
}
Also used : SingleNodeUpdateResponse(com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse) Test(org.junit.Test)

Aggregations

SingleNodeUpdateResponse (com.palantir.atlasdb.timelock.api.SingleNodeUpdateResponse)11 Test (org.junit.Test)9 ImmutableSingleNodeUpdateResponse (com.palantir.atlasdb.timelock.api.ImmutableSingleNodeUpdateResponse)5 Namespace (com.palantir.atlasdb.timelock.api.Namespace)5 DisableNamespacesResponse (com.palantir.atlasdb.timelock.api.DisableNamespacesResponse)3 SuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse)3 UnsuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse)3 ReenableNamespacesRequest (com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest)2 ReenableNamespacesResponse (com.palantir.atlasdb.timelock.api.ReenableNamespacesResponse)2 SuccessfulReenableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulReenableNamespacesResponse)2 UnsuccessfulReenableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulReenableNamespacesResponse)2 DisableNamespacesRequest (com.palantir.atlasdb.timelock.api.DisableNamespacesRequest)1 DisabledNamespacesUpdaterService (com.palantir.atlasdb.timelock.api.DisabledNamespacesUpdaterService)1