use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.
the class LockWatchingServiceImplTest method rowRangeWatchTest.
@Test
public void rowRangeWatchTest() {
byte[] startOfRange = PtBytes.toBytes("aaz");
byte[] endOfRange = PtBytes.toBytes("cca");
LockDescriptor cellInRange = AtlasCellLockDescriptor.of(TABLE.getQualifiedName(), startOfRange, ROW);
LockDescriptor cellOutOfRange = AtlasCellLockDescriptor.of(TABLE.getQualifiedName(), endOfRange, ROW);
LockDescriptor rowInRange = AtlasRowLockDescriptor.of(TABLE.getQualifiedName(), PtBytes.toBytes("b"));
LockDescriptor rowInRange2 = AtlasRowLockDescriptor.of(TABLE.getQualifiedName(), PtBytes.toBytes("cc"));
LockDescriptor rowOutOfRange = AtlasRowLockDescriptor.of(TABLE.getQualifiedName(), PtBytes.toBytes("cca"));
LockWatchRequest rangeRequest = LockWatchRequest.of(ImmutableSet.of(LockWatchReferenceUtils.rowRange(TABLE, startOfRange, endOfRange)));
lockWatcher.startWatching(rangeRequest);
ImmutableSet<LockDescriptor> locks = ImmutableSet.of(cellInRange, cellOutOfRange, rowInRange, rowInRange2, rowOutOfRange);
lockWatcher.registerLock(locks, TOKEN);
List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(rangeRequest.getReferences(), ImmutableSet.of()), lockEvent(ImmutableSet.of(cellInRange, rowInRange, rowInRange2)));
assertLoggedEvents(expectedEvents);
}
use of com.palantir.lock.watch.LockWatchEvent 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);
}
use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.
the class LockWatchingServiceImplTest method rowPrefixWatchMatchesSuffixes.
@Test
public void rowPrefixWatchMatchesSuffixes() {
byte[] rowPrefix = PtBytes.toBytes("ro");
LockDescriptor notPrefixDescriptor = AtlasRowLockDescriptor.of(TABLE.getQualifiedName(), PtBytes.toBytes("r"));
LockWatchRequest prefixRequest = prefixRequest(rowPrefix);
lockWatcher.startWatching(prefixRequest);
ImmutableSet<LockDescriptor> locks = ImmutableSet.of(CELL_DESCRIPTOR, ROW_DESCRIPTOR, notPrefixDescriptor);
lockWatcher.registerLock(locks, TOKEN);
List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(prefixRequest.getReferences(), ImmutableSet.of(ROW_DESCRIPTOR)), lockEvent(ImmutableSet.of(CELL_DESCRIPTOR, ROW_DESCRIPTOR)));
assertLoggedEvents(expectedEvents);
}
use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.
the class LockWatchEventCacheIntegrationTest method newEventsStartingWithTheSameVersionAsCurrentDoesNotThrow.
@Test
public void newEventsStartingWithTheSameVersionAsCurrentDoesNotThrow() {
setupInitialState();
LockWatchEvent earlyLockEvent = LockWatchCreatedEvent.builder(ImmutableSet.of(REFERENCE), ImmutableSet.of(DESCRIPTOR)).build(3L);
LockWatchStateUpdate success = LockWatchStateUpdate.success(LEADER, 4L, ImmutableList.of(earlyLockEvent, WATCH_EVENT));
assertThatCode(() -> eventCache.processStartTransactionsUpdate(TIMESTAMPS_2, success)).doesNotThrowAnyException();
}
use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.
the class LockWatchEventCacheIntegrationTest method veryOldSuccessfulUpdateThrowsRetriableException.
@Test
public void veryOldSuccessfulUpdateThrowsRetriableException() {
setupInitialState();
Set<Long> secondTimestamps = ImmutableSet.of(11L, 12L);
LockWatchEvent earlyEvent = LockEvent.builder(ImmutableSet.of(DESCRIPTOR_3), COMMIT_TOKEN).build(2L);
assertThatThrownBy(() -> eventCache.processStartTransactionsUpdate(secondTimestamps, LockWatchStateUpdate.success(LEADER, 2L, ImmutableList.of(earlyEvent)))).isExactlyInstanceOf(TransactionLockWatchFailedException.class).hasMessage("Cannot process events before the oldest event. The transaction should be retried, " + "although this should only happen very rarely.");
}
Aggregations