GenerateAndRunShaders { public static void mainHelper(String[] args) throws IOException, InterruptedException, ArgumentParserException { final Namespace ns = parse(args); final ShaderJobFileOperations fileOps = new ShaderJobFileOperations(); final File referencesDir = ns.get("references"); if (!fileOps.isDirectory(referencesDir)) { throw new IllegalArgumentException("References directory does not exist."); } final File donors = ns.get("donors"); if (!fileOps.isDirectory(donors)) { throw new IllegalArgumentException("Donors directory does not exist."); } final File outputDir = ns.get("output_dir"); fileOps.deleteDirectory(outputDir); fileOps.mkdir(outputDir); final BlockingQueue<ShaderJob> queue = new LinkedBlockingQueue<>(); final File crashStringsToIgnoreFile = ns.get("ignore_crash_strings"); final Set<String> crashStringsToIgnore = new HashSet<>(); if (crashStringsToIgnoreFile != null) { crashStringsToIgnore.addAll(fileOps.readLines(crashStringsToIgnoreFile)); } File[] shaderJobFiles = fileOps.listShaderJobFiles(referencesDir, (dir, name) -> true); if (shaderJobFiles.length <= 0) { throw new IllegalArgumentException("No shader jobs found."); } final Thread consumer = new Thread(new ShaderConsumer( LIMIT, queue, outputDir, ns.get("server"), ns.get("worker"), crashStringsToIgnore, fileOps)); consumer.start(); final Thread producer = new Thread(new ShaderProducer( LIMIT, shaderJobFiles, queue, referencesDir, donors, ns, fileOps)); producer.start(); consumer.join(); producer.join(); }  static void main(String[] args); static void mainHelper(String[] args);  }
@Test public void testNoReferences() throws Exception { final File donors = temporaryFolder.newFolder(); final File references = temporaryFolder.newFolder(); final String outputDir = new File(temporaryFolder.getRoot(), "output").getAbsolutePath(); assertTrue(references.delete()); try { GenerateAndRunShaders.mainHelper( new String[]{ references.getAbsolutePath(), donors.getAbsolutePath(), outputDir, "dummy_server", "dummy_worker" } ); throw new RuntimeException("Exception expected."); } catch (IllegalArgumentException exception) { assertEquals("References directory does not exist.", exception.getMessage()); } }
@Test public void testNoDonors() throws Exception { final File donors = temporaryFolder.newFolder(); final File references = temporaryFolder.newFolder(); final String outputDir = new File(temporaryFolder.getRoot(), "output").getAbsolutePath(); assertTrue(donors.delete()); try { GenerateAndRunShaders.mainHelper( new String[] { references.getAbsolutePath(), donors.getAbsolutePath(), outputDir, "dummy_server", "dummy_worker" } ); throw new RuntimeException("Exception expected."); } catch (IllegalArgumentException exception) { assertEquals("Donors directory does not exist.", exception.getMessage()); } }
@Test public void testMissingJson() throws Exception { final File donors = temporaryFolder.newFolder(); final File references = temporaryFolder.newFolder(); final String outputDir = new File(temporaryFolder.getRoot(), "output").getAbsolutePath(); new File(references, "a.frag").createNewFile(); try { GenerateAndRunShaders.mainHelper( new String[]{ references.getAbsolutePath(), donors.getAbsolutePath(), outputDir, "dummy_server", "dummy_worker" } ); throw new RuntimeException("Exception expected."); } catch (IllegalArgumentException exception) { assertEquals("No shader jobs found.", exception.getMessage()); } }