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/replica1 | |
| parent | c577b64ba33fca4fb5d879dc94a491b5003b0ae9 (diff) | |
| download | soen423-69a4c73336cfe88852251b131c14034208bb4658.zip | |
Modified replicas
Diffstat (limited to 'src/main/java/derms/replica1')
| -rw-r--r-- | src/main/java/derms/replica1/Replica1.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/derms/replica1/Replica1.java b/src/main/java/derms/replica1/Replica1.java index 7e10994..654ec44 100644 --- a/src/main/java/derms/replica1/Replica1.java +++ b/src/main/java/derms/replica1/Replica1.java @@ -22,6 +22,7 @@ public class Replica1 implements Replica { private final InetAddress localAddr; private final ResponderClient responderClient; private final ReplicaManager replicaManager; + private boolean byzFailure; public Replica1(ReplicaManager replicaManager) { this.replicaManager = replicaManager; @@ -46,6 +47,20 @@ public class Replica1 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; + } + pool.execute(DERMSServer::new); alive = true; log.info(getClass().getSimpleName() + " started."); @@ -54,6 +69,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; + } + String status = responderClient.addResource( request.getResourceID(), request.getResourceType(), @@ -70,6 +92,8 @@ public class Replica1 implements Replica { ThreadPool.shutdown(pool, log); alive = false; log.info("Finished shutting down."); + + // [TEST] Restart process without byzantine failure or crash startProcess(0, 0); } |