Move to URI in model and configuration

This commit is contained in:
Edward Capriolo
2016-06-02 09:23:55 -04:00
parent 968203e8a0
commit ddc9a67dd6
16 changed files with 153 additions and 162 deletions

View File

@ -19,6 +19,8 @@ package io.teknek.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;
@ -43,7 +45,7 @@ public class ShutdownDeadtimeTest {
private static final Logger log = Logger.getLogger(ShutdownDeadtimeTest.class );
@Test
//@Ignore
public void DeadNodesDoNotComeAliveAgain() throws InterruptedException, UnknownHostException {
public void DeadNodesDoNotComeAliveAgain() throws InterruptedException, UnknownHostException, URISyntaxException {
GossipSettings settings = new GossipSettings(1000, 10000);
String cluster = UUID.randomUUID().toString();
@ -51,7 +53,8 @@ public class ShutdownDeadtimeTest {
int seedNodes = 3;
List<GossipMember> startupMembers = new ArrayList<>();
for (int i = 1; i < seedNodes + 1; ++i) {
startupMembers.add(new RemoteGossipMember(cluster, "127.0.0.1", 50000 + i, i + ""));
URI uri = new URI("udp://" + "127.0.0.1" + ":" + (50000 + i));
startupMembers.add(new RemoteGossipMember(cluster, uri, i + ""));
}
log.info( "Adding clients" );
@ -59,7 +62,8 @@ public class ShutdownDeadtimeTest {
final int clusterMembers = 5;
for (int i = 1; i < clusterMembers+1; ++i) {
final int j = i;
GossipService gossipService = new GossipService(cluster, "127.0.0.1", 50000 + i, i + "",
URI uri = new URI("udp://" + "127.0.0.1" + ":" + (50000 + i));
GossipService gossipService = new GossipService(cluster, uri, i + "",
startupMembers, settings,
new GossipListener(){
@Override
@ -83,7 +87,7 @@ public class ShutdownDeadtimeTest {
Random r = new Random();
int randomClientId = r.nextInt(clusterMembers);
log.info( "shutting down " + randomClientId );
final int shutdownPort = clients.get(randomClientId).get_gossipManager().getMyself().getPort();
final int shutdownPort = clients.get(randomClientId).get_gossipManager().getMyself().getUri().getPort();
final String shutdownId = clients.get(randomClientId).get_gossipManager().getMyself().getId();
clients.get(randomClientId).shutdown();
TUnit.assertThat(new Callable<Integer> (){
@ -105,8 +109,9 @@ public class ShutdownDeadtimeTest {
return total;
}}).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo(4);
URI uri = new URI("udp://" + "127.0.0.1" + ":" + shutdownPort);
// start client again
GossipService gossipService = new GossipService(cluster, "127.0.0.1", shutdownPort, shutdownId + "",
GossipService gossipService = new GossipService(cluster, uri, shutdownId + "",
startupMembers, settings,
new GossipListener(){
@Override

View File

@ -30,6 +30,8 @@ import io.teknek.tunit.TUnit;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.UUID;
import java.util.concurrent.Callable;
@ -44,13 +46,14 @@ public class StartupSettingsTest {
private static final String CLUSTER = UUID.randomUUID().toString();
@Test
public void testUsingSettingsFile() throws IOException, InterruptedException, JSONException {
public void testUsingSettingsFile() throws IOException, InterruptedException, JSONException, URISyntaxException {
File settingsFile = File.createTempFile("gossipTest",".json");
log.debug( "Using settings file: " + settingsFile.getAbsolutePath() );
settingsFile.deleteOnExit();
writeSettingsFile(settingsFile);
URI uri = new URI("udp://" + "127.0.0.1" + ":" + 50000);
final GossipService firstService = new GossipService(
CLUSTER, "127.0.0.1", 50000, UUID.randomUUID().toString(),
CLUSTER, uri, UUID.randomUUID().toString(),
new ArrayList<GossipMember>(), new GossipSettings(), null);
firstService.start();
@ -76,11 +79,11 @@ public class StartupSettingsTest {
"[{\n" + // It is odd that this is meant to be in an array, but oh well.
" \"cluster\":\"" + CLUSTER + "\",\n" +
" \"id\":\"" + UUID.randomUUID() + "\",\n" +
" \"port\":50001,\n" +
" \"uri\":\"udp://127.0.0.1:50001\",\n" +
" \"gossip_interval\":1000,\n" +
" \"cleanup_interval\":10000,\n" +
" \"members\":[\n" +
" {\"cluster\": \"" + CLUSTER + "\",\"host\":\"127.0.0.1\", \"port\":50000}\n" +
" {\"cluster\": \"" + CLUSTER + "\",\"uri\":\"udp://127.0.0.1:5000\"}\n" +
" ]\n" +
"}]";

View File

@ -19,6 +19,8 @@ package io.teknek.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;
@ -41,16 +43,16 @@ public class TenNodeThreeSeedTest {
private static final Logger log = Logger.getLogger( TenNodeThreeSeedTest.class );
@Test
public void test() throws UnknownHostException, InterruptedException{
public void test() throws UnknownHostException, InterruptedException, URISyntaxException{
abc();
}
@Test
public void testAgain() throws UnknownHostException, InterruptedException{
public void testAgain() throws UnknownHostException, InterruptedException, URISyntaxException{
abc();
}
public void abc() throws InterruptedException, UnknownHostException{
public void abc() throws InterruptedException, UnknownHostException, URISyntaxException{
GossipSettings settings = new GossipSettings();
String cluster = UUID.randomUUID().toString();
@ -58,14 +60,16 @@ public class TenNodeThreeSeedTest {
int seedNodes = 3;
List<GossipMember> startupMembers = new ArrayList<>();
for (int i = 1; i < seedNodes+1; ++i) {
startupMembers.add(new RemoteGossipMember(cluster, "127.0.0.1", 50000 + i, i + ""));
URI uri = new URI("udp://" + "127.0.0.1" + ":" + (50000 + i));
startupMembers.add(new RemoteGossipMember(cluster, uri, i + ""));
}
log.info( "Adding clients" );
final List<GossipService> clients = new ArrayList<>();
final int clusterMembers = 5;
for (int i = 1; i < clusterMembers+1; ++i) {
GossipService gossipService = new GossipService(cluster, "127.0.0.1", 50000 + i, i + "",
URI uri = new URI("udp://" + "127.0.0.1" + ":" + (50000 + i));
GossipService gossipService = new GossipService(cluster, uri, i + "",
startupMembers, settings,
new GossipListener(){
@Override
@ -75,7 +79,6 @@ public class TenNodeThreeSeedTest {
});
clients.add(gossipService);
gossipService.start();
gossipService.get_gossipManager().getMemberList();
}
TUnit.assertThat(new Callable<Integer> (){
public Integer call() throws Exception {
@ -84,7 +87,7 @@ public class TenNodeThreeSeedTest {
total += clients.get(i).get_gossipManager().getMemberList().size();
}
return total;
}}).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo(20);
}}).afterWaitingAtMost(20, TimeUnit.SECONDS).isEqualTo(20);
for (int i = 0; i < clusterMembers; ++i) {
clients.get(i).shutdown();