@Test public void testCopyConfiguration() { File file = new File(TEST_CONFIG_DIR + "ehcache-copy.xml"); Configuration configuration = ConfigurationFactory.parseConfiguration(file); ConfigurationHelper configurationHelper = new ConfigurationHelper(manager, configuration); Ehcache copyOnReadCache = configurationHelper.createCacheFromName("copyOnReadCache"); assertTrue(copyOnReadCache.getCacheConfiguration().isCopyOnRead()); assertFalse(copyOnReadCache.getCacheConfiguration().isCopyOnWrite()); assertNotNull(copyOnReadCache.getCacheConfiguration().getCopyStrategy()); assertTrue(copyOnReadCache.getCacheConfiguration().getCopyStrategy() instanceof ReadWriteSerializationCopyStrategy); Ehcache copyOnWriteCache = configurationHelper.createCacheFromName("copyOnWriteCache"); assertFalse(copyOnWriteCache.getCacheConfiguration().isCopyOnRead()); assertTrue(copyOnWriteCache.getCacheConfiguration().isCopyOnWrite()); assertNotNull(copyOnWriteCache.getCacheConfiguration().getCopyStrategy()); assertTrue(copyOnWriteCache.getCacheConfiguration().getCopyStrategy() instanceof ReadWriteSerializationCopyStrategy); Ehcache copyCache = configurationHelper.createCacheFromName("copyCache"); assertTrue(copyCache.getCacheConfiguration().isCopyOnRead()); assertTrue(copyCache.getCacheConfiguration().isCopyOnWrite()); assertNotNull(copyCache.getCacheConfiguration().getCopyStrategy()); assertTrue(copyCache.getCacheConfiguration().getCopyStrategy() instanceof FakeCopyStrategy); try { new CacheManager(TEST_CONFIG_DIR + "ehcache-copy.xml"); fail("This should have thrown an Exception"); } catch (Exception e) { if(!(e instanceof InvalidConfigurationException)) { e.printStackTrace(); fail("Expected InvalidConfigurationException, but got "+ e.getClass().getSimpleName()); } } file = new File(TEST_CONFIG_DIR + "ehcache-copy-tc.xml"); configuration = ConfigurationFactory.parseConfiguration(file); configurationHelper = new ConfigurationHelper(manager, configuration); Ehcache nonCopyCache = configurationHelper.createCacheFromName("nonCopyOnReadCacheTcTrue"); assertFalse(nonCopyCache.getCacheConfiguration().isCopyOnRead()); assertTrue(nonCopyCache.getCacheConfiguration().getTerracottaConfiguration().isCopyOnRead()); Ehcache nonCopyCacheTc = configurationHelper.createCacheFromName("copyOnReadCacheTcFalse"); assertTrue(nonCopyCacheTc.getCacheConfiguration().isCopyOnRead()); assertFalse(nonCopyCacheTc.getCacheConfiguration().getTerracottaConfiguration().isCopyOnRead()); Ehcache copyOnReadCacheTc = configurationHelper.createCacheFromName("copyOnReadCacheTc"); assertTrue(copyOnReadCacheTc.getCacheConfiguration().isCopyOnRead()); assertTrue(copyOnReadCacheTc.getCacheConfiguration().getTerracottaConfiguration().isCopyOnRead()); }
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);  }