Search in sources :

Example 6 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LockEventLogImplTest method unlockUpdateTest.

@Test
public void unlockUpdateTest() {
    ImmutableSet<LockDescriptor> locks = ImmutableSet.of(DESCRIPTOR, DESCRIPTOR_2);
    log.logUnlock(locks);
    LockWatchStateUpdate update = log.getLogDiff(NEGATIVE_VERSION_CURRENT_LOG_ID);
    LockWatchStateUpdate.Success success = UpdateVisitors.assertSuccess(update);
    assertThat(success.events()).containsExactly(UnlockEvent.builder(locks).build(0L));
}
Also used : LockDescriptor(com.palantir.lock.LockDescriptor) AtlasRowLockDescriptor(com.palantir.lock.AtlasRowLockDescriptor) LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) Test(org.junit.Test)

Example 7 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LockEventLogImplTest method noKnownVersionReturnsSnapshotContainingCurrentMatchingLocks.

@Test
public void noKnownVersionReturnsSnapshotContainingCurrentMatchingLocks() {
    LockWatchReference entireTable = LockWatchReferenceUtils.entireTable(TABLE_REF);
    lockWatches.set(createWatchesFor(entireTable));
    LockWatchStateUpdate update = log.getLogDiff(Optional.empty());
    LockWatchStateUpdate.Snapshot snapshot = UpdateVisitors.assertSnapshot(update);
    assertThat(snapshot.lastKnownVersion()).isEqualTo(-1L);
    assertThat(snapshot.locked()).containsExactlyInAnyOrder(DESCRIPTOR_2, DESCRIPTOR_3);
    assertThat(snapshot.lockWatches()).containsExactly(entireTable);
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) LockWatchReference(com.palantir.lock.watch.LockWatchReferences.LockWatchReference) Test(org.junit.Test)

Example 8 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LockEventLogImplTest method snapshotIgnoresPreviousLogEntriesInLocksCalculation.

@Test
public void snapshotIgnoresPreviousLogEntriesInLocksCalculation() {
    LockWatchReference entireTable = LockWatchReferenceUtils.entireTable(TABLE_REF);
    lockWatches.set(createWatchesFor(entireTable));
    log.logLock(ImmutableSet.of(DESCRIPTOR), TOKEN);
    LockWatchStateUpdate update = log.getLogDiff(Optional.empty());
    LockWatchStateUpdate.Snapshot snapshot = UpdateVisitors.assertSnapshot(update);
    assertThat(snapshot.lastKnownVersion()).isEqualTo(0L);
    assertThat(snapshot.locked()).containsExactlyInAnyOrder(DESCRIPTOR_2, DESCRIPTOR_3);
    assertThat(snapshot.lockWatches()).containsExactly(entireTable);
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) LockWatchReference(com.palantir.lock.watch.LockWatchReferences.LockWatchReference) Test(org.junit.Test)

Example 9 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LockEventLogImplTest method createLockWatchUpdateTest.

@Test
public void createLockWatchUpdateTest() {
    LockWatchReference secondRowReference = LockWatchReferenceUtils.rowPrefix(TABLE_REF, PtBytes.toBytes("2"));
    LockWatches newWatches = createWatchesFor(secondRowReference);
    log.logLockWatchCreated(newWatches);
    LockWatchStateUpdate update = log.getLogDiff(NEGATIVE_VERSION_CURRENT_LOG_ID);
    LockWatchStateUpdate.Success success = UpdateVisitors.assertSuccess(update);
    assertThat(success.events()).containsExactly(LockWatchCreatedEvent.builder(newWatches.references(), ImmutableSet.of(DESCRIPTOR_2)).build(0L));
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) LockWatchReference(com.palantir.lock.watch.LockWatchReferences.LockWatchReference) Test(org.junit.Test)

Example 10 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LockEventLogImplTest method requestWithStaleLogIdReturnsSnapshot.

@Test
public void requestWithStaleLogIdReturnsSnapshot() {
    LockWatchReference entireTable = LockWatchReferenceUtils.entireTable(TABLE_REF);
    lockWatches.set(createWatchesFor(entireTable));
    LockWatchStateUpdate update = log.getLogDiff(Optional.of(LockWatchVersion.of(STALE_LOG_ID, -1L)));
    LockWatchStateUpdate.Snapshot snapshot = UpdateVisitors.assertSnapshot(update);
    assertThat(snapshot.lastKnownVersion()).isEqualTo(-1L);
    assertThat(snapshot.locked()).containsExactlyInAnyOrder(DESCRIPTOR_2, DESCRIPTOR_3);
    assertThat(snapshot.lockWatches()).containsExactly(entireTable);
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) LockWatchReference(com.palantir.lock.watch.LockWatchReferences.LockWatchReference) Test(org.junit.Test)

Aggregations

LockWatchStateUpdate (com.palantir.lock.watch.LockWatchStateUpdate)18 Test (org.junit.Test)15 LockWatchReference (com.palantir.lock.watch.LockWatchReferences.LockWatchReference)5 LockWatchEvent (com.palantir.lock.watch.LockWatchEvent)3 TransactionLockWatchFailedException (com.palantir.atlasdb.transaction.api.TransactionLockWatchFailedException)2 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)2 LockDescriptor (com.palantir.lock.LockDescriptor)2 Timer (com.codahale.metrics.Timer)1 LeaderTime (com.palantir.lock.v2.LeaderTime)1 TaggedMetricRegistry (com.palantir.tritium.metrics.registry.TaggedMetricRegistry)1 UUID (java.util.UUID)1