Refactoring (renaming) 2 classes: AsyncJobRunner.java -> AsyncClusterRunner.java...
[jabaws.git] / testsrc / compbio / runner / conservation / AAConTester.java
index fbb9720..37f50cd 100644 (file)
@@ -1,6 +1,8 @@
-/*\r
- * Copyright (c) 2010 Peter Troshin JAva Bioinformatics Analysis Web Services\r
- * (JABAWS) @version: 2.0 \r
+/* Copyright (c) 2010 Peter Troshin\r
+ * Copyright (c) 2013 Alexander Sherstnev\r
+ * \r
+ * Java Bioinformatics Analysis Web Services (JABAWS)\r
+ * (JABAWS) @version: 2.5 \r
  * \r
  * This library is free software; you can redistribute it and/or modify it under \r
  * the terms of the Apache License version 2 as published\r
@@ -37,8 +39,7 @@ import org.ggf.drmaa.JobInfo;
 import org.testng.annotations.BeforeMethod;\r
 import org.testng.annotations.Test;\r
 \r
-import compbio.conservation.Method;\r
-import compbio.data.sequence.MultiAnnotatedSequence;\r
+import compbio.data.sequence.ScoreManager;\r
 import compbio.engine.AsyncExecutor;\r
 import compbio.engine.Configurator;\r
 import compbio.engine.FilePuller;\r
@@ -47,10 +48,11 @@ import compbio.engine.client.ConfExecutable;
 import compbio.engine.client.ConfiguredExecutable;\r
 import compbio.engine.client.Executable;\r
 import compbio.engine.client.RunConfiguration;\r
-import compbio.engine.cluster.drmaa.ClusterUtil;\r
-import compbio.engine.cluster.drmaa.JobRunner;\r
+import compbio.engine.cluster.drmaa.ClusterEngineUtil;\r
+import compbio.engine.cluster.drmaa.ClusterRunner;\r
 import compbio.engine.cluster.drmaa.StatisticManager;\r
 import compbio.engine.local.LocalRunner;\r
+import compbio.metadata.AllTestSuit;\r
 import compbio.metadata.ChunkHolder;\r
 import compbio.metadata.JobExecutionException;\r
 import compbio.metadata.JobStatus;\r
@@ -60,18 +62,15 @@ import compbio.metadata.Preset;
 import compbio.metadata.PresetManager;\r
 import compbio.metadata.ResultNotAvailableException;\r
 import compbio.metadata.RunnerConfig;\r
-import compbio.runner.Util;\r
+import compbio.runner.RunnerUtil;\r
 import compbio.util.FileWatcher;\r
 import compbio.util.SysPrefs;\r
 \r
 public class AAConTester {\r
 \r
-       public static final String CURRENT_DIRECTORY = SysPrefs\r
-                       .getCurrentDirectory() + File.separator;\r
-\r
-       public static String test_outfile = "TO1381.aacon.out"; // "/homes/pvtroshin/TO1381.clustal.cluster.out\r
-       public static String test_alignment_input = CURRENT_DIRECTORY + "testsrc"\r
-                       + File.separator + "testdata" + File.separator + "TO1381.fasta.aln";\r
+       public static final String CURRENT_DIRECTORY = SysPrefs.getCurrentDirectory() + File.separator;\r
+       public static String test_outfile = "TO1381.aacon.out";\r
+       public static String test_alignment_input = CURRENT_DIRECTORY + "testsrc" + File.separator + "testdata" + File.separator + "TO1381.fasta.aln";\r
        private AACon aacon;\r
 \r
        @BeforeMethod(alwaysRun = true)\r
@@ -80,33 +79,26 @@ public class AAConTester {
                aacon.setInput(test_alignment_input).setOutput(test_outfile);\r
        }\r
 \r
-       @Test()\r
-       public void testRunOnCluster() {\r
-               assertFalse(SysPrefs.isWindows,\r
-                               "Cluster execution can only be in unix environment");\r
+       @Test(groups = {AllTestSuit.test_group_runner})\r
+       public void RunOnCluster() {\r
+               assertFalse(SysPrefs.isWindows, "Cluster execution can only be in unix environment");\r
                try {\r
-                       ConfiguredExecutable<AACon> confAAcon = Configurator\r
-                                       .configureExecutable(aacon, Executable.ExecProvider.Cluster);\r
-                       JobRunner runner = JobRunner.getInstance(confAAcon);\r
+                       ConfiguredExecutable<AACon> confAAcon = Configurator.configureExecutable(aacon, Executable.ExecProvider.Cluster);\r
+                       ClusterRunner runner = ClusterRunner.getInstance(confAAcon);\r
 \r
                        assertNotNull(runner, "Runner is NULL");\r
                        runner.executeJob();\r
-                       // assertNotNull("JobId is null", jobId1);\r
                        JobStatus status = runner.getJobStatus();\r
-                       assertTrue(status == JobStatus.PENDING\r
-                                       || status == JobStatus.RUNNING,\r
-                                       "Status of the process is wrong!");\r
+                       assertTrue(status == JobStatus.PENDING || status == JobStatus.RUNNING, "Status of the process is wrong!");\r
                        JobInfo info = runner.getJobInfo();\r
                        assertNotNull(info, "JobInfo is null");\r
                        StatisticManager sm = new StatisticManager(info);\r
                        assertNotNull(sm, "Statictic manager is null");\r
                        try {\r
-\r
                                String exits = sm.getExitStatus();\r
                                assertNotNull("Exit status is null", exits);\r
                                // cut 4 trailing zeros from the number\r
-                               int exitsInt = ClusterUtil.CLUSTER_STAT_IN_SEC.parse(exits)\r
-                                               .intValue();\r
+                               int exitsInt = ClusterEngineUtil.CLUSTER_STAT_IN_SEC.parse(exits).intValue();\r
                                assertEquals(0, exitsInt);\r
                                System.out.println(sm.getAllStats());\r
 \r
@@ -114,12 +106,10 @@ public class AAConTester {
                                e.printStackTrace();\r
                                fail("Parse Exception: " + e.getMessage());\r
                        }\r
-                       // assertFalse(runner.cleanup());\r
                        assertTrue(sm.hasExited());\r
                        assertFalse(sm.wasAborted());\r
                        assertFalse(sm.hasDump());\r
                        assertFalse(sm.hasSignaled());\r
-\r
                } catch (JobSubmissionException e) {\r
                        e.printStackTrace();\r
                        fail("DrmaaException caught:" + e.getMessage());\r
@@ -133,16 +123,14 @@ public class AAConTester {
        }\r
 \r
        /**\r
-        * This tests fails from time to time depending on the cluster load or some\r
+        * This test fails from time to time depending on the cluster load or some\r
         * other factors. Any client code has to adjust for this issue\r
         */\r
