@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)); }
@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)); }
@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 ")); } }
@Test public void testGetTimeoutNone() 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>", " </ehcache:service>", "", "</ehcache:config>" }; final Configuration configuration = new XmlConfiguration(makeConfig(config)); Collection<ServiceCreationConfiguration<?>> serviceCreationConfigurations = configuration.getServiceCreationConfigurations(); assertThat(serviceCreationConfigurations, is(not(Matchers.empty()))); ClusteringServiceConfiguration clusteringServiceConfiguration = ServiceUtils.findSingletonAmongst(ClusteringServiceConfiguration.class, serviceCreationConfigurations); assertThat(clusteringServiceConfiguration, is(notNullValue())); assertThat(clusteringServiceConfiguration.getTimeouts(), is(TimeoutsBuilder.timeouts().build())); }
}; final Configuration configuration = new XmlConfiguration(makeConfig(config)); Collection<ServiceCreationConfiguration<?>> serviceCreationConfigurations = configuration.getServiceCreationConfigurations(); ClusteringServiceConfiguration clusteringServiceConfiguration =
@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 ")); } }
@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'")); } }
}; final Configuration configuration = new XmlConfiguration(makeConfig(config)); Collection<ServiceCreationConfiguration<?>> serviceCreationConfigurations = configuration.getServiceCreationConfigurations(); ClusteringServiceConfiguration clusteringServiceConfiguration =
@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 = ServiceUtils.findSingletonAmongst(ClusteringServiceConfiguration.class, serviceCreationConfigurations); assertThat(clusteringServiceConfiguration, is(notNullValue())); TemporalUnit defaultUnit = convertToJavaTimeUnit(new TimeType().getUnit()); assertThat(clusteringServiceConfiguration.getTimeouts().getReadOperationTimeout(), is(equalTo(Duration.of(5, defaultUnit)))); }
}; final Configuration configuration = new XmlConfiguration(makeConfig(config));