use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.
the class LockWatchingServiceImplTest method exactCellWatchMatchesExactDescriptorOnly.
@Test
public void exactCellWatchMatchesExactDescriptorOnly() {
LockDescriptor cellSuffixDescriptor = AtlasCellLockDescriptor.of(TABLE.getQualifiedName(), CELL.getRowName(), PtBytes.toBytes("col2"));
LockWatchRequest request = LockWatchRequest.of(ImmutableSet.of(LockWatchReferenceUtils.exactCell(TABLE, CELL)));
lockWatcher.startWatching(request);
ImmutableSet<LockDescriptor> locks = ImmutableSet.of(CELL_DESCRIPTOR, cellSuffixDescriptor);
lockWatcher.registerLock(locks, TOKEN);
List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(request.getReferences(), ImmutableSet.of()), lockEvent(ImmutableSet.of(CELL_DESCRIPTOR)));
assertLoggedEvents(expectedEvents);
}
use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.
the class LockWatchingServiceImplTest method unlockWithoutLockTest.
@Test
public void unlockWithoutLockTest() {
LockWatchRequest tableRequest = tableRequest();
lockWatcher.startWatching(tableRequest);
lockWatcher.registerUnlock(ImmutableSet.of(CELL_DESCRIPTOR));
List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(tableRequest.getReferences(), ImmutableSet.of(ROW_DESCRIPTOR)), unlockEvent(ImmutableSet.of(CELL_DESCRIPTOR)));
assertLoggedEvents(expectedEvents);
}
use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.
the class LockWatchingServiceImplTest method registeringWatchWithNarrowerScopeIsNoop.
@Test
public void registeringWatchWithNarrowerScopeIsNoop() {
LockWatchRequest request = tableRequest();
lockWatcher.startWatching(request);
LockWatchRequest prefixRequest = prefixRequest(ROW);
lockWatcher.startWatching(prefixRequest);
List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(request.getReferences(), ImmutableSet.of(ROW_DESCRIPTOR)));
assertLoggedEvents(expectedEvents);
}
use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.
the class ArrayLockEventSlidingWindow method add.
void add(LockWatchEvent.Builder eventBuilder) {
LockWatchEvent event = eventBuilder.build(nextSequence);
buffer[LongMath.mod(nextSequence, maxSize)] = event;
nextSequence++;
}
use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.
the class LockWatchEventLog method getEventsBetweenVersionsInternal.
private ClientLogEvents getEventsBetweenVersionsInternal(VersionBounds versionBounds) {
Optional<LockWatchVersion> startVersion = versionBounds.startVersion().map(this::createStartVersion);
LockWatchVersion currentVersion = getLatestVersionAndVerify(versionBounds.endVersion());
if (startVersion.isEmpty() || differentLeaderOrTooFarBehind(currentVersion, versionBounds.startVersion().get(), startVersion.get())) {
long snapshotVersion = versionBounds.snapshotVersion() + 1;
Collection<LockWatchEvent> afterSnapshotEvents;
if (snapshotVersion > versionBounds.endVersion().version()) {
afterSnapshotEvents = ImmutableList.of();
} else {
afterSnapshotEvents = eventStore.getEventsBetweenVersionsInclusive(Optional.of(snapshotVersion), versionBounds.endVersion().version());
}
return ClientLogEvents.builder().clearCache(true).events(LockWatchEvents.builder().addEvents(getCompressedSnapshot(versionBounds)).addAllEvents(afterSnapshotEvents).build()).build();
} else {
versionBounds.startVersion().ifPresent(version -> Preconditions.checkState(version.version() <= versionBounds.endVersion().version(), "Cannot get update for transactions when the last known version is more recent than the " + "transactions"));
return ClientLogEvents.builder().clearCache(false).events(LockWatchEvents.builder().addAllEvents(eventStore.getEventsBetweenVersionsInclusive(Optional.of(startVersion.get().version()), versionBounds.endVersion().version())).build()).build();
}
}
Aggregations