Search in sources :

Example 1 with FakeTicker

use of com.google.common.testing.FakeTicker in project neo4j by neo4j.

the class LdapCachingTest method setup.

@Before
public void setup() throws Throwable {
    SecurityLog securityLog = mock(SecurityLog.class);
    InternalFlatFileRealm internalFlatFileRealm = new InternalFlatFileRealm(new InMemoryUserRepository(), new InMemoryRoleRepository(), new BasicPasswordPolicy(), new RateLimitedAuthenticationStrategy(Clock.systemUTC(), 3), mock(JobScheduler.class), new InMemoryUserRepository(), new InMemoryUserRepository());
    testRealm = new TestRealm(getLdapConfig(), securityLog, new SecureHasher());
    List<Realm> realms = listOf(internalFlatFileRealm, testRealm);
    fakeTicker = new FakeTicker();
    authManager = new MultiRealmAuthManager(internalFlatFileRealm, realms, new ShiroCaffeineCache.Manager(fakeTicker::read, 100, 10), securityLog, false);
    authManager.init();
    authManager.start();
    authManager.getUserManager().newUser("mike", "123", false);
    authManager.getUserManager().newUser("mats", "456", false);
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) RateLimitedAuthenticationStrategy(org.neo4j.server.security.auth.RateLimitedAuthenticationStrategy) SecurityLog(org.neo4j.server.security.enterprise.log.SecurityLog) InMemoryUserRepository(org.neo4j.server.security.auth.InMemoryUserRepository) FakeTicker(com.google.common.testing.FakeTicker) BasicPasswordPolicy(org.neo4j.server.security.auth.BasicPasswordPolicy) Realm(org.apache.shiro.realm.Realm) Before(org.junit.Before)

Example 2 with FakeTicker

use of com.google.common.testing.FakeTicker in project caffeine by ben-manes.

the class CacheBuilderGwtTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    fakeTicker = new FakeTicker();
}
Also used : FakeTicker(com.google.common.testing.FakeTicker)

Example 3 with FakeTicker

use of com.google.common.testing.FakeTicker in project caffeine by ben-manes.

the class CacheExpirationTest method testRemovalScheduler_expireAfterWrite.

public void testRemovalScheduler_expireAfterWrite() {
    FakeTicker ticker = new FakeTicker();
    CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
    WatchedCreatorLoader loader = new WatchedCreatorLoader();
    LoadingCache<String, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder().expireAfterWrite(EXPIRING_TIME, MILLISECONDS).executor(MoreExecutors.directExecutor()).removalListener(removalListener).ticker(ticker::read), loader);
    runRemovalScheduler(cache, removalListener, loader, ticker, KEY_PREFIX, EXPIRING_TIME);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeTicker(com.google.common.testing.FakeTicker)

Example 4 with FakeTicker

use of com.google.common.testing.FakeTicker in project caffeine by ben-manes.

the class CacheExpirationTest method testExpiration_expireAfterAccess.

public void testExpiration_expireAfterAccess() {
    FakeTicker ticker = new FakeTicker();
    CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
    WatchedCreatorLoader loader = new WatchedCreatorLoader();
    LoadingCache<String, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder().expireAfterAccess(EXPIRING_TIME, MILLISECONDS).executor(MoreExecutors.directExecutor()).removalListener(removalListener).ticker(ticker::read), loader);
    checkExpiration(cache, loader, ticker, removalListener);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeTicker(com.google.common.testing.FakeTicker)

Example 5 with FakeTicker

use of com.google.common.testing.FakeTicker in project caffeine by ben-manes.

the class CacheExpirationTest method testRemovalScheduler_expireAfterAccess.

public void testRemovalScheduler_expireAfterAccess() {
    FakeTicker ticker = new FakeTicker();
    CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
    WatchedCreatorLoader loader = new WatchedCreatorLoader();
    LoadingCache<String, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder().expireAfterAccess(EXPIRING_TIME, MILLISECONDS).executor(MoreExecutors.directExecutor()).removalListener(removalListener).ticker(ticker::read), loader);
    runRemovalScheduler(cache, removalListener, loader, ticker, KEY_PREFIX, EXPIRING_TIME);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeTicker(com.google.common.testing.FakeTicker)

Aggregations

FakeTicker (com.google.common.testing.FakeTicker)70 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)34 InvalidCacheLoadException (com.google.common.cache.CacheLoader.InvalidCacheLoadException)6 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)6 ExecutionException (java.util.concurrent.ExecutionException)6 IOException (java.io.IOException)4 IncrementingLoader (com.google.common.cache.TestingCacheLoaders.IncrementingLoader)3 CountingRemovalListener (com.google.common.cache.TestingRemovalListeners.CountingRemovalListener)3 TestingRemovalListeners.countingRemovalListener (com.google.common.cache.TestingRemovalListeners.countingRemovalListener)3 ExecutionError (com.google.common.util.concurrent.ExecutionError)3 Before (org.junit.Before)3 ReferenceEntry (com.google.common.cache.LocalCache.ReferenceEntry)2 RemovalCause (com.github.benmanes.caffeine.cache.RemovalCause)1 RemovalListener (com.github.benmanes.caffeine.cache.RemovalListener)1 QueuingRemovalListener (com.google.common.cache.TestingRemovalListeners.QueuingRemovalListener)1 Metadata (io.grpc.Metadata)1 Realm (org.apache.shiro.realm.Realm)1 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)1 BasicPasswordPolicy (org.neo4j.server.security.auth.BasicPasswordPolicy)1 InMemoryUserRepository (org.neo4j.server.security.auth.InMemoryUserRepository)1