@Test public void testLoadConfigurationFromFile() throws Exception { File file = new File(SRC_CONFIG_DIR + "ehcache.xml"); Configuration configuration = ConfigurationFactory.parseConfiguration(file); ConfigurationHelper configurationHelper = new ConfigurationHelper(manager, configuration); assertEquals(System.getProperty("java.io.tmpdir"), configurationHelper.getDiskStorePath()); Map<String,CacheManagerPeerProvider> peerProviders = configurationHelper.createCachePeerProviders(); CacheManagerPeerProvider peerProvider = peerProviders.get("RMI"); assertTrue(peerProvider instanceof MulticastRMICacheManagerPeerProvider); assertEquals(new Integer(1), ((MulticastRMICacheManagerPeerProvider) peerProvider).getHeartBeatSender().getTimeToLive()); Ehcache defaultCache = configurationHelper.createDefaultCache(); assertEquals("default", defaultCache.getName()); assertEquals(false, defaultCache.getCacheConfiguration().isEternal()); assertEquals(120, defaultCache.getCacheConfiguration().getTimeToIdleSeconds()); assertEquals(120, defaultCache.getCacheConfiguration().getTimeToLiveSeconds()); assertEquals(true, defaultCache.getCacheConfiguration().isOverflowToDisk()); assertEquals(10000, defaultCache.getCacheConfiguration().getMaxElementsInMemory()); assertEquals(10000000, defaultCache.getCacheConfiguration().getMaxElementsOnDisk()); assertEquals(6, configurationHelper.createCaches().size()); CacheConfiguration sampleCache1Config = (CacheConfiguration) configuration.getCacheConfigurations().get("sampleCache1"); assertEquals("sampleCache1", sampleCache1Config.getName()); assertEquals(false, sampleCache1Config.isEternal()); assertEquals(300, sampleCache1Config.getTimeToIdleSeconds()); assertEquals(600, sampleCache1Config.getTimeToLiveSeconds()); assertEquals(true, sampleCache1Config.isOverflowToDisk()); assertEquals(20, sampleCache1Config.getDiskSpoolBufferSizeMB()); Ehcache sampleCache1 = configurationHelper.createCacheFromName("sampleCache1"); assertEquals("sampleCache1", sampleCache1.getName()); assertEquals(false, sampleCache1.getCacheConfiguration().isEternal()); assertEquals(300, sampleCache1.getCacheConfiguration().getTimeToIdleSeconds()); assertEquals(1000, sampleCache1.getCacheConfiguration().getMaxElementsOnDisk()); assertEquals(600, sampleCache1.getCacheConfiguration().getTimeToLiveSeconds()); assertEquals(true, sampleCache1.getCacheConfiguration().isOverflowToDisk()); }
public static Configuration parseConfiguration(final File file) throws CacheException { if (file == null) { throw new CacheException("Attempt to configure ehcache from null file."); } if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "Configuring ehcache from file: " + file.toString()); } 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.log(Level.SEVERE, "IOException while closing configuration input stream. Error was " + e.getMessage()); } } 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."); } if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "Configuring ehcache from file: " + file.toString()); } 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.log(Level.SEVERE, "IOException while closing configuration input stream. Error was " + e.getMessage()); } } 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."); } if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "Configuring ehcache from file: " + file.toString()); } 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.log(Level.SEVERE, "IOException while closing configuration input stream. Error was " + e.getMessage()); } } 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."); } if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "Configuring ehcache from file: " + file.toString()); } 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.log(Level.SEVERE, "IOException while closing configuration input stream. Error was " + e.getMessage()); } } 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."); } if (LOG.isLoggable(Level.FINE)) { LOG.log(Level.FINE, "Configuring ehcache from file: " + file.toString()); } 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.log(Level.SEVERE, "IOException while closing configuration input stream. Error was " + e.getMessage()); } } 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);  }