@Override public void inject(Module module) { try { ClassLoader moduleClassLoader = System.getSecurityManager() == null ? module.getClassLoader() : AccessController.doPrivileged((PrivilegedAction<ClassLoader>) module::getClassLoader); Class<?> marshallerClass = Class.forName(marshallerClassName, false, moduleClassLoader); builder.compatibility().marshaller(marshallerClass.asSubclass(Marshaller.class).newInstance()); } catch (Exception e) { throw InfinispanMessages.MESSAGES.invalidCompatibilityMarshaller(e, marshaller); } } };
@Override public void inject(EmbeddedCacheManager cacheManager) { try { ClassLoader classLoader = cacheManager.getCacheManagerConfiguration().classLoader(); Class<?> marshallerClass = Class.forName(marshallerClassName, false, classLoader); builder.compatibility().marshaller(marshallerClass.asSubclass(Marshaller.class).newInstance()); } catch (Exception e) { throw InfinispanMessages.MESSAGES.unableToInstantiateClass(marshallerClassName); } } };
@Test(expectedExceptions = CacheConfigurationException.class) public void testCompatibility() { new ConfigurationBuilder().simpleCache(true).compatibility().enabled(true).build(); }
private void parseCompatibility(XMLExtendedStreamReader reader, ConfigurationBuilderHolder holder) throws XMLStreamException { ConfigurationBuilder builder = holder.getCurrentConfigurationBuilder(); for (int i = 0; i < reader.getAttributeCount(); i++) { ParseUtils.requireNoNamespaceAttribute(reader, i); String value = replaceProperties(reader.getAttributeValue(i)); Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case ENABLED: builder.compatibility().enabled(Boolean.parseBoolean(value)); break; case MARSHALLER_CLASS: builder.compatibility().marshaller(Util.<Marshaller>getInstance(value, holder.getClassLoader())); break; default: throw ParseUtils.unexpectedAttribute(reader, i); } } ParseUtils.requireNoContent(reader); }
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder dcc = getDefaultClusteredCacheConfig(cacheMode, transactional); if (compatibility) { dcc.compatibility().enable(); } if (transactional) { dcc.transaction().locking().isolationLevel(IsolationLevel.READ_COMMITTED); } createCluster(dcc, numNodes); waitForClusterToForm(); }
@Override protected ConfigurationBuilder getIndexCacheConfiguration() { ConfigurationBuilder indexedCache = new ConfigurationBuilder(); indexedCache.indexing().index(Index.PRIMARY_OWNER) .addProperty("default.directory_provider", "ram"); indexedCache.compatibility().enable().marshaller(new GenericJBossMarshaller()); return indexedCache; }
@Override protected ConfigurationBuilder getConfiguration() { ConfigurationBuilder builder = TestCacheManagerFactory.getDefaultCacheConfiguration(true, false); builder.compatibility().enable() .clustering() .cacheMode(CacheMode.DIST_SYNC) .stateTransfer().fetchInMemoryState(false) .transaction().cacheStopTimeout(0L); return builder; }
builder.compatibility().enabled(enabled);
@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 public void call() throws Exception { ComponentRegistry registry = cm.getCache().getAdvancedCache().getComponentRegistry(); testWith(DataConversion.DEFAULT_KEY, registry); testWith(DataConversion.DEFAULT_VALUE, registry); testWith(DataConversion.IDENTITY_KEY, registry); testWith(DataConversion.IDENTITY_VALUE, registry); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.compatibility().enable(); cm.defineConfiguration("compat", builder.build()); AdvancedCache<?, ?> compat = cm.getCache("compat").getAdvancedCache(); ComponentRegistry compatRegistry = compat.getComponentRegistry(); testWith(compat.getKeyDataConversion(), compatRegistry); testWith(compat.getValueDataConversion(), compatRegistry); AdvancedCache<?, ?> wrapped = compat.withEncoding(IdentityEncoder.class).withWrapping(IdentityWrapper.class); ComponentRegistry wrappedRegistry = wrapped.getComponentRegistry(); testWith(wrapped.getKeyDataConversion(), wrappedRegistry); testWith(wrapped.getValueDataConversion(), wrappedRegistry); } });