From d6067d28ce2a22c64cb595af6bca48c81b1664da Mon Sep 17 00:00:00 2001 From: BMatajsz <90217645+BMatajsz@users.noreply.github.com> Date: Tue, 3 Dec 2024 03:30:34 -0500 Subject: Test progress --- src/test/java/derms/test/SystemTest.java | 144 +++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 src/test/java/derms/test/SystemTest.java (limited to 'src/test/java') diff --git a/src/test/java/derms/test/SystemTest.java b/src/test/java/derms/test/SystemTest.java new file mode 100644 index 0000000..5354b54 --- /dev/null +++ b/src/test/java/derms/test/SystemTest.java @@ -0,0 +1,144 @@ +package derms.test; + +import derms.ReplicaManager; +import derms.Sequencer; +import derms.client.ResponderClient; +import derms.frontend.FE; +import derms.replica1.DERMSServerPublisher; + +import org.junit.jupiter.api.*; +import java.io.*; +import java.nio.file.*; +import java.util.*; +import derms.util.*; +import derms.replica3.*; + +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"; + + // [TODO] + // input IP and NET config + private static String IP = "127.0.0.1"; + private static String NET = "en0"; + + @BeforeEach + void clearLogFile() throws IOException { + TestLogger.clearLog(); + } + + @BeforeAll + static void runMains() throws IOException { + String[] argsFE = {IP, IP}; + String[] argsSQ = {IP, NET}; + + Thread feThread = new Thread(() -> { + try { + FE.main(argsFE); + } catch (Exception e) { + e.printStackTrace(); + } + }); + feThread.start(); + + Thread sequencerThread = new Thread(() -> { + try { + Sequencer.main(argsSQ); + } catch (Exception e) { + e.printStackTrace(); + } + }); + sequencerThread.start(); + } + + @AfterEach + void stopServers() { + // Stop the DERMSServerPublisher + DERMSServerPublisher.stop(); + } + + @Test + void testNormal() throws IOException { + // Replica 1 + String[] argsRM = {"1", "MTL", IP, "0", "0"}; + + // [TODO] + // Run the main function of the desired replica, for example: + DERMSServerPublisher.main(new String[0]); + + ReplicaManager.main(argsRM); + ResponderClient responderClient = new ResponderClient(IP); + ResponderClient.Add addCommand = responderClient.new Add(); + 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)); + } + + @Test + void testByzantine() throws IOException { + // Replica 1 + String[] argsRM = {"1", "MTL", IP, "1", "0"}; + + // [TODO] + // Run the main function of the desired replica, for example: + DERMSServerPublisher.main(new String[0]); + + ReplicaManager.main(argsRM); + ResponderClient responderClient = new ResponderClient(IP); + ResponderClient.Add addCommand = responderClient.new Add(); + 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)); + } + + @Test + void testCrash() throws IOException { + // Replica 1 + String[] argsRM = {"1", "MTL", IP, "0", "1"}; + + // [TODO] + // Run the main function of the desired replica, for example: + DERMSServerPublisher.main(new String[0]); + + ReplicaManager.main(argsRM); + ResponderClient responderClient = new ResponderClient(IP); + ResponderClient.Add addCommand = responderClient.new Add(); + 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)); + } + + @Test + void testCombined() throws IOException { + // Replica 1 and 2 + String[] argsRM1 = {"1", "MTL", IP, "1", "0"}; + String[] argsRM3 = {"3", "MTL", IP, "0", "1"}; + + // [TODO] + // Run the main function of the desired TWO replicas, for example: + DERMSServerPublisher.main(new String[0]); + MTLServer.main(new String[0]); + QUEServer.main(new String[0]); + SHEServer.main(new String[0]); + + ReplicaManager.main(argsRM1); + ReplicaManager.main(argsRM3); + + ResponderClient responderClient = new ResponderClient(IP); + ResponderClient.Add addCommand = responderClient.new Add(); + addCommand.add("MTL1001", "ambulance", "10"); + + ResponderClient responderClient2 = new ResponderClient(IP); + ResponderClient.Add addCommand2 = responderClient2.new Add(); + addCommand2.add("MTL1002", "ambulance", "11"); + + // 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)); + } +} \ No newline at end of file -- cgit v1.2.3 From 44df5df0b65df279aaf471fa8258da218ed7c522 Mon Sep 17 00:00:00 2001 From: BMatajsz <90217645+BMatajsz@users.noreply.github.com> Date: Tue, 3 Dec 2024 09:34:00 -0500 Subject: Added expected test results --- src/test/java/derms/test/SystemTest.java | 75 ++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 17 deletions(-) (limited to 'src/test/java') 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 -- cgit v1.2.3 From 4a4144cabda83c02eed0917eed884f3ec5641ba9 Mon Sep 17 00:00:00 2001 From: BMatajsz <90217645+BMatajsz@users.noreply.github.com> Date: Tue, 3 Dec 2024 09:39:46 -0500 Subject: Uncommented tests --- src/test/java/derms/test/SystemTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/derms/test/SystemTest.java b/src/test/java/derms/test/SystemTest.java index 6ee1f35..2112ce9 100644 --- a/src/test/java/derms/test/SystemTest.java +++ b/src/test/java/derms/test/SystemTest.java @@ -64,7 +64,7 @@ class SystemTest { DERMSServerPublisher.stop(); } - /* @Test + @Test void testNormal() throws IOException { // Replica 1 String[] argsRM = {"1", "MTL", IP, "0", "0"}; @@ -80,9 +80,9 @@ class SystemTest { // Compare the number of lines in the log files, to determine if they match or not 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"}; @@ -98,9 +98,9 @@ class SystemTest { // Compare the number of lines in the log files, to determine if they match or not 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"}; @@ -116,7 +116,7 @@ class SystemTest { // Compare the number of lines in the log files, to determine if they match or not assertTrue(LogComparator.compareFiles(TEST_LOG_PATH, EXPECTED_LOG_PATH_CRASH)); - } */ + } @Test void testCombined() throws IOException { -- cgit v1.2.3 From 33732b560ddc12e2a9e99729666ad88286013668 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Tue, 3 Dec 2024 09:57:33 -0500 Subject: SystemTest: infer network interface from ip address --- src/test/java/derms/test/SystemTest.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/derms/test/SystemTest.java b/src/test/java/derms/test/SystemTest.java index 2112ce9..3ae83a8 100644 --- a/src/test/java/derms/test/SystemTest.java +++ b/src/test/java/derms/test/SystemTest.java @@ -9,6 +9,8 @@ import derms.replica1.DERMSServerPublisher; import org.junit.jupiter.api.*; import java.io.*; import java.net.MalformedURLException; +import java.net.InetAddress; +import java.net.NetworkInterface; import java.nio.file.*; import java.util.*; import derms.util.*; @@ -27,7 +29,6 @@ class SystemTest { // [TODO] // input IP and NET config private static String IP = "127.0.0.1"; - private static String NET = "en0"; @BeforeEach void clearLogFile() throws IOException { @@ -37,7 +38,6 @@ class SystemTest { @BeforeAll static void runMains() throws IOException { String[] argsFE = {IP, IP}; - String[] argsSQ = {IP, NET}; Thread feThread = new Thread(() -> { try { @@ -50,7 +50,10 @@ class SystemTest { Thread sequencerThread = new Thread(() -> { try { - Sequencer.main(argsSQ); + InetAddress ip = InetAddress.getByName(IP); + NetworkInterface netIfc = NetworkInterface.getByInetAddress(ip); + Sequencer sequencer = new Sequencer(ip, netIfc); + sequencer.run(); } catch (Exception e) { e.printStackTrace(); } -- cgit v1.2.3 From 0123ebaac66527b0e17d89cec8b41e073afba885 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Tue, 3 Dec 2024 09:57:56 -0500 Subject: separate responder client from cli --- src/test/java/derms/test/SystemTest.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/derms/test/SystemTest.java b/src/test/java/derms/test/SystemTest.java index 3ae83a8..59b08fa 100644 --- a/src/test/java/derms/test/SystemTest.java +++ b/src/test/java/derms/test/SystemTest.java @@ -78,8 +78,7 @@ class SystemTest { ReplicaManager.main(argsRM); ResponderClient responderClient = new ResponderClient(IP); - ResponderClient.Add addCommand = responderClient.new Add(); - addCommand.add("MTL1001", "ambulance", "10"); + responderClient.addResource("MTL1001", "ambulance", 10); // Compare the number of lines in the log files, to determine if they match or not assertTrue(LogComparator.compareFiles(TEST_LOG_PATH, EXPECTED_LOG_PATH_NORM)); @@ -96,8 +95,7 @@ class SystemTest { ReplicaManager.main(argsRM); ResponderClient responderClient = new ResponderClient(IP); - ResponderClient.Add addCommand = responderClient.new Add(); - addCommand.add("MTL1001", "ambulance", "10"); + responderClient.addResource("MTL1001", "ambulance", 10); // Compare the number of lines in the log files, to determine if they match or not assertTrue(LogComparator.compareFiles(TEST_LOG_PATH, EXPECTED_LOG_PATH_BYZ)); @@ -114,8 +112,7 @@ class SystemTest { ReplicaManager.main(argsRM); ResponderClient responderClient = new ResponderClient(IP); - ResponderClient.Add addCommand = responderClient.new Add(); - addCommand.add("MTL1001", "ambulance", "10"); + responderClient.addResource("MTL1001", "ambulance", 10); // Compare the number of lines in the log files, to determine if they match or not assertTrue(LogComparator.compareFiles(TEST_LOG_PATH, EXPECTED_LOG_PATH_CRASH)); @@ -146,8 +143,7 @@ class SystemTest { e.printStackTrace(); } finally { if (responderClient != null) { - ResponderClient.Add addCommand = responderClient.new Add(); - addCommand.add("MTL1001", "ambulance", "10"); + responderClient.addResource("MTL1001", "ambulance", 10); } } }); @@ -160,8 +156,7 @@ class SystemTest { e.printStackTrace(); } finally { if (responderClient2 != null) { - ResponderClient.Add addCommand2 = responderClient2.new Add(); - addCommand2.add("MTL1002", "ambulance", "11"); + responderClient2.addResource("MTL1002", "ambulance", 11); } } }); -- cgit v1.2.3 From 19166b8af1bf635f3f11a21abcc22cba46cebd4a Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Tue, 3 Dec 2024 12:38:16 -0500 Subject: pass IP to replica manager --- src/test/java/derms/test/SystemTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/test/java') diff --git a/src/test/java/derms/test/SystemTest.java b/src/test/java/derms/test/SystemTest.java index 59b08fa..aa3e066 100644 --- a/src/test/java/derms/test/SystemTest.java +++ b/src/test/java/derms/test/SystemTest.java @@ -70,7 +70,7 @@ class SystemTest { @Test void testNormal() throws IOException { // Replica 1 - String[] argsRM = {"1", "MTL", IP, "0", "0"}; + String[] argsRM = {"1", "MTL", IP, IP, "0", "0"}; // [TODO] // Run the main function of the desired replica, for example: -- cgit v1.2.3 From 80c0584575d62ffd487668909ed3d6b0a0353591 Mon Sep 17 00:00:00 2001 From: BMatajsz <90217645+BMatajsz@users.noreply.github.com> Date: Tue, 3 Dec 2024 12:41:22 -0500 Subject: Re-added logs --- src/test/java/derms/test/SystemTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/test/java') diff --git a/src/test/java/derms/test/SystemTest.java b/src/test/java/derms/test/SystemTest.java index 59b08fa..3cc3f6b 100644 --- a/src/test/java/derms/test/SystemTest.java +++ b/src/test/java/derms/test/SystemTest.java @@ -28,7 +28,7 @@ class SystemTest { // [TODO] // input IP and NET config - private static String IP = "127.0.0.1"; + private static String IP = "172.16.62.225"; @BeforeEach void clearLogFile() throws IOException { -- cgit v1.2.3 From b0214bbc7e7a7ee6aac9dca2610060ac0f88dc77 Mon Sep 17 00:00:00 2001 From: BMatajsz <90217645+BMatajsz@users.noreply.github.com> Date: Tue, 3 Dec 2024 12:47:55 -0500 Subject: Modified args in test --- src/test/java/derms/test/SystemTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/derms/test/SystemTest.java b/src/test/java/derms/test/SystemTest.java index 3a69bfb..818b4e9 100644 --- a/src/test/java/derms/test/SystemTest.java +++ b/src/test/java/derms/test/SystemTest.java @@ -87,7 +87,7 @@ class SystemTest { @Test void testByzantine() throws IOException { // Replica 1 - String[] argsRM = {"1", "MTL", IP, "1", "0"}; + String[] argsRM = {"1", "MTL", IP, IP, "1", "0"}; // [TODO] // Run the main function of the desired replica, for example: @@ -104,7 +104,7 @@ class SystemTest { @Test void testCrash() throws IOException { // Replica 1 - String[] argsRM = {"1", "MTL", IP, "0", "1"}; + String[] argsRM = {"1", "MTL", IP, IP, "0", "1"}; // [TODO] // Run the main function of the desired replica, for example: @@ -121,8 +121,8 @@ class SystemTest { @Test void testCombined() throws IOException { // Replica 1 and 2 - String[] argsRM1 = {"1", "MTL", IP, "1", "0"}; - String[] argsRM3 = {"3", "MTL", IP, "0", "1"}; + String[] argsRM1 = {"1", "MTL", IP, IP, "1", "0"}; + String[] argsRM3 = {"3", "MTL", IP, IP, "0", "1"}; // [TODO] // Run the main function of the desired TWO replicas, for example: -- cgit v1.2.3