summaryrefslogtreecommitdiffstats
path: root/src/main/java/derms/replica1
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/derms/replica1')
-rw-r--r--src/main/java/derms/replica1/DERMSServerPublisher.java19
-rw-r--r--src/main/java/derms/replica1/Replica1.java30
2 files changed, 47 insertions, 2 deletions
diff --git a/src/main/java/derms/replica1/DERMSServerPublisher.java b/src/main/java/derms/replica1/DERMSServerPublisher.java
index 44ee879..c94cb34 100644
--- a/src/main/java/derms/replica1/DERMSServerPublisher.java
+++ b/src/main/java/derms/replica1/DERMSServerPublisher.java
@@ -3,8 +3,27 @@ package derms.replica1;
import javax.xml.ws.Endpoint;
public class DERMSServerPublisher {
+
+ private static Endpoint[] endpoints = new Endpoint[3];
+
public static void main(String[] args) {
// try {
+// endpoints[0] = Endpoint.publish("http://localhost:8387/ws/derms", new DERMSServer("MTL"));
+// endpoints[1] = Endpoint.publish("http://localhost:8081/ws/derms", new DERMSServer("QUE"));
+// endpoints[2] = Endpoint.publish("http://localhost:8082/ws/derms", new DERMSServer("SHE"));
+// } catch (InterruptedException e) {
+// throw new RuntimeException(e);
+// }
+ }
+
+ public static void stop() {
+ for (Endpoint endpoint : endpoints) {
+ if (endpoint != null && endpoint.isPublished()) {
+ endpoint.stop();
+ System.out.println("DERMS Server is stopped.");
+ }
+ }
+// try {
// Endpoint.publish("http://localhost:8387/ws/derms", new DERMSServer("MTL"));
// Endpoint.publish("http://localhost:8081/ws/derms", new DERMSServer("QUE"));
// Endpoint.publish("http://localhost:8082/ws/derms", new DERMSServer("SHE"));
diff --git a/src/main/java/derms/replica1/Replica1.java b/src/main/java/derms/replica1/Replica1.java
index 6863d5c..1520b73 100644
--- a/src/main/java/derms/replica1/Replica1.java
+++ b/src/main/java/derms/replica1/Replica1.java
@@ -5,6 +5,7 @@ import derms.ReplicaManager;
import derms.Request;
import derms.Response;
import derms.replica2.DermsLogger;
+import derms.util.TestLogger;
import derms.util.ThreadPool;
import javax.xml.ws.Endpoint;
@@ -32,6 +33,7 @@ public class Replica1 implements Replica {
private final ConcurrentHashMap<String, Integer> portsMap;
private final Random r = new Random();
+ private boolean byzFailure;
public Replica1(ReplicaManager replicaManager) {
this.replicaManager = replicaManager;
@@ -60,7 +62,21 @@ public class Replica1 implements Replica {
}
@Override
- public void startProcess() {
+ public void startProcess(int byzantine, int crash) {
+ // [TEST] Detect crash
+ if (crash == 1) {
+ alive = false;
+ } else {
+ alive = true;
+ }
+
+ // [TEST] Detect byzantine failure
+ if (byzantine == 1) {
+ byzFailure = true;
+ } else {
+ byzFailure = false;
+ }
+
try {
server = new DERMSServer("MTL", portsMap);
} catch (InterruptedException e) {
@@ -89,6 +105,13 @@ public class Replica1 implements Replica {
@Override
public void processRequest(Request request) {
+ // [TEST] Simulate byzantine failure (return incorrect value)
+ if (byzFailure == true) {
+ Response response = new Response(request, replicaManager.getReplicaId(), "BYZANTINE FAILURE", false);
+ replicaManager.sendResponseToFE(response);
+ return;
+ }
+
log.info(request.toString());
String status = "";
@@ -137,7 +160,10 @@ public class Replica1 implements Replica {
ThreadPool.shutdown(pool, log);
alive = false;
log.info("Finished shutting down.");
- startProcess();
+
+ // [TEST] Restart process without byzantine failure or crash
+ TestLogger.log("REPLICA 1: {RESTARTED}");
+ startProcess(0, 0);
}
@Override