Search in sources :

Example 11 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LeaderElectionReportingTimelockServiceTest method statisticsCausesMetricRegistryToBeReset.

@Test
public void statisticsCausesMetricRegistryToBeReset() {
    LockWatchStateUpdate.Snapshot secondUpdate = LockWatchStateUpdate.snapshot(UUID.randomUUID(), 1L, ImmutableSet.of(), ImmutableSet.of());
    LockWatchStateUpdate thirdUpdate = LockWatchStateUpdate.success(UUID.randomUUID(), 5L, ImmutableList.of());
    when(startTransactionsResponse.getLockWatchUpdate()).thenReturn(UPDATE).thenReturn(secondUpdate).thenReturn(secondUpdate).thenReturn(thirdUpdate);
    timelockService.startTransactions(startTransactionsRequest);
    timelockService.startTransactions(startTransactionsRequest);
    TaggedMetricRegistry newMockedRegistry = mock(TaggedMetricRegistry.class);
    Timer newMockedTimer = mock(Timer.class);
    when(newMockedRegistry.timer(any())).thenReturn(newMockedTimer);
    timelockService.getStatisticsAndSetRegistryTo(newMockedRegistry);
    verify(mockedRegistry, atLeastOnce()).timer(any());
    verify(mockedTimer).update(any());
    verify(mockedTimer).getSnapshot();
    verify(mockedSnapshot).size();
    timelockService.startTransactions(startTransactionsRequest);
    timelockService.startTransactions(startTransactionsRequest);
    verify(newMockedRegistry, atLeastOnce()).timer(any());
    verify(newMockedTimer).update(any());
    verifyNoMoreInteractions(mockedRegistry);
    verifyNoMoreInteractions(mockedTimer);
}
Also used : Timer(com.codahale.metrics.Timer) LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) Test(org.junit.Test)

Example 12 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LeaderElectionReportingTimelockServiceTest method executeCalls.

// I know what I am doing (TM)
@SuppressWarnings("DoNotMock")
private void executeCalls(SingleCall firstCall, SingleCall... otherCalls) {
    LockWatchStateUpdate updateMock = mock(LockWatchStateUpdate.class);
    when(startTransactionsResponse.getLockWatchUpdate()).thenReturn(updateMock);
    OngoingStubbing<Long> clockStubbing = when(mockedClock.getTimeMillis()).thenReturn(firstCall.requestMillis()).thenReturn(firstCall.responseMillis());
    OngoingStubbing<UUID> updateStubbing = when(updateMock.logId()).thenReturn(firstCall.responseLeader());
    for (SingleCall call : otherCalls) {
        clockStubbing = clockStubbing.thenReturn(call.requestMillis()).thenReturn(call.responseMillis());
        updateStubbing = updateStubbing.thenReturn(call.responseLeader());
    }
    for (int i = 0; i <= otherCalls.length; i++) {
        timelockService.startTransactions(startTransactionsRequest);
    }
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) UUID(java.util.UUID)

Example 13 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LockEventLogImpl method runTask.

@Override
public synchronized <T> ValueAndLockWatchStateUpdate<T> runTask(Optional<LockWatchVersion> lastKnownVersion, Supplier<T> task) {
    T t = task.get();
    LockWatchStateUpdate logDiff = getLogDiff(lastKnownVersion);
    return ValueAndLockWatchStateUpdate.of(logDiff, t);
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate)

Example 14 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LockEventLogImplTest method requestForTheFutureReturnsSnapshot.

@Test
public void requestForTheFutureReturnsSnapshot() {
    LockWatchReference entireTable = LockWatchReferenceUtils.entireTable(TABLE_REF);
    lockWatches.set(createWatchesFor(entireTable));
    LockWatchStateUpdate update = log.getLogDiff(FUTURE_VERSION_CURRENT_LOG_ID);
    LockWatchStateUpdate.Snapshot snapshot = UpdateVisitors.assertSnapshot(update);
    assertThat(snapshot.lastKnownVersion()).isEqualTo(-1L);
    assertThat(snapshot.locked()).containsExactlyInAnyOrder(DESCRIPTOR_2, DESCRIPTOR_3);
    assertThat(snapshot.lockWatches()).containsExactly(entireTable);
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) LockWatchReference(com.palantir.lock.watch.LockWatchReferences.LockWatchReference) Test(org.junit.Test)

Example 15 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LockEventLogImplTest method lockUpdateTest.

@Test
public void lockUpdateTest() {
    ImmutableSet<LockDescriptor> locks = ImmutableSet.of(DESCRIPTOR, DESCRIPTOR_2);
    log.logLock(locks, TOKEN);
    LockWatchStateUpdate update = log.getLogDiff(NEGATIVE_VERSION_CURRENT_LOG_ID);
    LockWatchStateUpdate.Success success = UpdateVisitors.assertSuccess(update);
    assertThat(success.events()).containsExactly(LockEvent.builder(locks, TOKEN).build(0L));
}
Also used : LockDescriptor(com.palantir.lock.LockDescriptor) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) Test(org.junit.Test)

Aggregations

LockWatchStateUpdate (com.palantir.lock.watch.LockWatchStateUpdate)18 Test (org.junit.Test)15 LockWatchReference (com.palantir.lock.watch.LockWatchReferences.LockWatchReference)5 LockWatchEvent (com.palantir.lock.watch.LockWatchEvent)3 TransactionLockWatchFailedException (com.palantir.atlasdb.transaction.api.TransactionLockWatchFailedException)2 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)2 LockDescriptor (com.palantir.lock.LockDescriptor)2 Timer (com.codahale.metrics.Timer)1 LeaderTime (com.palantir.lock.v2.LeaderTime)1 TaggedMetricRegistry (com.palantir.tritium.metrics.registry.TaggedMetricRegistry)1 UUID (java.util.UUID)1