Search in sources :

Example 11 with LockWatchEvent

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);
}
Also used : LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) LockWatchRequest(com.palantir.atlasdb.timelock.api.LockWatchRequest) Test(org.junit.Test)

Example 12 with LockWatchEvent

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);
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) LockWatchEvent(com.palantir.lock.watch.LockWatchEvent)

Example 13 with LockWatchEvent

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);
}
Also used : LockDescriptor(com.palantir.lock.LockDescriptor) AtlasCellLockDescriptor(com.palantir.lock.AtlasCellLockDescriptor) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) LockWatchRequest(com.palantir.atlasdb.timelock.api.LockWatchRequest) Test(org.junit.Test)

Example 14 with LockWatchEvent

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);
}
Also used : LockDescriptor(com.palantir.lock.LockDescriptor) AtlasCellLockDescriptor(com.palantir.lock.AtlasCellLockDescriptor) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) LockWatchRequest(com.palantir.atlasdb.timelock.api.LockWatchRequest) Test(org.junit.Test)

Example 15 with LockWatchEvent

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);
}
Also used : LockDescriptor(com.palantir.lock.LockDescriptor) AtlasCellLockDescriptor(com.palantir.lock.AtlasCellLockDescriptor) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) ExclusiveLock(com.palantir.atlasdb.timelock.lock.ExclusiveLock) LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) LockWatchReference(com.palantir.lock.watch.LockWatchReferences.LockWatchReference) Test(org.junit.Test)

Aggregations

LockWatchEvent (com.palantir.lock.watch.LockWatchEvent)20 Test (org.junit.Test)16 LockWatchRequest (com.palantir.atlasdb.timelock.api.LockWatchRequest)10 AtlasCellLockDescriptor (com.palantir.lock.AtlasCellLockDescriptor)7 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)7 LockDescriptor (com.palantir.lock.LockDescriptor)7 LockWatchStateUpdate (com.palantir.lock.watch.LockWatchStateUpdate)3 ExclusiveLock (com.palantir.atlasdb.timelock.lock.ExclusiveLock)2 LockWatchReference (com.palantir.lock.watch.LockWatchReferences.LockWatchReference)2 LockWatchVersion (com.palantir.lock.watch.LockWatchVersion)2 TransactionLockWatchFailedException (com.palantir.atlasdb.transaction.api.TransactionLockWatchFailedException)1 TransactionsLockWatchUpdate (com.palantir.lock.watch.TransactionsLockWatchUpdate)1