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