use of com.palantir.lock.watch.LockWatchReferences.LockWatchReference in project atlasdb by palantir.
the class LockWatchingServiceImpl method filterNewWatches.
private Optional<LockWatches> filterNewWatches(LockWatchRequest request, LockWatches oldWatches) {
Set<LockWatchReference> newRefs = new HashSet<>();
RangeSet<LockDescriptor> newRanges = TreeRangeSet.create();
for (LockWatchReference singleReference : request.getReferences()) {
Range<LockDescriptor> referenceAsRange = singleReference.accept(LockWatchReferences.TO_RANGES_VISITOR);
if (!oldWatches.ranges().encloses(referenceAsRange)) {
newRefs.add(singleReference);
newRanges.add(referenceAsRange);
}
}
return newRefs.isEmpty() ? Optional.empty() : Optional.of(ImmutableLockWatches.of(newRefs, newRanges));
}
use of com.palantir.lock.watch.LockWatchReferences.LockWatchReference 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.LockWatchReferences.LockWatchReference in project atlasdb by palantir.
the class LockWatchingServiceImplTest method registeringWatchWithOverlappingScopeLogsAlreadyWatchedLocksInScopeAgain.
@Test
public void registeringWatchWithOverlappingScopeLogsAlreadyWatchedLocksInScopeAgain() {
LockDescriptor ab = AtlasRowLockDescriptor.of(TABLE.getQualifiedName(), PtBytes.toBytes("ab"));
LockDescriptor bc = AtlasRowLockDescriptor.of(TABLE.getQualifiedName(), PtBytes.toBytes("bc"));
LockDescriptor cd = AtlasRowLockDescriptor.of(TABLE.getQualifiedName(), PtBytes.toBytes("cd"));
when(heldLocks.getLocks()).thenReturn(ImmutableList.of(LOCK, new ExclusiveLock(ab), new ExclusiveLock(bc), new ExclusiveLock(cd)));
LockWatchReference acRange = LockWatchReferenceUtils.rowRange(TABLE, PtBytes.toBytes("a"), PtBytes.toBytes("c"));
LockWatchReference bdRange = LockWatchReferenceUtils.rowRange(TABLE, PtBytes.toBytes("b"), PtBytes.toBytes("d"));
lockWatcher.startWatching(LockWatchRequest.of(ImmutableSet.of(acRange)));
lockWatcher.startWatching(LockWatchRequest.of(ImmutableSet.of(bdRange)));
List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(ImmutableSet.of(acRange), ImmutableSet.of(ab, bc)), createdEvent(ImmutableSet.of(bdRange), ImmutableSet.of(bc, cd)));
assertLoggedEvents(expectedEvents);
}
use of com.palantir.lock.watch.LockWatchReferences.LockWatchReference in project atlasdb by palantir.
the class LockWatchingServiceImplTest method onlyAlreadyWatchedRangesAreIgnoredOnRegistration.
@Test
public void onlyAlreadyWatchedRangesAreIgnoredOnRegistration() {
LockWatchRequest request = tableRequest();
lockWatcher.startWatching(request);
LockWatchReference newWatch = LockWatchReferenceUtils.entireTable(TABLE_2);
LockWatchRequest prefixAndOtherTableRequest = LockWatchRequest.of(ImmutableSet.of(LockWatchReferenceUtils.rowPrefix(TABLE, ROW), newWatch));
lockWatcher.startWatching(prefixAndOtherTableRequest);
List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(request.getReferences(), ImmutableSet.of(ROW_DESCRIPTOR)), createdEvent(ImmutableSet.of(newWatch), ImmutableSet.of(descriptorForOtherTable())));
assertLoggedEvents(expectedEvents);
}
Aggregations