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/main/java/derms/client/ResponderClient.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/java/derms/client') diff --git a/src/main/java/derms/client/ResponderClient.java b/src/main/java/derms/client/ResponderClient.java index 23361d7..ec599b4 100644 --- a/src/main/java/derms/client/ResponderClient.java +++ b/src/main/java/derms/client/ResponderClient.java @@ -9,7 +9,7 @@ public class ResponderClient extends CLI { private final DERMSInterface server; - private ResponderClient(String FEhost) throws MalformedURLException { + public ResponderClient(String FEhost) throws MalformedURLException { server = Client.connectToServer(FEhost); commands.put("add", new Add()); @@ -43,7 +43,7 @@ public class ResponderClient extends CLI { } } - private class Add implements Command { + public class Add implements Command { @Override public void exec(String[] args) { if (args.length < 3) @@ -52,7 +52,7 @@ public class ResponderClient extends CLI { add(args[0], args[1], args[2]); } - private void add(String resourceID, String resourceName, String durationStr) { + public void add(String resourceID, String resourceName, String durationStr) { try { int duration = Integer.parseInt(durationStr); if (duration < 0) { -- 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/main/java/derms/client/ResponderClient.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/main/java/derms/client') diff --git a/src/main/java/derms/client/ResponderClient.java b/src/main/java/derms/client/ResponderClient.java index ec599b4..43be3f3 100644 --- a/src/main/java/derms/client/ResponderClient.java +++ b/src/main/java/derms/client/ResponderClient.java @@ -1,8 +1,10 @@ package derms.client; import derms.frontend.DERMSInterface; +import derms.util.TestLogger; import java.net.MalformedURLException; +import java.util.Objects; public class ResponderClient extends CLI { public static final String usage = "Usage: java derms.client.ResponderClient "; @@ -60,6 +62,11 @@ public class ResponderClient extends CLI { } String response = server.addResource(resourceID, resourceName, duration); System.out.println(response); + if (response.contains("Fail")) { + TestLogger.log("[FAILED: " + response + "]"); + } else { + TestLogger.log("[SUCCESS: " + response + "]"); + } } catch (NumberFormatException e) { System.out.println("invalid duration: " + durationStr); } -- 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/main/java/derms/client/ResponderClient.java | 97 ++----------------- src/main/java/derms/client/ResponderClientCLI.java | 103 +++++++++++++++++++++ 2 files changed, 110 insertions(+), 90 deletions(-) create mode 100644 src/main/java/derms/client/ResponderClientCLI.java (limited to 'src/main/java/derms/client') diff --git a/src/main/java/derms/client/ResponderClient.java b/src/main/java/derms/client/ResponderClient.java index 43be3f3..4db30c8 100644 --- a/src/main/java/derms/client/ResponderClient.java +++ b/src/main/java/derms/client/ResponderClient.java @@ -6,105 +6,22 @@ import derms.util.TestLogger; import java.net.MalformedURLException; import java.util.Objects; -public class ResponderClient extends CLI { - public static final String usage = "Usage: java derms.client.ResponderClient "; - +public class ResponderClient { private final DERMSInterface server; public ResponderClient(String FEhost) throws MalformedURLException { server = Client.connectToServer(FEhost); - - commands.put("add", new Add()); - cmdDescriptions.add(new Description( - "add ", - "Add ad resource to the server")); - - commands.put("remove", new Remove()); - cmdDescriptions.add(new Description( - "remove ", - "Decrease the duration of a resource. If duration is negative, the resource is removed entirely.")); - - commands.put("list", new List()); - cmdDescriptions.add(new Description( - "list ", - "List available resources")); } - public static void main(String[] args) { - if (args.length < 1) { - System.err.println(usage); - System.exit(1); - } - - String FEhost = args[0]; - - try { - (new ResponderClient(FEhost)).run(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } + public String addResource(String resourceID, String resourceName, int duration) { + return server.addResource(resourceID, resourceName, duration); } - public class Add implements Command { - @Override - public void exec(String[] args) { - if (args.length < 3) - System.out.println("invalid arguments for 'add'"); - else - add(args[0], args[1], args[2]); - } - - public void add(String resourceID, String resourceName, String durationStr) { - try { - int duration = Integer.parseInt(durationStr); - if (duration < 0) { - throw new NumberFormatException("duration less than 0"); - } - String response = server.addResource(resourceID, resourceName, duration); - System.out.println(response); - if (response.contains("Fail")) { - TestLogger.log("[FAILED: " + response + "]"); - } else { - TestLogger.log("[SUCCESS: " + response + "]"); - } - } catch (NumberFormatException e) { - System.out.println("invalid duration: " + durationStr); - } - } + public String removeResource(String resourceID, int duration) { + return server.removeResource(resourceID, duration); } - private class Remove implements Command { - @Override - public void exec(String[] args) { - if (args.length < 2) - System.out.println("invalid arguments for 'remove'"); - else - remove(args[0], args[1]); - } - - private void remove(String resourceID, String durationStr) { - try { - int duration = Integer.parseInt(durationStr); - String response = server.removeResource(resourceID, duration); - System.out.println(response); - } catch (NumberFormatException e) { - System.out.println("invalid duration: " + durationStr); - } - } - } - - private class List implements Command { - @Override - public void exec(String[] args) { - if (args.length < 1) - System.out.println("invalid arguments for 'list'"); - else - list(args[0]); - } - - private void list(String resourceName) { - String response = server.listResourceAvailability(resourceName); - System.out.println(response); - } + public String listResourceAvailability(String resourceName) { + return server.listResourceAvailability(resourceName); } } diff --git a/src/main/java/derms/client/ResponderClientCLI.java b/src/main/java/derms/client/ResponderClientCLI.java new file mode 100644 index 0000000..86a5a9a --- /dev/null +++ b/src/main/java/derms/client/ResponderClientCLI.java @@ -0,0 +1,103 @@ +package derms.client; + +import derms.frontend.DERMSInterface; + +import java.net.MalformedURLException; + +public class ResponderClientCLI extends CLI { + public static final String usage = "Usage: java derms.client.ResponderClient "; + + private final DERMSInterface server; + + private ResponderClientCLI(String FEhost) throws MalformedURLException { + server = Client.connectToServer(FEhost); + + commands.put("add", new Add()); + cmdDescriptions.add(new CLI.Description( + "add ", + "Add ad resource to the server")); + + commands.put("remove", new Remove()); + cmdDescriptions.add(new CLI.Description( + "remove ", + "Decrease the duration of a resource. If duration is negative, the resource is removed entirely.")); + + commands.put("list", new List()); + cmdDescriptions.add(new CLI.Description( + "list ", + "List available resources")); + } + + public static void main(String[] args) { + if (args.length < 1) { + System.err.println(usage); + System.exit(1); + } + + String FEhost = args[0]; + + try { + (new ResponderClientCLI(FEhost)).run(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + } + + private class Add implements CLI.Command { + @Override + public void exec(String[] args) { + if (args.length < 3) + System.out.println("invalid arguments for 'add'"); + else + add(args[0], args[1], args[2]); + } + + private void add(String resourceID, String resourceName, String durationStr) { + try { + int duration = Integer.parseInt(durationStr); + if (duration < 0) { + throw new NumberFormatException("duration less than 0"); + } + String response = server.addResource(resourceID, resourceName, duration); + System.out.println(response); + } catch (NumberFormatException e) { + System.out.println("invalid duration: " + durationStr); + } + } + } + + private class Remove implements CLI.Command { + @Override + public void exec(String[] args) { + if (args.length < 2) + System.out.println("invalid arguments for 'remove'"); + else + remove(args[0], args[1]); + } + + private void remove(String resourceID, String durationStr) { + try { + int duration = Integer.parseInt(durationStr); + String response = server.removeResource(resourceID, duration); + System.out.println(response); + } catch (NumberFormatException e) { + System.out.println("invalid duration: " + durationStr); + } + } + } + + private class List implements CLI.Command { + @Override + public void exec(String[] args) { + if (args.length < 1) + System.out.println("invalid arguments for 'list'"); + else + list(args[0]); + } + + private void list(String resourceName) { + String response = server.listResourceAvailability(resourceName); + System.out.println(response); + } + } +} -- cgit v1.2.3 From 7d3234f615a5d7cdb49942988cbe5fe198dab93d Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Tue, 3 Dec 2024 10:29:55 -0500 Subject: non-cli coordinator client --- src/main/java/derms/client/CoordinatorClient.java | 112 +++---------------- .../java/derms/client/CoordinatorClientCLI.java | 119 +++++++++++++++++++++ 2 files changed, 131 insertions(+), 100 deletions(-) create mode 100644 src/main/java/derms/client/CoordinatorClientCLI.java (limited to 'src/main/java/derms/client') diff --git a/src/main/java/derms/client/CoordinatorClient.java b/src/main/java/derms/client/CoordinatorClient.java index 570d76b..40d8a94 100644 --- a/src/main/java/derms/client/CoordinatorClient.java +++ b/src/main/java/derms/client/CoordinatorClient.java @@ -4,116 +4,28 @@ import derms.frontend.DERMSInterface; import java.net.MalformedURLException; -public class CoordinatorClient extends CLI { - public static final String usage = "Usage: java derms.client.CoordinatorClient "; - - private final String coordinatorID; +public class CoordinatorClient { private final DERMSInterface server; + private final String coordinatorID; - private CoordinatorClient(String coordinatorID, String FEhost) throws MalformedURLException { - this.coordinatorID = coordinatorID; + public CoordinatorClient(String coordinatorID, String FEhost) throws MalformedURLException { this.server = Client.connectToServer(FEhost); - - commands.put("request", new Request()); - cmdDescriptions.add(new Description( - "request ", - "Borrow a resource.")); - - commands.put("find", new Find()); - cmdDescriptions.add(new Description( - "find ", - "List borrowed resources.")); - - commands.put("return", new Return()); - cmdDescriptions.add(new Description( - "return ", - "Return a borrowed resource.")); - - commands.put("swap", new Swap()); - cmdDescriptions.add(new Description( - "swap ", - "Return the old resource and borrow the new one.")); - } - - public static void main(String[] args) { - if (args.length < 2) { - System.err.println(usage); - System.exit(1); - } - - String coordinatorID = args[0]; - String FEhost = args[1]; - - try { - (new CoordinatorClient(coordinatorID, FEhost)).run(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } + this.coordinatorID = coordinatorID; } - private class Request implements Command { - @Override - public void exec(String[] args) { - if (args.length < 2) - System.out.println("invalid arguments for 'request'"); - else - request(args[0], args[1]); - } - - private void request(String resourceID, String durationStr) { - try { - int duration = Integer.parseInt(durationStr); - if (duration < 0) - throw new NumberFormatException("duration less than 0"); - String response = server.requestResource(coordinatorID, resourceID, duration); - System.out.println(response); - } catch (NumberFormatException e) { - System.out.println("invalid duration: " + e.getMessage()); - } - } + public String requestResource(String resourceID, int duration) { + return server.requestResource(coordinatorID, resourceID, duration); } - private class Find implements Command { - @Override - public void exec(String[] args) { - if (args.length < 1) - System.out.println("invalid arguments for 'find'"); - else find(args[0]); - } - - private void find(String resourceID) { - String response = server.findResource(coordinatorID, resourceID); - System.out.println(response); - } + public String findResource(String resourceName) { + return server.findResource(coordinatorID, resourceName); } - private class Return implements Command { - @Override - public void exec(String[] args) { - if (args.length < 1) - System.out.println("invalid arguments for 'return'"); - else - returnResource(args[0]); - } - - private void returnResource(String resourceID) { - String response = server.returnResource(coordinatorID, resourceID); - System.out.println(response); - } + public String returnResource(String resourceID) { + return server.returnResource(coordinatorID, resourceID); } - private class Swap implements Command { - @Override - public void exec(String[] args) { - if (args.length < 4) - System.out.println("invalid arguments for 'swap'"); - else - swap(args[0], args[1], args[2], args[3]); - } - - private void swap(String oldResourceID, String oldResourceType, String newResourceID, String newResourceType) { - String response = server.swapResource(coordinatorID, oldResourceID, oldResourceType, newResourceID, newResourceType); - System.out.println(response); - } + public String swapResource(String oldResourceID, String oldResourceType, String newResourceID, String newResourceType) { + return server.swapResource(coordinatorID, oldResourceID, oldResourceType, newResourceID, newResourceType); } } diff --git a/src/main/java/derms/client/CoordinatorClientCLI.java b/src/main/java/derms/client/CoordinatorClientCLI.java new file mode 100644 index 0000000..bddc6e6 --- /dev/null +++ b/src/main/java/derms/client/CoordinatorClientCLI.java @@ -0,0 +1,119 @@ +package derms.client; + +import derms.frontend.DERMSInterface; + +import java.net.MalformedURLException; + +public class CoordinatorClientCLI extends CLI { + public static final String usage = "Usage: java derms.client.CoordinatorClient "; + + private final String coordinatorID; + private final DERMSInterface server; + + private CoordinatorClientCLI(String coordinatorID, String FEhost) throws MalformedURLException { + this.coordinatorID = coordinatorID; + this.server = Client.connectToServer(FEhost); + + commands.put("request", new Request()); + cmdDescriptions.add(new CLI.Description( + "request ", + "Borrow a resource.")); + + commands.put("find", new Find()); + cmdDescriptions.add(new CLI.Description( + "find ", + "List borrowed resources.")); + + commands.put("return", new Return()); + cmdDescriptions.add(new CLI.Description( + "return ", + "Return a borrowed resource.")); + + commands.put("swap", new Swap()); + cmdDescriptions.add(new CLI.Description( + "swap ", + "Return the old resource and borrow the new one.")); + } + + public static void main(String[] args) { + if (args.length < 2) { + System.err.println(usage); + System.exit(1); + } + + String coordinatorID = args[0]; + String FEhost = args[1]; + + try { + (new CoordinatorClientCLI(coordinatorID, FEhost)).run(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + } + + private class Request implements CLI.Command { + @Override + public void exec(String[] args) { + if (args.length < 2) + System.out.println("invalid arguments for 'request'"); + else + request(args[0], args[1]); + } + + private void request(String resourceID, String durationStr) { + try { + int duration = Integer.parseInt(durationStr); + if (duration < 0) + throw new NumberFormatException("duration less than 0"); + String response = server.requestResource(coordinatorID, resourceID, duration); + System.out.println(response); + } catch (NumberFormatException e) { + System.out.println("invalid duration: " + e.getMessage()); + } + } + } + + private class Find implements CLI.Command { + @Override + public void exec(String[] args) { + if (args.length < 1) + System.out.println("invalid arguments for 'find'"); + else find(args[0]); + } + + private void find(String resourceID) { + String response = server.findResource(coordinatorID, resourceID); + System.out.println(response); + } + } + + private class Return implements CLI.Command { + @Override + public void exec(String[] args) { + if (args.length < 1) + System.out.println("invalid arguments for 'return'"); + else + returnResource(args[0]); + } + + private void returnResource(String resourceID) { + String response = server.returnResource(coordinatorID, resourceID); + System.out.println(response); + } + } + + private class Swap implements CLI.Command { + @Override + public void exec(String[] args) { + if (args.length < 4) + System.out.println("invalid arguments for 'swap'"); + else + swap(args[0], args[1], args[2], args[3]); + } + + private void swap(String oldResourceID, String oldResourceType, String newResourceID, String newResourceType) { + String response = server.swapResource(coordinatorID, oldResourceID, oldResourceType, newResourceID, newResourceType); + System.out.println(response); + } + } +} -- 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/main/java/derms/client/ResponderClient.java | 8 +++++++- src/main/java/derms/client/ResponderClientCLI.java | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src/main/java/derms/client') diff --git a/src/main/java/derms/client/ResponderClient.java b/src/main/java/derms/client/ResponderClient.java index 4db30c8..6834c76 100644 --- a/src/main/java/derms/client/ResponderClient.java +++ b/src/main/java/derms/client/ResponderClient.java @@ -14,7 +14,13 @@ public class ResponderClient { } public String addResource(String resourceID, String resourceName, int duration) { - return server.addResource(resourceID, resourceName, duration); + String res = server.addResource(resourceID, resourceName, duration); + if (res.contains("Fail")) { + TestLogger.log("[FAILED: " + res + "]"); + } else { + TestLogger.log("[SUCCESS: " + res + "]"); + } + return res; } public String removeResource(String resourceID, int duration) { diff --git a/src/main/java/derms/client/ResponderClientCLI.java b/src/main/java/derms/client/ResponderClientCLI.java index 86a5a9a..de046d5 100644 --- a/src/main/java/derms/client/ResponderClientCLI.java +++ b/src/main/java/derms/client/ResponderClientCLI.java @@ -1,6 +1,7 @@ package derms.client; import derms.frontend.DERMSInterface; +import derms.util.TestLogger; import java.net.MalformedURLException; -- cgit v1.2.3