@Override public JsonObject toJson() { JsonObject root = new JsonObject(); root.add("name", config.getName()); JsonArray publisherList = new JsonArray(); for (WanPublisherConfig publisherConfig : config.getWanPublisherConfigs()) { WanPublisherConfigDTO dto = new WanPublisherConfigDTO(publisherConfig); publisherList.add(dto.toJson()); } root.add("publishers", publisherList); return root; }
@Override public void fromJson(JsonObject json) { config = new WanReplicationConfig(); config.setName(json.get("name").asString()); List<WanPublisherConfig> publisherConfigs = config.getWanPublisherConfigs(); JsonArray publishers = json.get("publishers").asArray(); int size = publishers.size(); for (int i = 0; i < size; i++) { WanPublisherConfigDTO dto = new WanPublisherConfigDTO(new WanPublisherConfig()); dto.fromJson(publishers.get(0).asObject()); publisherConfigs.add(dto.getConfig()); } }
@Test public void testWanReplicationConfig() { WanReplicationConfig wcfg = config.getWanReplicationConfig("testWan"); assertNotNull(wcfg); assertEquals(2, wcfg.getTargetClusterConfigs().size()); WanTargetClusterConfig targetCfg = wcfg.getTargetClusterConfigs().get(0); assertNotNull(targetCfg); assertEquals("tokyo", targetCfg.getGroupName()); assertEquals("tokyo-pass", targetCfg.getGroupPassword()); assertEquals("com.hazelcast.wan.WanNoDelayReplication", targetCfg.getReplicationImpl()); assertEquals(2, targetCfg.getEndpoints().size()); assertEquals("10.2.1.1:5701", targetCfg.getEndpoints().get(0)); assertEquals("10.2.1.2:5701", targetCfg.getEndpoints().get(1)); assertEquals(wanReplication, wcfg.getTargetClusterConfigs().get(1).getReplicationImplObject()); }
@Test public void testWanReplicationConfig() { WanReplicationConfig wcfg = config.getWanReplicationConfig("testWan"); assertNotNull(wcfg); assertFalse(wcfg.isSnapshotEnabled()); assertEquals(2, wcfg.getTargetClusterConfigs().size()); WanTargetClusterConfig targetCfg = wcfg.getTargetClusterConfigs().get(0); assertNotNull(targetCfg); assertEquals("tokyo", targetCfg.getGroupName()); assertEquals("tokyo-pass", targetCfg.getGroupPassword()); assertEquals("com.hazelcast.wan.impl.WanNoDelayReplication", targetCfg.getReplicationImpl()); assertEquals(2, targetCfg.getEndpoints().size()); assertEquals("10.2.1.1:5701", targetCfg.getEndpoints().get(0)); assertEquals("10.2.1.2:5701", targetCfg.getEndpoints().get(1)); assertEquals(wanReplication, wcfg.getTargetClusterConfigs().get(1).getReplicationImplObject()); WanTargetClusterConfig targetClusterConfig0 = wcfg.getTargetClusterConfigs().get(0); WanTargetClusterConfig targetClusterConfig1 = wcfg.getTargetClusterConfigs().get(1); assertEquals( WanAcknowledgeType.ACK_ON_OPERATION_COMPLETE, targetClusterConfig0.getAcknowledgeType()); assertEquals(WanAcknowledgeType.ACK_ON_RECEIPT, targetClusterConfig1.getAcknowledgeType()); assertEquals(WANQueueFullBehavior.THROW_EXCEPTION, targetClusterConfig0.getQueueFullBehavior()); assertEquals(7, targetClusterConfig0.getBatchSize()); assertEquals(14, targetClusterConfig0.getBatchMaxDelayMillis()); assertEquals(21, targetClusterConfig0.getQueueCapacity()); assertEquals(28, targetClusterConfig0.getResponseTimeoutMillis()); }