Skip to content

Commit

Permalink
Fixed equals, hashCode and copyconstructor of JobDescription. Fixes #617
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaassen committed Mar 16, 2018
1 parent 0b07c84 commit c075fe9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 */
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> environment, Map<String, String> 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<String, String> environment, Map<String, String> jobOptions, int nodeCount, int processesPerNode,
int threadsPerProcess, int maxMemory, boolean startSingleProcess, int maxRuntime) {

List<String> tmp = new ArrayList<>(10);
Expand All @@ -166,9 +166,18 @@ private int doHash(String queueName, String executable, String name, String[] ar
}
}

List<String> 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();
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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<String, String> env = new HashMap<>(3);
env.put("ENV1", "ARG1");
env.put("ENV2", "ARG2");
Expand All @@ -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);
}
Expand Down Expand Up @@ -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<String, String> env = new HashMap<>(3);
env.put("ENV1", "ARG1");
env.put("ENV2", "ARG2");
Expand All @@ -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();
Expand All @@ -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<String, String> env = new HashMap<>(2);
env.put("ENV1", "ARG1");
Expand Down

0 comments on commit c075fe9

Please sign in to comment.