use of com.palantir.lock.watch.LockWatchReferences.LockWatchReference in project atlasdb by palantir.
the class LockWatchManagerImpl method create.
public static LockWatchManagerInternal create(MetricsManager metricsManager, Set<Schema> schemas, LockWatchStarter lockWatchingService, LockWatchCachingConfig config) {
Set<LockWatchReference> referencesFromSchema = schemas.stream().map(Schema::getLockWatches).flatMap(Set::stream).collect(Collectors.toSet());
Set<TableReference> watchedTablesFromSchema = referencesFromSchema.stream().map(schema -> schema.accept(LockWatchReferencesVisitor.INSTANCE)).collect(Collectors.toSet());
CacheMetrics metrics = CacheMetrics.create(metricsManager);
LockWatchEventCache eventCache = LockWatchEventCacheImpl.create(metrics);
LockWatchValueScopingCache valueCache = LockWatchValueScopingCacheImpl.create(eventCache, metrics, config.cacheSize(), config.validationProbability(), watchedTablesFromSchema);
return new LockWatchManagerImpl(referencesFromSchema, eventCache, valueCache, lockWatchingService);
}
use of com.palantir.lock.watch.LockWatchReferences.LockWatchReference 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);
}
use of com.palantir.lock.watch.LockWatchReferences.LockWatchReference 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);
}
use of com.palantir.lock.watch.LockWatchReferences.LockWatchReference 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));
}
use of com.palantir.lock.watch.LockWatchReferences.LockWatchReference 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);
}
Aggregations