summaryrefslogtreecommitdiffstats
path: root/src/main/java/derms/replica3/Replica3.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/derms/replica3/Replica3.java')
-rw-r--r--src/main/java/derms/replica3/Replica3.java33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/main/java/derms/replica3/Replica3.java b/src/main/java/derms/replica3/Replica3.java
index 5c6a113..456c4f1 100644
--- a/src/main/java/derms/replica3/Replica3.java
+++ b/src/main/java/derms/replica3/Replica3.java
@@ -13,6 +13,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import derms.replica3.Logger;
+import derms.util.TestLogger;
public class Replica3 implements Replica{
static final InetSocketAddress announceGroup = new InetSocketAddress("225.5.5.5", 5555);
@@ -27,6 +28,7 @@ public class Replica3 implements Replica{
// private final Logger log;
private boolean alive;
+ private boolean byzFailure;
private final ReplicaManager replicaManager;
public Replica3(City city, ReplicaManager replicaManager) throws IOException {
@@ -42,6 +44,7 @@ public class Replica3 implements Replica{
// log.config("Local address is "+localAddr.toString());
this.alive = true;
+ this.byzFailure = false;
}
public Replica3(String city, ReplicaManager replicaManager) throws IOException {
@@ -52,7 +55,21 @@ public class Replica3 implements Replica{
public boolean isAlive() { return alive; }
@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;
+ }
+
// TODO
// log.info(getClass().getSimpleName() + " started.");
System.out.println("process started");
@@ -61,6 +78,14 @@ public class Replica3 implements Replica{
@Override
public void processRequest(Request request) {
// log.info(request.toString());
+
+ // [TEST] Simulate byzantine failure (return incorrect value)
+ if (byzFailure == true) {
+ Response response = new Response(request, replicaManager.getReplicaId(), "BYZANTINE FAILURE", false);
+ replicaManager.sendResponseToFE(response);
+ return;
+ }
+
System.out.println("process request and good");
String status = "";
try {
@@ -104,7 +129,10 @@ public class Replica3 implements Replica{
public void restart() {
// TODO
shutdown();
- startProcess();
+
+ // [TEST] Restart process without byzantine failure or crash
+ TestLogger.log("REPLICA 3: {RESTARTED}");
+ startProcess(0, 0);
}
@Override
@@ -112,6 +140,7 @@ public class Replica3 implements Replica{
private void shutdown() {
// TODO
+ alive = false;
}
public synchronized String addResource(String resourceID, String resourceName, int duration) {