Search in sources :

Example 16 with LockWatchEvent

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);
}
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 17 with LockWatchEvent

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

Example 18 with LockWatchEvent

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);
}
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 19 with LockWatchEvent

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

Example 20 with LockWatchEvent

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.");
}
Also used : LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) TransactionLockWatchFailedException(com.palantir.atlasdb.transaction.api.TransactionLockWatchFailedException) 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