summaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/derms/test/SystemTest.java75
1 files changed, 58 insertions, 17 deletions
diff --git a/src/test/java/derms/test/SystemTest.java b/src/test/java/derms/test/SystemTest.java
index 5354b54..6ee1f35 100644
--- a/src/test/java/derms/test/SystemTest.java
+++ b/src/test/java/derms/test/SystemTest.java
@@ -8,6 +8,7 @@ import derms.replica1.DERMSServerPublisher;
import org.junit.jupiter.api.*;
import java.io.*;
+import java.net.MalformedURLException;
import java.nio.file.*;
import java.util.*;
import derms.util.*;
@@ -18,7 +19,10 @@ import static org.junit.jupiter.api.Assertions.*;
class SystemTest {
private static final String TEST_LOG_PATH = "SystemTest.log";
- private static final String EXPECTED_LOG_PATH = "TestExpected.log";
+ private static final String EXPECTED_LOG_PATH_NORM = "TestExpected.log";
+ private static final String EXPECTED_LOG_PATH_BYZ = "TestExpectedByz.log";
+ private static final String EXPECTED_LOG_PATH_CRASH = "TestExpectedCrash.log";
+ private static final String EXPECTED_LOG_PATH_COMBINED = "TestExpectedCombined.log";
// [TODO]
// input IP and NET config
@@ -60,7 +64,7 @@ class SystemTest {
DERMSServerPublisher.stop();
}
- @Test
+ /* @Test
void testNormal() throws IOException {
// Replica 1
String[] argsRM = {"1", "MTL", IP, "0", "0"};
@@ -75,10 +79,10 @@ class SystemTest {
addCommand.add("MTL1001", "ambulance", "10");
// Compare the number of lines in the log files, to determine if they match or not
- assertTrue(LogComparator.compareLineCounts(TEST_LOG_PATH, EXPECTED_LOG_PATH));
- }
+ assertTrue(LogComparator.compareFiles(TEST_LOG_PATH, EXPECTED_LOG_PATH_NORM));
+ } */
- @Test
+ /* @Test
void testByzantine() throws IOException {
// Replica 1
String[] argsRM = {"1", "MTL", IP, "1", "0"};
@@ -93,10 +97,10 @@ class SystemTest {
addCommand.add("MTL1001", "ambulance", "10");
// Compare the number of lines in the log files, to determine if they match or not
- assertTrue(LogComparator.compareLineCounts(TEST_LOG_PATH, EXPECTED_LOG_PATH));
- }
+ assertTrue(LogComparator.compareFiles(TEST_LOG_PATH, EXPECTED_LOG_PATH_BYZ));
+ } */
- @Test
+ /* @Test
void testCrash() throws IOException {
// Replica 1
String[] argsRM = {"1", "MTL", IP, "0", "1"};
@@ -111,8 +115,8 @@ class SystemTest {
addCommand.add("MTL1001", "ambulance", "10");
// Compare the number of lines in the log files, to determine if they match or not
- assertTrue(LogComparator.compareLineCounts(TEST_LOG_PATH, EXPECTED_LOG_PATH));
- }
+ assertTrue(LogComparator.compareFiles(TEST_LOG_PATH, EXPECTED_LOG_PATH_CRASH));
+ } */
@Test
void testCombined() throws IOException {
@@ -130,15 +134,52 @@ class SystemTest {
ReplicaManager.main(argsRM1);
ReplicaManager.main(argsRM3);
- ResponderClient responderClient = new ResponderClient(IP);
- ResponderClient.Add addCommand = responderClient.new Add();
- addCommand.add("MTL1001", "ambulance", "10");
+ Thread thread1 = new Thread(() -> {
+ ResponderClient responderClient = null;
+ try {
+ responderClient = new ResponderClient(IP);
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+ if (responderClient != null) {
+ ResponderClient.Add addCommand = responderClient.new Add();
+ addCommand.add("MTL1001", "ambulance", "10");
+ }
+ }
+ });
+
+ Thread thread2 = new Thread(() -> {
+ ResponderClient responderClient2 = null;
+ try {
+ responderClient2 = new ResponderClient(IP);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } finally {
+ if (responderClient2 != null) {
+ ResponderClient.Add addCommand2 = responderClient2.new Add();
+ addCommand2.add("MTL1002", "ambulance", "11");
+ }
+ }
+ });
- ResponderClient responderClient2 = new ResponderClient(IP);
- ResponderClient.Add addCommand2 = responderClient2.new Add();
- addCommand2.add("MTL1002", "ambulance", "11");
+ thread1.start();
+ thread2.start();
+
+ try {
+ thread1.join();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ try {
+ thread2.join();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
// Compare the number of lines in the log files, to determine if they match or not
- assertTrue(LogComparator.compareLineCounts(TEST_LOG_PATH, EXPECTED_LOG_PATH));
+ assertTrue(LogComparator.compareFiles(TEST_LOG_PATH, EXPECTED_LOG_PATH_COMBINED));
}
} \ No newline at end of file