@Test public void multiThreadedSavePdfPageAsPNG() throws IOException { long start = System.currentTimeMillis(); PdfTableReader reader = new PdfTableReader(); ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT); List<Future<Boolean>> futures = new ArrayList<>(); for (final int pageNum : IntStream.rangeClosed(1, PDFdoc.getNumberOfPages()).toArray()) { Callable<Boolean> callable = () -> { reader.savePdfPageAsPNG(PDFdoc, pageNum, TEST_OUT_PATH); return true; }; futures.add(executor.submit(callable)); } try { for (Future<Boolean> f : futures) { f.get(); } } catch (Exception e) { throw new TestException(e); } long end = System.currentTimeMillis(); System.out.println("save page image - multi thread: " + (end - start) / 1000.0); }
@Test public void multiThreadedSavePdfTablePageDebugImage() throws IOException { long start = System.currentTimeMillis(); PdfTableReader reader = new PdfTableReader(); ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT); List<Future<Boolean>> futures = new ArrayList<>(); for (final int pageNum : IntStream.rangeClosed(1, PDFdoc.getNumberOfPages()).toArray()) { Callable<Boolean> callable = () -> { reader.savePdfTablePageDebugImage(PDFdoc, pageNum, TEST_OUT_PATH); return true; }; futures.add(executor.submit(callable)); } try { for (Future<Boolean> f : futures) { f.get(); } } catch (Exception e) { throw new TestException(e); } long end = System.currentTimeMillis(); System.out.println("save debug images - multi thread: " + (end - start) / 1000.0); }
@DataProvider(name = "testsProvider") public static Iterator<Object[]> getTestsConfiguration(ITestContext context) throws Exception { // tests could be run using not standard runner (check RunTests class) - eg. IntelliJ IDEA. In that case we // need to read default configuration in the same way as RunTests does it. Tests run by other runner will // be executed in 1 thread (configuration parameter <threads/> will be ignored). if (!INITIALIZED && RunTests.readConfigAndInit() == null) { throw new TestException("Can not read tests configuration"); } log.debug("Reading tests configuration..."); Collection<Object[]> dpParams = new ArrayList<>(); File[] listOfFiles = TESTS_DIR_FILE.listFiles(); if (listOfFiles == null) { throw new FileNotFoundException("Problems with listing directory " + TESTS_DIR_FILE.getAbsolutePath()); } for (File file : listOfFiles) { if (file.isDirectory()) { processTestFiles(file, file.getName(), dpParams); } } log.debug("Running tests..."); return dpParams.iterator(); }
@Override public TestResults compare(TestParams testParams) throws Exception { CmpSqlResultsConfig cmpSqlResultsConfig = testParams.getCmpSqlResultsConfig(); CmpSqlResultsTest cmpSqlResultsTest = testParams.getCmpSqlResultsTest(); // (get(0) - IndexOutOfBoundsException) checked in TestDataProvider, but still - schema would be nice! Sql sql1 = cmpSqlResultsTest.getCompare().getSqls().get(0); Datasource datasource = cmpSqlResultsConfig.getDatasourceByName(sql1.getDatasourceName()); if (datasource == null) { throw new TestException( "Datasource '" + sql1.getDatasourceName() + "' not found! Please check configuration"); } String query = getCountQuery(sql1.getSql()); Connection connection = null; try { connection = DataSource.getConnection(datasource.getName()); return getTestResults(connection, query, sql1.getDatasourceName(), testParams); } catch (Exception e) { throw new Exception(e+"\nAssert Query : " + query); } finally { DataSource.closeConnection(connection); } }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { Object testInstance = method.getTestMethod().getInstance(); if (runningTests.containsValue(testInstance)) { return; } long currentThreadId = Thread.currentThread().getId(); if (isNewTestInProgress(testInstance)) { preDestroy(runningTests.remove(currentThreadId)); } String testName = testInstance.getClass().getName(); try { LOG.info("Dependencies injection in {}", testName); injectDependencies(testResult.getTestContext(), testInstance); } catch (Exception e) { String errorMessage = "Failed to inject fields in " + testName; LOG.error(errorMessage, e); throw new TestException(errorMessage, e); } finally { runningTests.put(currentThreadId, testInstance); } }
@Test public void testChildNacked() throws Exception { BasicAckableForTesting ackable = new BasicAckableForTesting(); HierarchicalAckable hierarchicalAckable = new HierarchicalAckable(Lists.newArrayList(ackable)); Ackable child1 = hierarchicalAckable.newChildAckable(); Ackable child2 = hierarchicalAckable.newChildAckable(); child2.ack(); Assert.assertEquals(ackable.acked, 0); Assert.assertEquals(ackable.nacked, 0); hierarchicalAckable.close(); Assert.assertEquals(ackable.acked, 0); Assert.assertEquals(ackable.nacked, 0); child1.nack(new TestException("test")); Assert.assertEquals(ackable.acked, 0); Assert.assertEquals(ackable.nacked, 1); Assert.assertNotNull(ackable.throwable); Assert.assertTrue(ackable.throwable instanceof HierarchicalAckable.ChildrenFailedException); Assert.assertEquals(((HierarchicalAckable.ChildrenFailedException) ackable.throwable).getFailureCauses().size(), 1); }
@Test(dataProvider = "maskData", groups = "sv") public void testMaskedKmers(final String seq1, final String seq2, final byte[] maskBytes, final boolean equal) { if (seq1.length() != seq2.length()) { throw new TestException("Kmer sequences must be of same length"); } final int K = seq1.length(); final SVKmerShort kmer1 = (SVKmerShort)SVKmerizer.toKmer(seq1, new SVKmerShort(K)); final SVKmerShort kmer2 = (SVKmerShort)SVKmerizer.toKmer(seq2, new SVKmerShort(K)); final SVKmerShort mask = SVKmerShort.getMask(maskBytes, K); if (equal) { Assert.assertEquals(kmer1.mask(mask), kmer2.mask(mask)); } else { Assert.assertNotEquals(kmer1.mask(mask), kmer2.mask(mask)); } }
private static String getTestCigar(final int readLength, final int insertionLength, final int deletionLength, final int clipLength) { final int numMatchOrMismatch = readLength - insertionLength - clipLength; if (numMatchOrMismatch < 0) { throw new TestException("Clip length plus insertions plus clipping was greater than read length"); } String cigar = ""; if (clipLength > 0) { cigar = cigar + clipLength + "S"; } if (insertionLength > 0) { cigar = cigar + insertionLength + "I"; } if (deletionLength > 0) { cigar = cigar + deletionLength + "D"; } if (numMatchOrMismatch > 0) { cigar = cigar + numMatchOrMismatch + "M"; } return cigar; }
private static GATKRead generateRead(final int length, final List<Integer> NM, final List<Integer> clip, final List<Integer> insert, final List<Integer> delete, final List<String> contig, final String altTag) { final GATKRead read = ArtificialReadUtils.createRandomRead(length); read.setAttribute("NM", NM.get(0)); read.setPosition(contig.get(0), 1); read.setCigar(getTestCigar(length, insert.get(0), delete.get(0), clip.get(0))); if (NM.size() > 1) { String tagValue = ""; for (int i = 1; i < NM.size(); i++) { if (altTag.equals("XA")) { tagValue += contig.get(i) + ",+1," + getTestCigar(length, insert.get(i), delete.get(i), clip.get(i)) + "," + NM.get(i) + ";"; } else if (altTag.equals("SA")) { tagValue += contig.get(i) + ",1,+," + getTestCigar(length, insert.get(i), delete.get(i), clip.get(i)) + ",0," + NM.get(i) + ";"; } else { throw new TestException("Unknown tag " + altTag); } } read.setAttribute(altTag, tagValue); } return read; }
@AfterMethod private void tearDown() { if (PDFdoc != null) { try { PDFdoc.close(); } catch (IOException ioe) { throw new TestException(ioe); } } }
@Override public TestResults compare(TestParams testParams) throws Exception { CmpSqlResultsConfig cmpSqlResultsConfig = testParams.getCmpSqlResultsConfig(); CmpSqlResultsTest cmpSqlResultsTest = testParams.getCmpSqlResultsTest(); // TODO xml config validation -> in MINUS mode sql queries shpould NOT have own datasources - only // default on "compare" level (in XML). Schema would be nice! String dataSrcName = cmpSqlResultsTest.getCompare().getDefaultDatasourceName(); Datasource datasource = cmpSqlResultsConfig.getDatasourceByName(dataSrcName); if (datasource == null) { throw new TestException("Datasource '" + dataSrcName + "' not found! Please check configuration"); } // (get(0)/get(1) - IndexOutOfBoundsException) checked in TestDataProvider, but still - schema would be nice! String sql1 = cmpSqlResultsTest.getCompare().getSqls().get(0).getSql(); String sql2 = cmpSqlResultsTest.getCompare().getSqls().get(1).getSql(); String query = getMinusQuery(datasource, sql1, sql2, testParams); Connection connection = null; try { connection = DataSource.getConnection(datasource.getName()); return getTestResults(connection, query, testParams, dataSrcName); } catch (Exception e) { throw new Exception(e+"\nMinus Query : " + query); } finally { DataSource.closeConnection(connection); } }
@Override public TestResults compare(TestParams testParams) throws Exception { CmpSqlResultsConfig cmpSqlResultsConfig = testParams.getCmpSqlResultsConfig(); CmpSqlResultsTest cmpSqlResultsTest = testParams.getCmpSqlResultsTest(); // (get(0) - IndexOutOfBoundsException) checked in TestDataProvider validation Sql sql = cmpSqlResultsTest.getCompare().getSqls().get(0); Datasource datasource = cmpSqlResultsConfig.getDatasourceByName(sql.getDatasourceName()); if (datasource == null) { throw new TestException("Datasource '" + datasource.getName() + "' not found! Please check configuration"); } String fileAbsPath = testParams.getTestConfigFile().getParentFile().getAbsolutePath(); fileAbsPath += "/" + cmpSqlResultsTest.getCompare().getFile().getFilename(); //null/empty checked in TestDataProvider File file = new File(fileAbsPath); if (!file.exists()) { throw new TestException("File '" + file.getAbsolutePath() + "' not found! Please check configuration"); } prepareCSVPattern(cmpSqlResultsTest.getCompare().getFile().getSeparator()); Connection connection = null; try { connection = DataSource.getConnection(datasource.getName()); return getTestResults(testParams, connection, file); } catch (Exception e) { throw new Exception(e+"\nQuery 1: " + sql.getSql()); } finally { DataSource.closeConnection(connection); } }
@Override public TestResults compare(TestParams testParams) throws Exception { CmpSqlResultsConfig cmpSqlResultsConfig = testParams.getCmpSqlResultsConfig(); CmpSqlResultsTest cmpSqlResultsTest = testParams.getCmpSqlResultsTest(); // (get(0)/get(1) - IndexOutOfBoundsException) checked in TestDataProvider, but still - schema would be nice! Sql sql1 = cmpSqlResultsTest.getCompare().getSqls().get(0); Sql sql2 = cmpSqlResultsTest.getCompare().getSqls().get(1); Datasource datasource1 = cmpSqlResultsConfig.getDatasourceByName(sql1.getDatasourceName()); Datasource datasource2 = cmpSqlResultsConfig.getDatasourceByName(sql2.getDatasourceName()); if (datasource1 == null) { throw new TestException( "Datasource '" + sql1.getDatasourceName() + "' not found! Please check configuration"); } if (datasource2 == null) { throw new TestException( "Datasource '" + sql2.getDatasourceName() + "' not found! Please check configuration"); } Connection connection1 = null; Connection connection2 = null; try { connection1 = DataSource.getConnection(datasource1.getName()); connection2 = DataSource.getConnection(datasource2.getName()); return getTestResults(connection1, connection2, testParams); } catch (Exception e) { throw new Exception(e+"\nQuery 1: " + sql1.getSql()+"\nQuery 2: " + sql2.getSql()); } finally { DataSource.closeConnection(connection1); DataSource.closeConnection(connection2); } }
@DataProvider(name="validVariantContexts") public Object[][] validVariantContexts(){ final ReferenceMultiSource reference = referenceMultiSource(REFERENCE_FILE.getAbsolutePath()); try (final VCFFileReader reader = new VCFFileReader(VALID_VARIANTS_FILE, false)) { return Utils.stream(reader) .map(vc -> new Object[]{vc, reference}) .toArray(Object[][]::new); } catch (final Throwable ex) { throw new TestException("could not load the valid context file: " + VALID_VARIANTS_FILE.getAbsolutePath(), ex); } }
@Test(dataProvider = "mapUnpaired", groups = "spark") public void testMapGroupedReadsToTaxUnpaired(final int readLength, final List<Integer> NM, final List<Integer> clip, final List<Integer> insert, final List<Integer> delete, final List<String> contig, final List<Integer> truthTax) { if (!(NM.size() == clip.size() && NM.size() == insert.size() && NM.size() == delete.size() && NM.size() == contig.size())) { throw new TestException("Input lists for read must be of uniform length"); } final JavaSparkContext ctx = SparkContextFactory.getTestSparkContext(); final Broadcast<PSTaxonomyDatabase> taxonomyDatabaseBroadcast = ctx.broadcast(taxonomyDatabase); //Test with alternate alignments assigned to the XA tag final List<Iterable<GATKRead>> readListXA = new ArrayList<>(); readListXA.add(generateUnpairedRead(readLength, NM, clip, insert, delete, contig, "XA")); final JavaRDD<Iterable<GATKRead>> pairsXA = ctx.parallelize(readListXA); final JavaRDD<Tuple2<Iterable<GATKRead>, PSPathogenAlignmentHit>> resultXA = PSScorer.mapGroupedReadsToTax(pairsXA, MIN_IDENT, IDENT_MARGIN, taxonomyDatabaseBroadcast); final PSPathogenAlignmentHit infoXA = resultXA.first()._2; Assert.assertNotNull(infoXA); Assert.assertEquals(infoXA.taxIDs.size(), truthTax.size()); Assert.assertTrue(infoXA.taxIDs.containsAll(truthTax)); Assert.assertEquals(infoXA.numMates, 1); //Test SA tag final List<Iterable<GATKRead>> readListSA = new ArrayList<>(); readListSA.add(generateUnpairedRead(readLength, NM, clip, insert, delete, contig, "SA")); final JavaRDD<Iterable<GATKRead>> pairsSA = ctx.parallelize(readListSA); final JavaRDD<Tuple2<Iterable<GATKRead>, PSPathogenAlignmentHit>> resultSA = PSScorer.mapGroupedReadsToTax(pairsSA, MIN_IDENT, IDENT_MARGIN, taxonomyDatabaseBroadcast); final PSPathogenAlignmentHit infoSA = resultSA.first()._2; Assert.assertNotNull(infoSA); Assert.assertEquals(infoSA.taxIDs.size(), truthTax.size()); Assert.assertTrue(infoSA.taxIDs.containsAll(truthTax)); Assert.assertEquals(infoSA.numMates, 1); }
@Test public void testCloseReader() { final BufferedReader r; try { r = new BufferedReader(new FileReader(hg19MiniReference)); } catch (IOException e) { throw new TestException(e); } }