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));
}
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());
}
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));
}
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();
}
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());
}
Aggregations