diff --git a/gradle/common.gradle b/gradle/common.gradle index 99bc7beba..72478a4ab 100644 --- a/gradle/common.gradle +++ b/gradle/common.gradle @@ -4,7 +4,7 @@ defaultTasks 'clean', 'assemble', 'test' // METADATA // ============== -version = '3.0.0' +version = '3.0.1' description = 'Xenon: a middleware abstraction library that provides a simple programming interface to various compute and storage resources.' // will generate a warning with JDK 8, since the runtime jar (rt.jar) of diff --git a/src/main/java/nl/esciencecenter/xenon/adaptors/schedulers/JobQueueScheduler.java b/src/main/java/nl/esciencecenter/xenon/adaptors/schedulers/JobQueueScheduler.java index f00a44e52..325bb970a 100644 --- a/src/main/java/nl/esciencecenter/xenon/adaptors/schedulers/JobQueueScheduler.java +++ b/src/main/java/nl/esciencecenter/xenon/adaptors/schedulers/JobQueueScheduler.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicLong; import org.slf4j.Logger; @@ -41,21 +40,10 @@ import nl.esciencecenter.xenon.schedulers.QueueStatus; import nl.esciencecenter.xenon.schedulers.Scheduler; import nl.esciencecenter.xenon.schedulers.Streams; +import nl.esciencecenter.xenon.utils.DaemonThreadFactory; public class JobQueueScheduler extends Scheduler { - /** - * Simple thread factory which returns daemon threads instead of normal threads - * - */ - private class DaemonThreadFactory implements ThreadFactory { - public Thread newThread(Runnable runnable) { - Thread thread = Executors.defaultThreadFactory().newThread(runnable); - thread.setDaemon(true); - return thread; - } - } - private static final Logger LOGGER = LoggerFactory.getLogger(JobQueueScheduler.class); private static final String SINGLE_QUEUE_NAME = "single"; @@ -125,11 +113,9 @@ public JobQueueScheduler(String uniqueID, String adaptorName, String location, C throw new BadParameterException(adaptorName, "Polling delay must be between " + MIN_POLLING_DELAY + " and " + MAX_POLLING_DELAY + "!"); } - ThreadFactory threadFactory = new DaemonThreadFactory(); - - unlimitedExecutor = Executors.newCachedThreadPool(threadFactory); - singleExecutor = Executors.newSingleThreadExecutor(threadFactory); - multiExecutor = Executors.newFixedThreadPool(multiQThreads, threadFactory); + unlimitedExecutor = Executors.newCachedThreadPool(new DaemonThreadFactory("JobExecutorThread." + uniqueID + "." + UNLIMITED_QUEUE_NAME)); + singleExecutor = Executors.newSingleThreadExecutor(new DaemonThreadFactory("JobExecutorThread." + uniqueID + "." + SINGLE_QUEUE_NAME)); + multiExecutor = Executors.newFixedThreadPool(multiQThreads, new DaemonThreadFactory("JobExecutorThread." + uniqueID + "." + MULTI_QUEUE_NAME)); } public long getCurrentJobID() { @@ -471,18 +457,15 @@ public QueueStatus[] getQueueStatuses(String... queueNames) throws XenonExceptio return result; } - public void end() { - singleExecutor.shutdownNow(); - multiExecutor.shutdownNow(); - unlimitedExecutor.shutdownNow(); - } - public FileSystem getFileSystem() throws XenonException { return filesystem; } @Override public void close() throws XenonException { + singleExecutor.shutdownNow(); + multiExecutor.shutdownNow(); + unlimitedExecutor.shutdownNow(); factory.close(); } diff --git a/src/main/java/nl/esciencecenter/xenon/adaptors/shared/ssh/SSHConnection.java b/src/main/java/nl/esciencecenter/xenon/adaptors/shared/ssh/SSHConnection.java index b798f36fe..b42c7cfb6 100644 --- a/src/main/java/nl/esciencecenter/xenon/adaptors/shared/ssh/SSHConnection.java +++ b/src/main/java/nl/esciencecenter/xenon/adaptors/shared/ssh/SSHConnection.java @@ -17,6 +17,7 @@ import java.io.IOException; +import org.apache.sshd.client.SshClient; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.client.subsystem.sftp.SftpClient; import org.apache.sshd.client.subsystem.sftp.SftpClientFactory; @@ -25,14 +26,16 @@ public class SSHConnection implements AutoCloseable { - private ClientSession[] sessions; - private Tunnel[] tunnels; + private final SshClient client; + private final ClientSession[] sessions; + private final Tunnel[] tunnels; private final int hops; private boolean closed = false; private ClientSession session; - protected SSHConnection(int hops) { + protected SSHConnection(SshClient client, int hops) { + this.client = client; this.hops = hops; sessions = new ClientSession[hops]; tunnels = new Tunnel[hops]; @@ -72,29 +75,33 @@ public void close() { closed = true; - if (session != null) { - try { - session.close(); - } catch (Exception e) { - // ignored? - } - } - - for (int i = hops - 1; i >= 0; i--) { - if (tunnels[i] != null) { + try { + if (session != null) { try { - tunnels[i].close(); + session.close(); } catch (Exception e) { // ignored? } } - if (sessions[i] != null) { - try { - sessions[i].close(); - } catch (Exception e) { - // ignored? + + for (int i = hops - 1; i >= 0; i--) { + if (tunnels[i] != null) { + try { + tunnels[i].close(); + } catch (Exception e) { + // ignored? + } + } + if (sessions[i] != null) { + try { + sessions[i].close(); + } catch (Exception e) { + // ignored? + } } } + } finally { + client.stop(); } } } diff --git a/src/main/java/nl/esciencecenter/xenon/adaptors/shared/ssh/SSHUtil.java b/src/main/java/nl/esciencecenter/xenon/adaptors/shared/ssh/SSHUtil.java index 1c5eaf131..d7f43afc9 100644 --- a/src/main/java/nl/esciencecenter/xenon/adaptors/shared/ssh/SSHUtil.java +++ b/src/main/java/nl/esciencecenter/xenon/adaptors/shared/ssh/SSHUtil.java @@ -33,7 +33,6 @@ import java.util.Map; import java.util.Set; -import com.google.common.net.HostAndPort; import org.apache.sshd.agent.local.ProxyAgentFactory; import org.apache.sshd.client.SshClient; import org.apache.sshd.client.channel.ChannelDirectTcpip; @@ -52,6 +51,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.net.HostAndPort; + import nl.esciencecenter.xenon.InvalidCredentialException; import nl.esciencecenter.xenon.InvalidLocationException; import nl.esciencecenter.xenon.XenonException; @@ -480,7 +481,7 @@ public static SSHConnection connect(String adaptorName, SshClient client, String SshdSocketAddress[] locations = extractLocations(adaptorName, location); UserCredential[] creds = extractCredentials(adaptorName, locations, credential); - SSHConnection connection = new SSHConnection(locations.length - 1); + SSHConnection connection = new SSHConnection(client, locations.length - 1); // Connect to the last location. This is either the destination (without tunneling) or the first hop. ClientSession session = connectAndAuthenticate(adaptorName, client, locations[0].getHostName(), locations[0].getPort(), creds[0], timeout); diff --git a/src/main/java/nl/esciencecenter/xenon/filesystems/FileSystem.java b/src/main/java/nl/esciencecenter/xenon/filesystems/FileSystem.java index f8e6cf9fc..7cce0dcae 100644 --- a/src/main/java/nl/esciencecenter/xenon/filesystems/FileSystem.java +++ b/src/main/java/nl/esciencecenter/xenon/filesystems/FileSystem.java @@ -29,7 +29,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -46,6 +45,7 @@ import nl.esciencecenter.xenon.adaptors.filesystems.FileAdaptor; import nl.esciencecenter.xenon.credentials.Credential; import nl.esciencecenter.xenon.credentials.DefaultCredential; +import nl.esciencecenter.xenon.utils.DaemonThreadFactory; /** * FileSystem represent a (possibly remote) file system that can be used to access data. @@ -419,14 +419,7 @@ protected FileSystem(String uniqueID, String adaptor, String location, Credentia this.workingDirectory = workDirectory; this.properties = properties; this.bufferSize = bufferSize; - - ThreadFactory f = r -> { - Thread t = new Thread(r, "CopyThread-" + adaptor + "-" + uniqueID); - t.setDaemon(true); - return t; - }; - - this.pool = Executors.newFixedThreadPool(1, f); + this.pool = Executors.newFixedThreadPool(1, new DaemonThreadFactory("CopyThread." + uniqueID)); } protected int getBufferSize() { diff --git a/src/main/java/nl/esciencecenter/xenon/utils/DaemonThreadFactory.java b/src/main/java/nl/esciencecenter/xenon/utils/DaemonThreadFactory.java new file mode 100644 index 000000000..6ee15339f --- /dev/null +++ b/src/main/java/nl/esciencecenter/xenon/utils/DaemonThreadFactory.java @@ -0,0 +1,40 @@ +/* + * Copyright 2013 Netherlands eScience Center + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.esciencecenter.xenon.utils; + +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; + +public class DaemonThreadFactory implements ThreadFactory { + + private final String name; + private int count = 0; + + public DaemonThreadFactory(String name) { + this.name = name; + } + + private synchronized int getCount() { + return count++; + } + + public Thread newThread(Runnable runnable) { + Thread thread = Executors.defaultThreadFactory().newThread(runnable); + thread.setDaemon(true); + thread.setName(name + "-" + getCount()); + return thread; + } +} diff --git a/src/test/java/nl/esciencecenter/xenon/adaptors/filesystems/sftp/MockSSHConnection.java b/src/test/java/nl/esciencecenter/xenon/adaptors/filesystems/sftp/MockSSHConnection.java index c61fe5392..73ebc27bb 100644 --- a/src/test/java/nl/esciencecenter/xenon/adaptors/filesystems/sftp/MockSSHConnection.java +++ b/src/test/java/nl/esciencecenter/xenon/adaptors/filesystems/sftp/MockSSHConnection.java @@ -26,11 +26,16 @@ public class MockSSHConnection extends SSHConnection { MockSftpClient client; protected MockSSHConnection(MockSftpClient client) { - super(0); + super(null, 0); this.client = client; } public SftpClient createSftpClient() throws IOException { return client; } + + @Override + public void close() { + // do nothing + } } diff --git a/src/test/java/nl/esciencecenter/xenon/adaptors/schedulers/JobQueueSchedulerTest.java b/src/test/java/nl/esciencecenter/xenon/adaptors/schedulers/JobQueueSchedulerTest.java index 502e71a22..602ca47d9 100644 --- a/src/test/java/nl/esciencecenter/xenon/adaptors/schedulers/JobQueueSchedulerTest.java +++ b/src/test/java/nl/esciencecenter/xenon/adaptors/schedulers/JobQueueSchedulerTest.java @@ -46,12 +46,10 @@ public void test_create() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - assertEquals("MockS", s.getAdaptorName()); - - s.end(); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { + assertEquals("MockS", s.getAdaptorName()); + } } @Test(expected = BadParameterException.class) @@ -91,12 +89,10 @@ public void test_getDefaultQueue() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - assertEquals("single", s.getDefaultQueueName()); - - s.end(); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { + assertEquals("single", s.getDefaultQueueName()); + } } @Test @@ -106,12 +102,10 @@ public void test_getQueues() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - assertArrayEquals(new String[] { "single", "multi", "unlimited" }, s.getQueueNames()); - - s.end(); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { + assertArrayEquals(new String[] { "single", "multi", "unlimited" }, s.getQueueNames()); + } } @Test @@ -121,10 +115,10 @@ public void test_getCurrentJobID() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - s.getCurrentJobID(); // BS test for coverage. + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { + s.getCurrentJobID(); + } } @Test(expected = NoSuchQueueException.class) @@ -134,18 +128,13 @@ public void test_verifyJobDescription_invalidQueue() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - ; - job.setQueueName("foobar"); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - try { + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setQueueName("foobar"); s.submitBatchJob(job); - } finally { - s.end(); } } @@ -156,15 +145,11 @@ public void test_verifyJobDescription_noExecutable() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - JobDescription job = new JobDescription(); - - try { + JobDescription job = new JobDescription(); s.submitBatchJob(job); - } finally { - s.end(); } } @@ -175,16 +160,12 @@ public void test_verifyJobDescription_invalidNodeCount() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - job.setTasks(42); - try { + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setTasks(42); s.submitBatchJob(job); - } finally { - s.end(); } } @@ -195,16 +176,12 @@ public void test_verifyJobDescription_invalidTasksPerNode() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - job.setTasksPerNode(42); - try { + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setTasksPerNode(42); s.submitBatchJob(job); - } finally { - s.end(); } } @@ -215,18 +192,13 @@ public void test_verifyJobDescription_invalidMaxTime() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - ; - job.setMaxRuntime(-3); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - try { + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setMaxRuntime(-3); s.submitBatchJob(job); - } finally { - s.end(); } } @@ -237,18 +209,13 @@ public void test_verifyJobDescription_invalidStdin() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - ; - job.setStdin("/tmp/stdin.txt"); - - try { + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setStdin("/tmp/stdin.txt"); s.submitInteractiveJob(job); - } finally { - s.end(); } } @@ -259,18 +226,13 @@ public void test_verifyJobDescription_invalidStdout() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - ; - job.setStdout("/tmp/stdout.txt"); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - try { + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setStdout("/tmp/stdout.txt"); s.submitInteractiveJob(job); - } finally { - s.end(); } } @@ -281,18 +243,13 @@ public void test_verifyJobDescription_invalidStderr() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - ; - job.setStderr("/tmp/stderr.txt"); - - try { + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setStderr("/tmp/stderr.txt"); s.submitInteractiveJob(job); - } finally { - s.end(); } } @@ -303,15 +260,13 @@ public void test_getJobs_empty() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - String[] result = s.getJobs(); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - assertNotNull(result); - assertTrue(result.length == 0); - - s.end(); + String[] result = s.getJobs(); + assertNotNull(result); + assertTrue(result.length == 0); + } } @Test @@ -321,16 +276,15 @@ public void test_getJobs_null() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - String[] queues = null; - String[] result = s.getJobs(queues); + String[] queues = null; + String[] result = s.getJobs(queues); - assertNotNull(result); - assertTrue(result.length == 0); - - s.end(); + assertNotNull(result); + assertTrue(result.length == 0); + } } @Test @@ -340,22 +294,20 @@ public void test_getJobs_notEmpty() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - ; + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); - String jobID = s.submitBatchJob(job); + String jobID = s.submitBatchJob(job); - String[] result = s.getJobs(new String[0]); + String[] result = s.getJobs(new String[0]); - assertNotNull(result); - assertTrue(result.length == 1); - assertEquals(jobID, result[0]); - - s.end(); + assertNotNull(result); + assertTrue(result.length == 1); + assertEquals(jobID, result[0]); + } } @Test(expected = NoSuchQueueException.class) @@ -365,13 +317,9 @@ public void test_getJobs_invalidQueue() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - try { + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { s.getJobs("foobar"); - } finally { - s.end(); } } @@ -382,32 +330,31 @@ public void test_getJobs_specificQueueEmpty() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - job.setQueueName("multi"); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - String jobID = s.submitBatchJob(job); + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setQueueName("multi"); - String[] result = s.getJobs("single"); + String jobID = s.submitBatchJob(job); - assertNotNull(result); - assertTrue(result.length == 0); + String[] result = s.getJobs("single"); - result = s.getJobs("multi"); + assertNotNull(result); + assertTrue(result.length == 0); - assertNotNull(result); - assertTrue(result.length == 1); - assertEquals(jobID, result[0]); + result = s.getJobs("multi"); - result = s.getJobs("unlimited"); + assertNotNull(result); + assertTrue(result.length == 1); + assertEquals(jobID, result[0]); - assertNotNull(result); - assertTrue(result.length == 0); + result = s.getJobs("unlimited"); - s.end(); + assertNotNull(result); + assertTrue(result.length == 0); + } } @Test(expected = IllegalArgumentException.class) @@ -417,13 +364,9 @@ public void test_getJobStatus_null() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - try { + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { s.getJobStatus(null); - } finally { - s.end(); } } @@ -434,13 +377,9 @@ public void test_getJobStatus_empty() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - try { + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { s.getJobStatus(null); - } finally { - s.end(); } } @@ -451,13 +390,9 @@ public void test_getJobStatus_unknownJob() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - try { + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { s.getJobStatus("foo"); - } finally { - s.end(); } } @@ -468,25 +403,21 @@ public void test_getJobStatus_knownJob() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(100); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - job.setQueueName("unlimited"); + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setQueueName("unlimited"); - String jobID = s.submitBatchJob(job); + String jobID = s.submitBatchJob(job); - JobStatus status = s.getJobStatus(jobID); + JobStatus status = s.getJobStatus(jobID); - status = s.waitUntilDone(jobID, 1000); + status = s.waitUntilDone(jobID, 1000); - assertTrue(status.isDone()); - - // System.out.println(status.getJobIdentifier() + " " + status.getState() + " " + status.isDone() + " " + status.isRunning() + " " + - // status.hasException()); - - s.end(); + assertTrue(status.isDone()); + } } @Test @@ -496,24 +427,22 @@ public void test_getJobStatus_afterDone() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(50); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - job.setQueueName("unlimited"); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - // Submit 50 ms job. - String jobID = s.submitBatchJob(job); + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setQueueName("unlimited"); - // Wait for 250 ms for the job to finish. - Thread.sleep(250); + // Submit 50 ms job. + String jobID = s.submitBatchJob(job); - JobStatus status = s.getJobStatus(jobID); + // Wait for 250 ms for the job to finish. + Thread.sleep(250); - assertTrue(status.isDone()); - - s.end(); + JobStatus status = s.getJobStatus(jobID); + assertTrue(status.isDone()); + } } @Test @@ -523,30 +452,29 @@ public void test_waitUntilRunning() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(100); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - job.setQueueName("single"); + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setQueueName("single"); - // Submit 2 100 ms. jobs that will be run sequentially - String jobID1 = s.submitBatchJob(job); - String jobID2 = s.submitBatchJob(job); + // Submit 2 100 ms. jobs that will be run sequentially + String jobID1 = s.submitBatchJob(job); + String jobID2 = s.submitBatchJob(job); - // Wait up to 1000 ms for second job to start. - JobStatus status = s.waitUntilRunning(jobID2, 1000); + // Wait up to 1000 ms for second job to start. + JobStatus status = s.waitUntilRunning(jobID2, 1000); - // Second job should have started after this time. - assertTrue(status.isRunning()); + // Second job should have started after this time. + assertTrue(status.isRunning()); - // Wait up to 1000 ms for second job to finish. - status = s.waitUntilDone(jobID2, 1000); + // Wait up to 1000 ms for second job to finish. + status = s.waitUntilDone(jobID2, 1000); - // Second job should have finished after this time. - assertTrue(status.isDone()); - - s.end(); + // Second job should have finished after this time. + assertTrue(status.isDone()); + } } @Test @@ -556,24 +484,30 @@ public void test_waitUntilDone() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(100); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - job.setQueueName("single"); + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setQueueName("single"); - // Submit 2 100 ms. jobs that will be run sequentially - String jobID1 = s.submitBatchJob(job); - String jobID2 = s.submitBatchJob(job); + // Submit 2 100 ms. jobs that will be run sequentially + String jobID1 = s.submitBatchJob(job); + String jobID2 = s.submitBatchJob(job); - // Wait up to 1000 ms for second job to start. - JobStatus status = s.waitUntilDone(jobID2, 1000); + // Wait up to 1000 ms for second job to start. + JobStatus status = s.waitUntilDone(jobID2, 1000); - // Second job should have finished after this time. - assertTrue(status.isDone()); + // Second job should have finished after this time. + assertTrue(status.isDone()); - s.end(); + // Wait up to 1000 ms for first job to start (should have been done?) + status = s.waitUntilDone(jobID1, 1000); + + // First job should have finished after this time. + assertTrue(status.isDone()); + + } } @Test @@ -583,29 +517,28 @@ public void test_waitUntilRunningWhenDone() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(100); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - job.setQueueName("single"); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - // Submit 2 100 ms. jobs that will be run sequentially - String jobID1 = s.submitBatchJob(job); - String jobID2 = s.submitBatchJob(job); + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setQueueName("single"); - // Wait up to 1000 ms for second job to start. - JobStatus status = s.waitUntilDone(jobID2, 1000); + // Submit 2 100 ms. jobs that will be run sequentially + String jobID1 = s.submitBatchJob(job); + String jobID2 = s.submitBatchJob(job); - // Both jobs should have finished after this time. - assertTrue(status.isDone()); + // Wait up to 1000 ms for second job to start. + JobStatus status = s.waitUntilDone(jobID2, 1000); - // First job should already be done! - status = s.waitUntilRunning(jobID1, 1000); + // Both jobs should have finished after this time. + assertTrue(status.isDone()); - assertTrue(status.isDone()); + // First job should already be done! + status = s.waitUntilRunning(jobID1, 1000); - s.end(); + assertTrue(status.isDone()); + } } @Test @@ -615,35 +548,34 @@ public void test_waitUntilDoneWhenNotDone() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(500); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - job.setQueueName("single"); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - // Submit a 500 ms. job - String jobID = s.submitBatchJob(job); + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setQueueName("single"); - // Wait up to 100 ms for job to start. - JobStatus status = s.waitUntilRunning(jobID, 100); + // Submit a 500 ms. job + String jobID = s.submitBatchJob(job); - // Job should be running now - assertTrue(status.isRunning()); + // Wait up to 100 ms for job to start. + JobStatus status = s.waitUntilRunning(jobID, 100); - // Wait up to 100 ms for job to finish. - status = s.waitUntilDone(jobID, 100); + // Job should be running now + assertTrue(status.isRunning()); - // Job should not be done - assertFalse(status.isDone()); + // Wait up to 100 ms for job to finish. + status = s.waitUntilDone(jobID, 100); - // Now wait up to 1000 ms for job to finish - status = s.waitUntilDone(jobID, 1000); + // Job should not be done + assertFalse(status.isDone()); - // And now it should be done! - assertTrue(status.isDone()); + // Now wait up to 1000 ms for job to finish + status = s.waitUntilDone(jobID, 1000); - s.end(); + // And now it should be done! + assertTrue(status.isDone()); + } } @Test @@ -653,21 +585,20 @@ public void test_cancel_immediately() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(500); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - job.setQueueName("unlimited"); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - // Submit 50 ms job. - String jobID = s.submitBatchJob(job); + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setQueueName("unlimited"); - JobStatus status = s.cancelJob(jobID); + // Submit 50 ms job. + String jobID = s.submitBatchJob(job); - assertTrue(status.isDone()); + JobStatus status = s.cancelJob(jobID); - s.end(); + assertTrue(status.isDone()); + } } @Test @@ -677,25 +608,24 @@ public void test_cancel_whenRunning() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(500); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - job.setQueueName("unlimited"); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - // Submit 50 ms job. - String jobID = s.submitBatchJob(job); + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setQueueName("unlimited"); - JobStatus status = s.waitUntilRunning(jobID, 250); + // Submit 50 ms job. + String jobID = s.submitBatchJob(job); - assertTrue(status.isRunning()); + JobStatus status = s.waitUntilRunning(jobID, 250); - status = s.cancelJob(jobID); + assertTrue(status.isRunning()); - assertTrue(status.isDone()); + status = s.cancelJob(jobID); - s.end(); + assertTrue(status.isDone()); + } } @Test @@ -705,27 +635,26 @@ public void test_cancel_afterDone() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(100); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); - job.setQueueName("unlimited"); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - // Submit 100 ms job. - String jobID = s.submitBatchJob(job); + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); + job.setQueueName("unlimited"); - JobStatus status = s.waitUntilRunning(jobID, 500); + // Submit 100 ms job. + String jobID = s.submitBatchJob(job); - assertTrue(status.isRunning()); + JobStatus status = s.waitUntilRunning(jobID, 500); - Thread.sleep(200); + assertTrue(status.isRunning()); - status = s.cancelJob(jobID); + Thread.sleep(200); - assertTrue(status.isDone()); + status = s.cancelJob(jobID); - s.end(); + assertTrue(status.isDone()); + } } @Test @@ -735,32 +664,33 @@ public void test_submitInteractive() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - JobDescription job = new JobDescription(); - job.setExecutable("/bin/aap"); + JobDescription job = new JobDescription(); + job.setExecutable("/bin/aap"); - // Submit 100 ms job. - Streams streams = s.submitInteractiveJob(job); + // Submit 100 ms job. + Streams streams = s.submitInteractiveJob(job); - OutputReader stdout = new OutputReader(streams.getStdout()); - OutputReader stderr = new OutputReader(streams.getStderr()); + OutputReader stdout = new OutputReader(streams.getStdout()); + OutputReader stderr = new OutputReader(streams.getStderr()); - streams.getStdin().close(); + streams.getStdin().close(); - stdout.waitUntilFinished(); + stderr.waitUntilFinished(); + stdout.waitUntilFinished(); - assertEquals("Hello World\n", stdout.getResultAsString()); + assertEquals("Hello World\n", stdout.getResultAsString()); - JobStatus status = s.cancelJob(streams.getJobIdentifier()); + JobStatus status = s.cancelJob(streams.getJobIdentifier()); - if (!status.isDone()) { - status = s.waitUntilDone(streams.getJobIdentifier(), 1000); - } + if (!status.isDone()) { + status = s.waitUntilDone(streams.getJobIdentifier(), 1000); + } - assertTrue(status.isDone()); - s.end(); + assertTrue(status.isDone()); + } } @Test(expected = IllegalArgumentException.class) @@ -770,13 +700,9 @@ public void test_getQueueStatus_null() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(100); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - try { + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { s.getQueueStatus(null); - } finally { - s.end(); } } @@ -787,13 +713,9 @@ public void test_getQueueStatus_unknownQueue() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(100); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - try { + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { s.getQueueStatus("foobar"); - } finally { - s.end(); } } @@ -804,16 +726,16 @@ public void test_getQueueStatus_validQueues() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(100); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - String[] queueNames = s.getQueueNames(); + String[] queueNames = s.getQueueNames(); - for (String q : queueNames) { - QueueStatus status = s.getQueueStatus(q); - assertEquals(q, status.getQueueName()); + for (String q : queueNames) { + QueueStatus status = s.getQueueStatus(q); + assertEquals(q, status.getQueueName()); + } } - s.end(); } @Test(expected = IllegalArgumentException.class) @@ -823,15 +745,11 @@ public void test_getQueueStatuses_null() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(100); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); - - String[] q = null; + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - try { + String[] q = null; s.getQueueStatuses(q); - } finally { - s.end(); } } @@ -842,18 +760,17 @@ public void test_getQueueStatuses_empty() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(100); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - QueueStatus[] status = s.getQueueStatuses(); + QueueStatus[] status = s.getQueueStatuses(); - assertNotNull(status); - assertTrue(status.length == 3); - assertEquals("single", status[0].getQueueName()); - assertEquals("multi", status[1].getQueueName()); - assertEquals("unlimited", status[2].getQueueName()); - - s.end(); + assertNotNull(status); + assertTrue(status.length == 3); + assertEquals("single", status[0].getQueueName()); + assertEquals("multi", status[1].getQueueName()); + assertEquals("unlimited", status[2].getQueueName()); + } } @Test @@ -863,18 +780,17 @@ public void test_getQueueStatuses() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(100); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - QueueStatus[] status = s.getQueueStatuses(s.getQueueNames()); + QueueStatus[] status = s.getQueueStatuses(s.getQueueNames()); - assertNotNull(status); - assertTrue(status.length == 3); - assertEquals("single", status[0].getQueueName()); - assertEquals("multi", status[1].getQueueName()); - assertEquals("unlimited", status[2].getQueueName()); - - s.end(); + assertNotNull(status); + assertTrue(status.length == 3); + assertEquals("single", status[0].getQueueName()); + assertEquals("multi", status[1].getQueueName()); + assertEquals("unlimited", status[2].getQueueName()); + } } @Test @@ -884,18 +800,17 @@ public void test_getQueueStatuses_withNull() throws Exception { MockInteractiveProcessFactory factory = new MockInteractiveProcessFactory(100); - JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, 10000L, - null); + try (JobQueueScheduler s = new JobQueueScheduler("SID", "MockS", "location", new DefaultCredential(), factory, fs, new Path("/home/xenon"), 2, 100, + 10000L, null)) { - QueueStatus[] status = s.getQueueStatuses(new String[] { "multi", null, "single" }); + QueueStatus[] status = s.getQueueStatuses(new String[] { "multi", null, "single" }); - assertNotNull(status); - assertTrue(status.length == 3); - assertEquals("multi", status[0].getQueueName()); - assertNull(status[1]); - assertEquals("single", status[2].getQueueName()); - - s.end(); + assertNotNull(status); + assertTrue(status.length == 3); + assertEquals("multi", status[0].getQueueName()); + assertNull(status[1]); + assertEquals("single", status[2].getQueueName()); + } } } diff --git a/src/test/java/nl/esciencecenter/xenon/adaptors/schedulers/ssh/MockSSHClient.java b/src/test/java/nl/esciencecenter/xenon/adaptors/schedulers/ssh/MockSSHClient.java new file mode 100644 index 000000000..61e95620b --- /dev/null +++ b/src/test/java/nl/esciencecenter/xenon/adaptors/schedulers/ssh/MockSSHClient.java @@ -0,0 +1,28 @@ +/* + * Copyright 2013 Netherlands eScience Center + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.esciencecenter.xenon.adaptors.schedulers.ssh; + +import org.apache.sshd.client.SshClient; + +public class MockSSHClient extends SshClient { + + public MockSSHClient() { + } + + public void stop() { + // do nothing + } +} diff --git a/src/test/java/nl/esciencecenter/xenon/adaptors/schedulers/ssh/MockSSHConnection.java b/src/test/java/nl/esciencecenter/xenon/adaptors/schedulers/ssh/MockSSHConnection.java index d4c8e7a36..13c2e4eff 100644 --- a/src/test/java/nl/esciencecenter/xenon/adaptors/schedulers/ssh/MockSSHConnection.java +++ b/src/test/java/nl/esciencecenter/xenon/adaptors/schedulers/ssh/MockSSHConnection.java @@ -21,8 +21,10 @@ public class MockSSHConnection extends SSHConnection { + boolean closed = false; + protected MockSSHConnection() { - super(0); + super(new MockSSHClient(), 0); } @Override