@Test(expectedExceptions=CacheConfigurationException.class) public void testMissingPosition() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.customInterceptors().addInterceptor().interceptor(new FooInterceptor()); TestCacheManagerFactory.createCacheManager(builder); }
@Test(expectedExceptions = CacheConfigurationException.class) public void testInterceptors() { new ConfigurationBuilder().simpleCache(true) .customInterceptors().addInterceptor().interceptor(new BaseCustomInterceptor()).build(); }
@Override protected EmbeddedCacheManager createCacheManager() throws Exception { ConfigurationBuilder builder = getDefaultStandaloneCacheConfig(false); builder.customInterceptors().addInterceptor().index(0).interceptor(new SomeAsyncInterceptor()); builder.customInterceptors().addInterceptor().index(1).interceptor(new SomeInterceptor()); return TestCacheManagerFactory.createCacheManager(builder); }
private void removeQueryInterceptorFromConfiguration(Configuration cfg) { ConfigurationBuilder builder = new ConfigurationBuilder(); CustomInterceptorsConfigurationBuilder customInterceptorsBuilder = builder.customInterceptors(); for (InterceptorConfiguration interceptorConfig : cfg.customInterceptors().interceptors()) { if (!(interceptorConfig.asyncInterceptor() instanceof QueryInterceptor)) { customInterceptorsBuilder.addInterceptor().read(interceptorConfig); } } cfg.customInterceptors().interceptors(builder.build().customInterceptors().interceptors()); }
private void removeQueryInterceptorFromConfiguration(Configuration cfg) { ConfigurationBuilder builder = new ConfigurationBuilder(); CustomInterceptorsConfigurationBuilder customInterceptorsBuilder = builder.customInterceptors(); for (InterceptorConfiguration interceptorConfig : cfg.customInterceptors().interceptors()) { if (!(interceptorConfig.asyncInterceptor() instanceof QueryInterceptor)) { customInterceptorsBuilder.addInterceptor().read(interceptorConfig); } } cfg.customInterceptors().interceptors(builder.build().customInterceptors().interceptors()); }
private void removeRemoteIndexingInterceptorFromConfig(Configuration cfg) { ConfigurationBuilder builder = new ConfigurationBuilder(); CustomInterceptorsConfigurationBuilder customInterceptorsBuilder = builder.customInterceptors(); for (InterceptorConfiguration interceptorConfig : cfg.customInterceptors().interceptors()) { if (!(interceptorConfig.interceptor() instanceof RemoteValueWrapperInterceptor)) { customInterceptorsBuilder.addInterceptor().read(interceptorConfig); } } cfg.customInterceptors().interceptors(builder.build().customInterceptors().interceptors()); } }
private void startClusterNode() { ConfigurationBuilder configurationBuilder = CacheTestSupport.createTestConfiguration(TransactionMode.NON_TRANSACTIONAL); configurationBuilder.customInterceptors().addInterceptor().after(NonTransactionalLockingInterceptor.class).interceptor(new SkipIndexingGuaranteed()); createClusteredCaches(1, "lucene", configurationBuilder); }
public void testCustomInterceptorsProgramatically() { ConfigurationBuilder cfg = new ConfigurationBuilder(); cfg.customInterceptors().addInterceptor().interceptor(new DummyInterceptor()).position(Position.FIRST); withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createCacheManager(cfg)) { @Override public void call() { Cache c = cm.getCache(); DummyInterceptor i = TestingUtil.findInterceptor(c, DummyInterceptor.class); assertNotNull(i); } }); }
public void testCustomInterceptorsProgramaticallyWithOverride() { final ConfigurationBuilder cfg = new ConfigurationBuilder(); cfg.customInterceptors().addInterceptor().interceptor(new DummyInterceptor()).position(Position.FIRST); withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createCacheManager()) { @Override public void call() { cm.defineConfiguration("custom", cfg.build()); Cache c = cm.getCache("custom"); DummyInterceptor i = TestingUtil.findInterceptor(c, DummyInterceptor.class); assertNotNull(i); } }); }
private void createRemoteIndexingInterceptor(ComponentRegistry cr, Configuration cfg) { BaseTypeConverterInterceptor wrapperInterceptor = cr.getComponent(RemoteValueWrapperInterceptor.class); if (wrapperInterceptor == null) { wrapperInterceptor = new RemoteValueWrapperInterceptor(); // Interceptor registration not needed, core configuration handling // already does it for all custom interceptors - UNLESS the InterceptorChain already exists in the component registry! InterceptorChain ic = cr.getComponent(InterceptorChain.class); ConfigurationBuilder builder = new ConfigurationBuilder().read(cfg); InterceptorConfigurationBuilder interceptorBuilder = builder.customInterceptors().addInterceptor(); interceptorBuilder.interceptor(wrapperInterceptor); if (ic != null) ic.addInterceptorAfter(wrapperInterceptor, InvocationContextInterceptor.class); interceptorBuilder.after(InvocationContextInterceptor.class); if (ic != null) { cr.registerComponent(wrapperInterceptor, RemoteValueWrapperInterceptor.class); } cfg.customInterceptors().interceptors(builder.build().customInterceptors().interceptors()); } }
public void testCustomInterceptorProperties() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.customInterceptors().addInterceptor().interceptor(new FooInterceptor()).position(Position.FIRST).addProperty("foo", "bar"); withCacheManager(new CacheManagerCallable( TestCacheManagerFactory.createCacheManager(builder)) { @Override public void call() { final Cache<Object,Object> cache = cm.getCache(); AsyncInterceptor i = cache.getAdvancedCache().getAsyncInterceptorChain().getInterceptors().get(0); assertTrue("Expecting FooInterceptor in the interceptor chain", i instanceof FooInterceptor); assertEquals("bar", ((FooInterceptor)i).getFoo()); } }); }
private ConfigurationBuilder getScriptCacheConfiguration() { GlobalConfiguration globalConfiguration = cacheManager.getGlobalComponentRegistry().getGlobalConfiguration(); ConfigurationBuilder cfg = new ConfigurationBuilder(); cfg.encoding().key().mediaType(APPLICATION_OBJECT_TYPE); cfg.encoding().value().mediaType(APPLICATION_OBJECT_TYPE); cfg.customInterceptors().addInterceptor().interceptor(new ScriptingInterceptor()).before(CacheMgmtInterceptor.class); if (globalConfiguration.security().authorization().enabled()) { globalConfiguration.security().authorization().roles().put(SCRIPT_MANAGER_ROLE, new CacheRoleImpl(SCRIPT_MANAGER_ROLE, AuthorizationPermission.ALL)); cfg.security().authorization().enable().role(SCRIPT_MANAGER_ROLE); globalAuthzHelper = cacheManager.getGlobalComponentRegistry().getComponent(AuthorizationHelper.class); } return cfg; }
public void testOtherThanFirstOrLastInterceptor() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.customInterceptors().addInterceptor().position(Position.OTHER_THAN_FIRST_OR_LAST).interceptor(new FooInterceptor()); final EmbeddedCacheManager cacheManager = TestCacheManagerFactory.createCacheManager(); cacheManager.defineConfiguration("interceptors", builder.build()); withCacheManager(new CacheManagerCallable(cacheManager) { @Override public void call() { AsyncInterceptorChain interceptorChain = cacheManager.getCache("interceptors").getAdvancedCache().getAsyncInterceptorChain(); assertEquals(interceptorChain.getInterceptors().get(1).getClass(), FooInterceptor.class); } }); }
public void testLastInterceptor() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.customInterceptors().addInterceptor().position(Position.LAST).interceptor(new FooInterceptor()); final EmbeddedCacheManager cacheManager = TestCacheManagerFactory.createCacheManager(); cacheManager.defineConfiguration("interceptors", builder.build()); withCacheManager(new CacheManagerCallable(cacheManager) { @Override public void call() { List<AsyncInterceptor> interceptors = cacheManager.getCache("interceptors").getAdvancedCache().getAsyncInterceptorChain() .getInterceptors(); assertEquals(FooInterceptor.class, interceptors.get(interceptors.size() - 2).getClass()); } }); }
@Override public void call() { ConfigurationBuilder offHeapConfig = new ConfigurationBuilder(); offHeapConfig.memory().storageType(StorageType.OFF_HEAP); offHeapConfig.customInterceptors().addInterceptor().after(EntryWrappingInterceptor.class).interceptor(new TestInterceptor(1)); ConfigurationBuilder compatConfig = new ConfigurationBuilder(); compatConfig.compatibility().enable().marshaller(new JavaSerializationMarshaller()); compatConfig.customInterceptors().addInterceptor().after(EntryWrappingInterceptor.class).interceptor(new TestInterceptor(1)); cm.defineConfiguration("offheap", offHeapConfig.build()); cm.defineConfiguration("compat", compatConfig.build()); Cache<Object, Object> cache = cm.getCache(); Cache<Object, Object> offheapCache = cm.getCache("offheap"); Cache<Object, Object> compatCache = cm.getCache("compat"); cache.put(1, 1); offheapCache.put(1, 1); compatCache.put(1, 1); assertEquals(1, cache.get(1)); assertEquals(1, offheapCache.get(1)); assertEquals(1, compatCache.get(1)); } });
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder builder = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, false); builder.clustering().hash().numOwners(1); builder.clustering().stateTransfer().fetchInMemoryState(false); builder.customInterceptors().addInterceptor().before(NonTransactionalLockingInterceptor.class).interceptorClass(ExceptionInRemotePutInterceptor.class); createClusteredCaches(2, builder); }
@Override protected EmbeddedCacheManager createCacheManager() throws Exception { EmbeddedCacheManager cm = TestCacheManagerFactory.createClusteredCacheManager(); for (CacheType cacheType : CacheType.values()) { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.persistence() .addStore(DummyInMemoryStoreConfigurationBuilder.class) .preload(true) .storeName(this.getClass().getName()).async().enable(); builder.transaction().transactionMode(cacheType.transactionMode).useSynchronization(cacheType.useSynchronization) .recovery().enabled(cacheType.useRecovery); builder.customInterceptors().addInterceptor().index(0).interceptor(new ExceptionTrackerInterceptor()); cm.defineConfiguration(cacheType.cacheName, builder.build()); } return cm; }
private ConfigurationBuilder buildConfig(LockingMode lockingMode, Class<?> commandToBlock, boolean isOriginator) { ConfigurationBuilder configurationBuilder = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC, lockingMode != null); configurationBuilder.transaction().lockingMode(lockingMode); // The coordinator will always be the primary owner configurationBuilder.clustering().hash().numSegments(1) .consistentHashFactory(new ReplicatedControlledConsistentHashFactory(0)); configurationBuilder.clustering().remoteTimeout(15000); configurationBuilder.clustering().stateTransfer().fetchInMemoryState(true); if (commandToBlock == LockControlCommand.class && !isOriginator) { configurationBuilder.customInterceptors().addInterceptor() .before(PessimisticLockingInterceptor.class).interceptor(new DelayInterceptor(commandToBlock)); } else { configurationBuilder.customInterceptors().addInterceptor() .after(EntryWrappingInterceptor.class).interceptor(new DelayInterceptor(commandToBlock)); } configurationBuilder.locking().isolationLevel(IsolationLevel.READ_COMMITTED); return configurationBuilder; }
private ConfigurationBuilder buildConfig(Class<?> commandToBlock) { ConfigurationBuilder configurationBuilder = getDefaultClusteredCacheConfig( CacheMode.REPL_ASYNC, false); configurationBuilder.clustering().remoteTimeout(15000); // The coordinator will always be the primary owner configurationBuilder.clustering().hash().numSegments(1).consistentHashFactory(new ReplicatedControlledConsistentHashFactory(0)); configurationBuilder.clustering().stateTransfer().fetchInMemoryState(true); // We must block after the commit was replicated, but before the entries are committed configurationBuilder.customInterceptors() .addInterceptor().after(EntryWrappingInterceptor.class).interceptor(new DelayInterceptor(commandToBlock)); return configurationBuilder; }
@Override protected void createCacheManagers() throws Throwable { for (int i = 0; i < NUM_NODES; ++i) { collectors[i] = new CollectKeysInterceptor(); ConfigurationBuilder builder = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, true); builder.transaction().lockingMode(pessimistic ? LockingMode.PESSIMISTIC : LockingMode.OPTIMISTIC); builder.customInterceptors().addInterceptor().interceptor(collectors[i]) .before(TxInterceptor.class); builder.clustering().hash().numOwners(2).groups().enabled(); addClusterEnabledCacheManager(builder); } waitForClusterToForm(); ahmKey = new MagicKey("AtomicMap", cache(0)); fgahmKey = new MagicKey("FineGrainedAtomicMap", cache(0)); }