-       @Test()\r
-       public void testRunOnClusterAsync() {\r
-               assertFalse(SysPrefs.isWindows,\r
-                               "Cluster execution can only be in unix environment");\r
+       @Test(groups = {AllTestSuit.test_group_runner, AllTestSuit.test_group_cluster})\r
+       public void RunOnClusterAsync() {\r
+               assertFalse(SysPrefs.isWindows, "Cluster execution can only be in unix environment");\r
                try {\r
-                       ConfiguredExecutable<AACon> confAAcon = Configurator\r
-                                       .configureExecutable(aacon, Executable.ExecProvider.Cluster);\r
+                       ConfiguredExecutable<AACon> confAAcon = Configurator.configureExecutable(aacon, Executable.ExecProvider.Cluster);\r
                        AsyncExecutor aengine = Configurator.getAsyncEngine(confAAcon);\r
                        String jobId = aengine.submitJob(confAAcon);\r
                        assertNotNull(jobId, "Runner is NULL");\r
@@ -153,14 +141,11 @@ public class AAConTester {
                                System.out.println("Job Status: " + status);\r
                                Thread.sleep(1000);\r
                                status = aengine.getJobStatus(jobId);\r
-                               ConfiguredExecutable<AACon> result = (ConfiguredExecutable<AACon>) aengine\r
-                                               .getResults(jobId);\r
+                               ConfiguredExecutable<AACon> result = (ConfiguredExecutable<AACon>) aengine.getResults(jobId);\r
                                assertNotNull(result);\r
                                System.out.println("RES:" + result);\r
-                               // Some times the job could be removed from the cluster\r
-                               // accounting\r
-                               // before it has been reported to finish. Make sure\r
-                               // to stop waiting in such case\r
+                               // Some times the job could be removed from the cluster accounting \r
+                               // before it has been reported to finish. Make sure to stop waiting in such case\r
                                if (status == JobStatus.UNDEFINED) {\r
                                        break;\r
                                }\r
@@ -177,20 +162,19 @@ public class AAConTester {
                }\r
        }\r
 \r
-       @Test()\r
-       public void testRunLocally() {\r
+       @Test(groups = {AllTestSuit.test_group_runner})\r
+       public void RunLocally() {\r
                try {\r
-                       ConfiguredExecutable<AACon> confAAcon = Configurator\r
-                                       .configureExecutable(aacon, Executable.ExecProvider.Local);\r
+                       ConfiguredExecutable<AACon> confAAcon = Configurator.configureExecutable(aacon, Executable.ExecProvider.Local);\r
 \r
                        // For local execution use relative\r
                        LocalRunner lr = new LocalRunner(confAAcon);\r
                        lr.executeJob();\r
                        ConfiguredExecutable<?> al1 = lr.waitForResult();\r
                        assertNotNull(al1.getResults());\r
-                       MultiAnnotatedSequence<Method> annotations = confAAcon.getResults();\r
+                       ScoreManager annotations = confAAcon.getResults();\r
                        assertNotNull(annotations);\r
-                       assertEquals(annotations.getAnnotations().size(), 1);\r
+                       assertEquals(annotations.asSet().size(), 18);\r
                        assertEquals(al1.getResults(), annotations);\r
                } catch (JobSubmissionException e) {\r
                        e.printStackTrace();\r
@@ -204,24 +188,22 @@ public class AAConTester {
                }\r
        }\r
 \r
-       @Test()\r
-       public void testRunLocallyWithPreset() {\r
+       @Test(groups = {AllTestSuit.test_group_runner})\r
+       public void RunLocallyWithPreset() {\r
                try {\r
-                       PresetManager<AACon> aaconPresets = Util.getPresets(AACon.class);\r
+                       PresetManager<AACon> aaconPresets = RunnerUtil.getPresets(AACon.class);\r
                        assert aaconPresets != null;\r
-                       ConfiguredExecutable<AACon> confAAcon = Configurator\r
-                                       .configureExecutable(aacon, Executable.ExecProvider.Local);\r
-                       Preset<AACon> quick = aaconPresets\r
-                                       .getPresetByName("Quick conservation");\r
+                       ConfiguredExecutable<AACon> confAAcon = Configurator.configureExecutable(aacon, Executable.ExecProvider.Local);\r
+                       Preset<AACon> quick = aaconPresets.getPresetByName("Quick conservation");\r
                        confAAcon.addParameters(quick.getOptions());\r
                        // For local execution use relative\r
                        LocalRunner lr = new LocalRunner(confAAcon);\r
                        lr.executeJob();\r
                        ConfiguredExecutable<?> al1 = lr.waitForResult();\r
                        assertNotNull(al1.getResults());\r
-                       MultiAnnotatedSequence<Method> annotations = confAAcon.getResults();\r
+                       ScoreManager annotations = confAAcon.getResults();\r
                        assertNotNull(annotations);\r
-                       assertEquals(annotations.getAnnotations().size(), 13);\r
+                       assertEquals(annotations.asSet().size(), 13);\r
                        assertEquals(al1.getResults(), annotations);\r
                } catch (JobSubmissionException e) {\r
                        e.printStackTrace();\r
@@ -235,15 +217,14 @@ public class AAConTester {
                }\r
        }\r
 \r
-       @Test()\r
-       public void testRunLocallyOnTwoCpu() {\r
+       @Test(groups = {AllTestSuit.test_group_runner})\r
+       public void RunLocallyOnTwoCpu() {\r
                try {\r
                        aacon = new AACon();\r
                        aacon.setInput(test_alignment_input).setOutput(test_outfile);\r
 \r
                        aacon.setNCore(2);\r
-                       ConfiguredExecutable<AACon> confAAcon = Configurator\r
-                                       .configureExecutable(aacon, Executable.ExecProvider.Local);\r
+                       ConfiguredExecutable<AACon> confAAcon = Configurator.configureExecutable(aacon, Executable.ExecProvider.Local);\r
                        confAAcon.addParameters(Arrays.asList("-m=KABAT,JORES"));\r
                        confAAcon.addParameters(Arrays.asList("-m=TAYLOR_GAPS"));\r
                        // For local execution use relative\r
@@ -252,9 +233,9 @@ public class AAConTester {
                        lr.executeJob();\r
                        ConfiguredExecutable<?> al1 = lr.waitForResult();\r
                        assertNotNull(al1.getResults());\r
-                       MultiAnnotatedSequence<Method> annotations = confAAcon.getResults();\r
+                       ScoreManager annotations = confAAcon.getResults();\r
                        assertNotNull(annotations);\r
-                       assertEquals(annotations.getAnnotations().size(), 3);\r
+                       assertEquals(annotations.asSet().size(), 3);\r
                        assertEquals(al1.getResults(), annotations);\r
                } catch (JobSubmissionException e) {\r
                        e.printStackTrace();\r
@@ -267,28 +248,27 @@ public class AAConTester {
                        fail(e.getLocalizedMessage());\r
                }\r
        }\r
-       @Test()\r
+       \r
+       @Test(groups = {AllTestSuit.test_group_runner})\r
        public void readStatistics() {\r
                try {\r
-                       ConfiguredExecutable<AACon> confAAcon = Configurator\r
-                                       .configureExecutable(aacon, Executable.ExecProvider.Local);\r
+                       ConfiguredExecutable<AACon> confAAcon = Configurator.configureExecutable(aacon, Executable.ExecProvider.Local);\r
                        // For local execution use relative\r
 \r
                        AsyncExecutor sexec = Configurator.getAsyncEngine(confAAcon);\r
                        String jobId = sexec.submitJob(confAAcon);\r
-                       FilePuller fw = FilePuller.newFilePuller(\r
-                                       confAAcon.getWorkDirectory() + File.separator\r
-                                                       + AACon.getStatFile(),\r
-                                       FileWatcher.MIN_CHUNK_SIZE_BYTES);\r
+                       String file = confAAcon.getWorkDirectory() + File.separator + AACon.getStatFile();\r
+                       FilePuller fw = FilePuller.newFilePuller(file, FileWatcher.MIN_CHUNK_SIZE_BYTES);\r
                        int count = 0;\r
                        long position = 0;\r
                        fw.waitForFile(2);\r
                        JobStatus status = sexec.getJobStatus(jobId);\r
                        do {\r
-                               ChunkHolder ch = fw.pull(position);\r
-                               String chunk = ch.getChunk();\r
-                               position = ch.getNextPosition();\r
-                               // System.out.println(chunk);\r
+                               if (fw.hasMoreData()) {\r
+                                       ChunkHolder ch = fw.pull(position);\r
+                                       String chunk = ch.getChunk();\r
+                                       position = ch.getNextPosition();\r
+                               }\r
                                count++;\r
                                // Make sure the loop is terminated if the job fails\r
                                if ((status == JobStatus.UNDEFINED || status == JobStatus.FAILED)) {\r
@@ -298,7 +278,6 @@ public class AAConTester {
                                Thread.sleep(300);\r
                                status = sexec.getJobStatus(jobId);\r
                        } while (status != JobStatus.FINISHED || fw.hasMoreData());\r
-\r
                        assertTrue(count >= 1);\r
                        ConfiguredExecutable<?> al = sexec.getResults(jobId);\r
                        assertNotNull(al.getResults());\r
@@ -317,22 +296,23 @@ public class AAConTester {
                }\r
        }\r
 \r
-       @Test()\r
-       public void testPersistance() {\r
+       @Test(groups = {AllTestSuit.test_group_runner})\r
+       public void Persistance() {\r
                try {\r
                        AACon aacon = new AACon();\r
-                       aacon.setError("errrr.txt").setInput(test_alignment_input)\r
-                                       .setOutput("outtt.txt");\r
+                       aacon.setError("errrr.txt");\r
+                       aacon.setInput(test_alignment_input);\r
+                       aacon.setOutput("outtt.txt");\r
                        assertEquals(aacon.getInput(), test_alignment_input);\r
                        assertEquals(aacon.getError(), "errrr.txt");\r
                        assertEquals(aacon.getOutput(), "outtt.txt");\r
-                       ConfiguredExecutable<AACon> cAAcon = Configurator\r
-                                       .configureExecutable(aacon, Executable.ExecProvider.Local);\r
+                       ConfiguredExecutable<AACon> cAAcon = Configurator.configureExecutable(aacon, Executable.ExecProvider.Local);\r
 \r
                        SyncExecutor sexec = Configurator.getSyncEngine(cAAcon);\r
                        sexec.executeJob();\r
                        ConfiguredExecutable<?> al = sexec.waitForResult();\r
                        assertNotNull(al.getResults());\r
+\r
                        // Save run configuration\r
                        assertTrue(cAAcon.saveRunConfiguration());\r
 \r
@@ -340,33 +320,27 @@ public class AAConTester {
                        RunConfiguration loadedRun = RunConfiguration\r
                                        .load(new FileInputStream(new File(cAAcon\r
                                                        .getWorkDirectory(), RunConfiguration.rconfigFile)));\r
-                       assertEquals(\r
-                                       ((ConfExecutable<AACon>) cAAcon).getRunConfiguration(),\r
-                                       loadedRun);\r
+                       assertEquals(((ConfExecutable<AACon>) cAAcon).getRunConfiguration(),loadedRun);\r
+\r
                        // Load run configuration as ConfExecutable\r
                        ConfiguredExecutable<AACon> resurrectedCAAcon = (ConfiguredExecutable<AACon>) cAAcon\r
                                        .loadRunConfiguration(new FileInputStream(new File(cAAcon\r
                                                        .getWorkDirectory(), RunConfiguration.rconfigFile)));\r
                        assertNotNull(resurrectedCAAcon);\r
-                       assertEquals(resurrectedCAAcon.getExecutable().getInput(),\r
-                                       test_alignment_input);\r
-                       assertEquals(resurrectedCAAcon.getExecutable().getError(),\r
-                                       "errrr.txt");\r
-                       assertEquals(resurrectedCAAcon.getExecutable().getOutput(),\r
-                                       "outtt.txt");\r
+                       assertEquals(resurrectedCAAcon.getExecutable().getInput(), test_alignment_input);\r
+                       assertEquals(resurrectedCAAcon.getExecutable().getError(), "errrr.txt");\r
+                       assertEquals(resurrectedCAAcon.getExecutable().getOutput(), "outtt.txt");\r
+\r
                        // See in details whether executables are the same\r
                        assertEquals(resurrectedCAAcon.getExecutable(), aacon);\r
 \r
-                       ConfiguredExecutable<AACon> resAAcon = Configurator\r
-                                       .configureExecutable(resurrectedCAAcon.getExecutable(),\r
+                       ConfiguredExecutable<AACon> resAAcon = Configurator.configureExecutable(resurrectedCAAcon.getExecutable(),\r
                                                        Executable.ExecProvider.Local);\r
 \r
-                       sexec = Configurator.getSyncEngine(resAAcon,\r
-                                       Executable.ExecProvider.Local);\r
+                       sexec = Configurator.getSyncEngine(resAAcon, Executable.ExecProvider.Local);\r
                        sexec.executeJob();\r
                        al = sexec.waitForResult();\r
                        assertNotNull(al);\r
-\r
                } catch (JobSubmissionException e) {\r
                        e.printStackTrace();\r
                        fail(e.getMessage());\r
@@ -385,24 +359,20 @@ public class AAConTester {
                }\r
        }\r
 \r
-       @Test()\r
-       public void testConfigurationLoading() {\r
+       @Test(groups = {AllTestSuit.test_group_runner})\r
+       public void ConfigurationLoading() {\r
                try {\r
-                       RunnerConfig<AACon> aaconConfig = ConfExecutable\r
-                                       .getRunnerOptions(AACon.class);\r
+                       RunnerConfig<AACon> aaconConfig = ConfExecutable.getRunnerOptions(AACon.class);\r
                        assertNotNull(aaconConfig);\r
                        assertTrue(aaconConfig.getArguments().size() > 0);\r
 \r
-                       PresetManager<AACon> aaconPresets = ConfExecutable\r
-                                       .getRunnerPresets(AACon.class);\r
+                       PresetManager<AACon> aaconPresets = ConfExecutable.getRunnerPresets(AACon.class);\r
                        assertNotNull(aaconPresets);\r
 \r
-                       LimitsManager<AACon> jronnLimits = ConfExecutable\r
-                                       .getRunnerLimits(AACon.class);\r
-                       assertNotNull(jronnLimits);\r
-                       assertTrue(jronnLimits.getLimits().size() > 0);\r
-                       jronnLimits.validate(aaconPresets);\r
-\r
+                       LimitsManager<AACon> aaconLimits = ConfExecutable.getRunnerLimits(AACon.class);\r
+                       assertNotNull(aaconLimits);\r
+                       assertTrue(aaconLimits.getLimits().size() > 0);\r
+                       aaconLimits.validate(aaconPresets);\r
                } catch (FileNotFoundException e) {\r
                        e.printStackTrace();\r
                        fail(e.getLocalizedMessage());\r
@@ -414,5 +384,4 @@ public class AAConTester {
                        fail(e.getLocalizedMessage());\r
                }\r
        }\r
-\r
 }\r