/** See {@link MutableConfiguration#setWriteThrough}. */ public void setWriteThrough(boolean isWriteThrough) { delegate.setWriteThrough(isWriteThrough); }
/** {@inheritDoc} */ @Override public CacheConfiguration<K, V> setWriteThrough(boolean isWriteThrough) { super.setWriteThrough(isWriteThrough); return this; }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); CachingProvider provider = Caching.getCachingProvider(); cacheManager = provider.getCacheManager(this.getClass().getResource("/ehcache-loader-writer-107.xml").toURI(), getClass().getClassLoader()); testCache = cacheManager.createCache("testCache", new MutableConfiguration<Number, CharSequence>() .setReadThrough(true) .setWriteThrough(true) .setCacheLoaderFactory(() -> cacheLoader) .setCacheWriterFactory(() -> cacheWriter) .setTypes(Number.class, CharSequence.class)); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); CachingProvider provider = Caching.getCachingProvider(); cacheManager = provider.getCacheManager(this.getClass().getResource("/ehcache-loader-writer-107-load-atomics.xml").toURI(), getClass().getClassLoader()); testCache = cacheManager.createCache("testCache", new MutableConfiguration<Number, CharSequence>() .setReadThrough(true) .setWriteThrough(true) .setCacheLoaderFactory(() -> cacheLoader) .setCacheWriterFactory(() -> cacheWriter) .setTypes(Number.class, CharSequence.class)); }
@Test public void jsr107WriterGetsRegistered() { MutableConfiguration<Object, Object> configuration = new MutableConfiguration<>(); CacheWriter<Object, Object> mock = mock(CacheWriter.class); RecordingFactory<CacheWriter<Object, Object>> factory = factoryOf(mock); configuration.setWriteThrough(true).setCacheWriterFactory(factory); merger.mergeConfigurations("cache", configuration); assertThat(factory.called, is(true)); verify(cacheLoaderWriterFactory).registerJsr107Loader(eq("cache"), ArgumentMatchers.<CacheLoaderWriter<Object, Object>>isNotNull()); }
@Test public void setWriteThroughWithoutWriterFails() { MutableConfiguration<Long, String> config = new MutableConfiguration<>(); config.setTypes(Long.class, String.class); config.setWriteThrough(true); try { merger.mergeConfigurations("cache", config); fail("Expected exception as no CacheLoader factory is configured and read-through is enabled."); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("write-through")); } }
private MutableConfiguration<Long, String> getConfiguration(final boolean readThrough, final CacheLoader<Long, String> cacheLoader, final boolean writeThrough, final CacheWriter<Long, String> cacheWriter) { MutableConfiguration<Long, String> config = new MutableConfiguration<>(); config.setTypes(Long.class, String.class); config.setReadThrough(readThrough); config.setCacheLoaderFactory(() -> cacheLoader); config.setWriteThrough(writeThrough); config.setCacheWriterFactory(() -> cacheWriter); return config; } }
/** {@inheritDoc} */ @Override public CacheConfiguration<K, V> setWriteThrough(boolean isWriteThrough) { super.setWriteThrough(isWriteThrough); return this; }
/** See {@link MutableConfiguration#setWriteThrough}. */ public void setWriteThrough(boolean isWriteThrough) { delegate.setWriteThrough(isWriteThrough); }
.setWriteThrough("true".equalsIgnoreCase(props.getProperty(prefix + "writeThrough", "false"))) .setManagementEnabled( "true".equalsIgnoreCase(props.getProperty(prefix + "managementEnabled", "false")))
.setWriteThrough("true".equalsIgnoreCase(props.getProperty(prefix + "writeThrough", "false"))) .setManagementEnabled( "true".equalsIgnoreCase(props.getProperty(prefix + "managementEnabled", "false")))
.setStoreByValue(false); configuration.setReadThrough("true".equals(properties.getProperty("read-through", "false"))); configuration.setWriteThrough("true".equals(properties.getProperty("write-through", "false"))); if (configuration.isReadThrough())
private Configuration getOrCreateCacheConfiguration() { if (configuration.getCacheConfiguration() != null) { return configuration.getCacheConfiguration(); } MutableConfiguration mutableConfiguration = new MutableConfiguration(); if (configuration.getCacheLoaderFactory() != null) { mutableConfiguration.setCacheLoaderFactory(configuration.getCacheLoaderFactory()); } if (configuration.getCacheWriterFactory() != null) { mutableConfiguration.setCacheWriterFactory(configuration.getCacheWriterFactory()); } if (configuration.getExpiryPolicyFactory() != null) { mutableConfiguration.setExpiryPolicyFactory(configuration.getExpiryPolicyFactory()); } mutableConfiguration.setManagementEnabled(configuration.isManagementEnabled()); mutableConfiguration.setStatisticsEnabled(configuration.isStatisticsEnabled()); mutableConfiguration.setReadThrough(configuration.isReadThrough()); mutableConfiguration.setStoreByValue(configuration.isStoreByValue()); mutableConfiguration.setWriteThrough(configuration.isWriteThrough()); return mutableConfiguration; } }
configuration.setTypes(Integer.class, String.class); configuration.setCacheWriterFactory(FactoryBuilder.factoryOf(theCacheWriter)); configuration.setWriteThrough(true);
/** * Configure write-through before each test. */ @Before public void onBeforeEachTest() throws IOException { // establish and open a CacheWriterServer to handle cache // cache loading requests from a CacheWriterClient cacheWriter = new RecordingCacheWriter<>(); cacheWriterServer = new CacheWriterServer<>(10000, cacheWriter); cacheWriterServer.open(); // establish the CacheManager for the tests cacheManager = Caching.getCachingProvider().getCacheManager(); // establish a CacheWriterClient that a Cache can use for writing/deleting entries // (via the CacheWriterServer) CacheWriterClient<Integer, String> theCacheWriter = new CacheWriterClient<>(cacheWriterServer.getInetAddress(), cacheWriterServer.getPort()); MutableConfiguration<Integer, String> configuration = new MutableConfiguration<>(); configuration.setTypes(Integer.class, String.class); configuration.setCacheWriterFactory(FactoryBuilder.factoryOf(theCacheWriter)); configuration.setWriteThrough(true); getCacheManager().createCache("cache-writer-test", configuration); cache = getCacheManager().getCache("cache-writer-test", Integer.class, String.class); }
configuration.setReadThrough(true); configuration.setCacheWriterFactory(FactoryBuilder.factoryOf(cacheWriter)); configuration.setWriteThrough(true);
@Test public void testCustomConfiguration() throws Exception { boolean storeByValue = false; MutableConfiguration configuration = new MutableConfiguration() .setReadThrough(false).setWriteThrough(false).setStoreByValue(storeByValue) .setTypes(java.math.BigDecimal.class, java.awt.Color.class) .setManagementEnabled(true).setStatisticsEnabled(false); Cache cache = null; try { cache = getCacheManager().createCache("customCache", configuration); } catch (UnsupportedOperationException e) { storeByValue = true; configuration.setStoreByValue(storeByValue); cache = getCacheManager().createCache("customCache", configuration); } assertEquals("java.math.BigDecimal", lookupManagementAttribute(cache, CacheConfiguration, "KeyType")); assertEquals("java.awt.Color", lookupManagementAttribute(cache, CacheConfiguration, "ValueType")); assertEquals(false, lookupManagementAttribute(cache, CacheConfiguration, "ReadThrough")); assertEquals(false, lookupManagementAttribute(cache, CacheConfiguration, "WriteThrough")); assertEquals(storeByValue, lookupManagementAttribute(cache, CacheConfiguration, "StoreByValue")); assertEquals(false, lookupManagementAttribute(cache, CacheConfiguration, "StatisticsEnabled")); assertEquals(true, lookupManagementAttribute(cache, CacheConfiguration, "ManagementEnabled")); //this used to just call close() but that does not work if an implementation maintains statistics on the cluster. cache.getCacheManager().destroyCache("customCache"); }
differentConfig1.setWriteThrough(!config1.isWriteThrough()); differentConfig1.hashCode(); assertFalse(config1.equals(differentConfig1));