From c075fe952167b2221647581216e9c12d31d5acea Mon Sep 17 00:00:00 2001 From: Jason Maassen Date: Fri, 16 Mar 2018 11:52:33 +0100 Subject: [PATCH] Fixed equals, hashCode and copyconstructor of JobDescription. Fixes #617 --- .../xenon/schedulers/JobDescription.java | 14 ++++--- .../xenon/schedulers/JobDescriptionTest.java | 37 ++++++++++++++----- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/main/java/nl/esciencecenter/xenon/schedulers/JobDescription.java b/src/main/java/nl/esciencecenter/xenon/schedulers/JobDescription.java index 934ac4d49..fb9d4bbc5 100644 --- a/src/main/java/nl/esciencecenter/xenon/schedulers/JobDescription.java +++ b/src/main/java/nl/esciencecenter/xenon/schedulers/JobDescription.java @@ -103,6 +103,7 @@ public JobDescription(JobDescription original) { executable = original.getExecutable(); name = original.getName(); arguments.addAll(original.getArguments()); + schedulerArguments.addAll(original.getSchedulerArguments()); stdin = original.getStdin(); stdout = original.getStdout(); stderr = original.getStderr(); @@ -560,10 +561,11 @@ public String getWorkingDirectory() { /* Generated */ @Override public String toString() { - return "JobDescription [name=" + name + ", queueName=" + queueName + ", executable=" + executable + ", arguments=" + arguments + ", stdin=" + stdin - + ", stdout=" + stdout + ", stderr=" + stderr + ", workingDirectory=" + workingDirectory + ", environment=" + environment + ", jobOptions=" - + jobOptions + ", nodeCount=" + nodeCount + ", processesPerNode=" + processesPerNode + ", threadsPerProcess=" + threadsPerProcess - + ", maxMemory=" + maxMemory + ", startSingleProcess=" + startSingleProcess + ", maxTime=" + maxRuntime + "]"; + return "JobDescription [name=" + name + ", queueName=" + queueName + ", executable=" + executable + ", arguments=" + arguments + ", schedulerArguments=" + + schedulerArguments + ", stdin=" + stdin + ", stdout=" + stdout + ", stderr=" + stderr + ", workingDirectory=" + workingDirectory + + ", environment=" + environment + ", jobOptions=" + jobOptions + ", nodeCount=" + nodeCount + ", processesPerNode=" + processesPerNode + + ", threadsPerProcess=" + threadsPerProcess + ", maxMemory=" + maxMemory + ", startSingleProcess=" + startSingleProcess + ", maxTime=" + + maxRuntime + "]"; } /* Generated */ @@ -573,6 +575,7 @@ public int hashCode() { final int prime = 31; int result = 1; result = prime * result + arguments.hashCode(); + result = prime * result + schedulerArguments.hashCode(); result = prime * result + environment.hashCode(); result = prime * result + ((executable == null) ? 0 : executable.hashCode()); result = prime * result + jobOptions.hashCode(); @@ -607,7 +610,8 @@ public boolean equals(Object obj) { && processesPerNode == other.processesPerNode && maxMemory == other.maxMemory && threadsPerProcess == other.threadsPerProcess && Objects.equals(name, other.name) && Objects.equals(executable, other.executable) && Objects.equals(workingDirectory, other.workingDirectory) && Objects.equals(queueName, other.queueName) && Objects.equals(stdin, other.stdin) && Objects.equals(stdout, other.stdout) - && Objects.equals(stderr, other.stderr) && Objects.equals(arguments, other.arguments) && Objects.equals(environment, other.environment) + && Objects.equals(stderr, other.stderr) && Objects.equals(arguments, other.arguments) + && Objects.equals(schedulerArguments, other.schedulerArguments) && Objects.equals(environment, other.environment) && Objects.equals(jobOptions, other.jobOptions); } } diff --git a/src/test/java/nl/esciencecenter/xenon/schedulers/JobDescriptionTest.java b/src/test/java/nl/esciencecenter/xenon/schedulers/JobDescriptionTest.java index 4c17c1141..c09231d84 100644 --- a/src/test/java/nl/esciencecenter/xenon/schedulers/JobDescriptionTest.java +++ b/src/test/java/nl/esciencecenter/xenon/schedulers/JobDescriptionTest.java @@ -154,8 +154,8 @@ public void test_jobOptionValueNull() throws Exception { j.addJobOption("key", null); } - private int doHash(String queueName, String executable, String name, String[] arguments, String stdin, String stdout, String stderr, - String workingDirectory, Map environment, Map jobOptions, int nodeCount, int processesPerNode, + private int doHash(String queueName, String executable, String name, String[] arguments, String[] schedulerArguments, String stdin, String stdout, + String stderr, String workingDirectory, Map environment, Map jobOptions, int nodeCount, int processesPerNode, int threadsPerProcess, int maxMemory, boolean startSingleProcess, int maxRuntime) { List tmp = new ArrayList<>(10); @@ -166,9 +166,18 @@ private int doHash(String queueName, String executable, String name, String[] ar } } + List tmp2 = new ArrayList<>(10); + + if (schedulerArguments != null && schedulerArguments.length > 0) { + for (String s : schedulerArguments) { + tmp2.add(s); + } + } + final int prime = 31; int result = 1; result = prime * result + tmp.hashCode(); + result = prime * result + tmp2.hashCode(); result = prime * result + environment.hashCode(); result = prime * result + ((executable == null) ? 0 : executable.hashCode()); result = prime * result + jobOptions.hashCode(); @@ -191,7 +200,8 @@ private int doHash(String queueName, String executable, String name, String[] ar public void test_hashCode() throws Exception { JobDescription j = new JobDescription(); - int expected = doHash(null, null, null, new String[0], null, null, null, null, new HashMap<>(5), new HashMap<>(5), 1, 1, -1, -1, false, 15); + int expected = doHash(null, null, null, new String[0], new String[0], null, null, null, null, new HashMap<>(5), new HashMap<>(5), 1, 1, -1, -1, false, + 15); int hash = j.hashCode(); assertEquals(expected, hash); @@ -223,7 +233,7 @@ public void test_hashCode2() throws Exception { opt.put("OPT2", "ARG2"); j.setJobOptions(opt); - int expected = doHash("queue", "exec", "name", args, "stdin", null, null, "workdir", env, opt, 1, 1, -1, -1, true, 15); + int expected = doHash("queue", "exec", "name", args, new String[0], "stdin", null, null, "workdir", env, opt, 1, 1, -1, -1, true, 15); int hash = j.hashCode(); assertEquals(expected, hash); @@ -246,6 +256,9 @@ public void test_hashCode3() throws Exception { String[] args = new String[] { "a", "b", "c" }; j.setArguments(args); + String[] schedArgs = new String[] { "1", "2", "3" }; + j.setSchedulerArguments(schedArgs); + Map env = new HashMap<>(3); env.put("ENV1", "ARG1"); env.put("ENV2", "ARG2"); @@ -256,7 +269,7 @@ public void test_hashCode3() throws Exception { opt.put("OPT2", "ARG2"); j.setJobOptions(opt); - int expected = doHash("noot", "exec", null, args, "stdin", "stdout", "stderr", "aap", env, opt, 1, 1, 4, 1024, true, 15); + int expected = doHash("noot", "exec", null, args, schedArgs, "stdin", "stdout", "stderr", "aap", env, opt, 1, 1, 4, 1024, true, 15); int hash = j.hashCode(); assertEquals(expected, hash); } @@ -349,6 +362,11 @@ public void test_equals() throws Exception { assertFalse(j.equals(other)); j.setArguments(args); + String[] schedArgs = new String[] { "1", "2", "3" }; + other.setSchedulerArguments(schedArgs); + assertFalse(j.equals(other)); + j.setSchedulerArguments(schedArgs); + Map env = new HashMap<>(3); env.put("ENV1", "ARG1"); env.put("ENV2", "ARG2"); @@ -370,8 +388,8 @@ public void test_equals() throws Exception { @Test public void test_toString() throws Exception { - String expected = "JobDescription [name=job, queueName=noot, executable=exec, arguments=[a, b, c], stdin=stdin.txt, stdout=stdout.txt," - + " stderr=stderr.txt, workingDirectory=aap, environment={ENV1=ARG1}, jobOptions={OPT1=ARG1}," + String expected = "JobDescription [name=job, queueName=noot, executable=exec, arguments=[a, b, c], schedulerArguments=[1, 2, 3], stdin=stdin.txt," + + " stdout=stdout.txt, stderr=stderr.txt, workingDirectory=aap, environment={ENV1=ARG1}, jobOptions={OPT1=ARG1}," + " nodeCount=1, processesPerNode=1, threadsPerProcess=4, maxMemory=1024, startSingleProcess=false, maxTime=15]"; JobDescription j = new JobDescription(); @@ -384,9 +402,8 @@ public void test_toString() throws Exception { j.setExecutable("exec"); j.setThreadsPerProcess(4); j.setMaxMemory(1024); - - String[] args = new String[] { "a", "b", "c" }; - j.setArguments(args); + j.setArguments(new String[] { "a", "b", "c" }); + j.setSchedulerArguments(new String[] { "1", "2", "3" }); Map env = new HashMap<>(2); env.put("ENV1", "ARG1");