@Test public void testTranslateServiceCreationConfigurationWithInetSocketAddress() { InetSocketAddress firstServer = InetSocketAddress.createUnresolved("100.100.100.100", 9510); InetSocketAddress secondServer = InetSocketAddress.createUnresolved("server-2", 0); InetSocketAddress thirdServer = InetSocketAddress.createUnresolved("[::1]", 0); InetSocketAddress fourthServer = InetSocketAddress.createUnresolved("[fe80::1453:846e:7be4:15fe]", 9710); List<InetSocketAddress> servers = Arrays.asList(firstServer, secondServer, thirdServer, fourthServer); ClusteringServiceConfiguration serviceConfig = ClusteringServiceConfigurationBuilder.cluster(servers, "my-application") .timeouts(Timeouts.DEFAULT) .build(); ClusteringCacheManagerServiceConfigurationParser parser = new ClusteringCacheManagerServiceConfigurationParser(); Element returnElement = parser.unparseServiceCreationConfiguration(serviceConfig); String inputString = "<tc:cluster xmlns:tc = \"http://www.ehcache.org/v3/clustered\">" + "<tc:cluster-connection cluster-tier-manager = \"my-application\">" + "<tc:server host = \"100.100.100.100\" port = \"9510\"/>" + "<tc:server host = \"server-2\"/>" + "<tc:server host = \"[::1]\"/>" + "<tc:server host = \"[fe80::1453:846e:7be4:15fe]\" port = \"9710\"/>" + "</tc:cluster-connection>" + "<tc:read-timeout unit = \"seconds\">5</tc:read-timeout>" + "<tc:write-timeout unit = \"seconds\">5</tc:write-timeout>" + "<tc:connection-timeout unit = \"seconds\">150</tc:connection-timeout>" + "<tc:server-side-config auto-create = \"false\"/></tc:cluster>"; assertElement(inputString, returnElement); }
@Test public void testTranslateServiceCreationConfigurationWithNoServerSideConfig() throws Exception { URI connectionUri = new URI("terracotta://localhost:9510/my-application"); ClusteringServiceConfiguration serviceConfig = ClusteringServiceConfigurationBuilder.cluster(connectionUri) .timeouts(Timeouts.DEFAULT) .build(); ClusteringCacheManagerServiceConfigurationParser parser = new ClusteringCacheManagerServiceConfigurationParser(); Element returnElement = parser.unparseServiceCreationConfiguration(serviceConfig); String inputString = "<tc:cluster xmlns:tc = \"http://www.ehcache.org/v3/clustered\">" + "<tc:connection url = \"terracotta://localhost:9510/my-application\"/>" + "<tc:read-timeout unit = \"seconds\">5</tc:read-timeout>" + "<tc:write-timeout unit = \"seconds\">5</tc:write-timeout>" + "<tc:connection-timeout unit = \"seconds\">150</tc:connection-timeout>" + "<tc:server-side-config auto-create = \"false\">" + "</tc:server-side-config></tc:cluster>"; assertElement(inputString, returnElement); }
@Test public void testTranslateServiceCreationConfigurationWithNoResourcePoolAndAutoCreateFalse() throws Exception { URI connectionUri = new URI("terracotta://localhost:9510/my-application"); ClusteringServiceConfiguration serviceConfig = ClusteringServiceConfigurationBuilder.cluster(connectionUri) .timeouts(Timeouts.DEFAULT) .expecting() .defaultServerResource("main") .build(); ClusteringCacheManagerServiceConfigurationParser parser = new ClusteringCacheManagerServiceConfigurationParser(); Element returnElement = parser.unparseServiceCreationConfiguration(serviceConfig); String inputString = "<tc:cluster xmlns:tc = \"http://www.ehcache.org/v3/clustered\">" + "<tc:connection url = \"terracotta://localhost:9510/my-application\"/>" + "<tc:read-timeout unit = \"seconds\">5</tc:read-timeout>" + "<tc:write-timeout unit = \"seconds\">5</tc:write-timeout>" + "<tc:connection-timeout unit = \"seconds\">150</tc:connection-timeout>" + "<tc:server-side-config auto-create = \"false\">" + "<tc:default-resource from = \"main\"/>" + "</tc:server-side-config></tc:cluster>"; assertElement(inputString, returnElement); }
@Test public void testTranslateServiceCreationConfiguration() throws Exception { URI connectionUri = new URI("terracotta://localhost:9510/my-application"); ClusteringServiceConfiguration serviceConfig = ClusteringServiceConfigurationBuilder.cluster(connectionUri) .timeouts(Timeouts.DEFAULT) .autoCreate() .defaultServerResource("main") .resourcePool("primaryresource", 5, MemoryUnit.GB) .resourcePool("secondaryresource", 10, MemoryUnit.GB, "optional") .build(); ClusteringCacheManagerServiceConfigurationParser parser = new ClusteringCacheManagerServiceConfigurationParser(); Element returnElement = parser.unparseServiceCreationConfiguration(serviceConfig); String inputString = "<tc:cluster xmlns:tc = \"http://www.ehcache.org/v3/clustered\">" + "<tc:connection url = \"terracotta://localhost:9510/my-application\"/>" + "<tc:read-timeout unit = \"seconds\">5</tc:read-timeout>" + "<tc:write-timeout unit = \"seconds\">5</tc:write-timeout>" + "<tc:connection-timeout unit = \"seconds\">150</tc:connection-timeout>" + "<tc:server-side-config auto-create = \"true\">" + "<tc:default-resource from = \"main\"/>" + "<tc:shared-pool name = \"primaryresource\" unit = \"B\">5368709120</tc:shared-pool>" + "<tc:shared-pool from = \"optional\" name = \"secondaryresource\" unit = \"B\">10737418240</tc:shared-pool>" + "</tc:server-side-config></tc:cluster>"; assertElement(inputString, returnElement); }