http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/manager/handlers/DefaultMessageInvoker.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/manager/handlers/DefaultMessageInvoker.java b/src/main/java/org/apache/gossip/manager/handlers/DefaultMessageInvoker.java index 034691d..5b78ce3 100644 --- a/src/main/java/org/apache/gossip/manager/handlers/DefaultMessageInvoker.java +++ b/src/main/java/org/apache/gossip/manager/handlers/DefaultMessageInvoker.java @@ -29,8 +29,8 @@ public class DefaultMessageInvoker implements MessageInvoker { mic = new MessageInvokerCombiner(); mic.add(new SimpleMessageInvoker(Response.class, new ResponseHandler())); mic.add(new SimpleMessageInvoker(ShutdownMessage.class, new ShutdownMessageHandler())); - mic.add(new SimpleMessageInvoker(GossipDataMessage.class, new GossipDataMessageHandler())); - mic.add(new SimpleMessageInvoker(SharedGossipDataMessage.class, new SharedGossipDataMessageHandler())); + mic.add(new SimpleMessageInvoker(PerNodeDataMessage.class, new PerNodeDataMessageHandler())); + mic.add(new SimpleMessageInvoker(SharedDataMessage.class, new SharedDataMessageHandler())); mic.add(new SimpleMessageInvoker(ActiveGossipMessage.class, new ActiveGossipMessageHandler())); }
http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/manager/handlers/GossipDataMessageHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/manager/handlers/GossipDataMessageHandler.java b/src/main/java/org/apache/gossip/manager/handlers/GossipDataMessageHandler.java deleted file mode 100644 index edf2579..0000000 --- a/src/main/java/org/apache/gossip/manager/handlers/GossipDataMessageHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.gossip.manager.handlers; - -import org.apache.gossip.manager.GossipCore; -import org.apache.gossip.manager.GossipManager; -import org.apache.gossip.model.Base; -import org.apache.gossip.udp.UdpGossipDataMessage; - -public class GossipDataMessageHandler implements MessageHandler { - @Override - public void invoke(GossipCore gossipCore, GossipManager gossipManager, Base base) { - UdpGossipDataMessage message = (UdpGossipDataMessage) base; - gossipCore.addPerNodeData(message); - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/manager/handlers/PerNodeDataMessageHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/manager/handlers/PerNodeDataMessageHandler.java b/src/main/java/org/apache/gossip/manager/handlers/PerNodeDataMessageHandler.java new file mode 100644 index 0000000..b3a785e --- /dev/null +++ b/src/main/java/org/apache/gossip/manager/handlers/PerNodeDataMessageHandler.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gossip.manager.handlers; + +import org.apache.gossip.manager.GossipCore; +import org.apache.gossip.manager.GossipManager; +import org.apache.gossip.model.Base; +import org.apache.gossip.udp.UdpPerNodeDataMessage; + +public class PerNodeDataMessageHandler implements MessageHandler { + @Override + public void invoke(GossipCore gossipCore, GossipManager gossipManager, Base base) { + UdpPerNodeDataMessage message = (UdpPerNodeDataMessage) base; + gossipCore.addPerNodeData(message); + } +} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/manager/handlers/SharedDataMessageHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/manager/handlers/SharedDataMessageHandler.java b/src/main/java/org/apache/gossip/manager/handlers/SharedDataMessageHandler.java new file mode 100644 index 0000000..89ca4a0 --- /dev/null +++ b/src/main/java/org/apache/gossip/manager/handlers/SharedDataMessageHandler.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gossip.manager.handlers; + +import org.apache.gossip.manager.GossipCore; +import org.apache.gossip.manager.GossipManager; +import org.apache.gossip.model.Base; +import org.apache.gossip.udp.UdpSharedDataMessage; + +public class SharedDataMessageHandler implements MessageHandler{ + @Override + public void invoke(GossipCore gossipCore, GossipManager gossipManager, Base base) { + UdpSharedDataMessage message = (UdpSharedDataMessage) base; + gossipCore.addSharedData(message); + } +} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/manager/handlers/SharedGossipDataMessageHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/manager/handlers/SharedGossipDataMessageHandler.java b/src/main/java/org/apache/gossip/manager/handlers/SharedGossipDataMessageHandler.java deleted file mode 100644 index e9d5343..0000000 --- a/src/main/java/org/apache/gossip/manager/handlers/SharedGossipDataMessageHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.gossip.manager.handlers; - -import org.apache.gossip.manager.GossipCore; -import org.apache.gossip.manager.GossipManager; -import org.apache.gossip.model.Base; -import org.apache.gossip.udp.UdpSharedGossipDataMessage; - -public class SharedGossipDataMessageHandler implements MessageHandler{ - @Override - public void invoke(GossipCore gossipCore, GossipManager gossipManager, Base base) { - UdpSharedGossipDataMessage message = (UdpSharedGossipDataMessage) base; - gossipCore.addSharedData(message); - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/manager/handlers/ShutdownMessageHandler.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/manager/handlers/ShutdownMessageHandler.java b/src/main/java/org/apache/gossip/manager/handlers/ShutdownMessageHandler.java index c4adea2..a40c7a1 100644 --- a/src/main/java/org/apache/gossip/manager/handlers/ShutdownMessageHandler.java +++ b/src/main/java/org/apache/gossip/manager/handlers/ShutdownMessageHandler.java @@ -20,14 +20,14 @@ package org.apache.gossip.manager.handlers; import org.apache.gossip.manager.GossipCore; import org.apache.gossip.manager.GossipManager; import org.apache.gossip.model.Base; -import org.apache.gossip.model.GossipDataMessage; +import org.apache.gossip.model.PerNodeDataMessage; import org.apache.gossip.model.ShutdownMessage; public class ShutdownMessageHandler implements MessageHandler { @Override public void invoke(GossipCore gossipCore, GossipManager gossipManager, Base base) { ShutdownMessage s = (ShutdownMessage) base; - GossipDataMessage m = new GossipDataMessage(); + PerNodeDataMessage m = new PerNodeDataMessage(); m.setKey(ShutdownMessage.PER_NODE_KEY); m.setNodeId(s.getNodeId()); m.setPayload(base); http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/manager/random/RandomGossipManager.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/manager/random/RandomGossipManager.java b/src/main/java/org/apache/gossip/manager/random/RandomGossipManager.java deleted file mode 100644 index 3ac237a..0000000 --- a/src/main/java/org/apache/gossip/manager/random/RandomGossipManager.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.gossip.manager.random; - -import com.codahale.metrics.MetricRegistry; -import com.fasterxml.jackson.core.JsonGenerator.Feature; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.gossip.GossipMember; -import org.apache.gossip.GossipSettings; -import org.apache.gossip.crdt.CrdtModule; -import org.apache.gossip.event.GossipListener; -import org.apache.gossip.manager.GossipManager; -import org.apache.gossip.manager.handlers.DefaultMessageInvoker; -import org.apache.gossip.manager.handlers.MessageInvoker; - -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class RandomGossipManager extends GossipManager { - - public static ManagerBuilder newBuilder() { - return new ManagerBuilder(); - } - - public static final class ManagerBuilder { - private String cluster; - private URI uri; - private String id; - private GossipSettings settings; - private List<GossipMember> gossipMembers; - private GossipListener listener; - private MetricRegistry registry; - private Map<String,String> properties; - private ObjectMapper objectMapper; - private MessageInvoker messageInvoker; - - private ManagerBuilder() {} - - private void checkArgument(boolean check, String msg) { - if (!check) { - throw new IllegalArgumentException(msg); - } - } - - public ManagerBuilder cluster(String cluster) { - this.cluster = cluster; - return this; - } - - public ManagerBuilder properties(Map<String,String> properties) { - this.properties = properties; - return this; - } - - public ManagerBuilder withId(String id) { - this.id = id; - return this; - } - - public ManagerBuilder settings(GossipSettings settings) { - this.settings = settings; - return this; - } - - public ManagerBuilder gossipMembers(List<GossipMember> members) { - this.gossipMembers = members; - return this; - } - - public ManagerBuilder listener(GossipListener listener) { - this.listener = listener; - return this; - } - - public ManagerBuilder registry(MetricRegistry registry) { - this.registry = registry; - return this; - } - - public ManagerBuilder uri(URI uri){ - this.uri = uri; - return this; - } - - public ManagerBuilder mapper(ObjectMapper objectMapper){ - this.objectMapper = objectMapper; - return this; - } - - public ManagerBuilder messageInvoker(MessageInvoker messageInvoker) { - this.messageInvoker = messageInvoker; - return this; - } - - public RandomGossipManager build() { - checkArgument(id != null, "You must specify an id"); - checkArgument(cluster != null, "You must specify a cluster name"); - checkArgument(settings != null, "You must specify gossip settings"); - checkArgument(uri != null, "You must specify a uri"); - checkArgument(registry != null, "You must specify a MetricRegistry"); - if (properties == null){ - properties = new HashMap<String,String>(); - } - if (listener == null){ - listener((a,b) -> {}); - } - if (gossipMembers == null) { - gossipMembers = new ArrayList<>(); - } - if (objectMapper == null) { - objectMapper = new ObjectMapper(); - objectMapper.enableDefaultTyping(); - objectMapper.registerModule(new CrdtModule()); - objectMapper.configure(Feature.WRITE_NUMBERS_AS_STRINGS, false); - } - if (messageInvoker == null) { - messageInvoker = new DefaultMessageInvoker(); - } - return new RandomGossipManager(cluster, uri, id, properties, settings, gossipMembers, listener, registry, objectMapper, messageInvoker); - } - } - - private RandomGossipManager(String cluster, URI uri, String id, Map<String,String> properties, GossipSettings settings, - List<GossipMember> gossipMembers, GossipListener listener, MetricRegistry registry, ObjectMapper objectMapper, MessageInvoker messageInvoker) { - super(cluster, uri, id, properties, settings, gossipMembers, listener, registry, objectMapper, messageInvoker); - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/model/ActiveGossipMessage.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/model/ActiveGossipMessage.java b/src/main/java/org/apache/gossip/model/ActiveGossipMessage.java index 438f42a..a3c45b8 100644 --- a/src/main/java/org/apache/gossip/model/ActiveGossipMessage.java +++ b/src/main/java/org/apache/gossip/model/ActiveGossipMessage.java @@ -22,17 +22,17 @@ import java.util.List; public class ActiveGossipMessage extends Base { - private List<GossipMember> members = new ArrayList<>(); + private List<Member> members = new ArrayList<>(); public ActiveGossipMessage(){ } - public List<GossipMember> getMembers() { + public List<Member> getMembers() { return members; } - public void setMembers(List<GossipMember> members) { + public void setMembers(List<Member> members) { this.members = members; } http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/model/Base.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/model/Base.java b/src/main/java/org/apache/gossip/model/Base.java index 4551f2a..1b66310 100644 --- a/src/main/java/org/apache/gossip/model/Base.java +++ b/src/main/java/org/apache/gossip/model/Base.java @@ -19,9 +19,9 @@ package org.apache.gossip.model; import org.apache.gossip.udp.UdpActiveGossipMessage; import org.apache.gossip.udp.UdpActiveGossipOk; -import org.apache.gossip.udp.UdpGossipDataMessage; +import org.apache.gossip.udp.UdpPerNodeDataMessage; import org.apache.gossip.udp.UdpNotAMemberFault; -import org.apache.gossip.udp.UdpSharedGossipDataMessage; +import org.apache.gossip.udp.UdpSharedDataMessage; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonSubTypes; @@ -39,10 +39,10 @@ import com.fasterxml.jackson.annotation.JsonSubTypes.Type; @Type(value = UdpActiveGossipOk.class, name = "UdpActiveGossipOk"), @Type(value = UdpActiveGossipMessage.class, name = "UdpActiveGossipMessage"), @Type(value = UdpNotAMemberFault.class, name = "UdpNotAMemberFault"), - @Type(value = GossipDataMessage.class, name = "GossipDataMessage"), - @Type(value = UdpGossipDataMessage.class, name = "UdpGossipDataMessage"), - @Type(value = SharedGossipDataMessage.class, name = "SharedGossipDataMessage"), - @Type(value = UdpSharedGossipDataMessage.class, name = "UdpSharedGossipDataMessage") + @Type(value = PerNodeDataMessage.class, name = "PerNodeDataMessage"), + @Type(value = UdpPerNodeDataMessage.class, name = "UdpPerNodeDataMessage"), + @Type(value = SharedDataMessage.class, name = "SharedDataMessage"), + @Type(value = UdpSharedDataMessage.class, name = "UdpSharedDataMessage") }) public class Base { http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/model/GossipDataMessage.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/model/GossipDataMessage.java b/src/main/java/org/apache/gossip/model/GossipDataMessage.java deleted file mode 100644 index e9aae61..0000000 --- a/src/main/java/org/apache/gossip/model/GossipDataMessage.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.gossip.model; - -public class GossipDataMessage extends Base { - - private String nodeId; - private String key; - private Object payload; - private Long timestamp; - private Long expireAt; - - public String getNodeId() { - return nodeId; - } - public void setNodeId(String nodeId) { - this.nodeId = nodeId; - } - public String getKey() { - return key; - } - public void setKey(String key) { - this.key = key; - } - public Object getPayload() { - return payload; - } - public void setPayload(Object payload) { - this.payload = payload; - } - public Long getTimestamp() { - return timestamp; - } - public void setTimestamp(Long timestamp) { - this.timestamp = timestamp; - } - public Long getExpireAt() { - return expireAt; - } - public void setExpireAt(Long expireAt) { - this.expireAt = expireAt; - } - @Override - public String toString() { - return "GossipDataMessage [nodeId=" + nodeId + ", key=" + key + ", payload=" + payload - + ", timestamp=" + timestamp + ", expireAt=" + expireAt + "]"; - } - - - -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/model/GossipMember.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/model/GossipMember.java b/src/main/java/org/apache/gossip/model/GossipMember.java deleted file mode 100644 index a318776..0000000 --- a/src/main/java/org/apache/gossip/model/GossipMember.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.gossip.model; - -import java.util.Map; - -public class GossipMember { - - private String cluster; - private String uri; - private String id; - private Long heartbeat; - private Map<String,String> properties; - - public GossipMember(){ - - } - - public GossipMember(String cluster, String uri, String id, Long heartbeat){ - this.cluster = cluster; - this.uri = uri; - this.id = id; - this.heartbeat = heartbeat; - } - - public String getCluster() { - return cluster; - } - - public void setCluster(String cluster) { - this.cluster = cluster; - } - - public String getUri() { - return uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public Long getHeartbeat() { - return heartbeat; - } - - public void setHeartbeat(Long heartbeat) { - this.heartbeat = heartbeat; - } - - public Map<String, String> getProperties() { - return properties; - } - - public void setProperties(Map<String, String> properties) { - this.properties = properties; - } - - @Override - public String toString() { - return "GossipMember [cluster=" + cluster + ", uri=" + uri + ", id=" + id + ", heartbeat=" - + heartbeat + ", properties=" + properties + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/model/Member.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/model/Member.java b/src/main/java/org/apache/gossip/model/Member.java new file mode 100644 index 0000000..d86aad8 --- /dev/null +++ b/src/main/java/org/apache/gossip/model/Member.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gossip.model; + +import java.util.Map; + +public class Member { + + private String cluster; + private String uri; + private String id; + private Long heartbeat; + private Map<String,String> properties; + + public Member(){ + + } + + public Member(String cluster, String uri, String id, Long heartbeat){ + this.cluster = cluster; + this.uri = uri; + this.id = id; + this.heartbeat = heartbeat; + } + + public String getCluster() { + return cluster; + } + + public void setCluster(String cluster) { + this.cluster = cluster; + } + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Long getHeartbeat() { + return heartbeat; + } + + public void setHeartbeat(Long heartbeat) { + this.heartbeat = heartbeat; + } + + public Map<String, String> getProperties() { + return properties; + } + + public void setProperties(Map<String, String> properties) { + this.properties = properties; + } + + @Override + public String toString() { + return "Member [cluster=" + cluster + ", uri=" + uri + ", id=" + id + ", heartbeat=" + + heartbeat + ", properties=" + properties + "]"; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/model/PerNodeDataMessage.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/model/PerNodeDataMessage.java b/src/main/java/org/apache/gossip/model/PerNodeDataMessage.java new file mode 100644 index 0000000..2d1cdef --- /dev/null +++ b/src/main/java/org/apache/gossip/model/PerNodeDataMessage.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gossip.model; + +public class PerNodeDataMessage extends Base { + + private String nodeId; + private String key; + private Object payload; + private Long timestamp; + private Long expireAt; + + public String getNodeId() { + return nodeId; + } + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + public String getKey() { + return key; + } + public void setKey(String key) { + this.key = key; + } + public Object getPayload() { + return payload; + } + public void setPayload(Object payload) { + this.payload = payload; + } + public Long getTimestamp() { + return timestamp; + } + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + public Long getExpireAt() { + return expireAt; + } + public void setExpireAt(Long expireAt) { + this.expireAt = expireAt; + } + @Override + public String toString() { + return "GossipDataMessage [nodeId=" + nodeId + ", key=" + key + ", payload=" + payload + + ", timestamp=" + timestamp + ", expireAt=" + expireAt + "]"; + } + + + +} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/model/SharedDataMessage.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/model/SharedDataMessage.java b/src/main/java/org/apache/gossip/model/SharedDataMessage.java new file mode 100644 index 0000000..e423be8 --- /dev/null +++ b/src/main/java/org/apache/gossip/model/SharedDataMessage.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gossip.model; + +public class SharedDataMessage extends Base { + + private String nodeId; + private String key; + private Object payload; + private Long timestamp; + private Long expireAt; + + public String getNodeId() { + return nodeId; + } + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + public String getKey() { + return key; + } + public void setKey(String key) { + this.key = key; + } + public Object getPayload() { + return payload; + } + public void setPayload(Object payload) { + this.payload = payload; + } + public Long getTimestamp() { + return timestamp; + } + public void setTimestamp(Long timestamp) { + this.timestamp = timestamp; + } + public Long getExpireAt() { + return expireAt; + } + public void setExpireAt(Long expireAt) { + this.expireAt = expireAt; + } + @Override + public String toString() { + return "SharedGossipDataMessage [nodeId=" + nodeId + ", key=" + key + ", payload=" + payload + + ", timestamp=" + timestamp + ", expireAt=" + expireAt + "]"; + } +} + http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/model/SharedGossipDataMessage.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/model/SharedGossipDataMessage.java b/src/main/java/org/apache/gossip/model/SharedGossipDataMessage.java deleted file mode 100644 index dc80f05..0000000 --- a/src/main/java/org/apache/gossip/model/SharedGossipDataMessage.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.gossip.model; - -public class SharedGossipDataMessage extends Base { - - private String nodeId; - private String key; - private Object payload; - private Long timestamp; - private Long expireAt; - - public String getNodeId() { - return nodeId; - } - public void setNodeId(String nodeId) { - this.nodeId = nodeId; - } - public String getKey() { - return key; - } - public void setKey(String key) { - this.key = key; - } - public Object getPayload() { - return payload; - } - public void setPayload(Object payload) { - this.payload = payload; - } - public Long getTimestamp() { - return timestamp; - } - public void setTimestamp(Long timestamp) { - this.timestamp = timestamp; - } - public Long getExpireAt() { - return expireAt; - } - public void setExpireAt(Long expireAt) { - this.expireAt = expireAt; - } - @Override - public String toString() { - return "SharedGossipDataMessage [nodeId=" + nodeId + ", key=" + key + ", payload=" + payload - + ", timestamp=" + timestamp + ", expireAt=" + expireAt + "]"; - } -} - http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/udp/UdpGossipDataMessage.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/udp/UdpGossipDataMessage.java b/src/main/java/org/apache/gossip/udp/UdpGossipDataMessage.java deleted file mode 100644 index f2042a5..0000000 --- a/src/main/java/org/apache/gossip/udp/UdpGossipDataMessage.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.gossip.udp; - -import org.apache.gossip.model.GossipDataMessage; - -public class UdpGossipDataMessage extends GossipDataMessage implements Trackable { - - private String uriFrom; - private String uuid; - - public String getUriFrom() { - return uriFrom; - } - - public void setUriFrom(String uriFrom) { - this.uriFrom = uriFrom; - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - @Override - public String toString() { - return "UdpGossipDataMessage [uriFrom=" + uriFrom + ", uuid=" + uuid + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/udp/UdpPerNodeDataMessage.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/udp/UdpPerNodeDataMessage.java b/src/main/java/org/apache/gossip/udp/UdpPerNodeDataMessage.java new file mode 100644 index 0000000..6eb170a --- /dev/null +++ b/src/main/java/org/apache/gossip/udp/UdpPerNodeDataMessage.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gossip.udp; + +import org.apache.gossip.model.PerNodeDataMessage; + +public class UdpPerNodeDataMessage extends PerNodeDataMessage implements Trackable { + + private String uriFrom; + private String uuid; + + public String getUriFrom() { + return uriFrom; + } + + public void setUriFrom(String uriFrom) { + this.uriFrom = uriFrom; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + @Override + public String toString() { + return "UdpGossipDataMessage [uriFrom=" + uriFrom + ", uuid=" + uuid + "]"; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/udp/UdpSharedDataMessage.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/udp/UdpSharedDataMessage.java b/src/main/java/org/apache/gossip/udp/UdpSharedDataMessage.java new file mode 100644 index 0000000..1658503 --- /dev/null +++ b/src/main/java/org/apache/gossip/udp/UdpSharedDataMessage.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gossip.udp; + +import org.apache.gossip.model.SharedDataMessage; + +public class UdpSharedDataMessage extends SharedDataMessage implements Trackable { + + private String uriFrom; + private String uuid; + + public String getUriFrom() { + return uriFrom; + } + + public void setUriFrom(String uriFrom) { + this.uriFrom = uriFrom; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + @Override + public String toString() { + return "UdpSharedGossipDataMessage [uriFrom=" + uriFrom + ", uuid=" + uuid + ", getNodeId()=" + + getNodeId() + ", getKey()=" + getKey() + ", getPayload()=" + getPayload() + + ", getTimestamp()=" + getTimestamp() + ", getExpireAt()=" + getExpireAt() + "]"; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/main/java/org/apache/gossip/udp/UdpSharedGossipDataMessage.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/gossip/udp/UdpSharedGossipDataMessage.java b/src/main/java/org/apache/gossip/udp/UdpSharedGossipDataMessage.java deleted file mode 100644 index 6020328..0000000 --- a/src/main/java/org/apache/gossip/udp/UdpSharedGossipDataMessage.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.gossip.udp; - -import org.apache.gossip.model.SharedGossipDataMessage; - -public class UdpSharedGossipDataMessage extends SharedGossipDataMessage implements Trackable { - - private String uriFrom; - private String uuid; - - public String getUriFrom() { - return uriFrom; - } - - public void setUriFrom(String uriFrom) { - this.uriFrom = uriFrom; - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - @Override - public String toString() { - return "UdpSharedGossipDataMessage [uriFrom=" + uriFrom + ", uuid=" + uuid + ", getNodeId()=" - + getNodeId() + ", getKey()=" + getKey() + ", getPayload()=" + getPayload() - + ", getTimestamp()=" + getTimestamp() + ", getExpireAt()=" + getExpireAt() + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/test/java/org/apache/gossip/AbstractIntegrationBase.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/AbstractIntegrationBase.java b/src/test/java/org/apache/gossip/AbstractIntegrationBase.java new file mode 100644 index 0000000..896157f --- /dev/null +++ b/src/test/java/org/apache/gossip/AbstractIntegrationBase.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.gossip; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.gossip.manager.GossipManager; +import org.junit.After; +import org.junit.Before; + +public abstract class AbstractIntegrationBase { + + List <GossipManager> nodes = new ArrayList<GossipManager>(); + + public void register(GossipManager manager){ + nodes.add(manager); + } + + @Before + public void before(){ + nodes = new ArrayList<GossipManager>(); + } + + @After + public void after(){ + for (GossipManager node: nodes){ + if (node !=null){ + node.shutdown(); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/test/java/org/apache/gossip/DataTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/DataTest.java b/src/test/java/org/apache/gossip/DataTest.java index 3892e9b..147702d 100644 --- a/src/test/java/org/apache/gossip/DataTest.java +++ b/src/test/java/org/apache/gossip/DataTest.java @@ -17,26 +17,26 @@ */ package org.apache.gossip; -import com.codahale.metrics.MetricRegistry; import java.net.URI; import java.net.URISyntaxException; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; import org.apache.gossip.crdt.GrowOnlySet; import org.apache.gossip.crdt.OrSet; -import org.apache.gossip.model.GossipDataMessage; -import org.apache.gossip.model.SharedGossipDataMessage; +import org.apache.gossip.manager.GossipManager; +import org.apache.gossip.manager.GossipManagerBuilder; +import org.apache.gossip.model.PerNodeDataMessage; +import org.apache.gossip.model.SharedDataMessage; import org.junit.Test; import io.teknek.tunit.TUnit; -public class DataTest { +public class DataTest extends AbstractIntegrationBase { private String orSetKey = "cror"; @@ -47,25 +47,25 @@ public class DataTest { settings.setPersistDataState(false); String cluster = UUID.randomUUID().toString(); int seedNodes = 1; - List<GossipMember> startupMembers = new ArrayList<>(); + List<Member> startupMembers = new ArrayList<>(); for (int i = 1; i < seedNodes+1; ++i) { URI uri = new URI("udp://" + "127.0.0.1" + ":" + (50000 + i)); - startupMembers.add(new RemoteGossipMember(cluster, uri, i + "")); + startupMembers.add(new RemoteMember(cluster, uri, i + "")); } - final List<GossipService> clients = new ArrayList<>(); + final List<GossipManager> clients = new ArrayList<>(); final int clusterMembers = 2; - for (int i = 1; i < clusterMembers+1; ++i) { + for (int i = 1; i < clusterMembers + 1; ++i) { URI uri = new URI("udp://" + "127.0.0.1" + ":" + (50000 + i)); - GossipService gossipService = new GossipService(cluster, uri, i + "", - new HashMap<String,String>(), startupMembers, settings, - (a,b) -> {}, new MetricRegistry()); + GossipManager gossipService = GossipManagerBuilder.newBuilder().cluster(cluster).uri(uri) + .id(i + "").gossipMembers(startupMembers).gossipSettings(settings).build(); clients.add(gossipService); - gossipService.start(); + gossipService.init(); + register(gossipService); } TUnit.assertThat(() -> { int total = 0; for (int i = 0; i < clusterMembers; ++i) { - total += clients.get(i).getGossipManager().getLiveMembers().size(); + total += clients.get(i).getLiveMembers().size(); } return total; }).afterWaitingAtMost(20, TimeUnit.SECONDS).isEqualTo(2); @@ -73,7 +73,7 @@ public class DataTest { clients.get(0).gossipSharedData(sharedMsg()); TUnit.assertThat(()-> { - GossipDataMessage x = clients.get(1).findPerNodeData(1 + "", "a"); + PerNodeDataMessage x = clients.get(1).findPerNodeGossipData(1 + "", "a"); if (x == null) return ""; else @@ -81,7 +81,7 @@ public class DataTest { }).afterWaitingAtMost(20, TimeUnit.SECONDS).isEqualTo("b"); TUnit.assertThat(() -> { - SharedGossipDataMessage x = clients.get(1).findSharedData("a"); + SharedDataMessage x = clients.get(1).findSharedGossipData("a"); if (x == null) return ""; else @@ -95,71 +95,67 @@ public class DataTest { assertThatOrSetIsMerged(clients); dropIt(clients); assertThatOrSetDelIsMerged(clients); - - for (int i = 0; i < clusterMembers; ++i) { - clients.get(i).shutdown(); - } } - private void givenOrs(List<GossipService> clients) { + private void givenOrs(List<GossipManager> clients) { { - SharedGossipDataMessage d = new SharedGossipDataMessage(); + SharedDataMessage d = new SharedDataMessage(); d.setKey(orSetKey); d.setPayload(new OrSet<String>("1", "2")); d.setExpireAt(Long.MAX_VALUE); d.setTimestamp(System.currentTimeMillis()); - clients.get(0).getGossipManager().merge(d); + clients.get(0).merge(d); } { - SharedGossipDataMessage d = new SharedGossipDataMessage(); + SharedDataMessage d = new SharedDataMessage(); d.setKey(orSetKey); d.setPayload(new OrSet<String>("3", "4")); d.setExpireAt(Long.MAX_VALUE); d.setTimestamp(System.currentTimeMillis()); - clients.get(1).getGossipManager().merge(d); + clients.get(1).merge(d); } } - private void dropIt(List<GossipService> clients) { + private void dropIt(List<GossipManager> clients) { @SuppressWarnings("unchecked") - OrSet<String> o = (OrSet<String>) clients.get(0).getGossipManager().findCrdt(orSetKey); + OrSet<String> o = (OrSet<String>) clients.get(0).findCrdt(orSetKey); OrSet<String> o2 = new OrSet<String>(o, new OrSet.Builder<String>().remove("3")); - SharedGossipDataMessage d = new SharedGossipDataMessage(); + SharedDataMessage d = new SharedDataMessage(); d.setKey(orSetKey); d.setPayload(o2); d.setExpireAt(Long.MAX_VALUE); d.setTimestamp(System.currentTimeMillis()); - clients.get(0).getGossipManager().merge(d); + clients.get(0).merge(d); } - private void assertThatOrSetIsMerged(final List<GossipService> clients){ + private void assertThatOrSetIsMerged(final List<GossipManager> clients){ TUnit.assertThat(() -> { - return clients.get(0).getGossipManager().findCrdt(orSetKey).value(); + return clients.get(0).findCrdt(orSetKey).value(); }).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo(new OrSet<String>("1", "2", "3", "4").value()); TUnit.assertThat(() -> { - return clients.get(1).getGossipManager().findCrdt(orSetKey).value(); + return clients.get(1).findCrdt(orSetKey).value(); }).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo(new OrSet<String>("1", "2", "3", "4").value()); } - private void assertThatOrSetDelIsMerged(final List<GossipService> clients){ + private void assertThatOrSetDelIsMerged(final List<GossipManager> clients){ TUnit.assertThat(() -> { - return clients.get(0).getGossipManager().findCrdt(orSetKey); + return clients.get(0).findCrdt(orSetKey); }).afterWaitingAtMost(10, TimeUnit.SECONDS).equals(new OrSet<String>("1", "2", "4")); } - private void givenDifferentDatumsInSet(final List<GossipService> clients){ - clients.get(0).getGossipManager().merge(CrdtMessage("1")); - clients.get(1).getGossipManager().merge(CrdtMessage("2")); + private void givenDifferentDatumsInSet(final List<GossipManager> clients){ + clients.get(0).merge(CrdtMessage("1")); + clients.get(1).merge(CrdtMessage("2")); } - private void assertThatListIsMerged(final List<GossipService> clients){ + private void assertThatListIsMerged(final List<GossipManager> clients){ TUnit.assertThat(() -> { - return clients.get(0).getGossipManager().findCrdt("cr"); + return clients.get(0).findCrdt("cr"); }).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo(new GrowOnlySet<String>(Arrays.asList("1","2"))); } - private SharedGossipDataMessage CrdtMessage(String item){ - SharedGossipDataMessage d = new SharedGossipDataMessage(); + private SharedDataMessage CrdtMessage(String item){ + SharedDataMessage d = new SharedDataMessage(); d.setKey("cr"); d.setPayload(new GrowOnlySet<String>( Arrays.asList(item))); d.setExpireAt(Long.MAX_VALUE); @@ -167,8 +163,8 @@ public class DataTest { return d; } - private GossipDataMessage msg(){ - GossipDataMessage g = new GossipDataMessage(); + private PerNodeDataMessage msg(){ + PerNodeDataMessage g = new PerNodeDataMessage(); g.setExpireAt(Long.MAX_VALUE); g.setKey("a"); g.setPayload("b"); @@ -176,8 +172,8 @@ public class DataTest { return g; } - private SharedGossipDataMessage sharedMsg(){ - SharedGossipDataMessage g = new SharedGossipDataMessage(); + private SharedDataMessage sharedMsg(){ + SharedDataMessage g = new SharedDataMessage(); g.setExpireAt(Long.MAX_VALUE); g.setKey("a"); g.setPayload("c"); http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/test/java/org/apache/gossip/GossipMemberTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/GossipMemberTest.java b/src/test/java/org/apache/gossip/GossipMemberTest.java deleted file mode 100644 index 272c7fb..0000000 --- a/src/test/java/org/apache/gossip/GossipMemberTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.gossip; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; - -import org.junit.Assert; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; - -@RunWith(JUnitPlatform.class) -public class GossipMemberTest { - - @Test - public void testHashCodeFromGossip40() throws URISyntaxException { - Assert.assertNotEquals( - new LocalGossipMember("mycluster", new URI("udp://4.4.4.4:1000"), "myid", 1, new HashMap<String,String>(), 10, 5, "exponential") - .hashCode(), - new LocalGossipMember("mycluster", new URI("udp://4.4.4.5:1005"), "yourid", 11, new HashMap<String,String>(), 11, 6, "exponential") - .hashCode()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/test/java/org/apache/gossip/IdAndPropertyTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/IdAndPropertyTest.java b/src/test/java/org/apache/gossip/IdAndPropertyTest.java index 1eb0aee..7c02d2d 100644 --- a/src/test/java/org/apache/gossip/IdAndPropertyTest.java +++ b/src/test/java/org/apache/gossip/IdAndPropertyTest.java @@ -28,43 +28,54 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import org.apache.gossip.manager.DatacenterRackAwareActiveGossiper; +import org.apache.gossip.manager.GossipManager; +import org.apache.gossip.manager.GossipManagerBuilder; import org.junit.jupiter.api.Test; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; -import com.codahale.metrics.MetricRegistry; - import io.teknek.tunit.TUnit; @RunWith(JUnitPlatform.class) -public class IdAndPropertyTest { +public class IdAndPropertyTest extends AbstractIntegrationBase { @Test - public void testDatacenterRackGossiper() throws URISyntaxException, UnknownHostException, InterruptedException{ + public void testDatacenterRackGossiper() throws URISyntaxException, UnknownHostException, InterruptedException { GossipSettings settings = new GossipSettings(); settings.setActiveGossipClass(DatacenterRackAwareActiveGossiper.class.getName()); - List<GossipMember> startupMembers = new ArrayList<>(); + List<Member> startupMembers = new ArrayList<>(); Map<String, String> x = new HashMap<>(); x.put("a", "b"); x.put("datacenter", "dc1"); x.put("rack", "rack1"); - GossipService gossipService1 = new GossipService("a", new URI("udp://" + "127.0.0.1" + ":" + (29000 + 0)), "0", x, startupMembers, settings, - (a, b) -> {}, new MetricRegistry()); - gossipService1.start(); + GossipManager gossipService1 = GossipManagerBuilder.newBuilder() + .cluster("a") + .uri(new URI("udp://" + "127.0.0.1" + ":" + (29000 + 0))) + .id("0") + .properties(x) + .gossipMembers(startupMembers) + .gossipSettings(settings).build(); + gossipService1.init(); + register(gossipService1); Map<String, String> y = new HashMap<>(); y.put("a", "c"); y.put("datacenter", "dc2"); y.put("rack", "rack2"); - GossipService gossipService2 = new GossipService("a", new URI("udp://" + "127.0.0.1" + ":" + (29000 + 1)), "1", y, - Arrays.asList(new RemoteGossipMember("a", - new URI("udp://" + "127.0.0.1" + ":" + (29000 + 0)), "0")), - settings, (a, b) -> { }, new MetricRegistry()); - gossipService2.start(); + GossipManager gossipService2 = GossipManagerBuilder.newBuilder().cluster("a") + .uri( new URI("udp://" + "127.0.0.1" + ":" + (29000 + 1))) + .id("1") + .properties(y) + .gossipMembers(Arrays.asList(new RemoteMember("a", + new URI("udp://" + "127.0.0.1" + ":" + (29000 + 0)), "0"))) + .gossipSettings(settings).build(); + gossipService2.init(); + register(gossipService2); + TUnit.assertThat(() -> { String value = ""; try { - value = gossipService1.getGossipManager().getLiveMembers().get(0).getProperties().get("a"); + value = gossipService1.getLiveMembers().get(0).getProperties().get("a"); } catch (RuntimeException e){ } return value; }).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo("c"); @@ -72,12 +83,9 @@ public class IdAndPropertyTest { TUnit.assertThat(() -> { String value = ""; try { - value = gossipService2.getGossipManager().getLiveMembers().get(0).getProperties().get("a"); + value = gossipService2.getLiveMembers().get(0).getProperties().get("a"); } catch (RuntimeException e){ } return value; - }).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo("b"); - gossipService1.shutdown(); - gossipService2.shutdown(); - + }).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo("b"); } } http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/test/java/org/apache/gossip/MemberTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/MemberTest.java b/src/test/java/org/apache/gossip/MemberTest.java new file mode 100644 index 0000000..5f0d18a --- /dev/null +++ b/src/test/java/org/apache/gossip/MemberTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.gossip; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; + +import org.junit.Assert; +import org.junit.jupiter.api.Test; +import org.junit.platform.runner.JUnitPlatform; +import org.junit.runner.RunWith; + +@RunWith(JUnitPlatform.class) +public class MemberTest { + + @Test + public void testHashCodeFromGossip40() throws URISyntaxException { + Assert.assertNotEquals( + new LocalMember("mycluster", new URI("udp://4.4.4.4:1000"), "myid", 1, new HashMap<String,String>(), 10, 5, "exponential") + .hashCode(), + new LocalMember("mycluster", new URI("udp://4.4.4.5:1005"), "yourid", 11, new HashMap<String,String>(), 11, 6, "exponential") + .hashCode()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/test/java/org/apache/gossip/ShutdownDeadtimeTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/ShutdownDeadtimeTest.java b/src/test/java/org/apache/gossip/ShutdownDeadtimeTest.java index 6a0765b..48fb2cb 100644 --- a/src/test/java/org/apache/gossip/ShutdownDeadtimeTest.java +++ b/src/test/java/org/apache/gossip/ShutdownDeadtimeTest.java @@ -17,7 +17,6 @@ */ package org.apache.gossip; -import com.codahale.metrics.MetricRegistry; import io.teknek.tunit.TUnit; import java.net.URI; @@ -25,13 +24,14 @@ import java.net.URISyntaxException; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Random; import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; +import org.apache.gossip.manager.GossipManager; +import org.apache.gossip.manager.GossipManagerBuilder; import org.apache.log4j.Logger; import org.junit.platform.runner.JUnitPlatform; @@ -52,25 +52,31 @@ public class ShutdownDeadtimeTest { settings.setPersistDataState(false); String cluster = UUID.randomUUID().toString(); int seedNodes = 3; - List<GossipMember> startupMembers = new ArrayList<>(); + List<Member> startupMembers = new ArrayList<>(); for (int i = 1; i < seedNodes + 1; ++i) { URI uri = new URI("udp://" + "127.0.0.1" + ":" + (30300 + i)); - startupMembers.add(new RemoteGossipMember(cluster, uri, i + "")); + startupMembers.add(new RemoteMember(cluster, uri, i + "")); } - final List<GossipService> clients = Collections.synchronizedList(new ArrayList<GossipService>()); + final List<GossipManager> clients = Collections.synchronizedList(new ArrayList<GossipManager>()); final int clusterMembers = 5; for (int i = 1; i < clusterMembers + 1; ++i) { URI uri = new URI("udp://" + "127.0.0.1" + ":" + (30300 + i)); - GossipService gossipService = new GossipService(cluster, uri, i + "", new HashMap<String,String>(), startupMembers, - settings, (a,b) -> {}, new MetricRegistry()); + GossipManager gossipService = GossipManagerBuilder.newBuilder() + .cluster(cluster) + .uri(uri) + .id(i + "") + .gossipMembers(startupMembers) + .gossipSettings(settings) + .build(); clients.add(gossipService); - gossipService.start(); + gossipService.init(); + } TUnit.assertThat(new Callable<Integer>() { public Integer call() throws Exception { int total = 0; for (int i = 0; i < clusterMembers; ++i) { - total += clients.get(i).getGossipManager().getLiveMembers().size(); + total += clients.get(i).getLiveMembers().size(); } return total; } @@ -79,15 +85,15 @@ public class ShutdownDeadtimeTest { Random r = new Random(); int randomClientId = r.nextInt(clusterMembers); log.info("shutting down " + randomClientId); - final int shutdownPort = clients.get(randomClientId).getGossipManager().getMyself().getUri() + final int shutdownPort = clients.get(randomClientId).getMyself().getUri() .getPort(); - final String shutdownId = clients.get(randomClientId).getGossipManager().getMyself().getId(); + final String shutdownId = clients.get(randomClientId).getMyself().getId(); clients.get(randomClientId).shutdown(); TUnit.assertThat(new Callable<Integer>() { public Integer call() throws Exception { int total = 0; for (int i = 0; i < clusterMembers; ++i) { - total += clients.get(i).getGossipManager().getLiveMembers().size(); + total += clients.get(i).getLiveMembers().size(); } return total; } @@ -98,7 +104,7 @@ public class ShutdownDeadtimeTest { public Integer call() throws Exception { int total = 0; for (int i = 0; i < clusterMembers - 1; ++i) { - total += clients.get(i).getGossipManager().getDeadMembers().size(); + total += clients.get(i).getDeadMembers().size(); } return total; } @@ -106,17 +112,22 @@ public class ShutdownDeadtimeTest { URI uri = new URI("udp://" + "127.0.0.1" + ":" + shutdownPort); // start client again - GossipService gossipService = new GossipService(cluster, uri, shutdownId + "", new HashMap<String,String>(), startupMembers, - settings, (a,b) -> {}, new MetricRegistry()); + GossipManager gossipService = GossipManagerBuilder.newBuilder() + .gossipSettings(settings) + .cluster(cluster) + .uri(uri) + .id(shutdownId+"") + .gossipMembers(startupMembers) + .build(); clients.add(gossipService); - gossipService.start(); + gossipService.init(); // verify that the client is alive again for every node TUnit.assertThat(new Callable<Integer>() { public Integer call() throws Exception { int total = 0; for (int i = 0; i < clusterMembers; ++i) { - total += clients.get(i).getGossipManager().getLiveMembers().size(); + total += clients.get(i).getLiveMembers().size(); } return total; } http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/test/java/org/apache/gossip/SignedMessageTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/SignedMessageTest.java b/src/test/java/org/apache/gossip/SignedMessageTest.java index 6bea974..50e3cb5 100644 --- a/src/test/java/org/apache/gossip/SignedMessageTest.java +++ b/src/test/java/org/apache/gossip/SignedMessageTest.java @@ -25,33 +25,36 @@ import java.net.UnknownHostException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; +import org.apache.gossip.manager.GossipManager; +import org.apache.gossip.manager.GossipManagerBuilder; import org.apache.gossip.manager.PassiveGossipConstants; import org.apache.gossip.secure.KeyTool; import org.junit.Assert; import org.junit.Test; -import com.codahale.metrics.MetricRegistry; - import io.teknek.tunit.TUnit; -public class SignedMessageTest { +public class SignedMessageTest extends AbstractIntegrationBase { - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void ifSignMustHaveKeys() throws URISyntaxException, UnknownHostException, InterruptedException { String cluster = UUID.randomUUID().toString(); GossipSettings settings = gossiperThatSigns(); - List<GossipMember> startupMembers = new ArrayList<>(); + List<Member> startupMembers = new ArrayList<>(); URI uri = new URI("udp://" + "127.0.0.1" + ":" + (30000 + 1)); - GossipService gossipService = new GossipService(cluster, uri, 1 + "", - new HashMap<String, String>(), startupMembers, settings, (a, b) -> { }, - new MetricRegistry()); - gossipService.start(); + GossipManager gossipService = GossipManagerBuilder.newBuilder() + .cluster(cluster) + .uri(uri) + .id(1 + "") + .gossipMembers(startupMembers) + .gossipSettings(settings) + .build(); + gossipService.init(); } private GossipSettings gossiperThatSigns(){ @@ -63,48 +66,52 @@ public class SignedMessageTest { } @Test - public void dataTest() throws InterruptedException, URISyntaxException, NoSuchAlgorithmException, NoSuchProviderException, IOException{ + public void dataTest() throws InterruptedException, URISyntaxException, NoSuchAlgorithmException, NoSuchProviderException, IOException { String keys = "./keys"; GossipSettings settings = gossiperThatSigns(); setup(keys); String cluster = UUID.randomUUID().toString(); - List<GossipMember> startupMembers = new ArrayList<>(); + List<Member> startupMembers = new ArrayList<>(); for (int i = 1; i < 2; ++i) { URI uri = new URI("udp://" + "127.0.0.1" + ":" + (30000 + i)); - startupMembers.add(new RemoteGossipMember(cluster, uri, i + "")); + startupMembers.add(new RemoteMember(cluster, uri, i + "")); } - final List<GossipService> clients = new ArrayList<>(); + final List<GossipManager> clients = new ArrayList<>(); for (int i = 1; i < 3; ++i) { URI uri = new URI("udp://" + "127.0.0.1" + ":" + (30000 + i)); - GossipService gossipService = new GossipService(cluster, uri, i + "", - new HashMap<String,String>(), startupMembers, settings, - (a,b) -> {}, new MetricRegistry()); + GossipManager gossipService = GossipManagerBuilder.newBuilder() + .cluster(cluster) + .uri(uri) + .id(i + "") + .gossipMembers(startupMembers) + .gossipSettings(settings) + .build(); + gossipService.init(); clients.add(gossipService); - gossipService.start(); } assertTwoAlive(clients); assertOnlySignedMessages(clients); cleanup(keys, clients); } - private void assertTwoAlive(List<GossipService> clients){ + private void assertTwoAlive(List<GossipManager> clients){ TUnit.assertThat(() -> { int total = 0; for (int i = 0; i < clients.size(); ++i) { - total += clients.get(i).getGossipManager().getLiveMembers().size(); + total += clients.get(i).getLiveMembers().size(); } return total; }).afterWaitingAtMost(20, TimeUnit.SECONDS).isEqualTo(2); } - private void assertOnlySignedMessages(List<GossipService> clients){ - Assert.assertEquals(0, clients.get(0).getGossipManager().getRegistry() + private void assertOnlySignedMessages(List<GossipManager> clients){ + Assert.assertEquals(0, clients.get(0).getRegistry() .meter(PassiveGossipConstants.UNSIGNED_MESSAGE).getCount()); - Assert.assertTrue(clients.get(0).getGossipManager().getRegistry() + Assert.assertTrue(clients.get(0).getRegistry() .meter(PassiveGossipConstants.SIGNED_MESSAGE).getCount() > 0); } - private void cleanup(String keys, List<GossipService> clients){ + private void cleanup(String keys, List<GossipManager> clients){ new File(keys, "1").delete(); new File(keys, "2").delete(); new File(keys).delete(); http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/test/java/org/apache/gossip/StartupSettingsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/StartupSettingsTest.java b/src/test/java/org/apache/gossip/StartupSettingsTest.java index aa4d255..d6c4a1e 100644 --- a/src/test/java/org/apache/gossip/StartupSettingsTest.java +++ b/src/test/java/org/apache/gossip/StartupSettingsTest.java @@ -17,7 +17,8 @@ */ package org.apache.gossip; -import com.codahale.metrics.MetricRegistry; +import org.apache.gossip.manager.GossipManager; +import org.apache.gossip.manager.GossipManagerBuilder; import org.apache.log4j.Logger; import org.junit.jupiter.api.Test; @@ -27,8 +28,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.HashMap; import java.util.UUID; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; @@ -39,7 +38,7 @@ import org.junit.runner.RunWith; */ @RunWith(JUnitPlatform.class) public class StartupSettingsTest { - private static final Logger log = Logger.getLogger( StartupSettingsTest.class ); + private static final Logger log = Logger.getLogger(StartupSettingsTest.class); private static final String CLUSTER = UUID.randomUUID().toString(); @Test @@ -48,15 +47,17 @@ public class StartupSettingsTest { settingsFile.deleteOnExit(); writeSettingsFile(settingsFile); URI uri = new URI("udp://" + "127.0.0.1" + ":" + 50000); - final GossipService firstService = new GossipService( - CLUSTER, uri, "1", new HashMap<String, String>(), - new ArrayList<GossipMember>(), new GossipSettings(), null, new MetricRegistry()); - firstService.start(); - final GossipService serviceUnderTest = new GossipService( - StartupSettings.fromJSONFile(settingsFile)); - serviceUnderTest.start(); + GossipManager firstService = GossipManagerBuilder.newBuilder() + .cluster(CLUSTER) + .uri(uri) + .id("1") + .gossipSettings(new GossipSettings()).build(); + firstService.init(); + GossipManager manager = GossipManagerBuilder.newBuilder() + .startupSettings(StartupSettings.fromJSONFile(settingsFile)).build(); + manager.init(); firstService.shutdown(); - serviceUnderTest.shutdown(); + manager.shutdown(); } private void writeSettingsFile( File target ) throws IOException { http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/test/java/org/apache/gossip/TenNodeThreeSeedTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/TenNodeThreeSeedTest.java b/src/test/java/org/apache/gossip/TenNodeThreeSeedTest.java index 8a9a9ab..8ae783e 100644 --- a/src/test/java/org/apache/gossip/TenNodeThreeSeedTest.java +++ b/src/test/java/org/apache/gossip/TenNodeThreeSeedTest.java @@ -17,20 +17,20 @@ */ package org.apache.gossip; -import com.codahale.metrics.MetricRegistry; import io.teknek.tunit.TUnit; import java.net.URI; import java.net.URISyntaxException; import java.net.UnknownHostException; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; +import org.apache.gossip.manager.GossipManager; +import org.apache.gossip.manager.GossipManagerBuilder; import org.junit.jupiter.api.Test; @RunWith(JUnitPlatform.class) @@ -42,35 +42,40 @@ public class TenNodeThreeSeedTest { } @Test - public void testAgain() throws UnknownHostException, InterruptedException, URISyntaxException{ + public void testAgain() throws UnknownHostException, InterruptedException, URISyntaxException { abc(30100); } - public void abc(int base) throws InterruptedException, UnknownHostException, URISyntaxException{ - GossipSettings settings = new GossipSettings(1000, 10000, 1000, 1, 2.0, "exponential"); + public void abc(int base) throws InterruptedException, UnknownHostException, URISyntaxException { + GossipSettings settings = new GossipSettings(1000, 10000, 1000, 1, 1.6, "exponential"); settings.setPersistRingState(false); settings.setPersistDataState(false); String cluster = UUID.randomUUID().toString(); int seedNodes = 3; - List<GossipMember> startupMembers = new ArrayList<>(); + List<Member> startupMembers = new ArrayList<>(); for (int i = 1; i < seedNodes+1; ++i) { URI uri = new URI("udp://" + "127.0.0.1" + ":" + (base + i)); - startupMembers.add(new RemoteGossipMember(cluster, uri, i + "")); + startupMembers.add(new RemoteMember(cluster, uri, i + "")); } - final List<GossipService> clients = new ArrayList<>(); + final List<GossipManager> clients = new ArrayList<>(); final int clusterMembers = 5; for (int i = 1; i < clusterMembers+1; ++i) { URI uri = new URI("udp://" + "127.0.0.1" + ":" + (base + i)); - GossipService gossipService = new GossipService(cluster, uri, i + "", new HashMap<String,String>(), - startupMembers, settings, (a,b) -> {}, new MetricRegistry()); + GossipManager gossipService = GossipManagerBuilder.newBuilder() + .cluster(cluster) + .uri(uri) + .id(i + "") + .gossipSettings(settings) + .gossipMembers(startupMembers) + .build(); + gossipService.init(); clients.add(gossipService); - gossipService.start(); } TUnit.assertThat(new Callable<Integer> (){ public Integer call() throws Exception { int total = 0; for (int i = 0; i < clusterMembers; ++i) { - total += clients.get(i).getGossipManager().getLiveMembers().size(); + total += clients.get(i).getLiveMembers().size(); } return total; }}).afterWaitingAtMost(40, TimeUnit.SECONDS).isEqualTo(20); http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/test/java/org/apache/gossip/accrual/FailureDetectorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/accrual/FailureDetectorTest.java b/src/test/java/org/apache/gossip/accrual/FailureDetectorTest.java index 69d46b8..b00c0c3 100644 --- a/src/test/java/org/apache/gossip/accrual/FailureDetectorTest.java +++ b/src/test/java/org/apache/gossip/accrual/FailureDetectorTest.java @@ -19,7 +19,7 @@ package org.apache.gossip.accrual; import java.net.URI; -import org.apache.gossip.LocalGossipMember; +import org.apache.gossip.LocalMember; import org.junit.Assert; import org.junit.Ignore; import org.junit.jupiter.api.Test; @@ -33,7 +33,7 @@ public class FailureDetectorTest { public void aNormalTest(){ int samples = 1; int windowSize = 1000; - LocalGossipMember member = new LocalGossipMember("", URI.create("udp://127.0.0.1:1000"), + LocalMember member = new LocalMember("", URI.create("udp://127.0.0.1:1000"), "", 0L, null, windowSize, samples, "normal"); member.recordHeartbeat(5); member.recordHeartbeat(10); @@ -44,7 +44,7 @@ public class FailureDetectorTest { public void aTest(){ int samples = 1; int windowSize = 1000; - LocalGossipMember member = new LocalGossipMember("", URI.create("udp://127.0.0.1:1000"), + LocalMember member = new LocalMember("", URI.create("udp://127.0.0.1:1000"), "", 0L, null, windowSize, samples, "exponential"); member.recordHeartbeat(5); member.recordHeartbeat(10); @@ -64,7 +64,7 @@ public class FailureDetectorTest { public void sameHeartbeatTest(){ int samples = 1; int windowSize = 1000; - LocalGossipMember member = new LocalGossipMember("", URI.create("udp://127.0.0.1:1000"), + LocalMember member = new LocalMember("", URI.create("udp://127.0.0.1:1000"), "", 0L, null, windowSize, samples, "exponential"); member.recordHeartbeat(5); member.recordHeartbeat(5); http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/test/java/org/apache/gossip/crdt/OrSetTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/crdt/OrSetTest.java b/src/test/java/org/apache/gossip/crdt/OrSetTest.java index e576764..b3d8af3 100644 --- a/src/test/java/org/apache/gossip/crdt/OrSetTest.java +++ b/src/test/java/org/apache/gossip/crdt/OrSetTest.java @@ -21,18 +21,15 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.Arrays; -import java.util.HashMap; import java.util.SortedSet; import java.util.TreeSet; -import org.apache.gossip.GossipService; import org.apache.gossip.GossipSettings; -import org.apache.gossip.RemoteGossipMember; +import org.apache.gossip.manager.GossipManager; +import org.apache.gossip.manager.GossipManagerBuilder; import org.junit.Assert; import org.junit.Test; -import com.codahale.metrics.MetricRegistry; - public class OrSetTest { @Test @@ -91,14 +88,16 @@ public class OrSetTest { @Test public void serialTest() throws InterruptedException, URISyntaxException, IOException { - GossipService gossipService2 = new GossipService("a", new URI("udp://" + "127.0.0.1" + ":" + (29000 + 1)), "1", new HashMap<>(), - Arrays.asList(new RemoteGossipMember("a", - new URI("udp://" + "127.0.0.1" + ":" + (29000 + 0)), "0")), - new GossipSettings(), (a, b) -> { }, new MetricRegistry()); + GossipManager gossipService2 = GossipManagerBuilder.newBuilder() + .cluster("a") + .uri(new URI("udp://" + "127.0.0.1" + ":" + (29000 + 1))) + .id("1") + .gossipSettings(new GossipSettings()) + .build(); OrSet<Integer> i = new OrSet<Integer>(new OrSet.Builder<Integer>().add(1).remove(1)); - String s = gossipService2.getGossipManager().getObjectMapper().writeValueAsString(i); + String s = gossipService2.getObjectMapper().writeValueAsString(i); @SuppressWarnings("unchecked") - OrSet<Integer> back = gossipService2.getGossipManager().getObjectMapper().readValue(s, OrSet.class); + OrSet<Integer> back = gossipService2.getObjectMapper().readValue(s, OrSet.class); Assert.assertEquals(back, i); } http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/51998219/src/test/java/org/apache/gossip/manager/DataReaperTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/manager/DataReaperTest.java b/src/test/java/org/apache/gossip/manager/DataReaperTest.java index a9c861c..e328c24 100644 --- a/src/test/java/org/apache/gossip/manager/DataReaperTest.java +++ b/src/test/java/org/apache/gossip/manager/DataReaperTest.java @@ -21,9 +21,8 @@ import com.codahale.metrics.MetricRegistry; import java.net.URI; import org.apache.gossip.GossipSettings; -import org.apache.gossip.manager.random.RandomGossipManager; -import org.apache.gossip.model.GossipDataMessage; -import org.apache.gossip.model.SharedGossipDataMessage; +import org.apache.gossip.model.PerNodeDataMessage; +import org.apache.gossip.model.SharedDataMessage; import org.junit.Assert; import org.junit.Test; @@ -41,8 +40,8 @@ public class DataReaperTest { GossipSettings settings = new GossipSettings(); settings.setPersistRingState(false); settings.setPersistDataState(false); - GossipManager gm = RandomGossipManager.newBuilder().cluster("abc").settings(settings) - .withId(myId).uri(URI.create("udp://localhost:6000")).registry(registry).build(); + GossipManager gm = GossipManagerBuilder.newBuilder().cluster("abc").gossipSettings(settings) + .id(myId).uri(URI.create("udp://localhost:6000")).registry(registry).build(); gm.init(); gm.gossipPerNodeData(perNodeDatum(key, value)); gm.gossipSharedData(sharedDatum(key, value)); @@ -65,8 +64,8 @@ public class DataReaperTest { TUnit.assertThat(() -> gm.findSharedGossipData(key)).equals(null); } - private GossipDataMessage perNodeDatum(String key, String value) { - GossipDataMessage m = new GossipDataMessage(); + private PerNodeDataMessage perNodeDatum(String key, String value) { + PerNodeDataMessage m = new PerNodeDataMessage(); m.setExpireAt(System.currentTimeMillis() + 5L); m.setKey(key); m.setPayload(value); @@ -74,8 +73,8 @@ public class DataReaperTest { return m; } - private SharedGossipDataMessage sharedDatum(String key, String value) { - SharedGossipDataMessage m = new SharedGossipDataMessage(); + private SharedDataMessage sharedDatum(String key, String value) { + SharedDataMessage m = new SharedDataMessage(); m.setExpireAt(System.currentTimeMillis() + 5L); m.setKey(key); m.setPayload(value); @@ -89,11 +88,11 @@ public class DataReaperTest { String key = "key"; String value = "a"; GossipSettings settings = new GossipSettings(); - GossipManager gm = RandomGossipManager.newBuilder().cluster("abc").settings(settings) - .withId(myId).uri(URI.create("udp://localhost:7000")).registry(registry).build(); + GossipManager gm = GossipManagerBuilder.newBuilder().cluster("abc").gossipSettings(settings) + .id(myId).uri(URI.create("udp://localhost:7000")).registry(registry).build(); gm.init(); - GossipDataMessage before = perNodeDatum(key, value); - GossipDataMessage after = perNodeDatum(key, "b"); + PerNodeDataMessage before = perNodeDatum(key, value); + PerNodeDataMessage after = perNodeDatum(key, "b"); after.setTimestamp(after.getTimestamp() - 1); gm.gossipPerNodeData(before); Assert.assertEquals(value, gm.findPerNodeGossipData(myId, key).getPayload());
