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/replica2/Replica2.java | |
| parent | c577b64ba33fca4fb5d879dc94a491b5003b0ae9 (diff) | |
| download | soen423-69a4c73336cfe88852251b131c14034208bb4658.zip | |
Modified replicas
Diffstat (limited to 'src/main/java/derms/replica2/Replica2.java')
| -rw-r--r-- | src/main/java/derms/replica2/Replica2.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main/java/derms/replica2/Replica2.java b/src/main/java/derms/replica2/Replica2.java index 9383cf5..5f24e24 100644 --- a/src/main/java/derms/replica2/Replica2.java +++ b/src/main/java/derms/replica2/Replica2.java @@ -24,6 +24,7 @@ public class Replica2 implements Replica { private final ReplicaManager replicaManager; private final ExecutorService pool; private boolean alive = false; + private boolean byzFailure; public Replica2(City city, ReplicaManager replicaManager) throws IOException { this.city = city; @@ -58,6 +59,20 @@ public class Replica2 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; + } + try { pool.execute(new ResourceAvailability.Server(localAddr, resources)); } catch (IOException e) { @@ -113,6 +128,13 @@ public class Replica2 implements Replica { 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; + } + String status = ""; try { switch (request.getFunction()) { @@ -153,6 +175,8 @@ public class Replica2 implements Replica { @Override public void restart() { shutdown(); + + // [TEST] Restart process without byzantine failure or crash startProcess(0, 0); } |