org.ehcache.xml.XmlConfiguration Java Examples
The following examples show how to use
org.ehcache.xml.XmlConfiguration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EHCache3Manager.java From javalite with Apache License 2.0 | 6 votes |
public EHCache3Manager() throws ClassNotFoundException, InstantiationException, IllegalAccessException { URL url = getClass().getResource("/activejdbc-ehcache.xml"); if(url == null){ throw new InitException("You are using " + getClass().getName() + " but failed to provide a EHCache configuration file on classpath: activejdbc-ehcache.xml"); } XmlConfiguration xmlConfiguration = new XmlConfiguration(url); cacheTemplate = xmlConfiguration.newCacheConfigurationBuilderFromTemplate("activejdbc", String.class, Object.class); if(cacheTemplate == null){ throw new InitException("Please, provide a <cache-template name=\"activejdbc\"> element in activejdbc-ehcache.xml file"); } cacheManager = CacheManagerBuilder.newCacheManager(xmlConfiguration); cacheManager.init(); }
Example #2
Source File: GettingStarted.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void testXmlToString() throws IOException { // tag::xmlTranslation[] CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder() .with(CacheManagerBuilder.persistence(tmpDir.newFile("myData"))) .withCache("threeTieredCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.newResourcePoolsBuilder() .heap(10, EntryUnit.ENTRIES) .offheap(1, MemoryUnit.MB) .disk(20, MemoryUnit.MB, true)) .withExpiry(ExpiryPolicyBuilder.timeToIdleExpiration(Duration.ofSeconds(20))) ).build(false); Configuration configuration = cacheManager.getRuntimeConfiguration(); XmlConfiguration xmlConfiguration = new XmlConfiguration(configuration); // <1> String xml = xmlConfiguration.toString(); // <2> // end::xmlTranslation[] }
Example #3
Source File: TransactionalOsgiTest.java From ehcache3 with Apache License 2.0 | 6 votes |
public static void testXmlConfiguration() throws Exception { BitronixTransactionManager transactionManager = getTransactionManager(); try (CacheManager cacheManager = newCacheManager( new XmlConfiguration(TestMethods.class.getResource("ehcache-xa-osgi.xml"), TestMethods.class.getClassLoader()) )) { cacheManager.init(); Cache<Long, String> xaCache = cacheManager.getCache("xaCache", Long.class, String.class); transactionManager.begin(); try { xaCache.put(1L, "one"); } catch (Throwable t) { transactionManager.rollback(); } transactionManager.commit(); } transactionManager.shutdown(); }
Example #4
Source File: DefaultSerializerConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void parseServiceConfiguration() throws Exception { CacheConfiguration<?, ?> cacheConfiguration = new XmlConfiguration(getClass().getResource("/configs/default-serializer.xml")).getCacheConfigurations().get("foo"); @SuppressWarnings("rawtypes") Collection<DefaultSerializerConfiguration> copierConfigs = findAmongst(DefaultSerializerConfiguration.class, cacheConfiguration.getServiceConfigurations()); assertThat(copierConfigs).hasSize(2); for(DefaultSerializerConfiguration<?> copierConfig : copierConfigs) { if(copierConfig.getType() == DefaultSerializerConfiguration.Type.KEY) { assertThat(copierConfig.getClazz()).isEqualTo(TestSerializer3.class); } else { assertThat(copierConfig.getClazz()).isEqualTo(TestSerializer4.class); } } }
Example #5
Source File: ClusteredXML.java From ehcache3-samples with Apache License 2.0 | 6 votes |
public static void main(String[] args) { LOGGER.info("Creating clustered cache manager from XML"); URL myUrl = ClusteredXML.class.getResource("/ehcache.xml"); Configuration xmlConfig = new XmlConfiguration(myUrl); try (CacheManager cacheManager = newCacheManager(xmlConfig)) { cacheManager.init(); Cache<Long, String> basicCache = cacheManager.getCache("basicCache", Long.class, String.class); LOGGER.info("Getting from cache"); String value = basicCache.get(1L); LOGGER.info("Retrieved '{}'", value); LOGGER.info("Closing cache manager"); } LOGGER.info("Exiting"); }
Example #6
Source File: BasicXML.java From ehcache3-samples with Apache License 2.0 | 6 votes |
public static void main(String[] args) { LOGGER.info("Creating cache manager via XML resource"); Configuration xmlConfig = new XmlConfiguration(BasicXML.class.getResource("/ehcache.xml")); try (CacheManager cacheManager = newCacheManager(xmlConfig)) { cacheManager.init(); Cache<Long, String> basicCache = cacheManager.getCache("basicCache", Long.class, String.class); LOGGER.info("Putting to cache"); basicCache.put(1L, "da one!"); String value = basicCache.get(1L); LOGGER.info("Retrieved '{}'", value); LOGGER.info("Closing cache manager"); } LOGGER.info("Exiting"); }
Example #7
Source File: DefaultWriteBehindConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void parseServiceConfigurationBatching() throws Exception { CacheConfiguration<?, ?> cacheConfiguration = new XmlConfiguration(getClass().getResource("/configs/writebehind-cache.xml")).getCacheConfigurations().get("template1"); DefaultWriteBehindConfiguration writeBehindConfig = findSingletonAmongst(DefaultWriteBehindConfiguration.class, cacheConfiguration.getServiceConfigurations()); assertThat(writeBehindConfig).isNotNull(); assertThat(writeBehindConfig.getConcurrency()).isEqualTo(1); assertThat(writeBehindConfig.getMaxQueueSize()).isEqualTo(10); WriteBehindConfiguration.BatchingConfiguration batchingConfiguration = writeBehindConfig.getBatchingConfiguration(); assertThat(batchingConfiguration).isNotNull(); assertThat(batchingConfiguration.getBatchSize()).isEqualTo(2); assertThat(batchingConfiguration.isCoalescing()).isEqualTo(false); assertThat(batchingConfiguration.getMaxDelay()).isEqualTo(10); assertThat(batchingConfiguration.getMaxDelayUnit()).isEqualTo(TimeUnit.SECONDS); }
Example #8
Source File: DefaultCopierConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void parseServiceConfiguration() throws Exception { CacheConfiguration<?, ?> cacheConfiguration = new XmlConfiguration(getClass().getResource("/configs/cache-copiers.xml")).getCacheConfigurations().get("baz"); @SuppressWarnings("rawtypes") Collection<DefaultCopierConfiguration> copierConfigs = findAmongst(DefaultCopierConfiguration.class, cacheConfiguration.getServiceConfigurations()); assertThat(copierConfigs).hasSize(2); for(DefaultCopierConfiguration<?> copierConfig : copierConfigs) { if(copierConfig.getType() == DefaultCopierConfiguration.Type.KEY) { assertThat(copierConfig.getClazz()).isEqualTo(SerializingCopier.class); } else { assertThat(copierConfig.getClazz()).isEqualTo(AnotherPersonCopier.class); } } }
Example #9
Source File: PooledExecutionServiceConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void parseServiceCreationConfiguration() throws SAXException, JAXBException, ParserConfigurationException, IOException, ClassNotFoundException { Configuration xmlConfig = new XmlConfiguration(getClass().getResource("/configs/thread-pools.xml")); assertThat(xmlConfig.getServiceCreationConfigurations()).hasSize(1); ServiceCreationConfiguration<?, ?> configuration = xmlConfig.getServiceCreationConfigurations().iterator().next(); assertThat(configuration).isExactlyInstanceOf(PooledExecutionServiceConfiguration.class); PooledExecutionServiceConfiguration providerConfiguration = (PooledExecutionServiceConfiguration) configuration; assertThat(providerConfiguration.getPoolConfigurations()).containsKeys("big", "small"); PooledExecutionServiceConfiguration.PoolConfiguration small = providerConfiguration.getPoolConfigurations().get("small"); assertThat(small.minSize()).isEqualTo(1); assertThat(small.maxSize()).isEqualTo(1); PooledExecutionServiceConfiguration.PoolConfiguration big = providerConfiguration.getPoolConfigurations().get("big"); assertThat(big.minSize()).isEqualTo(4); assertThat(big.maxSize()).isEqualTo(32); assertThat(providerConfiguration.getDefaultPoolAlias()).isEqualTo("big"); }
Example #10
Source File: DefaultSerializationProviderConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void parseServiceCreationConfiguration() throws SAXException, JAXBException, ParserConfigurationException, IOException, ClassNotFoundException { Configuration xmlConfig = new XmlConfiguration(getClass().getResource("/configs/default-serializer.xml")); assertThat(xmlConfig.getServiceCreationConfigurations()).hasSize(1); ServiceCreationConfiguration<?, ?> configuration = xmlConfig.getServiceCreationConfigurations().iterator().next(); assertThat(configuration).isExactlyInstanceOf(DefaultSerializationProviderConfiguration.class); DefaultSerializationProviderConfiguration factoryConfiguration = (DefaultSerializationProviderConfiguration) configuration; Map<Class<?>, Class<? extends Serializer<?>>> defaultSerializers = factoryConfiguration.getDefaultSerializers(); assertThat(defaultSerializers).hasSize(4); assertThat(defaultSerializers.get(CharSequence.class)).isEqualTo(TestSerializer.class); assertThat(defaultSerializers.get(Number.class)).isEqualTo(TestSerializer2.class); assertThat(defaultSerializers.get(Long.class)).isEqualTo(TestSerializer3.class); assertThat(defaultSerializers.get(Integer.class)).isEqualTo(TestSerializer4.class); }
Example #11
Source File: DefaultCopyProviderConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void parseServiceCreationConfiguration() throws SAXException, JAXBException, ParserConfigurationException, IOException, ClassNotFoundException { Configuration xmlConfig = new XmlConfiguration(getClass().getResource("/configs/cache-copiers.xml")); assertThat(xmlConfig.getServiceCreationConfigurations()).hasSize(1); ServiceCreationConfiguration<?, ?> configuration = xmlConfig.getServiceCreationConfigurations().iterator().next(); assertThat(configuration).isExactlyInstanceOf(DefaultCopyProviderConfiguration.class); DefaultCopyProviderConfiguration factoryConfiguration = (DefaultCopyProviderConfiguration) configuration; Map<Class<?>, DefaultCopierConfiguration<?>> defaults = factoryConfiguration.getDefaults(); assertThat(defaults).hasSize(2); assertThat(defaults.get(Description.class).getClazz()).isEqualTo(DescriptionCopier.class); assertThat(defaults.get(Person.class).getClazz()).isEqualTo((PersonCopier.class)); }
Example #12
Source File: ClusteredOsgiTest.java From ehcache3 with Apache License 2.0 | 6 votes |
public static void testXmlClusteredCache(OsgiTestUtils.Cluster cluster) throws Exception { File config = cluster.getWorkingArea().resolve("ehcache.xml").toFile(); Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(TestMethods.class.getResourceAsStream("ehcache-clustered-osgi.xml")); XPath xpath = XPathFactory.newInstance().newXPath(); Node clusterUriAttribute = (Node) xpath.evaluate("//config/service/cluster/connection/@url", doc, XPathConstants.NODE); clusterUriAttribute.setTextContent(cluster.getConnectionUri().toString() + "/cache-manager"); Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(new DOMSource(doc), new StreamResult(config)); try (PersistentCacheManager cacheManager = (PersistentCacheManager) CacheManagerBuilder.newCacheManager( new XmlConfiguration(config.toURI().toURL(), TestMethods.class.getClassLoader()) )) { cacheManager.init(); final Cache<Long, Person> cache = cacheManager.getCache("clustered-cache", Long.class, Person.class); cache.put(1L, new Person("Brian")); assertThat(cache.get(1L).name, is("Brian")); } }
Example #13
Source File: ConfigurationMergerTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void jsr107DefaultEh107IdentityCopierForImmutableTypesWithCMLevelDefaults() { XmlConfiguration xmlConfiguration = new XmlConfiguration(getClass().getResource("/ehcache-107-immutable-types-cm-level-copiers.xml")); DefaultJsr107Service jsr107Service = new DefaultJsr107Service(ServiceUtils.findSingletonAmongst(Jsr107Configuration.class, xmlConfiguration.getServiceCreationConfigurations())); merger = new ConfigurationMerger(xmlConfiguration, jsr107Service, mock(Eh107CacheLoaderWriterProvider.class)); MutableConfiguration<Long, String> stringCacheConfiguration = new MutableConfiguration<>(); stringCacheConfiguration.setTypes(Long.class, String.class); ConfigurationMerger.ConfigHolder<Long, String> configHolder1 = merger.mergeConfigurations("stringCache", stringCacheConfiguration); assertThat(configHolder1.cacheConfiguration.getServiceConfigurations().isEmpty(), is(true)); for (ServiceCreationConfiguration<?, ?> serviceCreationConfiguration : xmlConfiguration.getServiceCreationConfigurations()) { if (serviceCreationConfiguration instanceof DefaultCopyProviderConfiguration) { DefaultCopyProviderConfiguration copierConfig = (DefaultCopyProviderConfiguration)serviceCreationConfiguration; assertThat(copierConfig.getDefaults().size(), is(6)); assertThat(copierConfig.getDefaults().get(Long.class).getClazz().isAssignableFrom(IdentityCopier.class), is(true)); assertThat(copierConfig.getDefaults().get(String.class).getClazz().isAssignableFrom(Eh107IdentityCopier.class), is(true)); assertThat(copierConfig.getDefaults().get(Float.class).getClazz().isAssignableFrom(Eh107IdentityCopier.class), is(true)); assertThat(copierConfig.getDefaults().get(Double.class).getClazz().isAssignableFrom(Eh107IdentityCopier.class), is(true)); assertThat(copierConfig.getDefaults().get(Character.class).getClazz().isAssignableFrom(Eh107IdentityCopier.class), is(true)); assertThat(copierConfig.getDefaults().get(Integer.class).getClazz().isAssignableFrom(Eh107IdentityCopier.class), is(true)); } } }
Example #14
Source File: EHCacheTokenReplayCache.java From cxf with Apache License 2.0 | 6 votes |
public EHCacheTokenReplayCache(String configFile, Bus bus) throws IllegalAccessException, ClassNotFoundException, InstantiationException { if (bus == null) { bus = BusFactory.getThreadDefaultBus(true); } URL configFileURL = null; try { configFileURL = ResourceUtils.getClasspathResourceURL(configFile, EHCacheTokenReplayCache.class, bus); } catch (Exception ex) { // ignore } XmlConfiguration xmlConfig = new XmlConfiguration(getConfigFileURL(configFileURL)); CacheConfigurationBuilder<String, EHCacheValue> configurationBuilder = xmlConfig.newCacheConfigurationBuilderFromTemplate(CACHE_KEY, String.class, EHCacheValue.class); // Note, we don't require strong random values here String diskKey = CACHE_KEY + "-" + Math.abs(new Random().nextInt()); cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache(CACHE_KEY, configurationBuilder) .with(CacheManagerBuilder.persistence(new File(System.getProperty("java.io.tmpdir"), diskKey))).build(); cacheManager.init(); cache = cacheManager.getCache(CACHE_KEY, String.class, EHCacheValue.class); }
Example #15
Source File: EHCacheIdentityCache.java From cxf with Apache License 2.0 | 6 votes |
public EHCacheIdentityCache( IdentityMapper identityMapper, String key, Bus b, URL configFileURL ) { super(b, identityMapper); if (b != null) { b.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this); InstrumentationManager im = b.getExtension(InstrumentationManager.class); if (im != null) { try { im.register(this); } catch (JMException e) { LOG.log(Level.WARNING, "Registering EHCacheIdentityCache failed.", e); } } } URL xmlConfigURL = configFileURL != null ? configFileURL : getDefaultConfigFileURL(); Configuration xmlConfig = new XmlConfiguration(xmlConfigURL); cacheManager = CacheManagerBuilder.newCacheManager(xmlConfig); cacheManager.init(); cache = cacheManager.getCache(KEY, String.class, EHCacheIdentityValue.class); }
Example #16
Source File: ClusteringCacheManagerServiceConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test public void testBothAutoCreateAndClientModeIsDisallowed() throws IOException { final String[] config = new String[] { "<ehcache:config", " xmlns:ehcache=\"http://www.ehcache.org/v3\"", " xmlns:tc=\"http://www.ehcache.org/v3/clustered\">", " <ehcache:service>", " <tc:cluster>", " <tc:connection url=\"terracotta://example.com:9540/cachemanager\" />", " <tc:server-side-config auto-create=\"true\" client-mode=\"auto-create\"/>", " </tc:cluster>", " </ehcache:service>", "</ehcache:config>" }; try { new XmlConfiguration(makeConfig(config)); } catch (XmlConfigurationException e) { assertThat(e.getMessage(), is("Cannot define both 'auto-create' and 'client-mode' attributes")); } }
Example #17
Source File: ClusteringCacheManagerServiceConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("deprecation") public void testAutoCreateTrueMapsToAutoCreate() throws IOException { final String[] config = new String[] { "<ehcache:config", " xmlns:ehcache=\"http://www.ehcache.org/v3\"", " xmlns:tc=\"http://www.ehcache.org/v3/clustered\">", " <ehcache:service>", " <tc:cluster>", " <tc:connection url=\"terracotta://example.com:9540/cachemanager\" />", " <tc:server-side-config auto-create=\"true\"/>", " </tc:cluster>", " </ehcache:service>", "</ehcache:config>" }; XmlConfiguration configuration = new XmlConfiguration(makeConfig(config)); ClusteringServiceConfiguration clusterConfig = findSingletonAmongst(ClusteringServiceConfiguration.class, configuration.getServiceCreationConfigurations()); assertThat(clusterConfig.isAutoCreate(), is(true)); assertThat(clusterConfig.getClientMode(), is(ClusteringServiceConfiguration.ClientMode.AUTO_CREATE)); }
Example #18
Source File: ClusteringCacheManagerServiceConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("deprecation") public void testAutoCreateFalseMapsToExpecting() throws IOException { final String[] config = new String[] { "<ehcache:config", " xmlns:ehcache=\"http://www.ehcache.org/v3\"", " xmlns:tc=\"http://www.ehcache.org/v3/clustered\">", " <ehcache:service>", " <tc:cluster>", " <tc:connection url=\"terracotta://example.com:9540/cachemanager\" />", " <tc:server-side-config auto-create=\"false\"/>", " </tc:cluster>", " </ehcache:service>", "</ehcache:config>" }; XmlConfiguration configuration = new XmlConfiguration(makeConfig(config)); ClusteringServiceConfiguration clusterConfig = findSingletonAmongst(ClusteringServiceConfiguration.class, configuration.getServiceCreationConfigurations()); assertThat(clusterConfig.isAutoCreate(), is(false)); assertThat(clusterConfig.getClientMode(), is(ClusteringServiceConfiguration.ClientMode.EXPECTING)); }
Example #19
Source File: ClusteringCacheManagerServiceConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test(expected = XmlConfigurationException.class) public void testServersOnly() throws Exception { final String[] config = new String[] { "<ehcache:config", " xmlns:ehcache=\"http://www.ehcache.org/v3\"", " xmlns:tc=\"http://www.ehcache.org/v3/clustered\">", "", " <ehcache:service>", " <tc:cluster>", " <tc:cluster-connection>", " <tc:server host=\"blah\" port=\"1234\" />", " </tc:cluster-connection>", " </tc:cluster>", " </ehcache:service>", "", "</ehcache:config>" }; new XmlConfiguration(makeConfig(config)); }
Example #20
Source File: ClusteringCacheManagerServiceConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 6 votes |
@Test(expected = XmlConfigurationException.class) public void testUrlAndServers() throws Exception { final String[] config = new String[] { "<ehcache:config", " xmlns:ehcache=\"http://www.ehcache.org/v3\"", " xmlns:tc=\"http://www.ehcache.org/v3/clustered\">", "", " <ehcache:service>", " <tc:cluster>", " <tc:connection url=\"terracotta://example.com:9540/cachemanager\" />", " <tc:cluster-connection cluster-tier-manager=\"cM\">", " <tc:server host=\"blah\" port=\"1234\" />", " </tc:cluster-connection>", " </tc:cluster>", " </ehcache:service>", "", "</ehcache:config>" }; new XmlConfiguration(makeConfig(config)); }
Example #21
Source File: EhCacheProvider3.java From J2Cache with Apache License 2.0 | 6 votes |
@Override public void start(Properties props) { String sDefaultHeapSize = props.getProperty("defaultHeapSize"); try { this.defaultHeapSize = Long.parseLong(sDefaultHeapSize); }catch(Exception e) { log.warn("Failed to read ehcache3.defaultHeapSize = {} , use default {}", sDefaultHeapSize, defaultHeapSize); } String configXml = props.getProperty("configXml"); if(configXml == null || configXml.trim().length() == 0) configXml = "/ehcache3.xml"; URL url = getClass().getResource(configXml); url = (url == null) ? getClass().getClassLoader().getResource(configXml) : url; Configuration xmlConfig = new XmlConfiguration(url); manager = CacheManagerBuilder.newCacheManager(xmlConfig); manager.init(); }
Example #22
Source File: XmlMultiConfiguration.java From ehcache3 with Apache License 2.0 | 5 votes |
private static Element unparseEhcacheConfiguration(Configuration config) { if (config instanceof XmlConfiguration) { return ((XmlConfiguration) config).asDocument().getDocumentElement(); } else { return new XmlConfiguration(config).asDocument().getDocumentElement(); } }
Example #23
Source File: DefaultWriteBehindConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void parseServiceConfigurationNonBatching() throws Exception { CacheConfiguration<?, ?> cacheConfiguration = new XmlConfiguration(getClass().getResource("/configs/writebehind-cache.xml")).getCacheConfigurations().get("bar"); DefaultWriteBehindConfiguration writeBehindConfig = findSingletonAmongst(DefaultWriteBehindConfiguration.class, cacheConfiguration.getServiceConfigurations()); assertThat(writeBehindConfig).isNotNull(); assertThat(writeBehindConfig.getConcurrency()).isEqualTo(1); assertThat(writeBehindConfig.getMaxQueueSize()).isEqualTo(10); assertThat(writeBehindConfig.getBatchingConfiguration()).isNull(); }
Example #24
Source File: ClusteringCacheManagerServiceConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void testGetTimeoutValueOmitted() throws Exception { final String[] config = new String[] { "<ehcache:config", " xmlns:ehcache=\"http://www.ehcache.org/v3\"", " xmlns:tc=\"http://www.ehcache.org/v3/clustered\">", "", " <ehcache:service>", " <tc:cluster>", " <tc:connection url=\"terracotta://example.com:9540/cachemanager\"/>", " <tc:read-timeout unit=\"seconds\"></tc:read-timeout>", " </tc:cluster>", " </ehcache:service>", "", "</ehcache:config>" }; try { new XmlConfiguration(makeConfig(config)); fail("Expecting XmlConfigurationException"); } catch (XmlConfigurationException e) { assertThat(e.getMessage(), containsString("Error parsing XML configuration ")); assertThat(e.getCause().getMessage(), containsString("'' is not a valid value for 'integer'")); } }
Example #25
Source File: ClusteringCacheManagerServiceConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void testGetTimeoutValueTooBig() throws Exception { final String[] config = new String[] { "<ehcache:config", " xmlns:ehcache=\"http://www.ehcache.org/v3\"", " xmlns:tc=\"http://www.ehcache.org/v3/clustered\">", "", " <ehcache:service>", " <tc:cluster>", " <tc:connection url=\"terracotta://example.com:9540/cachemanager\"/>", " <tc:read-timeout unit=\"seconds\">" + BigInteger.ONE.add(BigInteger.valueOf(Long.MAX_VALUE)) + "</tc:read-timeout>", " </tc:cluster>", " </ehcache:service>", "", "</ehcache:config>" }; try { new XmlConfiguration(makeConfig(config)); fail("Expecting XmlConfigurationException"); } catch (XmlConfigurationException e) { assertThat(e.getMessage(), containsString(" exceeds allowed value ")); } }
Example #26
Source File: ClusteringCacheManagerServiceConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void testGetTimeoutUnitBad() throws Exception { final String[] config = new String[] { "<ehcache:config", " xmlns:ehcache=\"http://www.ehcache.org/v3\"", " xmlns:tc=\"http://www.ehcache.org/v3/clustered\">", "", " <ehcache:service>", " <tc:cluster>", " <tc:connection url=\"terracotta://example.com:9540/cachemanager\"/>", " <tc:read-timeout unit=\"femtos\">5</tc:read-timeout>", " </tc:cluster>", " </ehcache:service>", "", "</ehcache:config>" }; try { new XmlConfiguration(makeConfig(config)); fail("Expecting XmlConfigurationException"); } catch (XmlConfigurationException e) { assertThat(e.getMessage(), containsString("Error parsing XML configuration ")); assertThat(e.getCause().getMessage(), containsString("Value 'femtos' is not facet-valid with respect to enumeration ")); } }
Example #27
Source File: ClusteringCacheManagerServiceConfigurationParserTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void testGetTimeoutUnitDefault() throws Exception { final String[] config = new String[] { "<ehcache:config", " xmlns:ehcache=\"http://www.ehcache.org/v3\"", " xmlns:tc=\"http://www.ehcache.org/v3/clustered\">", "", " <ehcache:service>", " <tc:cluster>", " <tc:connection url=\"terracotta://example.com:9540/cachemanager\"/>", " <tc:read-timeout>5</tc:read-timeout>", " </tc:cluster>", " </ehcache:service>", "", "</ehcache:config>" }; final Configuration configuration = new XmlConfiguration(makeConfig(config)); Collection<ServiceCreationConfiguration<?, ?>> serviceCreationConfigurations = configuration.getServiceCreationConfigurations(); assertThat(serviceCreationConfigurations, is(not(Matchers.empty()))); ClusteringServiceConfiguration clusteringServiceConfiguration = findSingletonAmongst(ClusteringServiceConfiguration.class, serviceCreationConfigurations); assertThat(clusteringServiceConfiguration, is(notNullValue())); TemporalUnit defaultUnit = convertToJavaTimeUnit(new TimeType().getUnit()); assertThat(clusteringServiceConfiguration.getTimeouts().getReadOperationTimeout(), is(equalTo(Duration.of(5, defaultUnit)))); }
Example #28
Source File: XmlUnknownCacheTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void testGetUnknownCacheInvalidAttribute() { try { new XmlConfiguration(this.getClass().getResource("/configs/unknown-cluster-cache-invalid-attribute.xml")); fail("Expected XmlConfigurationException"); } catch(XmlConfigurationException xce) { Assert.assertThat(xce.getCause().getMessage(), endsWith("Attribute 'unit' is not allowed to appear in element 'tc:clustered'.")); } }
Example #29
Source File: TerracottaUriXmlTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void testFailsWithInvalidClusterUri() { try { new XmlConfiguration(getClass().getResource("/configs/cluster-invalid-uri.xml")); } catch (XmlConfigurationException e) { assertThat(e.getCause().getMessage(), containsString("not facet-valid with respect to pattern")); } }
Example #30
Source File: SimpleClusteredCacheByXmlTest.java From ehcache3 with Apache License 2.0 | 5 votes |
@Test public void testViaXml() throws Exception { final Configuration configuration = new XmlConfiguration(this.getClass().getResource(SIMPLE_CLUSTER_XML)); final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration); assertThat(cacheManager, is(instanceOf(PersistentCacheManager.class))); cacheManager.init(); final Cache<Long, String> cache = cacheManager.getCache("simple-cache", Long.class, String.class); assertThat(cache, is(not(nullValue()))); cacheManager.close(); }