From 0393d99c099d8c77c6aed22fda99058fe2eb8b3c Mon Sep 17 00:00:00 2001 From: Ian Date: Sat, 30 Jan 2016 14:43:39 +1100 Subject: [PATCH] Change to unit test so that it doesn't require the setup of multiple loopback devices. Instead of using addresses in the format of `"127.0.0." + i` it now instead uses a first address of 127.0.0.1 with variable ports in the form of `50000 + i`. This way straight out of the repo you can run the tests, and to some degree achieves the same level of functional testing. Also added a small additional bit of debug logging in `GossipService` as well as some `INFO` logging in the test - as I figure it's a test that should be suitable. --- .../java/com/google/code/gossip/GossipService.java | 3 +++ .../java/io/teknek/gossip/TenNodeThreeSeedTest.java | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/code/gossip/GossipService.java b/src/main/java/com/google/code/gossip/GossipService.java index 5c8ac7b..728e77e 100644 --- a/src/main/java/com/google/code/gossip/GossipService.java +++ b/src/main/java/com/google/code/gossip/GossipService.java @@ -47,6 +47,9 @@ public class GossipService { } public void start() { + String address = get_gossipManager().getMyself().getHost() + ":" + get_gossipManager().getMyself().getPort(); + LOGGER.debug( "Starting: " + _gossipManager.getName() + " - " + address ); + _gossipManager.start(); } diff --git a/src/test/java/io/teknek/gossip/TenNodeThreeSeedTest.java b/src/test/java/io/teknek/gossip/TenNodeThreeSeedTest.java index f91f689..5dcca8c 100644 --- a/src/test/java/io/teknek/gossip/TenNodeThreeSeedTest.java +++ b/src/test/java/io/teknek/gossip/TenNodeThreeSeedTest.java @@ -9,6 +9,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; +import org.apache.log4j.Logger; import org.junit.Assert; import org.junit.Test; @@ -20,6 +21,7 @@ import com.google.code.gossip.event.GossipListener; import com.google.code.gossip.event.GossipState; public class TenNodeThreeSeedTest { + private static final Logger log = Logger.getLogger( TenNodeThreeSeedTest.class ); @Test public void test() throws UnknownHostException, InterruptedException{ @@ -33,15 +35,19 @@ public class TenNodeThreeSeedTest { public void abc() throws InterruptedException, UnknownHostException{ GossipSettings settings = new GossipSettings(); + + log.info( "Adding seed nodes" ); int seedNodes = 3; List startupMembers = new ArrayList<>(); for (int i = 1; i < seedNodes+1; ++i) { - startupMembers.add(new RemoteGossipMember("127.0.0." + i, 2000, i + "")); + startupMembers.add(new RemoteGossipMember("127.0.0.1", 50000 + i, i + "")); } + + log.info( "Adding clients" ); final List clients = new ArrayList<>(); final int clusterMembers = 5; for (int i = 1; i < clusterMembers+1; ++i) { - GossipService gossipService = new GossipService("127.0.0." + i, 2000, i + "", + GossipService gossipService = new GossipService("127.0.0.1", 50000 + i, i + "", startupMembers, settings, new GossipListener(){ @Override