Search in sources :

Example 1 with GetCommitTimestampsResponse

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

the class MultiClientCommitTimestampGetterTest method doesNotUpdateCacheIfClientNotServed.

@Test
public void doesNotUpdateCacheIfClientNotServed() {
    Namespace alpha = Namespace.of("alpha" + UUID.randomUUID());
    Namespace beta = Namespace.of("beta" + UUID.randomUUID());
    BatchElement<NamespacedRequest, Long> requestForAlpha = batchElementForNamespace(alpha);
    BatchElement<NamespacedRequest, Long> requestForBeta = batchElementForNamespace(beta);
    List<BatchElement<NamespacedRequest, Long>> allRequests = ImmutableList.of(requestForAlpha, requestForBeta);
    List<BatchElement<NamespacedRequest, Long>> alphaRequestList = ImmutableList.of(requestForAlpha);
    Map<Namespace, GetCommitTimestampsResponse> responseMap = getCommitTimestamps(alphaRequestList);
    when(timelockService.getCommitTimestamps(any())).thenReturn(responseMap).thenThrow(EXCEPTION);
    assertThatThrownBy(() -> consumer.accept(allRequests)).isEqualTo(EXCEPTION);
    // assert requests made by client alpha are served
    assertSanityOfResponse(alphaRequestList, ImmutableMap.of(alpha, ImmutableList.of(responseMap.get(alpha))));
    LockWatchCache alphaCache = lockWatchCacheMap.get(alpha);
    verify(alphaCache).processCommitTimestampsUpdate(any(), any());
    assertThat(requestForBeta.result().isDone()).as("No requests made by client - beta were successful").isFalse();
    LockWatchCache betaCache = lockWatchCacheMap.get(beta);
    verify(betaCache, never()).processCommitTimestampsUpdate(any(), any());
}
Also used : NamespacedRequest(com.palantir.lock.client.MultiClientCommitTimestampGetter.NamespacedRequest) LockWatchCache(com.palantir.lock.watch.LockWatchCache) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) Namespace(com.palantir.atlasdb.timelock.api.Namespace) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) Test(org.junit.Test)

Example 2 with GetCommitTimestampsResponse

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

the class MultiNodePaxosTimeLockServerIntegrationTest method sanityCheckMultiClientGetCommitTimestampsAgainstConjureTimelockService.

@Test
public void sanityCheckMultiClientGetCommitTimestampsAgainstConjureTimelockService() {
    TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
    // Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
    Assume.assumeFalse(leader.isMultiLeader());
    MultiClientConjureTimelockService multiClientService = leader.multiClientService();
    Set<String> expectedNamespaces = ImmutableSet.of("alta", "mp");
    Map<Namespace, GetCommitTimestampsResponse> multiClientResponses = multiClientService.getCommitTimestampsForClients(AUTH_HEADER, defaultGetCommitTimestampsRequests(expectedNamespaces));
    assertSanityOfNamespacesServed(expectedNamespaces, multiClientResponses);
    // Whether we hit the multi client endpoint or conjureTimelockService endpoint(services one client in one
    // call), for a namespace, the underlying service to process the request is the same
    multiClientResponses.forEach((namespace, responseFromBatchedEndpoint) -> {
        GetCommitTimestampsResponse conjureGetCommitTimestampResponse = leader.client(namespace.get()).namespacedConjureTimelockService().getCommitTimestamps(defaultCommitTimestampRequest());
        assertThat(conjureGetCommitTimestampResponse.getLockWatchUpdate().logId()).isEqualTo(responseFromBatchedEndpoint.getLockWatchUpdate().logId());
        assertThat(conjureGetCommitTimestampResponse.getInclusiveLower()).as("timestamps should contiguously increase per namespace if there are no elections.").isEqualTo(responseFromBatchedEndpoint.getInclusiveUpper() + 1);
    });
}
Also used : MultiClientConjureTimelockService(com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService) Namespace(com.palantir.atlasdb.timelock.api.Namespace) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) Test(org.junit.Test)

Example 3 with GetCommitTimestampsResponse

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

the class MultiNodePaxosTimeLockServerIntegrationTest method sanityCheckMultiClientGetCommitTimestamps.

@Test
public void sanityCheckMultiClientGetCommitTimestamps() {
    TestableTimelockServer leader = cluster.currentLeaderFor(client.namespace());
    // Multi client batched TimeLock endpoints do not support multi-leader mode on TimeLock
    Assume.assumeFalse(leader.isMultiLeader());
    MultiClientConjureTimelockService service = leader.multiClientService();
    Set<String> expectedNamespaces = ImmutableSet.of("cli-1", "cli-2");
    Map<Namespace, GetCommitTimestampsResponse> multiClientResponses = service.getCommitTimestampsForClients(AUTH_HEADER, defaultGetCommitTimestampsRequests(expectedNamespaces));
    assertSanityOfNamespacesServed(expectedNamespaces, multiClientResponses);
    Set<UUID> leadershipIds = multiClientResponses.values().stream().map(GetCommitTimestampsResponse::getLockWatchUpdate).map(LockWatchStateUpdate::logId).collect(Collectors.toSet());
    assertThat(leadershipIds).hasSameSizeAs(expectedNamespaces);
}
Also used : MultiClientConjureTimelockService(com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService) UUID(java.util.UUID) Namespace(com.palantir.atlasdb.timelock.api.Namespace) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) Test(org.junit.Test)

Aggregations

GetCommitTimestampsResponse (com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse)3 Namespace (com.palantir.atlasdb.timelock.api.Namespace)3 Test (org.junit.Test)3 MultiClientConjureTimelockService (com.palantir.atlasdb.timelock.api.MultiClientConjureTimelockService)2 BatchElement (com.palantir.atlasdb.autobatch.BatchElement)1 NamespacedRequest (com.palantir.lock.client.MultiClientCommitTimestampGetter.NamespacedRequest)1 LockWatchCache (com.palantir.lock.watch.LockWatchCache)1 UUID (java.util.UUID)1