@Test public void testWriterConfig() { File file = new File(TEST_CONFIG_DIR + "ehcache-writer.xml"); Configuration configuration = ConfigurationFactory.parseConfiguration(file); ConfigurationHelper configurationHelper = new ConfigurationHelper(manager, configuration); CacheWriterConfiguration defaultCacheWriterConfig = new CacheWriterConfiguration(); CacheConfiguration configDefault = configurationHelper.getConfigurationBean().getDefaultCacheConfiguration(); assertEquals(false, configDefault.isEternal()); assertEquals(5, configDefault.getTimeToIdleSeconds()); assertEquals(10, configDefault.getTimeToLiveSeconds()); assertEquals(false, configDefault.isOverflowToDisk()); assertEquals(10, configDefault.getMaxElementsInMemory()); assertNotNull(configDefault.getCacheWriterConfiguration()); assertEquals(defaultCacheWriterConfig.getWriteMode(), configDefault.getCacheWriterConfiguration().getWriteMode()); assertEquals(defaultCacheWriterConfig.getCacheWriterFactoryConfiguration(), configDefault.getCacheWriterConfiguration() .getCacheWriterFactoryConfiguration()); assertEquals(defaultCacheWriterConfig.getNotifyListenersOnException(), configDefault.getCacheWriterConfiguration() .getNotifyListenersOnException()); assertEquals(defaultCacheWriterConfig.getMaxWriteDelay(), configDefault.getCacheWriterConfiguration().getMaxWriteDelay()); assertEquals(defaultCacheWriterConfig.getRateLimitPerSecond(), configDefault.getCacheWriterConfiguration().getRateLimitPerSecond()); assertEquals(defaultCacheWriterConfig.getWriteCoalescing(), configDefault.getCacheWriterConfiguration().getWriteCoalescing()); assertEquals(defaultCacheWriterConfig.getWriteBatching(), configDefault.getCacheWriterConfiguration().getWriteBatching()); assertEquals(defaultCacheWriterConfig.getWriteBatchSize(), configDefault.getCacheWriterConfiguration().getWriteBatchSize()); assertEquals(defaultCacheWriterConfig.getRetryAttempts(), configDefault.getCacheWriterConfiguration().getRetryAttempts()); assertEquals(defaultCacheWriterConfig.getRetryAttemptDelaySeconds(), configDefault.getCacheWriterConfiguration() .getRetryAttemptDelaySeconds()); Ehcache defaultCache = configurationHelper.createDefaultCache(); assertEquals("default", defaultCache.getName()); assertNotNull(defaultCache.getCacheConfiguration().getCacheWriterConfiguration()); Map<String, CacheConfiguration> configs = configurationHelper.getConfigurationBean().getCacheConfigurations(); CacheConfiguration config1 = configs.get("writeThroughCache1"); assertNotNull(config1.getCacheWriterConfiguration()); assertEquals(defaultCacheWriterConfig.getWriteMode(), config1.getCacheWriterConfiguration().getWriteMode()); assertEquals(defaultCacheWriterConfig.getCacheWriterFactoryConfiguration(), config1.getCacheWriterConfiguration() .getCacheWriterFactoryConfiguration()); assertEquals(defaultCacheWriterConfig.getNotifyListenersOnException(), config1.getCacheWriterConfiguration() .getNotifyListenersOnException()); assertEquals(defaultCacheWriterConfig.getMaxWriteDelay(), config1.getCacheWriterConfiguration().getMaxWriteDelay()); assertEquals(defaultCacheWriterConfig.getRateLimitPerSecond(), config1.getCacheWriterConfiguration().getRateLimitPerSecond()); assertEquals(defaultCacheWriterConfig.getWriteCoalescing(), config1.getCacheWriterConfiguration().getWriteCoalescing()); assertEquals(defaultCacheWriterConfig.getWriteBatching(), config1.getCacheWriterConfiguration().getWriteBatching()); assertEquals(defaultCacheWriterConfig.getWriteBatchSize(), config1.getCacheWriterConfiguration().getWriteBatchSize()); assertEquals(defaultCacheWriterConfig.getRetryAttempts(), config1.getCacheWriterConfiguration().getRetryAttempts()); assertEquals(defaultCacheWriterConfig.getRetryAttemptDelaySeconds(), config1.getCacheWriterConfiguration().getRetryAttemptDelaySeconds()); CacheConfiguration config2 = configs.get("writeThroughCache2"); assertNotNull(config2.getCacheWriterConfiguration()); assertEquals(defaultCacheWriterConfig.getWriteMode(), config2.getCacheWriterConfiguration().getWriteMode()); assertEquals(defaultCacheWriterConfig.getCacheWriterFactoryConfiguration(), config2.getCacheWriterConfiguration() .getCacheWriterFactoryConfiguration()); assertEquals(defaultCacheWriterConfig.getNotifyListenersOnException(), config2.getCacheWriterConfiguration() .getNotifyListenersOnException()); assertEquals(defaultCacheWriterConfig.getMaxWriteDelay(), config2.getCacheWriterConfiguration().getMaxWriteDelay()); assertEquals(defaultCacheWriterConfig.getRateLimitPerSecond(), config2.getCacheWriterConfiguration().getRateLimitPerSecond()); assertEquals(defaultCacheWriterConfig.getWriteCoalescing(), config2.getCacheWriterConfiguration().getWriteCoalescing()); assertEquals(defaultCacheWriterConfig.getWriteBatching(), config2.getCacheWriterConfiguration().getWriteBatching()); assertEquals(defaultCacheWriterConfig.getWriteBatchSize(), config2.getCacheWriterConfiguration().getWriteBatchSize()); assertEquals(defaultCacheWriterConfig.getRetryAttempts(), config2.getCacheWriterConfiguration().getRetryAttempts()); assertEquals(defaultCacheWriterConfig.getRetryAttemptDelaySeconds(), config2.getCacheWriterConfiguration().getRetryAttemptDelaySeconds()); CacheConfiguration config3 = configs.get("writeThroughCache3"); assertNotNull(config3.getCacheWriterConfiguration()); assertEquals(CacheWriterConfiguration.WriteMode.WRITE_THROUGH, config3.getCacheWriterConfiguration().getWriteMode()); assertEquals(defaultCacheWriterConfig.getCacheWriterFactoryConfiguration(), config3.getCacheWriterConfiguration() .getCacheWriterFactoryConfiguration()); assertEquals(true, config3.getCacheWriterConfiguration().getNotifyListenersOnException()); assertEquals(30, config3.getCacheWriterConfiguration().getMaxWriteDelay()); assertEquals(10, config3.getCacheWriterConfiguration().getRateLimitPerSecond()); assertEquals(true, config3.getCacheWriterConfiguration().getWriteCoalescing()); assertEquals(true, config3.getCacheWriterConfiguration().getWriteBatching()); assertEquals(8, config3.getCacheWriterConfiguration().getWriteBatchSize()); assertEquals(20, config3.getCacheWriterConfiguration().getRetryAttempts()); assertEquals(60, config3.getCacheWriterConfiguration().getRetryAttemptDelaySeconds()); CacheConfiguration config4 = configs.get("writeThroughCache4"); assertNotNull(config4.getCacheWriterConfiguration()); assertEquals(CacheWriterConfiguration.WriteMode.WRITE_THROUGH, config4.getCacheWriterConfiguration().getWriteMode()); assertEquals("net.sf.ehcache.writer.TestCacheWriterFactory", config4.getCacheWriterConfiguration().getCacheWriterFactoryConfiguration() .getFullyQualifiedClassPath()); assertEquals(null, config4.getCacheWriterConfiguration().getCacheWriterFactoryConfiguration().getProperties()); assertEquals(null, config4.getCacheWriterConfiguration().getCacheWriterFactoryConfiguration().getPropertySeparator()); assertEquals(false, config4.getCacheWriterConfiguration().getNotifyListenersOnException()); assertEquals(0, config4.getCacheWriterConfiguration().getMaxWriteDelay()); assertEquals(0, config4.getCacheWriterConfiguration().getRateLimitPerSecond()); assertEquals(false, config4.getCacheWriterConfiguration().getWriteCoalescing()); assertEquals(false, config4.getCacheWriterConfiguration().getWriteBatching()); assertEquals(1, config4.getCacheWriterConfiguration().getWriteBatchSize()); assertEquals(0, config4.getCacheWriterConfiguration().getRetryAttempts()); assertEquals(0, config4.getCacheWriterConfiguration().getRetryAttemptDelaySeconds()); CacheConfiguration config5 = configs.get("writeBehindCache5"); assertNotNull(config5.getCacheWriterConfiguration()); assertEquals(CacheWriterConfiguration.WriteMode.WRITE_BEHIND, config5.getCacheWriterConfiguration().getWriteMode()); assertEquals("net.sf.ehcache.writer.TestCacheWriterFactory", config5.getCacheWriterConfiguration().getCacheWriterFactoryConfiguration() .getFullyQualifiedClassPath()); assertEquals("just.some.property=test; another.property=test2", config5.getCacheWriterConfiguration().getCacheWriterFactoryConfiguration() .getProperties()); assertEquals(";", config5.getCacheWriterConfiguration().getCacheWriterFactoryConfiguration().getPropertySeparator()); assertEquals(true, config5.getCacheWriterConfiguration().getNotifyListenersOnException()); assertEquals(8, config5.getCacheWriterConfiguration().getMaxWriteDelay()); assertEquals(5, config5.getCacheWriterConfiguration().getRateLimitPerSecond()); assertEquals(true, config5.getCacheWriterConfiguration().getWriteCoalescing()); assertEquals(false, config5.getCacheWriterConfiguration().getWriteBatching()); assertEquals(20, config5.getCacheWriterConfiguration().getWriteBatchSize()); assertEquals(2, config5.getCacheWriterConfiguration().getRetryAttempts()); assertEquals(2, config5.getCacheWriterConfiguration().getRetryAttemptDelaySeconds()); Ehcache cache5 = configurationHelper.createCacheFromName("writeBehindCache5"); Properties properties5 = ((TestCacheWriter) cache5.getRegisteredCacheWriter()).getProperties(); assertEquals(2, properties5.size()); assertEquals("test", properties5.getProperty("just.some.property")); assertEquals("test2", properties5.getProperty("another.property")); }
public static Configuration parseConfiguration(final File file) throws CacheException { if (file == null) { throw new CacheException("Attempt to configure ehcache from null file."); } LOG.debug("Configuring ehcache from file: {}", file); Configuration configuration = null; InputStream input = null; try { input = new BufferedInputStream(new FileInputStream(file)); configuration = parseConfiguration(input); } catch (Exception e) { throw new CacheException("Error configuring from " + file + ". Initial cause was " + e.getMessage(), e); } finally { try { if (input != null) { input.close(); } } catch (IOException e) { LOG.error("IOException while closing configuration input stream. Error was " + e.getMessage()); } } configuration.setSource(ConfigurationSource.getConfigurationSource(file)); return configuration; }
ConfigurationFactory { public static Configuration parseConfiguration(final File file) throws CacheException { if (file == null) { throw new CacheException("Attempt to configure ehcache from null file."); } LOG.debug("Configuring ehcache from file: {}", file); Configuration configuration = null; InputStream input = null; try { input = new BufferedInputStream(new FileInputStream(file)); configuration = parseConfiguration(input); } catch (Exception e) { throw new CacheException("Error configuring from " + file + ". Initial cause was " + e.getMessage(), e); } finally { try { if (input != null) { input.close(); } } catch (IOException e) { LOG.error("IOException while closing configuration input stream. Error was " + e.getMessage()); } } configuration.setSource(ConfigurationSource.getConfigurationSource(file)); return configuration; } }
ConfigurationFactory { public static Configuration parseConfiguration(final File file) throws CacheException { if (file == null) { throw new CacheException("Attempt to configure ehcache from null file."); } LOG.debug("Configuring ehcache from file: {}", file); Configuration configuration = null; InputStream input = null; try { input = new BufferedInputStream(new FileInputStream(file)); configuration = parseConfiguration(input); } catch (Exception e) { throw new CacheException("Error configuring from " + file + ". Initial cause was " + e.getMessage(), e); } finally { try { if (input != null) { input.close(); } } catch (IOException e) { LOG.error("IOException while closing configuration input stream. Error was " + e.getMessage()); } } configuration.setSource(ConfigurationSource.getConfigurationSource(file)); return configuration; } private  ConfigurationFactory(); }
ConfigurationFactory { public static Configuration parseConfiguration(final File file) throws CacheException { if (file == null) { throw new CacheException("Attempt to configure ehcache from null file."); } LOG.debug("Configuring ehcache from file: {}", file); Configuration configuration = null; InputStream input = null; try { input = new BufferedInputStream(new FileInputStream(file)); configuration = parseConfiguration(input); } catch (Exception e) { throw new CacheException("Error configuring from " + file + ". Initial cause was " + e.getMessage(), e); } finally { try { if (input != null) { input.close(); } } catch (IOException e) { LOG.error("IOException while closing configuration input stream. Error was " + e.getMessage()); } } configuration.setSource(ConfigurationSource.getConfigurationSource(file)); return configuration; } private  ConfigurationFactory(); static Configuration parseConfiguration(final File file); static Configuration parseConfiguration(final URL url); static Configuration parseConfiguration(); static Configuration parseConfiguration(final InputStream inputStream); }
ConfigurationFactory { public static Configuration parseConfiguration(final File file) throws CacheException { if (file == null) { throw new CacheException("Attempt to configure ehcache from null file."); } LOG.debug("Configuring ehcache from file: {}", file); Configuration configuration = null; InputStream input = null; try { input = new BufferedInputStream(new FileInputStream(file)); configuration = parseConfiguration(input); } catch (Exception e) { throw new CacheException("Error configuring from " + file + ". Initial cause was " + e.getMessage(), e); } finally { try { if (input != null) { input.close(); } } catch (IOException e) { LOG.error("IOException while closing configuration input stream. Error was " + e.getMessage()); } } configuration.setSource(ConfigurationSource.getConfigurationSource(file)); return configuration; } private  ConfigurationFactory(); static Configuration parseConfiguration(final File file); static Configuration parseConfiguration(final URL url); static Configuration parseConfiguration(); static Configuration parseConfiguration(final InputStream inputStream);  }