use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.
the class LockWatchingServiceImplTest method watchNewLockWatchLogsHeldLocksInRange.
@Test
public void watchNewLockWatchLogsHeldLocksInRange() {
LockWatchRequest request = tableRequest();
lockWatcher.startWatching(request);
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 LockWatchingServiceImplTest method assertLoggedEvents.
private void assertLoggedEvents(List<LockWatchEvent> expectedEvents) {
LockWatchStateUpdate update = lockWatcher.getWatchStateUpdate(Optional.of(LockWatchVersion.of(LOG_ID, -1L)));
List<LockWatchEvent> events = UpdateVisitors.assertSuccess(update).events();
assertThat(events).containsExactlyElementsOf(expectedEvents);
}
use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.
the class LockWatchingServiceImplTest method exactRowWatchMatchesExactDescriptorOnly.
@Test
public void exactRowWatchMatchesExactDescriptorOnly() {
LockWatchRequest rowRequest = LockWatchRequest.of(ImmutableSet.of(LockWatchReferenceUtils.exactRow(TABLE, ROW)));
lockWatcher.startWatching(rowRequest);
ImmutableSet<LockDescriptor> locks = ImmutableSet.of(CELL_DESCRIPTOR, ROW_DESCRIPTOR);
lockWatcher.registerLock(locks, TOKEN);
List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(rowRequest.getReferences(), ImmutableSet.of(ROW_DESCRIPTOR)), lockEvent(ImmutableSet.of(ROW_DESCRIPTOR)));
assertLoggedEvents(expectedEvents);
}
use of com.palantir.lock.watch.LockWatchEvent in project atlasdb by palantir.
the class LockWatchingServiceImplTest method entireTableWatchTest.
@Test
public void entireTableWatchTest() {
LockDescriptor cellOutOfRange = AtlasCellLockDescriptor.of(TABLE_2.getQualifiedName(), ROW, ROW);
LockDescriptor rowInRange = AtlasRowLockDescriptor.of(TABLE.getQualifiedName(), ROW);
LockDescriptor rowOutOfRange = AtlasRowLockDescriptor.of(TABLE_2.getQualifiedName(), ROW);
LockWatchRequest tableRequest = tableRequest();
lockWatcher.startWatching(tableRequest);
ImmutableSet<LockDescriptor> locks = ImmutableSet.of(CELL_DESCRIPTOR, cellOutOfRange, rowInRange, rowOutOfRange);
lockWatcher.registerLock(locks, TOKEN);
List<LockWatchEvent> expectedEvents = ImmutableList.of(createdEvent(tableRequest.getReferences(), ImmutableSet.of(ROW_DESCRIPTOR)), lockEvent(ImmutableSet.of(ROW_DESCRIPTOR, CELL_DESCRIPTOR, rowInRange)));
assertLoggedEvents(expectedEvents);
}
use of com.palantir.lock.watch.LockWatchEvent 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);
}
Aggregations