public InfinispanCacheProperties(Configuration config) { this.transactional = config.transaction().transactionMode().isTransactional(); this.lockOnWrite = this.transactional && (config.transaction().lockingMode() == LockingMode.PESSIMISTIC); this.lockOnRead = this.lockOnWrite && (config.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ); boolean clustered = config.clustering().cacheMode().needsStateTransfer(); boolean hasStore = config.persistence().usingStores(); this.marshalling = clustered || hasStore; this.persistent = clustered || (hasStore && !config.persistence().passivation()); }
private static <T> T getStoreConfiguration(Configuration c, Class<T> configurationClass) { for (StoreConfiguration pc: c.persistence().stores()) { if (configurationClass.isInstance(pc)) { return (T) pc; } } throw new NoSuchElementException("There is no store of type " + configurationClass); }
private StoreConfiguration buildCacheManagerWithCacheStore(final String config) throws IOException { InputStream is = new ByteArrayInputStream(config.getBytes()); cacheManager = TestCacheManagerFactory.fromStream(is); assert cacheManager.getDefaultCacheConfiguration().persistence().stores().size() == 1; return cacheManager.getDefaultCacheConfiguration().persistence().stores().get(0); } }
private static void validateMetadataCache(Cache<?, ?> cache, String indexName) { Configuration configuration = cache.getCacheConfiguration(); if (configuration.memory().isEvictionEnabled()) { throw log.evictionNotAllowedInMetadataCache(indexName, cache.getName()); } if (configuration.persistence().usingStores() && !configuration.persistence().preload()) { throw log.preloadNeededIfPersistenceIsEnabledForMetadataCache(indexName, cache.getName()); } }
private static void validateMetadataCache(Cache<?, ?> cache, String indexName) { Configuration configuration = cache.getCacheConfiguration(); if (configuration.memory().isEvictionEnabled()) { throw log.evictionNotAllowedInMetadataCache(indexName, cache.getName()); } if (configuration.persistence().usingStores() && !configuration.persistence().preload()) { throw log.preloadNeededIfPersistenceIsEnabledForMetadataCache(indexName, cache.getName()); } }
public void testLoaders() { List<StoreConfiguration> stores = cacheManager.getCache("customLoaderCache").getCacheConfiguration().persistence().stores(); assertEquals(stores.size(), 1); StoreConfiguration storeConfiguration = stores.get(0); assertTrue(storeConfiguration instanceof ClusterLoaderConfiguration); ClusterLoaderConfiguration csc = (ClusterLoaderConfiguration) storeConfiguration; assertEquals(csc.remoteCallTimeout(), 1222); } }
public void testConfiguration() { Cache<Object,Object> customLoaderCache = cacheManager.getCache("customLoaderCache"); List<StoreConfiguration> loaders = customLoaderCache.getCacheConfiguration().persistence().stores(); assertEquals(loaders.size(), 1); } }
public InfinispanCacheProperties(Configuration config) { this.transactional = config.transaction().transactionMode().isTransactional(); this.lockOnWrite = this.transactional && (config.transaction().lockingMode() == LockingMode.PESSIMISTIC); this.lockOnRead = this.lockOnWrite && (config.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ); boolean clustered = config.clustering().cacheMode().needsStateTransfer(); boolean hasStore = config.persistence().usingStores(); this.marshalling = clustered || hasStore; this.persistent = clustered || (hasStore && !config.persistence().passivation()); }
public InfinispanCacheProperties(Configuration config) { this.transactional = config.transaction().transactionMode().isTransactional(); this.lockOnWrite = this.transactional && (config.transaction().lockingMode() == LockingMode.PESSIMISTIC); this.lockOnRead = this.lockOnWrite && (config.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ); boolean clustered = config.clustering().cacheMode().needsStateTransfer(); boolean hasStore = config.persistence().usingStores(); this.marshalling = clustered || hasStore; this.persistent = clustered || (hasStore && !config.persistence().passivation()); }
public static <K, V> CacheLoader<K, V> getCacheLoader(Cache<K, V> cache) { if (cache.getCacheConfiguration().persistence().usingStores()) { return TestingUtil.getFirstLoader(cache); } else { return null; } }
@Test public void testClearStores() { Configuration c = new ConfigurationBuilder() .persistence() .addStore(DummyInMemoryStoreConfigurationBuilder.class) .persistence() .clearStores() .build(); assertEquals(c.persistence().stores().size(), 0); }
@Override public void call() { PersistenceConfiguration cfg = cm.getDefaultCacheConfiguration().persistence(); StoreConfiguration config = cfg.stores().get(0); assertTrue(config instanceof DummyInMemoryStoreConfiguration); DummyInMemoryStoreConfiguration dummyInMemoryStoreConfiguration = (DummyInMemoryStoreConfiguration)config; assertEquals("myStore", dummyInMemoryStoreConfiguration.storeName()); } });
@Override public void call() { PersistenceConfiguration cfg = cm.getDefaultCacheConfiguration().persistence(); StoreConfiguration config = cfg.stores().get(0); assertTrue(config instanceof AbstractStoreConfiguration); AbstractStoreConfiguration abstractStoreConfiguration = (AbstractStoreConfiguration)config; assertTrue(abstractStoreConfiguration.fetchPersistentState()); assertTrue(abstractStoreConfiguration.preload()); } });
@Override public void check(ConfigurationBuilderHolder holder) { Configuration local = getConfiguration(holder, "local"); PersistenceConfiguration persistenceConfiguration = local.persistence(); assertEquals(5, persistenceConfiguration.connectionAttempts()); assertEquals(100, persistenceConfiguration.connectionInterval()); assertEquals(2000, persistenceConfiguration.availabilityInterval()); assertFalse(persistenceConfiguration.stores().isEmpty()); AsyncStoreConfiguration asyncConfig = persistenceConfiguration.stores().iterator().next().async(); assertTrue(asyncConfig.failSilently()); } },
public void testImplicitPooledConnectionFactory() { ConfigurationBuilder b = new ConfigurationBuilder(); b.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class) .connectionPool().connectionUrl(JDBC_URL); Configuration configuration = b.build(); JdbcStringBasedStoreConfiguration store = (JdbcStringBasedStoreConfiguration) configuration.persistence().stores().get(0); assert store.connectionFactory() instanceof PooledConnectionFactoryConfiguration; }
public static InitializationContext createContext(String nodeName, Configuration configuration, StreamingMarshaller marshaller, TimeService timeService) { Cache mockCache = mockCache(nodeName, configuration, timeService); return new InitializationContextImpl(configuration.persistence().stores().get(0), mockCache, SingleSegmentKeyPartitioner.getInstance(), marshaller, timeService, new ByteBufferFactoryImpl(), new MarshalledEntryFactoryImpl(marshaller), new WithinThreadExecutor()); }
public void testOverrideWithStore() { final ConfigurationBuilder builder1 = new ConfigurationBuilder(); builder1.persistence().addStore(DummyInMemoryStoreConfigurationBuilder.class); cm = TestCacheManagerFactory.createCacheManager(builder1); ConfigurationBuilder builder2 = new ConfigurationBuilder(); builder2.read(cm.getDefaultCacheConfiguration()); builder2.memory().size(1000); Configuration configuration = cm.defineConfiguration("named", builder2.build()); assertEquals(1, configuration.persistence().stores().size()); }
@SuppressWarnings("unchecked") @Override protected void initializeKeyAndCheckData(Object key, Object value) { assertTrue("A cache store should be configured!", cache.getCacheConfiguration().persistence().usingStores()); cache.put(key, value); DataContainer container = cache.getAdvancedCache().getDataContainer(); InternalCacheEntry entry = container.get(key); CacheLoader<Object, Object> loader = TestingUtil.getFirstLoader(cache); assertNotNull("Key " + key + " does not exist in data container.", entry); assertEquals("Wrong value for key " + key + " in data container.", value, entry.getValue()); MarshalledEntry<Object, Object> entryLoaded = loader.load(key); assertNull("Key " + key + " exists in cache loader.", entryLoaded); }
@SuppressWarnings("unchecked") @Override protected void initializeKeyAndCheckData(Object key, Object value) { assertTrue("A cache store should be configured!", cache.getCacheConfiguration().persistence().usingStores()); cache.put(key, value); DataContainer container = cache.getAdvancedCache().getDataContainer(); InternalCacheEntry entry = container.get(key); CacheLoader<Object, Object> loader = TestingUtil.getFirstLoader(cache); assertNotNull("Key " + key + " does not exist in data container.", entry); assertEquals("Wrong value for key " + key + " in data container.", value, entry.getValue()); MarshalledEntry<Object, Object> entryLoaded = loader.load(key); assertNull("Key " + key + " exists in cache loader.", entryLoaded); }
@SuppressWarnings("unchecked") protected void initializeKeyAndCheckData(Object key, Object value) { assertTrue("A cache store should be configured!", cache.getCacheConfiguration().persistence().usingStores()); cache.put(key, value); DataContainer container = cache.getAdvancedCache().getDataContainer(); InternalCacheEntry entry = container.get(key); CacheLoader<Object, Object> loader = TestingUtil.getFirstLoader(cache); assertNotNull("Key " + key + " does not exist in data container.", entry); assertEquals("Wrong value for key " + key + " in data container.", value, entry.getValue()); MarshalledEntry<Object, Object> entryLoaded = loader.load(key); assertNotNull("Key " + key + " does not exist in cache loader.", entryLoaded); assertEquals("Wrong value for key " + key + " in cache loader.", value, entryLoaded.getValue()); }