Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 51D0D200C55 for ; Thu, 13 Apr 2017 18:16:08 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 504AB160B8B; Thu, 13 Apr 2017 16:16:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 28409160BA7 for ; Thu, 13 Apr 2017 18:16:06 +0200 (CEST) Received: (qmail 88247 invoked by uid 500); 13 Apr 2017 16:16:05 -0000 Mailing-List: contact commits-help@gossip.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@gossip.incubator.apache.org Delivered-To: mailing list commits@gossip.incubator.apache.org Received: (qmail 88238 invoked by uid 99); 13 Apr 2017 16:16:05 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Apr 2017 16:16:05 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id D449B1A0223 for ; Thu, 13 Apr 2017 16:16:04 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.222 X-Spam-Level: X-Spam-Status: No, score=-4.222 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id z_H6JF5LK4Xq for ; Thu, 13 Apr 2017 16:15:54 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id E59E85FAC9 for ; Thu, 13 Apr 2017 16:15:51 +0000 (UTC) Received: (qmail 88048 invoked by uid 99); 13 Apr 2017 16:15:51 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Apr 2017 16:15:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0611BDFC31; Thu, 13 Apr 2017 16:15:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ecapriolo@apache.org To: commits@gossip.incubator.apache.org Date: Thu, 13 Apr 2017 16:15:51 -0000 Message-Id: <543ec56491d545718547ca0851e53065@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/7] incubator-gossip git commit: GOSSIP-78 refactor into a multi-module maven project archived-at: Thu, 13 Apr 2017 16:16:08 -0000 Repository: incubator-gossip Updated Branches: refs/heads/master 6a4d50cae -> 298b1ae3a http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/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 deleted file mode 100644 index f0c2186..0000000 --- a/src/test/java/org/apache/gossip/DataTest.java +++ /dev/null @@ -1,238 +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.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import org.apache.gossip.crdt.GrowOnlyCounter; -import org.apache.gossip.crdt.GrowOnlySet; -import org.apache.gossip.crdt.OrSet; -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 extends AbstractIntegrationBase { - - private String orSetKey = "cror"; - private String gCounterKey = "crdtgc"; - - @Test - public void dataTest() throws InterruptedException, UnknownHostException, URISyntaxException{ - GossipSettings settings = new GossipSettings(); - settings.setPersistRingState(false); - settings.setPersistDataState(false); - String cluster = UUID.randomUUID().toString(); - int seedNodes = 1; - List 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 RemoteMember(cluster, uri, i + "")); - } - final List clients = new ArrayList<>(); - final int clusterMembers = 2; - for (int i = 1; i < clusterMembers + 1; ++i) { - URI uri = new URI("udp://" + "127.0.0.1" + ":" + (50000 + i)); - GossipManager gossipService = GossipManagerBuilder.newBuilder().cluster(cluster).uri(uri) - .id(i + "").gossipMembers(startupMembers).gossipSettings(settings).build(); - clients.add(gossipService); - gossipService.init(); - register(gossipService); - } - TUnit.assertThat(() -> { - int total = 0; - for (int i = 0; i < clusterMembers; ++i) { - total += clients.get(i).getLiveMembers().size(); - } - return total; - }).afterWaitingAtMost(20, TimeUnit.SECONDS).isEqualTo(2); - clients.get(0).gossipPerNodeData(msg()); - clients.get(0).gossipSharedData(sharedMsg()); - - TUnit.assertThat(()-> { - PerNodeDataMessage x = clients.get(1).findPerNodeGossipData(1 + "", "a"); - if (x == null) - return ""; - else - return x.getPayload(); - }).afterWaitingAtMost(20, TimeUnit.SECONDS).isEqualTo("b"); - - TUnit.assertThat(() -> { - SharedDataMessage x = clients.get(1).findSharedGossipData("a"); - if (x == null) - return ""; - else - return x.getPayload(); - }).afterWaitingAtMost(20, TimeUnit.SECONDS).isEqualTo("c"); - - - givenDifferentDatumsInSet(clients); - assertThatListIsMerged(clients); - - givenOrs(clients); - assertThatOrSetIsMerged(clients); - dropIt(clients); - assertThatOrSetDelIsMerged(clients); - - - // test g counter - givenDifferentIncrement(clients); - assertThatCountIsUpdated(clients, 3); - givenIncreaseOther(clients); - assertThatCountIsUpdated(clients, 7); - - for (int i = 0; i < clusterMembers; ++i) { - clients.get(i).shutdown(); - } - } - - private void givenDifferentIncrement(final List clients) { - { - SharedDataMessage d = new SharedDataMessage(); - d.setKey(gCounterKey); - d.setPayload(new GrowOnlyCounter(new GrowOnlyCounter.Builder(clients.get(0)).increment(1L))); - d.setExpireAt(Long.MAX_VALUE); - d.setTimestamp(System.currentTimeMillis()); - clients.get(0).merge(d); - } - { - SharedDataMessage d = new SharedDataMessage(); - d.setKey(gCounterKey); - d.setPayload(new GrowOnlyCounter(new GrowOnlyCounter.Builder(clients.get(1)).increment(2L))); - d.setExpireAt(Long.MAX_VALUE); - d.setTimestamp(System.currentTimeMillis()); - clients.get(1).merge(d); - } - } - - private void givenIncreaseOther(final List clients) { - GrowOnlyCounter gc = (GrowOnlyCounter) clients.get(1).findCrdt(gCounterKey); - GrowOnlyCounter gc2 = new GrowOnlyCounter(gc, - new GrowOnlyCounter.Builder(clients.get(1)).increment(4L)); - - SharedDataMessage d = new SharedDataMessage(); - d.setKey(gCounterKey); - d.setPayload(gc2); - d.setExpireAt(Long.MAX_VALUE); - d.setTimestamp(System.currentTimeMillis()); - clients.get(1).merge(d); - } - - private void givenOrs(List clients) { - { - SharedDataMessage d = new SharedDataMessage(); - d.setKey(orSetKey); - d.setPayload(new OrSet("1", "2")); - d.setExpireAt(Long.MAX_VALUE); - d.setTimestamp(System.currentTimeMillis()); - clients.get(0).merge(d); - } - { - SharedDataMessage d = new SharedDataMessage(); - d.setKey(orSetKey); - d.setPayload(new OrSet("3", "4")); - d.setExpireAt(Long.MAX_VALUE); - d.setTimestamp(System.currentTimeMillis()); - clients.get(1).merge(d); - } - } - - private void dropIt(List clients) { - @SuppressWarnings("unchecked") - OrSet o = (OrSet) clients.get(0).findCrdt(orSetKey); - OrSet o2 = new OrSet(o, new OrSet.Builder().remove("3")); - SharedDataMessage d = new SharedDataMessage(); - d.setKey(orSetKey); - d.setPayload(o2); - d.setExpireAt(Long.MAX_VALUE); - d.setTimestamp(System.currentTimeMillis()); - clients.get(0).merge(d); - } - - private void assertThatOrSetIsMerged(final List clients){ - TUnit.assertThat(() -> { - return clients.get(0).findCrdt(orSetKey).value(); - }).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo(new OrSet("1", "2", "3", "4").value()); - TUnit.assertThat(() -> { - return clients.get(1).findCrdt(orSetKey).value(); - }).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo(new OrSet("1", "2", "3", "4").value()); - } - - private void assertThatOrSetDelIsMerged(final List clients){ - TUnit.assertThat(() -> { - return clients.get(0).findCrdt(orSetKey); - }).afterWaitingAtMost(10, TimeUnit.SECONDS).equals(new OrSet("1", "2", "4")); - } - - private void givenDifferentDatumsInSet(final List clients){ - clients.get(0).merge(CrdtMessage("1")); - clients.get(1).merge(CrdtMessage("2")); - } - - - private void assertThatCountIsUpdated(final List clients, long finalCount) { - TUnit.assertThat(() -> { - return clients.get(0).findCrdt(gCounterKey); - }).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo(new GrowOnlyCounter( - new GrowOnlyCounter.Builder(clients.get(0)).increment(finalCount))); - } - - private void assertThatListIsMerged(final List clients){ - TUnit.assertThat(() -> { - return clients.get(0).findCrdt("cr"); - }).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo(new GrowOnlySet(Arrays.asList("1","2"))); - } - - private SharedDataMessage CrdtMessage(String item){ - SharedDataMessage d = new SharedDataMessage(); - d.setKey("cr"); - d.setPayload(new GrowOnlySet( Arrays.asList(item))); - d.setExpireAt(Long.MAX_VALUE); - d.setTimestamp(System.currentTimeMillis()); - return d; - } - - private PerNodeDataMessage msg(){ - PerNodeDataMessage g = new PerNodeDataMessage(); - g.setExpireAt(Long.MAX_VALUE); - g.setKey("a"); - g.setPayload("b"); - g.setTimestamp(System.currentTimeMillis()); - return g; - } - - private SharedDataMessage sharedMsg(){ - SharedDataMessage g = new SharedDataMessage(); - g.setExpireAt(Long.MAX_VALUE); - g.setKey("a"); - g.setPayload("c"); - g.setTimestamp(System.currentTimeMillis()); - return g; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/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 deleted file mode 100644 index 7f550de..0000000 --- a/src/test/java/org/apache/gossip/IdAndPropertyTest.java +++ /dev/null @@ -1,91 +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.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -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 io.teknek.tunit.TUnit; - -@RunWith(JUnitPlatform.class) -public class IdAndPropertyTest extends AbstractIntegrationBase { - - @Test - public void testDatacenterRackGossiper() throws URISyntaxException, UnknownHostException, InterruptedException { - GossipSettings settings = new GossipSettings(); - settings.setActiveGossipClass(DatacenterRackAwareActiveGossiper.class.getName()); - List startupMembers = new ArrayList<>(); - Map x = new HashMap<>(); - x.put("a", "b"); - x.put("datacenter", "dc1"); - x.put("rack", "rack1"); - 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 y = new HashMap<>(); - y.put("a", "c"); - y.put("datacenter", "dc2"); - y.put("rack", "rack2"); - GossipManager gossipService2 = GossipManagerBuilder.newBuilder().cluster("a") - .uri( new URI("udp://" + "127.0.0.1" + ":" + (29000 + 10))) - .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.getLiveMembers().get(0).getProperties().get("a"); - } catch (RuntimeException e){ } - return value; - }).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo("c"); - - TUnit.assertThat(() -> { - String value = ""; - try { - value = gossipService2.getLiveMembers().get(0).getProperties().get("a"); - } catch (RuntimeException e){ } - return value; - }).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo("b"); - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/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 deleted file mode 100644 index 5f0d18a..0000000 --- a/src/test/java/org/apache/gossip/MemberTest.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 MemberTest { - - @Test - public void testHashCodeFromGossip40() throws URISyntaxException { - Assert.assertNotEquals( - new LocalMember("mycluster", new URI("udp://4.4.4.4:1000"), "myid", 1, new HashMap(), 10, 5, "exponential") - .hashCode(), - new LocalMember("mycluster", new URI("udp://4.4.4.5:1005"), "yourid", 11, new HashMap(), 11, 6, "exponential") - .hashCode()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/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 deleted file mode 100644 index 54005c3..0000000 --- a/src/test/java/org/apache/gossip/ShutdownDeadtimeTest.java +++ /dev/null @@ -1,146 +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 io.teknek.tunit.TUnit; - -import java.net.URI; -import java.net.URISyntaxException; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Collections; -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; -import org.junit.jupiter.api.Test; - -import org.junit.runner.RunWith; - -@RunWith(JUnitPlatform.class) -public class ShutdownDeadtimeTest { - - private static final Logger log = Logger.getLogger(ShutdownDeadtimeTest.class); - - @Test - public void DeadNodesDoNotComeAliveAgain() - throws InterruptedException, UnknownHostException, URISyntaxException { - GossipSettings settings = new GossipSettings(100, 10000, 1000, 1, 10.0, "normal"); - settings.setPersistRingState(false); - settings.setPersistDataState(false); - String cluster = UUID.randomUUID().toString(); - int seedNodes = 3; - List 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 RemoteMember(cluster, uri, i + "")); - } - final List clients = Collections.synchronizedList(new ArrayList()); - final int clusterMembers = 5; - for (int i = 1; i < clusterMembers + 1; ++i) { - URI uri = new URI("udp://" + "127.0.0.1" + ":" + (30300 + i)); - GossipManager gossipService = GossipManagerBuilder.newBuilder() - .cluster(cluster) - .uri(uri) - .id(i + "") - .gossipMembers(startupMembers) - .gossipSettings(settings) - .build(); - clients.add(gossipService); - gossipService.init(); - - } - TUnit.assertThat(new Callable() { - public Integer call() throws Exception { - int total = 0; - for (int i = 0; i < clusterMembers; ++i) { - total += clients.get(i).getLiveMembers().size(); - } - return total; - } - }).afterWaitingAtMost(40, TimeUnit.SECONDS).isEqualTo(20); - - // shutdown one client and verify that one client is lost. - Random r = new Random(); - int randomClientId = r.nextInt(clusterMembers); - log.info("shutting down " + randomClientId); - final int shutdownPort = clients.get(randomClientId).getMyself().getUri() - .getPort(); - final String shutdownId = clients.get(randomClientId).getMyself().getId(); - clients.get(randomClientId).shutdown(); - TUnit.assertThat(new Callable() { - public Integer call() throws Exception { - int total = 0; - for (int i = 0; i < clusterMembers; ++i) { - total += clients.get(i).getLiveMembers().size(); - } - return total; - } - }).afterWaitingAtMost(40, TimeUnit.SECONDS).isEqualTo(16); - clients.remove(randomClientId); - - TUnit.assertThat(new Callable() { - public Integer call() throws Exception { - int total = 0; - for (int i = 0; i < clusterMembers - 1; ++i) { - total += clients.get(i).getDeadMembers().size(); - } - return total; - } - }).afterWaitingAtMost(50, TimeUnit.SECONDS).isEqualTo(4); - - URI uri = new URI("udp://" + "127.0.0.1" + ":" + shutdownPort); - // start client again - GossipManager gossipService = GossipManagerBuilder.newBuilder() - .gossipSettings(settings) - .cluster(cluster) - .uri(uri) - .id(shutdownId+"") - .gossipMembers(startupMembers) - .build(); - clients.add(gossipService); - gossipService.init(); - - // verify that the client is alive again for every node - TUnit.assertThat(new Callable() { - public Integer call() throws Exception { - int total = 0; - for (int i = 0; i < clusterMembers; ++i) { - total += clients.get(i).getLiveMembers().size(); - } - return total; - } - }).afterWaitingAtMost(60, TimeUnit.SECONDS).isEqualTo(20); - - for (int i = 0; i < clusterMembers; ++i) { - final int j = i; - new Thread() { - public void run(){ - clients.get(j).shutdown(); - } - }.start(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/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 deleted file mode 100644 index 5c3bb76..0000000 --- a/src/test/java/org/apache/gossip/SignedMessageTest.java +++ /dev/null @@ -1,135 +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.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.UnknownHostException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -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 io.teknek.tunit.TUnit; - -public class SignedMessageTest extends AbstractIntegrationBase { - - @Test(expected = IllegalArgumentException.class) - public void ifSignMustHaveKeys() - throws URISyntaxException, UnknownHostException, InterruptedException { - String cluster = UUID.randomUUID().toString(); - GossipSettings settings = gossiperThatSigns(); - List startupMembers = new ArrayList<>(); - URI uri = new URI("udp://" + "127.0.0.1" + ":" + (30000 + 1)); - GossipManager gossipService = GossipManagerBuilder.newBuilder() - .cluster(cluster) - .uri(uri) - .id(1 + "") - .gossipMembers(startupMembers) - .gossipSettings(settings) - .build(); - gossipService.init(); - } - - private GossipSettings gossiperThatSigns(){ - GossipSettings settings = new GossipSettings(); - settings.setPersistRingState(false); - settings.setPersistDataState(false); - settings.setSignMessages(true); - return settings; - } - - private GossipSettings gossiperThatSigns(String keysDir){ - GossipSettings settings = gossiperThatSigns(); - settings.setPathToKeyStore(Objects.requireNonNull(keysDir)); - return settings; - } - - @Test - public void dataTest() throws InterruptedException, URISyntaxException, NoSuchAlgorithmException, NoSuchProviderException, IOException { - final String keys = System.getProperty("java.io.tmpdir") + "/keys"; - GossipSettings settings = gossiperThatSigns(keys); - setup(keys); - String cluster = UUID.randomUUID().toString(); - List startupMembers = new ArrayList<>(); - for (int i = 1; i < 2; ++i) { - URI uri = new URI("udp://" + "127.0.0.1" + ":" + (30000 + i)); - startupMembers.add(new RemoteMember(cluster, uri, i + "")); - } - final List clients = new ArrayList<>(); - for (int i = 1; i < 3; ++i) { - URI uri = new URI("udp://" + "127.0.0.1" + ":" + (30000 + i)); - GossipManager gossipService = GossipManagerBuilder.newBuilder() - .cluster(cluster) - .uri(uri) - .id(i + "") - .gossipMembers(startupMembers) - .gossipSettings(settings) - .build(); - gossipService.init(); - clients.add(gossipService); - } - assertTwoAlive(clients); - assertOnlySignedMessages(clients); - cleanup(keys, clients); - } - - private void assertTwoAlive(List clients){ - TUnit.assertThat(() -> { - int total = 0; - for (int i = 0; i < clients.size(); ++i) { - total += clients.get(i).getLiveMembers().size(); - } - return total; - }).afterWaitingAtMost(20, TimeUnit.SECONDS).isEqualTo(2); - } - - private void assertOnlySignedMessages(List clients){ - Assert.assertEquals(0, clients.get(0).getRegistry() - .meter(PassiveGossipConstants.UNSIGNED_MESSAGE).getCount()); - Assert.assertTrue(clients.get(0).getRegistry() - .meter(PassiveGossipConstants.SIGNED_MESSAGE).getCount() > 0); - } - - private void cleanup(String keys, List clients){ - new File(keys, "1").delete(); - new File(keys, "2").delete(); - new File(keys).delete(); - for (int i = 0; i < clients.size(); ++i) { - clients.get(i).shutdown(); - } - } - - private void setup(String keys) throws NoSuchAlgorithmException, NoSuchProviderException, IOException { - new File(keys).mkdir(); - KeyTool.generatePubandPrivateKeyFiles(keys, "1"); - KeyTool.generatePubandPrivateKeyFiles(keys, "2"); - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/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 deleted file mode 100644 index d6c4a1e..0000000 --- a/src/test/java/org/apache/gossip/StartupSettingsTest.java +++ /dev/null @@ -1,86 +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 org.apache.gossip.manager.GossipManager; -import org.apache.gossip.manager.GossipManagerBuilder; -import org.apache.log4j.Logger; - -import org.junit.jupiter.api.Test; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.UUID; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; - -/** - * Tests support of using {@code StartupSettings} and thereby reading - * setup config from file. - */ -@RunWith(JUnitPlatform.class) -public class StartupSettingsTest { - private static final Logger log = Logger.getLogger(StartupSettingsTest.class); - private static final String CLUSTER = UUID.randomUUID().toString(); - - @Test - public void testUsingSettingsFile() throws IOException, InterruptedException, URISyntaxException { - File settingsFile = File.createTempFile("gossipTest",".json"); - settingsFile.deleteOnExit(); - writeSettingsFile(settingsFile); - URI uri = new URI("udp://" + "127.0.0.1" + ":" + 50000); - 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(); - manager.shutdown(); - } - - private void writeSettingsFile( File target ) throws IOException { - String settings = - "[{\n" + // It is odd that this is meant to be in an array, but oh well. - " \"cluster\":\"" + CLUSTER + "\",\n" + - " \"id\":\"" + "2" + "\",\n" + - " \"uri\":\"udp://127.0.0.1:50001\",\n" + - " \"gossip_interval\":1000,\n" + - " \"window_size\":1000,\n" + - " \"minimum_samples\":5,\n" + - " \"cleanup_interval\":10000,\n" + - " \"convict_threshold\":2.6,\n" + - " \"distribution\":\"exponential\",\n" + - " \"properties\":{},\n" + - " \"members\":[\n" + - " {\"cluster\": \"" + CLUSTER + "\",\"uri\":\"udp://127.0.0.1:5000\"}\n" + - " ]\n" + - "}]"; - - log.info( "Using settings file with contents of:\n---\n" + settings + "\n---" ); - FileOutputStream output = new FileOutputStream(target); - output.write(settings.getBytes()); - output.close(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/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 deleted file mode 100644 index 8ae783e..0000000 --- a/src/test/java/org/apache/gossip/TenNodeThreeSeedTest.java +++ /dev/null @@ -1,92 +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 io.teknek.tunit.TUnit; - -import java.net.URI; -import java.net.URISyntaxException; -import java.net.UnknownHostException; -import java.util.ArrayList; -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) -public class TenNodeThreeSeedTest { - - @Test - public void test() throws UnknownHostException, InterruptedException, URISyntaxException { - abc(30150); - } - - @Test - 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, 1.6, "exponential"); - settings.setPersistRingState(false); - settings.setPersistDataState(false); - String cluster = UUID.randomUUID().toString(); - int seedNodes = 3; - List 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 RemoteMember(cluster, uri, i + "")); - } - final List 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)); - GossipManager gossipService = GossipManagerBuilder.newBuilder() - .cluster(cluster) - .uri(uri) - .id(i + "") - .gossipSettings(settings) - .gossipMembers(startupMembers) - .build(); - gossipService.init(); - clients.add(gossipService); - } - TUnit.assertThat(new Callable (){ - public Integer call() throws Exception { - int total = 0; - for (int i = 0; i < clusterMembers; ++i) { - total += clients.get(i).getLiveMembers().size(); - } - return total; - }}).afterWaitingAtMost(40, TimeUnit.SECONDS).isEqualTo(20); - - for (int i = 0; i < clusterMembers; ++i) { - int j = i; - new Thread(){ - public void run(){ - clients.get(j).shutdown(); - } - }.start(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/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 deleted file mode 100644 index 3434c17..0000000 --- a/src/test/java/org/apache/gossip/accrual/FailureDetectorTest.java +++ /dev/null @@ -1,113 +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.accrual; - -import org.apache.gossip.GossipSettings; -import org.junit.Assert; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -@RunWith(JUnitPlatform.class) -public class FailureDetectorTest { - - @FunctionalInterface - interface TriConsumer { - void accept(A a, B b, C c); - } - - static final Double failureThreshold = new GossipSettings().getConvictThreshold(); - - List generateTimeList(int begin, int end, int step) { - List values = new ArrayList<>(); - Random rand = new Random(); - for (int i = begin; i < end; i += step) { - int delta = (int) ((rand.nextDouble() - 0.5) * step / 2); - - values.add(i + delta); - } - return values; - } - - @Test - public void normalDistribution() { - FailureDetector fd = new FailureDetector(1, 1000, "normal"); - List values = generateTimeList(0, 10000, 100); - Double deltaSum = 0.0; - Integer deltaCount = 0; - for (int i = 0; i < values.size() - 1; i++) { - fd.recordHeartbeat(values.get(i)); - if (i != 0) { - deltaSum += values.get(i) - values.get(i - 1); - deltaCount++; - } - } - Integer lastRecorded = values.get(values.size() - 2); - - //after "step" delay we need to be considered UP - Assert.assertTrue(fd.computePhiMeasure(values.get(values.size() - 1)) < failureThreshold); - - //if we check phi-measure after mean delay we get value for 0.5 probability(normal distribution) - Assert.assertEquals(fd.computePhiMeasure(lastRecorded + Math.round(deltaSum / deltaCount)), -Math.log10(0.5), 0.1); - } - - @Test - public void checkMinimumSamples() { - Integer minimumSamples = 5; - FailureDetector fd = new FailureDetector(minimumSamples, 1000, "normal"); - for (int i = 0; i < minimumSamples + 1; i++) { // +1 because we don't place first heartbeat into structure - Assert.assertNull(fd.computePhiMeasure(100)); - fd.recordHeartbeat(i); - } - Assert.assertNotNull(fd.computePhiMeasure(100)); - } - - @Test - public void checkMonotonicDead() { - final FailureDetector fd = new FailureDetector(5, 1000, "normal"); - TriConsumer checkAlive = (begin, end, step) -> { - List times = generateTimeList(begin, end, step); - for (int i = 0; i < times.size(); i++) { - Double current = fd.computePhiMeasure(times.get(i)); - if (current != null) { - Assert.assertTrue(current < failureThreshold); - } - fd.recordHeartbeat(times.get(i)); - } - }; - - TriConsumer checkDeadMonotonic = (begin, end, step) -> { - List times = generateTimeList(begin, end, step); - Double prev = null; - for (int i = 0; i < times.size(); i++) { - Double current = fd.computePhiMeasure(times.get(i)); - if (current != null && prev != null) { - Assert.assertTrue(current >= prev); - } - prev = current; - } - }; - - checkAlive.accept(0, 20000, 100); - checkDeadMonotonic.accept(20000, 20500, 5); - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/src/test/java/org/apache/gossip/crdt/GrowOnlyCounterTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/crdt/GrowOnlyCounterTest.java b/src/test/java/org/apache/gossip/crdt/GrowOnlyCounterTest.java deleted file mode 100644 index 3a134af..0000000 --- a/src/test/java/org/apache/gossip/crdt/GrowOnlyCounterTest.java +++ /dev/null @@ -1,54 +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.crdt; - -import org.junit.Assert; -import org.junit.Test; - -import java.util.HashMap; -import java.util.Map; - -public class GrowOnlyCounterTest { - - @Test - public void mergeTest() { - - Map node1Counter = new HashMap<>(); - node1Counter.put("1", 3L); - Map node2Counter = new HashMap<>(); - node2Counter.put("2", 1L); - Map node3Counter = new HashMap<>(); - node3Counter.put("3", 2L); - - GrowOnlyCounter gCounter1 = new GrowOnlyCounter(node1Counter); - GrowOnlyCounter gCounter2 = new GrowOnlyCounter(node2Counter); - GrowOnlyCounter gCounter3 = new GrowOnlyCounter(node3Counter); - - // After node 2 receive from node 1 - gCounter2 = gCounter2.merge(gCounter1); - Assert.assertEquals(4, (long) gCounter2.value()); - - // After node 3 receive from node 1 - gCounter3 = gCounter3.merge(gCounter1); - Assert.assertEquals(5, (long) gCounter3.value()); - - // After node 3 receive from node 2 - gCounter3 = gCounter3.merge(gCounter2); - Assert.assertEquals(6, (long) gCounter3.value()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/src/test/java/org/apache/gossip/crdt/GrowOnlySetTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/crdt/GrowOnlySetTest.java b/src/test/java/org/apache/gossip/crdt/GrowOnlySetTest.java deleted file mode 100644 index d4f12b6..0000000 --- a/src/test/java/org/apache/gossip/crdt/GrowOnlySetTest.java +++ /dev/null @@ -1,38 +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.crdt; - -import java.util.Arrays; -import java.util.concurrent.ConcurrentHashMap; - -import org.junit.Assert; -import org.junit.Test; - -public class GrowOnlySetTest { - - @SuppressWarnings("rawtypes") - @Test - public void mergeTest(){ - ConcurrentHashMap a = new ConcurrentHashMap<>(); - GrowOnlySet gset = new GrowOnlySet<>(Arrays.asList("a", "b")); - Assert.assertEquals(gset, a.merge("a", gset, new CrdtBiFunctionMerge())); - GrowOnlySet over = new GrowOnlySet<>(Arrays.asList("b", "d")); - Assert.assertEquals(new GrowOnlySet<>(Arrays.asList("a", "b", "d")), - a.merge("a", over, CrdtBiFunctionMerge::applyStatic)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/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 deleted file mode 100644 index b19f221..0000000 --- a/src/test/java/org/apache/gossip/crdt/OrSetTest.java +++ /dev/null @@ -1,115 +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.crdt; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.apache.gossip.GossipSettings; -import org.apache.gossip.manager.GossipManager; -import org.apache.gossip.manager.GossipManagerBuilder; -import org.junit.Assert; -import org.junit.Test; - -public class OrSetTest { - - @Test - public void atest() { - OrSet i = new OrSet<>(new OrSet.Builder().add(4).add(5).add(6).remove(5)); - Assert.assertArrayEquals(Arrays.asList(4, 6).toArray(), i.value().toArray()); - } - - @Test - public void mergeTest(){ - OrSet i = new OrSet<>(new OrSet.Builder().add(4).add(5).add(6).remove(5)); - Assert.assertArrayEquals(Arrays.asList(4, 6).toArray(), i.value().toArray()); - OrSet j = new OrSet<>(new OrSet.Builder().add(9).add(4).add(5).remove(6)); - OrSet h = i.merge(j); - Assert.assertEquals(new OrSet(4,6,9,5), h); - } - - @Test - public void mergeTest2(){ - OrSet i = new OrSet<>(new OrSet.Builder().add(5).add(4).remove(4).add(6)); - Assert.assertEquals(new OrSet(5,6), i); - SortedSet tree = new TreeSet<>(); - for (Integer in: i.value()){ - tree.add(in); - } - TreeSet compare = new TreeSet<>(); - compare.add(5); - compare.add(6); - Assert.assertEquals(tree, compare); - } - - @Test - public void mergeTest4() { - Assert.assertArrayEquals(new Integer[] {}, - new OrSet(new OrSet.Builder().add(1).remove(1)).toArray()); - } - - @Test - public void mergeTest3(){ - OrSet i = new OrSet<>(1); - OrSet j = new OrSet<>(2); - OrSet k = new OrSet<>(i.merge(j), new OrSet.Builder().remove(1)); - Assert.assertArrayEquals(new Integer[] { 2 }, i.merge(j).merge(k).toArray()); - Assert.assertArrayEquals(new Integer[] { 2 }, j.merge(i).merge(k).toArray()); - Assert.assertArrayEquals(new Integer[] { 2 }, k.merge(i).merge(j).toArray()); - Assert.assertArrayEquals(new Integer[] { 2 }, k.merge(j).merge(i).toArray()); - Assert.assertEquals(j , i.merge(j.merge(k))); - } - - @Test - public void mergeTest9(){ - OrSet i = new OrSet<>(19); - OrSet j = i.merge(i); - Assert.assertEquals(i.value(), j.value()); - } - - @Test - public void serialTest() throws InterruptedException, URISyntaxException, IOException { - GossipManager gossipService2 = GossipManagerBuilder.newBuilder() - .cluster("a") - .uri(new URI("udp://" + "127.0.0.1" + ":" + (29000 + 1))) - .id("1") - .gossipSettings(new GossipSettings()) - .build(); - OrSet i = new OrSet(new OrSet.Builder().add(1).remove(1)); - String s = gossipService2.getObjectMapper().writeValueAsString(i); - @SuppressWarnings("unchecked") - OrSet back = gossipService2.getObjectMapper().readValue(s, OrSet.class); - Assert.assertEquals(back, i); - } - - @Test - public void mergeTestSame() { - OrSet i = new OrSet<>(19); - OrSet j = new OrSet<>(19); - OrSet k = i.merge(j); - Assert.assertEquals(2, k.getElements().get(19).size()); - OrSet y = new OrSet<>(k, new OrSet.Builder().remove(19)); - Assert.assertEquals(2, y.getTombstones().get(19).size()); - Assert.assertEquals(2, y.getElements().get(19).size()); - Assert.assertEquals(new OrSet().value(), y.value()); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/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 deleted file mode 100644 index e328c24..0000000 --- a/src/test/java/org/apache/gossip/manager/DataReaperTest.java +++ /dev/null @@ -1,104 +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; - -import com.codahale.metrics.MetricRegistry; -import java.net.URI; - -import org.apache.gossip.GossipSettings; -import org.apache.gossip.model.PerNodeDataMessage; -import org.apache.gossip.model.SharedDataMessage; -import org.junit.Assert; -import org.junit.Test; - -import io.teknek.tunit.TUnit; - -public class DataReaperTest { - - private final MetricRegistry registry = new MetricRegistry(); - String myId = "4"; - String key = "key"; - String value = "a"; - - @Test - public void testReaperOneShot() { - GossipSettings settings = new GossipSettings(); - settings.setPersistRingState(false); - settings.setPersistDataState(false); - 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)); - assertDataIsAtCorrectValue(gm); - gm.getDataReaper().runPerNodeOnce(); - gm.getDataReaper().runSharedOnce(); - assertDataIsRemoved(gm); - gm.shutdown(); - } - - private void assertDataIsAtCorrectValue(GossipManager gm){ - Assert.assertEquals(value, gm.findPerNodeGossipData(myId, key).getPayload()); - Assert.assertEquals(1, registry.getGauges().get(GossipCoreConstants.PER_NODE_DATA_SIZE).getValue()); - Assert.assertEquals(value, gm.findSharedGossipData(key).getPayload()); - Assert.assertEquals(1, registry.getGauges().get(GossipCoreConstants.SHARED_DATA_SIZE).getValue()); - } - - private void assertDataIsRemoved(GossipManager gm){ - TUnit.assertThat(() -> gm.findPerNodeGossipData(myId, key)).equals(null); - TUnit.assertThat(() -> gm.findSharedGossipData(key)).equals(null); - } - - private PerNodeDataMessage perNodeDatum(String key, String value) { - PerNodeDataMessage m = new PerNodeDataMessage(); - m.setExpireAt(System.currentTimeMillis() + 5L); - m.setKey(key); - m.setPayload(value); - m.setTimestamp(System.currentTimeMillis()); - return m; - } - - private SharedDataMessage sharedDatum(String key, String value) { - SharedDataMessage m = new SharedDataMessage(); - m.setExpireAt(System.currentTimeMillis() + 5L); - m.setKey(key); - m.setPayload(value); - m.setTimestamp(System.currentTimeMillis()); - return m; - } - - @Test - public void testHigherTimestampWins() { - String myId = "4"; - String key = "key"; - String value = "a"; - GossipSettings settings = new GossipSettings(); - GossipManager gm = GossipManagerBuilder.newBuilder().cluster("abc").gossipSettings(settings) - .id(myId).uri(URI.create("udp://localhost:7000")).registry(registry).build(); - gm.init(); - 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()); - gm.gossipPerNodeData(after); - Assert.assertEquals(value, gm.findPerNodeGossipData(myId, key).getPayload()); - gm.shutdown(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/src/test/java/org/apache/gossip/manager/GossipManagerBuilderTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/manager/GossipManagerBuilderTest.java b/src/test/java/org/apache/gossip/manager/GossipManagerBuilderTest.java deleted file mode 100644 index 8842643..0000000 --- a/src/test/java/org/apache/gossip/manager/GossipManagerBuilderTest.java +++ /dev/null @@ -1,121 +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; - -import com.codahale.metrics.MetricRegistry; -import org.apache.gossip.Member; -import org.apache.gossip.GossipSettings; -import org.apache.gossip.LocalMember; -import org.apache.gossip.manager.handlers.DefaultMessageInvoker; -import org.apache.gossip.manager.handlers.MessageInvoker; -import org.apache.gossip.manager.handlers.ResponseHandler; -import org.apache.gossip.manager.handlers.SimpleMessageInvoker; -import org.junit.Assert; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; - -import javax.xml.ws.Response; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.expectThrows; - -@RunWith(JUnitPlatform.class) -public class GossipManagerBuilderTest { - - @Test - public void idShouldNotBeNull() { - expectThrows(IllegalArgumentException.class,() -> { - GossipManagerBuilder.newBuilder().cluster("aCluster").build(); - }); - } - - @Test - public void clusterShouldNotBeNull() { - expectThrows(IllegalArgumentException.class,() -> { - GossipManagerBuilder.newBuilder().id("id").build(); - }); - } - - @Test - public void settingsShouldNotBeNull() { - expectThrows(IllegalArgumentException.class,() -> { - GossipManagerBuilder.newBuilder().id("id").cluster("aCluster").build(); - }); - } - - @Test - public void createMembersListIfNull() throws URISyntaxException { - GossipManager gossipManager = GossipManagerBuilder.newBuilder() - .id("id") - .cluster("aCluster") - .uri(new URI("udp://localhost:2000")) - .gossipSettings(new GossipSettings()) - .gossipMembers(null).registry(new MetricRegistry()).build(); - assertNotNull(gossipManager.getLiveMembers()); - } - - @Test - public void createDefaultMessageInvokerIfNull() throws URISyntaxException { - GossipManager gossipManager = GossipManagerBuilder.newBuilder() - .id("id") - .cluster("aCluster") - .uri(new URI("udp://localhost:2000")) - .gossipSettings(new GossipSettings()) - .messageInvoker(null).registry(new MetricRegistry()).build(); - assertNotNull(gossipManager.getMessageInvoker()); - Assert.assertEquals(gossipManager.getMessageInvoker().getClass(), new DefaultMessageInvoker().getClass()); - } - - @Test - public void testMessageInvokerKeeping() throws URISyntaxException { - MessageInvoker mi = new SimpleMessageInvoker(Response.class, new ResponseHandler()); - GossipManager gossipManager = GossipManagerBuilder.newBuilder() - .id("id") - .cluster("aCluster") - .uri(new URI("udp://localhost:2000")) - .gossipSettings(new GossipSettings()) - .messageInvoker(mi).registry(new MetricRegistry()).build(); - assertNotNull(gossipManager.getMessageInvoker()); - Assert.assertEquals(gossipManager.getMessageInvoker(), mi); - } - - @Test - public void useMemberListIfProvided() throws URISyntaxException { - LocalMember member = new LocalMember( - "aCluster", new URI("udp://localhost:2000"), "aGossipMember", - System.nanoTime(), new HashMap(), 1000, 1, "exponential"); - List memberList = new ArrayList<>(); - memberList.add(member); - GossipManager gossipManager = GossipManagerBuilder.newBuilder() - .id("id") - .cluster("aCluster") - .gossipSettings(new GossipSettings()) - .uri(new URI("udp://localhost:8000")) - .gossipMembers(memberList).registry(new MetricRegistry()).build(); - assertEquals(1, gossipManager.getDeadMembers().size()); - assertEquals(member.getId(), gossipManager.getDeadMembers().get(0).getId()); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/src/test/java/org/apache/gossip/manager/RingPersistenceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/manager/RingPersistenceTest.java b/src/test/java/org/apache/gossip/manager/RingPersistenceTest.java deleted file mode 100644 index d448b98..0000000 --- a/src/test/java/org/apache/gossip/manager/RingPersistenceTest.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.manager; - -import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.UnknownHostException; -import java.util.Arrays; -import org.apache.gossip.GossipSettings; -import org.apache.gossip.RemoteMember; -import org.junit.Assert; -import org.junit.Test; - -public class RingPersistenceTest { - - @Test - public void givenThatRingIsPersisted() throws UnknownHostException, InterruptedException, URISyntaxException { - GossipSettings settings = new GossipSettings(); - File f = aGossiperPersists(settings); - Assert.assertTrue(f.exists()); - aNewInstanceGetsRingInfo(settings); - f.delete(); - } - - private File aGossiperPersists(GossipSettings settings) throws UnknownHostException, InterruptedException, URISyntaxException { - GossipManager gossipService = GossipManagerBuilder.newBuilder() - .cluster("a") - .uri(new URI("udp://" + "127.0.0.1" + ":" + (29000 + 1))) - .id("1") - .gossipSettings(settings) - .gossipMembers( - Arrays.asList( - new RemoteMember("a", new URI("udp://" + "127.0.0.1" + ":" + (29000 + 0)), "0"), - new RemoteMember("a", new URI("udp://" + "127.0.0.1" + ":" + (29000 + 2)), "2"))).build(); - gossipService.getRingState().writeToDisk(); - return gossipService.getRingState().computeTarget(); - } - - private void aNewInstanceGetsRingInfo(GossipSettings settings) throws UnknownHostException, InterruptedException, URISyntaxException { - GossipManager gossipService2 = GossipManagerBuilder.newBuilder() - .cluster("a") - .uri(new URI("udp://" + "127.0.0.1" + ":" + (29000 + 1))) - .id("1") - .gossipSettings(settings).build(); - Assert.assertEquals(2, gossipService2.getMembers().size()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/src/test/java/org/apache/gossip/manager/UserDataPersistenceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/manager/UserDataPersistenceTest.java b/src/test/java/org/apache/gossip/manager/UserDataPersistenceTest.java deleted file mode 100644 index 7b17e41..0000000 --- a/src/test/java/org/apache/gossip/manager/UserDataPersistenceTest.java +++ /dev/null @@ -1,114 +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; - -import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.UnknownHostException; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.gossip.GossipSettings; -import org.apache.gossip.model.PerNodeDataMessage; -import org.apache.gossip.model.SharedDataMessage; -import org.junit.Assert; -import org.junit.Test; - -public class UserDataPersistenceTest { - - String nodeId = "1"; - - private GossipManager sameService() throws URISyntaxException { - GossipSettings settings = new GossipSettings(); - return GossipManagerBuilder.newBuilder() - .cluster("a") - .uri(new URI("udp://" + "127.0.0.1" + ":" + (29000 + 1))) - .id(nodeId) - .gossipSettings(settings).build(); - } - - @Test - public void givenThatRingIsPersisted() throws UnknownHostException, InterruptedException, URISyntaxException { - - { //Create a gossip service and force it to persist its user data - GossipManager gossipService = sameService(); - gossipService.init(); - gossipService.gossipPerNodeData(getToothpick()); - gossipService.gossipSharedData(getAnotherToothpick()); - gossipService.getUserDataState().writePerNodeToDisk(); - gossipService.getUserDataState().writeSharedToDisk(); - { //read the raw data and confirm - ConcurrentHashMap> l = gossipService.getUserDataState().readPerNodeFromDisk(); - Assert.assertEquals("red", ((AToothpick) l.get(nodeId).get("a").getPayload()).getColor()); - } - { - ConcurrentHashMap l = - gossipService.getUserDataState().readSharedDataFromDisk(); - Assert.assertEquals("blue", ((AToothpick) l.get("a").getPayload()).getColor()); - } - gossipService.shutdown(); - } - { //recreate the service and see that the data is read back in - GossipManager gossipService = sameService(); - gossipService.init(); - Assert.assertEquals("red", ((AToothpick) gossipService.findPerNodeGossipData(nodeId, "a").getPayload()).getColor()); - Assert.assertEquals("blue", ((AToothpick) gossipService.findSharedGossipData("a").getPayload()).getColor()); - File f = gossipService.getUserDataState().computeSharedTarget(); - File g = gossipService.getUserDataState().computePerNodeTarget(); - gossipService.shutdown(); - f.delete(); - g.delete(); - } - } - - public PerNodeDataMessage getToothpick(){ - AToothpick a = new AToothpick(); - a.setColor("red"); - PerNodeDataMessage d = new PerNodeDataMessage(); - d.setExpireAt(Long.MAX_VALUE); - d.setKey("a"); - d.setPayload(a); - d.setTimestamp(System.currentTimeMillis()); - return d; - } - - public SharedDataMessage getAnotherToothpick(){ - AToothpick a = new AToothpick(); - a.setColor("blue"); - SharedDataMessage d = new SharedDataMessage(); - d.setExpireAt(Long.MAX_VALUE); - d.setKey("a"); - d.setPayload(a); - d.setTimestamp(System.currentTimeMillis()); - return d; - } - - public static class AToothpick { - private String color; - public AToothpick(){ - - } - public String getColor() { - return color; - } - public void setColor(String color) { - this.color = color; - } - - } -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/src/test/java/org/apache/gossip/manager/handlers/MessageInvokerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/gossip/manager/handlers/MessageInvokerTest.java b/src/test/java/org/apache/gossip/manager/handlers/MessageInvokerTest.java deleted file mode 100644 index 571d7ba..0000000 --- a/src/test/java/org/apache/gossip/manager/handlers/MessageInvokerTest.java +++ /dev/null @@ -1,178 +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.ActiveGossipMessage; -import org.apache.gossip.model.Base; -import org.apache.gossip.udp.UdpSharedDataMessage; -import org.junit.Assert; -import org.junit.Test; - -public class MessageInvokerTest { - private class FakeMessage extends Base { - public FakeMessage() { - } - } - - private class FakeMessageData extends Base { - public int data; - - public FakeMessageData(int data) { - this.data = data; - } - } - - private class FakeMessageDataHandler implements MessageHandler { - public int data; - - public FakeMessageDataHandler() { - data = 0; - } - - public void invoke(GossipCore gossipCore, GossipManager gossipManager, Base base) { - data = ((FakeMessageData) base).data; - } - } - - private class FakeMessageHandler implements MessageHandler { - public int counter; - - public FakeMessageHandler() { - counter = 0; - } - - public void invoke(GossipCore gossipCore, GossipManager gossipManager, Base base) { - counter++; - } - } - - @Test - public void testSimpleInvoker() { - MessageInvoker mi = new SimpleMessageInvoker(FakeMessage.class, new FakeMessageHandler()); - Assert.assertTrue(mi.invoke(null, null, new FakeMessage())); - Assert.assertFalse(mi.invoke(null, null, new ActiveGossipMessage())); - } - - @Test(expected = NullPointerException.class) - public void testSimpleInvokerNullClassConstructor() { - new SimpleMessageInvoker(null, new FakeMessageHandler()); - } - - @Test(expected = NullPointerException.class) - public void testSimpleInvokerNullHandlerConstructor() { - new SimpleMessageInvoker(FakeMessage.class, null); - } - - @Test - public void testCallCountSimpleInvoker() { - FakeMessageHandler h = new FakeMessageHandler(); - MessageInvoker mi = new SimpleMessageInvoker(FakeMessage.class, h); - mi.invoke(null, null, new FakeMessage()); - Assert.assertEquals(1, h.counter); - mi.invoke(null, null, new ActiveGossipMessage()); - Assert.assertEquals(1, h.counter); - mi.invoke(null, null, new FakeMessage()); - Assert.assertEquals(2, h.counter); - } - - @Test(expected = NullPointerException.class) - public void cantAddNullInvoker() { - MessageInvokerCombiner mi = new MessageInvokerCombiner(); - mi.add(null); - } - - @Test - public void testCombinerClear() { - MessageInvokerCombiner mi = new MessageInvokerCombiner(); - mi.add(new SimpleMessageInvoker(FakeMessage.class, new FakeMessageHandler())); - Assert.assertTrue(mi.invoke(null, null, new FakeMessage())); - - mi.clear(); - Assert.assertFalse(mi.invoke(null, null, new FakeMessage())); - } - - @Test - public void testMessageInvokerCombiner() { - //Empty combiner - false result - MessageInvokerCombiner mi = new MessageInvokerCombiner(); - Assert.assertFalse(mi.invoke(null, null, new Base())); - - FakeMessageHandler h = new FakeMessageHandler(); - mi.add(new SimpleMessageInvoker(FakeMessage.class, h)); - mi.add(new SimpleMessageInvoker(FakeMessage.class, h)); - - Assert.assertTrue(mi.invoke(null, null, new FakeMessage())); - Assert.assertFalse(mi.invoke(null, null, new ActiveGossipMessage())); - Assert.assertEquals(2, h.counter); - - //Increase size in runtime. Should be 3 calls: 2+3 = 5 - mi.add(new SimpleMessageInvoker(FakeMessage.class, h)); - Assert.assertTrue(mi.invoke(null, null, new FakeMessage())); - Assert.assertEquals(5, h.counter); - } - - @Test - public void testMessageInvokerCombiner2levels() { - MessageInvokerCombiner mi = new MessageInvokerCombiner(); - FakeMessageHandler h = new FakeMessageHandler(); - - MessageInvokerCombiner mi1 = new MessageInvokerCombiner(); - mi1.add(new SimpleMessageInvoker(FakeMessage.class, h)); - mi1.add(new SimpleMessageInvoker(FakeMessage.class, h)); - - MessageInvokerCombiner mi2 = new MessageInvokerCombiner(); - mi2.add(new SimpleMessageInvoker(FakeMessage.class, h)); - mi2.add(new SimpleMessageInvoker(FakeMessage.class, h)); - - mi.add(mi1); - mi.add(mi2); - - Assert.assertTrue(mi.invoke(null, null, new FakeMessage())); - Assert.assertEquals(4, h.counter); - } - - @Test - public void testMessageInvokerCombinerDataShipping() { - MessageInvokerCombiner mi = new MessageInvokerCombiner(); - FakeMessageDataHandler h = new FakeMessageDataHandler(); - mi.add(new SimpleMessageInvoker(FakeMessageData.class, h)); - - Assert.assertTrue(mi.invoke(null, null, new FakeMessageData(101))); - Assert.assertEquals(101, h.data); - } - - @Test - public void testCombiningDefaultInvoker() { - MessageInvokerCombiner mi = new MessageInvokerCombiner(); - mi.add(new DefaultMessageInvoker()); - mi.add(new SimpleMessageInvoker(FakeMessage.class, new FakeMessageHandler())); - //UdpSharedGossipDataMessage with null gossipCore -> exception - boolean thrown = false; - try { - mi.invoke(null, null, new UdpSharedDataMessage()); - } catch (NullPointerException e) { - thrown = true; - } - Assert.assertTrue(thrown); - //DefaultInvoker skips FakeMessage and FakeHandler works ok - Assert.assertTrue(mi.invoke(null, null, new FakeMessage())); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-gossip/blob/298b1ae3/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties deleted file mode 100644 index e2a60e1..0000000 --- a/src/test/resources/log4j.properties +++ /dev/null @@ -1,20 +0,0 @@ -# Licensed 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. - -log4j.rootLogger=INFO,stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%5p %d{HH:mm:ss,SSS} %m%n - -log4j.logger.io.teknek=DEBUG -log4j.logger.com.google.code.gossip=INFO