use of com.palantir.atlasdb.keyvalue.api.cache.LockWatchValueScopingCache 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.atlasdb.keyvalue.api.cache.LockWatchValueScopingCache in project atlasdb by palantir.
the class ResilientLockWatchProxyTest method valueCacheProxyAlsoFallsBackOnException.
@Test
public void valueCacheProxyAlsoFallsBackOnException() {
LockWatchValueScopingCache defaultCache = mock(LockWatchValueScopingCache.class);
LockWatchValueScopingCache fallbackCache = mock(LockWatchValueScopingCache.class);
ResilientLockWatchProxy<LockWatchValueScopingCache> proxyFactory = ResilientLockWatchProxy.newValueCacheProxyFactory(fallbackCache, metrics);
proxyFactory.setDelegate(defaultCache);
LockWatchValueScopingCache proxyCache = proxyFactory.newValueCacheProxy();
// Normal operation
long timestamp = 1L;
Set<Long> timestamps = ImmutableSet.of(timestamp);
proxyCache.updateCacheWithCommitTimestampsInformation(timestamps);
verify(defaultCache).updateCacheWithCommitTimestampsInformation(timestamps);
verify(fallbackCache, never()).updateCacheWithCommitTimestampsInformation(any());
// Failure
when(defaultCache.getTransactionScopedCache(timestamp)).thenThrow(new TransactionFailedNonRetriableException(""));
assertThatThrownBy(() -> proxyCache.getTransactionScopedCache(timestamp)).isExactlyInstanceOf(TransactionLockWatchFailedException.class);
verify(defaultCache).getTransactionScopedCache(timestamp);
// Fallback operation
proxyCache.processStartTransactions(timestamps);
verify(fallbackCache).processStartTransactions(timestamps);
verifyNoMoreInteractions(defaultCache);
verifyNoMoreInteractions(fallbackCache);
}
use of com.palantir.atlasdb.keyvalue.api.cache.LockWatchValueScopingCache in project atlasdb by palantir.
the class ResilientLockWatchProxyTest method valueCacheProxyThrowsIfDelegateNotSet.
@Test
public void valueCacheProxyThrowsIfDelegateNotSet() {
LockWatchValueScopingCache fallbackCache = mock(LockWatchValueScopingCache.class);
ResilientLockWatchProxy<LockWatchValueScopingCache> proxyFactory = ResilientLockWatchProxy.newValueCacheProxyFactory(fallbackCache, metrics);
assertThatThrownBy(proxyFactory::newValueCacheProxy).isExactlyInstanceOf(SafeNullPointerException.class).hasMessage("Delegate cache must be set before creating proxy");
}
Aggregations