diff options
| author | ShazaAhmed <ShazaMamdouh@aucegypt.edu> | 2024-12-03 13:26:06 -0500 |
|---|---|---|
| committer | ShazaAhmed <ShazaMamdouh@aucegypt.edu> | 2024-12-03 13:27:17 -0500 |
| commit | b7f7d9872b5820521b77f4a3175c5d1c1a0c4058 (patch) | |
| tree | 81fc7c283e327cca153544d7e3600933f54a5132 /src/main/java/derms/replica3 | |
| parent | a0a6fcd7bd2dd2fb736477bcbd3d034b38565fba (diff) | |
| parent | b0214bbc7e7a7ee6aac9dca2610060ac0f88dc77 (diff) | |
| download | soen423-b7f7d9872b5820521b77f4a3175c5d1c1a0c4058.zip | |
Merge branch 'test'
Diffstat (limited to 'src/main/java/derms/replica3')
| -rw-r--r-- | src/main/java/derms/replica3/Replica3.java | 33 |
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) { |