+++ /dev/null
-/* Copyright (c) 2009 Peter Troshin\r
- * \r
- * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0 \r
- * \r
- * This library is free software; you can redistribute it and/or modify it under the terms of the\r
- * Apache License version 2 as published by the Apache Software Foundation\r
- * \r
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
- * License for more details.\r
- * \r
- * A copy of the license is in apache_license.txt. It is also available here:\r
- * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
- * \r
- * Any republication or derived work distributed in source code form\r
- * must include this copyright and license notice.\r
- */\r
-\r
-package compbio.engine;\r
-\r
-import static org.testng.Assert.assertEquals;\r
-import static org.testng.Assert.assertNotNull;\r
-import static org.testng.Assert.fail;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.util.concurrent.TimeUnit;\r
-\r
-import org.testng.annotations.BeforeTest;\r
-import org.testng.annotations.Test;\r
-\r
-import compbio.engine.client.ConfiguredExecutable;\r
-import compbio.engine.client.Executable;\r
-import compbio.engine.local.AsyncLocalRunner;\r
-import compbio.metadata.AllTestSuit;\r
-import compbio.metadata.ChunkHolder;\r
-import compbio.metadata.JobSubmissionException;\r
-import compbio.metadata.ResultNotAvailableException;\r
-import compbio.runner.msa.ClustalW;\r
-import compbio.runner.msa.Muscle;\r
-\r
-public class FilePullerTester {\r
-\r
- public static String test_input = AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
- + "TO1381.fasta";\r
-\r
- String jobId;\r
- String jobId2;\r
- String jobId3;\r
-\r
- @BeforeTest(alwaysRun = true)\r
- public void init() {\r
- ClustalW clustal = new ClustalW();\r
- clustal.setInput(test_input);\r
- Muscle ms = new Muscle().setInput(test_input);\r
- Muscle ms2 = new Muscle().setInput(test_input);\r
-\r
- try {\r
- // For local execution use relavive\r
- ConfiguredExecutable<ClustalW> confClustal = Configurator\r
- .configureExecutable(clustal, Executable.ExecProvider.Local);\r
- ConfiguredExecutable<Muscle> confms = Configurator\r
- .configureExecutable(ms, Executable.ExecProvider.Local);\r
-\r
- ConfiguredExecutable<Muscle> confms2 = Configurator\r
- .configureExecutable(ms2, Executable.ExecProvider.Local);\r
-\r
- AsyncLocalRunner as = new AsyncLocalRunner();\r
- jobId = as.submitJob(confClustal);\r
- jobId2 = as.submitJob(confms);\r
- jobId3 = as.submitJob(confms2);\r
-\r
- ConfiguredExecutable<?> al = as.getResults(jobId);\r
- ConfiguredExecutable<?> al2 = as.getResults(jobId2);\r
- ConfiguredExecutable<?> al3 = as.getResults(jobId3);\r
- assertNotNull(al);\r
- assertNotNull(al2);\r
- assertNotNull(al3);\r
- } catch (JobSubmissionException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- } catch (ResultNotAvailableException e) {\r
- e.printStackTrace();\r
- fail(e.getLocalizedMessage());\r
- }\r
- }\r
-\r
- @Test(groups = { AllTestSuit.test_group_engine })\r
- public void testPull() {\r
- assertNotNull(jobId, "init() method failed!");\r
- String workDir = Configurator.getWorkDirectory(jobId);\r
- String statFile = workDir + File.separator + ClustalW.getStatFile();\r
-\r
- ChunkHolder ch = ProgressGetter.pull(statFile, 0);\r
- while (ch == null) {\r
- ch = ProgressGetter.pull(statFile, 0);\r
- }\r
- String chunk = "";\r
- long pos = 0;\r
- do {\r
- chunk = ch.getChunk();\r
- assertNotNull(chunk);\r
- pos = ch.getNextPosition();\r
- ch = ProgressGetter.pull(statFile, pos);\r
- } while (chunk.length() > 0);\r
-\r
- // All consequent pulls just return empty chunk and same position =\r
- // file.length\r
- ch = ProgressGetter.pull(statFile, pos);\r
- assertNotNull(ch);\r
- assertEquals(ch.getChunk().length(), 0);\r
- // Output file size depends on the operation system fs!\r
- // assertEquals(ch.getNextPosition(), 668);\r
-\r
- ch = ProgressGetter.pull(statFile, pos);\r
- assertNotNull(ch);\r
- assertEquals(ch.getChunk().length(), 0);\r
- // Output file size depends on the operation system and fs!\r
- // assertEquals(ch.getNextPosition(), 668);\r
-\r
- }\r
-\r
- @Test(groups = { AllTestSuit.test_group_engine })\r
- public void testGetDelay() {\r
- FilePuller fp = FilePuller.newFilePuller(Configurator\r
- .getWorkDirectory(jobId)\r
- + File.separator + "stat.log", 256);\r
- // default delay is 5 minutes\r
- assertEquals(fp.getDelayValue(TimeUnit.SECONDS), 5 * 60);\r
- long d = 1000 * 1000 * 1000L * 60; // 1m in nanoseconds\r
- fp.setDelay(d, TimeUnit.NANOSECONDS);\r
- assertEquals(fp.getDelayValue(TimeUnit.NANOSECONDS), d);\r
- assertEquals(fp.getDelayValue(TimeUnit.SECONDS), 60);\r
- assertEquals(fp.getDelayValue(TimeUnit.MINUTES), 1);\r
- }\r
-\r
- @Test(groups = { AllTestSuit.test_group_engine }, dependsOnMethods = { "testPull" })\r
- public void testCache() {\r
- assertNotNull(jobId, "init() method failed!");\r
- assertNotNull(jobId2, "init() method failed!");\r
- assertEquals(PulledFileCache.getSize(), 1); // One is from previous test\r
-\r
- String statFile = Configurator.getWorkDirectory(jobId) + File.separator\r
- + ClustalW.getStatFile();\r
- String statFile2 = Configurator.getWorkDirectory(jobId2)\r
- + File.separator + Muscle.getStatFile();\r
- String statFile3 = Configurator.getWorkDirectory(jobId3)\r
- + File.separator + Muscle.getStatFile();\r
-\r
- ChunkHolder ch = ProgressGetter.pull(statFile, 0);\r
- assertEquals(PulledFileCache.getSize(), 1); // Still one as job has been\r
- // retrieved from cache\r
- ChunkHolder ch2 = ProgressGetter\r
- .pull(statFile2, 0, 5, TimeUnit.SECONDS); // 5\r
- // second delay\r
- assertEquals(PulledFileCache.getSize(), 2); // One is from previous test\r
-\r
- // Pull the first job completely\r
- while (ch == null) {\r
- ch = ProgressGetter.pull(statFile, 0);\r
- }\r
- String chunk = "";\r
- long pos = 0;\r
- do {\r
- chunk = ch.getChunk();\r
- assertNotNull(chunk);\r
- pos = ch.getNextPosition();\r
- ch = ProgressGetter.pull(statFile, pos);\r
- } while (chunk.length() > 0);\r
-\r
- try {\r
- Thread.sleep(1000 * 6);\r
- } catch (InterruptedException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- }\r
- // Elements are removed on put operation only\r
- assertEquals(PulledFileCache.getSize(), 2); // One is from previous test\r
- ChunkHolder ch3 = ProgressGetter.pull(statFile3, 0);\r
- // Now old element was removed, but new added, thus size remains\r
- // constant\r
- assertEquals(PulledFileCache.getSize(), 2); // One is from previous test\r
-\r
- }\r
-\r
- @Test\r
- public void testGet() {\r
-\r
- FilePuller pp = FilePuller\r
- .newProgressPuller(AllTestSuit.TEST_DATA_PATH_ABSOLUTE\r
- + "percentProgress.txt");\r
- try {\r
- assertEquals(pp.getProgress(), 12);\r
- pp.disconnect();\r
- } catch (NumberFormatException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- fail(e.getMessage());\r
- }\r
- }\r
-}\r