GOSSIP-25 Create reaper process to expire per-node data

This commit is contained in:
Edward Capriolo
2016-10-07 02:03:43 -04:00
parent daea6edb15
commit f35dddd8f2
12 changed files with 206 additions and 46 deletions

View File

@ -46,17 +46,17 @@ public class DataTest {
public Integer call() throws Exception {
int total = 0;
for (int i = 0; i < clusterMembers; ++i) {
total += clients.get(i).get_gossipManager().getLiveMembers().size();
total += clients.get(i).getGossipManager().getLiveMembers().size();
}
return total;
}}).afterWaitingAtMost(20, TimeUnit.SECONDS).isEqualTo(2);
clients.get(0).gossipData(msg());
clients.get(0).gossipPerNodeData(msg());
Thread.sleep(10000);
TUnit.assertThat(
new Callable<Object> (){
public Object call() throws Exception {
GossipDataMessage x = clients.get(1).findGossipData(1+"" , "a");
GossipDataMessage x = clients.get(1).findPerNodeData(1+"" , "a");
if (x == null) return "";
else return x.getPayload();
}})

View File

@ -78,7 +78,7 @@ public class ShutdownDeadtimeTest {
public Integer call() throws Exception {
int total = 0;
for (int i = 0; i < clusterMembers; ++i) {
total += clients.get(i).get_gossipManager().getLiveMembers().size();
total += clients.get(i).getGossipManager().getLiveMembers().size();
}
return total;
}
@ -88,15 +88,15 @@ 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().getUri()
final int shutdownPort = clients.get(randomClientId).getGossipManager().getMyself().getUri()
.getPort();
final String shutdownId = clients.get(randomClientId).get_gossipManager().getMyself().getId();
final String shutdownId = clients.get(randomClientId).getGossipManager().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).get_gossipManager().getLiveMembers().size();
total += clients.get(i).getGossipManager().getLiveMembers().size();
}
return total;
}
@ -107,7 +107,7 @@ public class ShutdownDeadtimeTest {
public Integer call() throws Exception {
int total = 0;
for (int i = 0; i < clusterMembers - 1; ++i) {
total += clients.get(i).get_gossipManager().getDeadList().size();
total += clients.get(i).getGossipManager().getDeadList().size();
}
return total;
}
@ -130,7 +130,7 @@ public class ShutdownDeadtimeTest {
public Integer call() throws Exception {
int total = 0;
for (int i = 0; i < clusterMembers; ++i) {
total += clients.get(i).get_gossipManager().getLiveMembers().size();
total += clients.get(i).getGossipManager().getLiveMembers().size();
}
return total;
}

View File

@ -62,7 +62,7 @@ public class StartupSettingsTest {
TUnit.assertThat(new Callable<Integer> (){
public Integer call() throws Exception {
return firstService.get_gossipManager().getLiveMembers().size();
return firstService.getGossipManager().getLiveMembers().size();
}}).afterWaitingAtMost(30, TimeUnit.SECONDS).isEqualTo(0);
final GossipService serviceUnderTest = new GossipService(
StartupSettings.fromJSONFile( settingsFile )
@ -70,7 +70,7 @@ public class StartupSettingsTest {
serviceUnderTest.start();
TUnit.assertThat(new Callable<Integer> (){
public Integer call() throws Exception {
return serviceUnderTest.get_gossipManager().getLiveMembers().size();
return serviceUnderTest.getGossipManager().getLiveMembers().size();
}}).afterWaitingAtMost(10, TimeUnit.SECONDS).isEqualTo(1);
firstService.shutdown();
serviceUnderTest.shutdown();

View File

@ -82,7 +82,7 @@ public class TenNodeThreeSeedTest {
public Integer call() throws Exception {
int total = 0;
for (int i = 0; i < clusterMembers; ++i) {
total += clients.get(i).get_gossipManager().getLiveMembers().size();
total += clients.get(i).getGossipManager().getLiveMembers().size();
}
return total;
}}).afterWaitingAtMost(20, TimeUnit.SECONDS).isEqualTo(20);

View File

@ -0,0 +1,55 @@
package org.apache.gossip.manager;
import java.net.URI;
import org.apache.gossip.GossipSettings;
import org.apache.gossip.manager.random.RandomGossipManager;
import org.apache.gossip.model.GossipDataMessage;
import org.junit.Assert;
import org.junit.Test;
import io.teknek.tunit.TUnit;
public class DataReaperTest {
@Test
public void testReaperOneShot() {
String myId = "4";
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:5000")).build();
gm.gossipPerNodeData(perNodeDatum(key, value));
Assert.assertEquals(value, gm.findGossipData(myId, key).getPayload());
gm.getDataReaper().runOnce();
TUnit.assertThat(() -> gm.findGossipData(myId, key)).equals(null);
}
private GossipDataMessage perNodeDatum(String key, String value) {
GossipDataMessage m = new GossipDataMessage();
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 = RandomGossipManager.newBuilder().cluster("abc").settings(settings)
.withId(myId).uri(URI.create("udp://localhost:5000")).build();
GossipDataMessage before = perNodeDatum(key, value);
GossipDataMessage after = perNodeDatum(key, "b");
after.setTimestamp(after.getTimestamp() - 1);
gm.gossipPerNodeData(before);
Assert.assertEquals(value, gm.findGossipData(myId, key).getPayload());
gm.gossipPerNodeData(after);
Assert.assertEquals(value, gm.findGossipData(myId, key).getPayload());
}
}