diff options
| author | BMatajsz <90217645+BMatajsz@users.noreply.github.com> | 2024-12-03 00:15:41 -0500 |
|---|---|---|
| committer | BMatajsz <90217645+BMatajsz@users.noreply.github.com> | 2024-12-03 00:15:41 -0500 |
| commit | 69a4c73336cfe88852251b131c14034208bb4658 (patch) | |
| tree | dcd3a4c85e380f33bd5bb2cfdd2bd2a5bf30df85 /src/main/java/derms/replica3 | |
| parent | c577b64ba33fca4fb5d879dc94a491b5003b0ae9 (diff) | |
| download | soen423-69a4c73336cfe88852251b131c14034208bb4658.zip | |
Modified replicas
Diffstat (limited to 'src/main/java/derms/replica3')
| -rw-r--r-- | src/main/java/derms/replica3/Replica3.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/java/derms/replica3/Replica3.java b/src/main/java/derms/replica3/Replica3.java index ca01fdf..b7cf8ef 100644 --- a/src/main/java/derms/replica3/Replica3.java +++ b/src/main/java/derms/replica3/Replica3.java @@ -27,6 +27,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 +43,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 { @@ -53,6 +55,20 @@ public class Replica3 implements Replica{ @Override 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 +77,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,6 +128,8 @@ public class Replica3 implements Replica{ public void restart() { // TODO shutdown(); + + // [TEST] Restart process without byzantine failure or crash startProcess(0, 0); } @@ -112,6 +138,7 @@ public class Replica3 implements Replica{ private void shutdown() { // TODO + alive = false; } public synchronized String addResource(String resourceID, String resourceName, int duration) { |