Search in sources :

Example 1 with NamespacedRequest

use of com.palantir.lock.client.MultiClientCommitTimestampGetter.NamespacedRequest in project atlasdb by palantir.

the class MultiClientCommitTimestampGetterTest method updatesCacheWhileProcessingResponse.

@Test
public void updatesCacheWhileProcessingResponse() {
    Namespace client = Namespace.of("Kitty");
    List<BatchElement<NamespacedRequest, Long>> batchElements = IntStream.range(0, COMMIT_TS_LIMIT_PER_REQUEST * 2).mapToObj(ind -> batchElementForNamespace(client)).collect(toList());
    setupServiceAndAssertSanityOfResponse(batchElements);
    LockWatchCache cache = lockWatchCacheMap.get(client);
    verify(cache, times(2)).processCommitTimestampsUpdate(any(), any());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DisruptorFuture(com.palantir.atlasdb.autobatch.DisruptorAutobatcher.DisruptorFuture) IntStream(java.util.stream.IntStream) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) HashMap(java.util.HashMap) GetCommitTimestampsRequest(com.palantir.atlasdb.timelock.api.GetCommitTimestampsRequest) Mockito.spy(org.mockito.Mockito.spy) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) ArrayList(java.util.ArrayList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) GetCommitTimestampsResponse(com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse) LockWatchCache(com.palantir.lock.watch.LockWatchCache) NamespacedRequest(com.palantir.lock.client.MultiClientCommitTimestampGetter.NamespacedRequest) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) KeyedStream(com.palantir.common.streams.KeyedStream) LockToken(com.palantir.lock.v2.LockToken) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) Mockito.never(org.mockito.Mockito.never) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) StreamEx(one.util.streamex.StreamEx) LockWatchCacheImpl(com.palantir.lock.watch.LockWatchCacheImpl) Mockito.mock(org.mockito.Mockito.mock) LockWatchCache(com.palantir.lock.watch.LockWatchCache) BatchElement(com.palantir.atlasdb.autobatch.BatchElement) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 2 with NamespacedRequest

use of com.palantir.lock.client.MultiClientCommitTimestampGetter.NamespacedRequest 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)

Aggregations

BatchElement (com.palantir.atlasdb.autobatch.BatchElement)2 GetCommitTimestampsResponse (com.palantir.atlasdb.timelock.api.GetCommitTimestampsResponse)2 Namespace (com.palantir.atlasdb.timelock.api.Namespace)2 NamespacedRequest (com.palantir.lock.client.MultiClientCommitTimestampGetter.NamespacedRequest)2 LockWatchCache (com.palantir.lock.watch.LockWatchCache)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Maps (com.google.common.collect.Maps)1 Futures (com.google.common.util.concurrent.Futures)1 DisruptorFuture (com.palantir.atlasdb.autobatch.DisruptorAutobatcher.DisruptorFuture)1 GetCommitTimestampsRequest (com.palantir.atlasdb.timelock.api.GetCommitTimestampsRequest)1 KeyedStream (com.palantir.common.streams.KeyedStream)1 LockToken (com.palantir.lock.v2.LockToken)1 LockWatchCacheImpl (com.palantir.lock.watch.LockWatchCacheImpl)1 LockWatchStateUpdate (com.palantir.lock.watch.LockWatchStateUpdate)1 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1