m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/GossipGirlMessage.java25
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/InitiateGossipMessage.java11
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java4
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/ModuleType.java3
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java37
5 files changed, 78 insertions, 2 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/GossipGirlMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/GossipGirlMessage.java
new file mode 100644
index 0000000..705d64a
--- /dev/null
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/GossipGirlMessage.java
@@ -0,0 +1,25 @@
+package pl.edu.mimuw.cloudatlas.agent.messages;
+
+import pl.edu.mimuw.cloudatlas.agent.modules.Module;
+import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType;
+
+public abstract class GossipGirlMessage extends AgentMessage {
+ public enum Type {
+ INITIATE
+ }
+
+ private Type type;
+
+ public GossipGirlMessage(String messageId, long timestamp, Type type) {
+ super(messageId, ModuleType.GOSSIP, timestamp);
+ this.type = type;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public void callMe(Module module) throws InterruptedException, Module.InvalidMessageType {
+ module.handleTyped(this);
+ }
+}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/InitiateGossipMessage.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/InitiateGossipMessage.java
new file mode 100644
index 0000000..d216d59
--- /dev/null
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/messages/InitiateGossipMessage.java
@@ -0,0 +1,11 @@
+package pl.edu.mimuw.cloudatlas.agent.messages;
+
+import pl.edu.mimuw.cloudatlas.agent.modules.ModuleType;
+
+public class InitiateGossipMessage extends GossipGirlMessage {
+ private long nextGossipId = 0;
+
+ public InitiateGossipMessage(String messageId, long timestamp) {
+ super(messageId, timestamp, Type.INITIATE);
+ }
+}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java
index 67fdab9..ec87649 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Module.java
@@ -28,6 +28,10 @@ public abstract class Module {
throw new InvalidMessageType("Got a TimerSchedulerMessage in module " + moduleType.toString());
}
+ public void handleTyped(GossipGirlMessage message) throws InterruptedException, InvalidMessageType {
+ throw new InvalidMessageType("Got a GossipGirlMessage in module " + moduleType.toString());
+ }
+
public void handleTyped(QurnikMessage message) throws InterruptedException, InvalidMessageType {
throw new InvalidMessageType("Got a QurnikMessage in module " + moduleType.toString());
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/ModuleType.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/ModuleType.java
index d221f06..40e629a 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/ModuleType.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/ModuleType.java
@@ -5,8 +5,7 @@ public enum ModuleType {
TIMER_GTP,
RMI,
UDP,
- GOSSIP_IN,
- GOSSIP_OUT,
+ GOSSIP,
STATE,
QUERY,
// for testing
diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java
new file mode 100644
index 0000000..0658b65
--- /dev/null
+++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlTest.java
@@ -0,0 +1,37 @@
+package pl.edu.mimuw.cloudatlas.agent.modules;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import pl.edu.mimuw.cloudatlas.agent.MockExecutor;
+import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.GetStateMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.GossipGirlMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.InitiateGossipMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.StanikMessage;
+
+public class GossipGirlTest {
+ private GossipGirl gossipGirl;
+ private MockExecutor executor;
+
+ @Before
+ public void setupLocals() {
+ gossipGirl = new GossipGirl();
+ executor = new MockExecutor(gossipGirl);
+ }
+
+ @Test
+ public void initiateGossipRequestsState() throws Exception {
+ InitiateGossipMessage message = new InitiateGossipMessage("test_msg", 0);
+ gossipGirl.handleTyped(message);
+
+ AgentMessage receivedMessage = executor.messagesToPass.poll();
+ assertNotNull(receivedMessage);
+ assertEquals(ModuleType.STATE, receivedMessage.getDestinationModule());
+ StanikMessage stanikMessage = (StanikMessage) receivedMessage;
+ assertEquals(StanikMessage.Type.GET_STATE, stanikMessage.getType());
+ GetStateMessage getStateMessage = (GetStateMessage) stanikMessage;
+ assertEquals(ModuleType.GOSSIP, getStateMessage.getRequestingModule());
+ }
+}