public AfterPassivationOrCacheWriter injectThis(Cache<Object, Object> injectInCache) { AsyncInterceptorChain chain = extractComponent(injectInCache, AsyncInterceptorChain.class); AsyncInterceptor interceptor = chain.findInterceptorExtending(CacheWriterInterceptor.class); if (interceptor == null) { interceptor = chain.findInterceptorExtending(CacheLoaderInterceptor.class); } if (interceptor == null) { throw new IllegalStateException("Should not happen!"); } chain.addInterceptorAfter(this, interceptor.getClass()); return this; }
public AfterEntryWrappingInterceptor injectThis(Cache<Object, Object> injectInCache) { injectInCache.getAdvancedCache().getAsyncInterceptorChain().addInterceptorAfter(this, EntryWrappingInterceptor.class); return this; }
public AfterActivationOrCacheLoader injectThis(Cache<Object, Object> injectInCache) { AsyncInterceptorChain chain = TestingUtil.extractComponent(injectInCache, AsyncInterceptorChain.class); AsyncInterceptor loaderInterceptor = chain.findInterceptorExtending(org.infinispan.interceptors.impl.CacheLoaderInterceptor.class); injectInCache.getAdvancedCache().getAsyncInterceptorChain().addInterceptorAfter(this, loaderInterceptor.getClass()); return this; }
@TestCachePermission(AuthorizationPermission.ADMIN) public void testAddInterceptorAfter_CommandInterceptor_Class(SecureCache<String, String> cache) { cache.getAsyncInterceptorChain().addInterceptorAfter(interceptor, InvocationContextInterceptor.class); cache.getAsyncInterceptorChain().removeInterceptor(interceptor.getClass()); }
@Test(expectedExceptions = CacheException.class, expectedExceptionsMessageRegExp = "java.lang.RuntimeException: Induced!") public void testExceptionDuringGet() { advancedCache(0).getAsyncInterceptorChain().addInterceptorAfter(new CommandInterceptor() { @Override protected Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable { throw new RuntimeException("Induced!"); } }, PessimisticLockingInterceptor.class); cache(0).get("k"); assert false; } }
public static ExpectingInterceptor get(AdvancedCache cache) { ExpectingInterceptor self = cache.getAsyncInterceptorChain().findInterceptorWithClass(ExpectingInterceptor.class); if (self != null) { return self; } ExpectingInterceptor ei = new ExpectingInterceptor(); // We are adding this after ICI because we want to handle silent failures, too cache.getAsyncInterceptorChain().addInterceptorAfter(ei, InvocationContextInterceptor.class); return ei; }
cache.getAdvancedCache().getAsyncInterceptorChain().addInterceptorAfter(new BaseCustomAsyncInterceptor() { @Override public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable {
ic.addInterceptorAfter(queryInterceptor, lastLoadingInterceptor.getClass()); cr.registerComponent(QueryInterceptor.class, queryInterceptor, true); cr.addDynamicDependency(AsyncInterceptorChain.class.getName(), QueryInterceptor.class.getName());
private static BlockCommandInterceptor injectBlockCommandInterceptorIfAbsent(Cache<GroupKey, String> cache) { AsyncInterceptorChain chain = cache.getAdvancedCache().getAsyncInterceptorChain(); BlockCommandInterceptor interceptor = chain.findInterceptorWithClass(BlockCommandInterceptor.class); if (interceptor == null) { interceptor = new BlockCommandInterceptor(); EntryWrappingInterceptor ewi = chain.findInterceptorExtending(EntryWrappingInterceptor.class); assertNotNull(ewi); chain.addInterceptorAfter(interceptor, ewi.getClass()); } interceptor.reset(); return interceptor; }
ic.addInterceptorAfter(pt, TxInterceptor.class); ic.addInterceptorAfter(ct, TxInterceptor.class);
private BlockCommandInterceptor injectIfAbsent(Cache<?, ?> cache) { log.debugf("Injecting BlockCommandInterceptor in %s", cache); AsyncInterceptorChain chain = cache.getAdvancedCache().getAsyncInterceptorChain(); BlockCommandInterceptor interceptor = chain.findInterceptorExtending(BlockCommandInterceptor.class); if (interceptor == null) { interceptor = new BlockCommandInterceptor(log); EntryWrappingInterceptor ewi = chain.findInterceptorExtending(EntryWrappingInterceptor.class); AssertJUnit.assertTrue(chain.addInterceptorAfter(interceptor, ewi.getClass())); } interceptor.reset(); log.debugf("Injected BlockCommandInterceptor in %s. Interceptor=%s", cache, interceptor); return interceptor; }
public void testBothOwnersSuspected(Method m) throws ExecutionException, InterruptedException { initAndCheck(m); CountDownLatch arrival = new CountDownLatch(2); CountDownLatch release = new CountDownLatch(1); AtomicInteger thrown = new AtomicInteger(); AtomicInteger retried = new AtomicInteger(); cache(0).getAdvancedCache().getAsyncInterceptorChain().addInterceptorAfter(new CheckOTEInterceptor(thrown, retried), StateTransferInterceptor.class); cache(1).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(arrival, release), 0); cache(2).getAdvancedCache().getAsyncInterceptorChain().addInterceptor(new DelayingInterceptor(arrival, release), 0); Future<Object> future = fork(() -> cache(0).get(key)); assertTrue(arrival.await(10, TimeUnit.SECONDS)); installNewView(cache(0), cache(0)); // The entry was lost, so we'll get null assertNull(future.get()); // Since we've lost all owners, we get an OutdatedTopologyException and we retry assertEquals(1, thrown.get()); assertEquals(1, retried.get()); release.countDown(); }
public void testExpireAfterWrapping() { // Every time a get is invoked it increases time by 2 seconds - causing entry to expire cache.getAdvancedCache().getAsyncInterceptorChain().addInterceptorAfter(new BaseCustomAsyncInterceptor() { @Override public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable { timeService.advance(TimeUnit.SECONDS.toMillis(2)); return super.visitGetKeyValueCommand(ctx, command); } }, EntryWrappingInterceptor.class); String key = "some-key"; Object value = cache.get(key); assertEquals(SimpleLoader.VALUE, value); value = cache.get(key); assertEquals(SimpleLoader.VALUE, value); }
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder configuration = defaultRecoveryConfig(); configuration.transaction().autoCommit(false); configuration.locking().isolationLevel(IsolationLevel.READ_COMMITTED); //skip WSC exceptions createCluster(configuration, 3); waitForClusterToForm(); key = getKey(); failureInterceptor0 = new InDoubtWithCommitFailsTest.ForceFailureInterceptor(); failureInterceptor1 = new InDoubtWithCommitFailsTest.ForceFailureInterceptor(); advancedCache(0).getAsyncInterceptorChain().addInterceptorAfter(failureInterceptor0, InvocationContextInterceptor.class); advancedCache(1).getAsyncInterceptorChain().addInterceptorAfter(failureInterceptor1, InvocationContextInterceptor.class); }
private void createQueryInterceptorIfNeeded(ComponentRegistry cr, Configuration cfg, SearchIntegrator searchFactory) { QueryInterceptor queryInterceptor = cr.getComponent(QueryInterceptor.class); if (queryInterceptor == null) { queryInterceptor = buildQueryInterceptor(cfg, searchFactory, cr.getComponent(Cache.class)); // Interceptor registration not needed, core configuration handling // already does it for all custom interceptors - UNLESS the InterceptorChain already exists in the component registry! AsyncInterceptorChain ic = cr.getComponent(AsyncInterceptorChain.class); ConfigurationBuilder builder = new ConfigurationBuilder().read(cfg); InterceptorConfigurationBuilder interceptorBuilder = builder.customInterceptors().addInterceptor(); interceptorBuilder.interceptor(queryInterceptor); boolean txVersioned = Configurations.isTxVersioned(cfg); boolean isTotalOrder = cfg.transaction().transactionProtocol().isTotalOrder(); Class<? extends DDAsyncInterceptor> wrappingInterceptor = EntryWrappingInterceptor.class; if (txVersioned) { wrappingInterceptor = isTotalOrder ? TotalOrderVersionedEntryWrappingInterceptor.class : VersionedEntryWrappingInterceptor.class; } if (ic != null) ic.addInterceptorAfter(queryInterceptor, wrappingInterceptor); interceptorBuilder.after(wrappingInterceptor); if (ic != null) { cr.registerComponent(queryInterceptor, QueryInterceptor.class); cr.registerComponent(queryInterceptor, queryInterceptor.getClass().getName(), true); } cfg.customInterceptors().interceptors(builder.build().customInterceptors().interceptors()); } }
BlockingInterceptor blockingInterceptor1 = new BlockingInterceptor<>(beforeCommitCache1Barrier, getVisitableCommand(op), false, false); primaryOwnerCache.getAsyncInterceptorChain().addInterceptorAfter(blockingInterceptor1, StateTransferInterceptor.class);
public void testContentsOfContext() throws Exception { Cache<Key, String> c = cacheManager.getCache(); ContextExtractingInterceptor cex = new ContextExtractingInterceptor(); assertTrue(c.getAdvancedCache().getAsyncInterceptorChain().addInterceptorAfter(cex, InvocationContextInterceptor.class)); c.put(new Key("k"), "v"); assertEquals("v", c.get(new Key("k"))); TransactionManager tm = c.getAdvancedCache().getTransactionManager(); tm.begin(); c.getAdvancedCache().lock(new Key("k")); LockManager lockManager = TestingUtil.extractComponent(c, LockManager.class); assertTrue(cex.ctx instanceof LocalTxInvocationContext); assertEquals("Looked up key should not be in transactional invocation context " + "as we don't perform any changes", 0, cex.ctx.lookedUpEntriesCount()); assertEquals("Only one lock should be held", 1, lockManager.getNumberOfLocksHeld()); c.put(new Key("k"), "v2"); assertEquals("Still should only be one entry in the context", 1, cex.ctx.lookedUpEntriesCount()); assertEquals("Only one lock should be held", 1, lockManager.getNumberOfLocksHeld()); tm.commit(); assertEquals("No locks should be held anymore", 0, lockManager.getNumberOfLocksHeld()); assertEquals("v2", c.get(new Key("k"))); }
.addInterceptorAfter(new AssertNoRetryInterceptor(), StateTransferInterceptor.class);
.addInterceptorAfter(new AssertNoRetryInterceptor(), StateTransferInterceptor.class);
.addInterceptorAfter(new AssertNoRetryInterceptor(), StateTransferInterceptor.class);