@Test public void testCopyToDirectory() throws Exception { this.setup.groupBySetup(); String uriTemplate = Paths.get(folder.getRoot().toURI()).toUri().toString(); SQLResponse response = execute("copy characters to DIRECTORY ?", new Object[] {uriTemplate}); assertThat(response.rowCount(), is(7L)); List<String> lines = new ArrayList<>(7); DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(folder.getRoot().toURI()), "*.json"); for (Path entry : stream) { lines.addAll(Files.readAllLines(entry, StandardCharsets.UTF_8)); } String[] list = folder.getRoot().list(); assertThat(list.length, greaterThanOrEqualTo(1)); for (String file : list) { assertThat(file, startsWith("characters_")); } assertThat(lines.size(), is(7)); for (String line : lines) { assertThat(line, startsWith("{")); assertThat(line, endsWith("}")); } }
/** Fake installation on Unix. */ @Test public void fakeUnixInstall() throws Exception { Assume.assumeFalse("If we're on Windows, don't bother doing this", Functions.isWindows()); File bundle = File.createTempFile("fake-jdk-by-hudson", "sh"); try { new FilePath(bundle) .write( "#!/bin/bash -ex\n" + "mkdir -p jdk1.6.0_dummy/bin\n" + "touch jdk1.6.0_dummy/bin/java", "ASCII"); TaskListener l = StreamTaskListener.fromStdout(); new JDKInstaller("", true) .install( new LocalLauncher(l), Platform.LINUX, new JDKInstaller.FilePathFileSystem(j.jenkins), l, tmp.getRoot().getPath(), bundle.getPath()); assertTrue(new File(tmp.getRoot(), "bin/java").exists()); } finally { bundle.delete(); } }
@Test public void testOutputFailed() throws IOException { ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmpDir.getRoot().toPath()); ChromeTraceBuildListener listener = new ChromeTraceBuildListener( projectFilesystem, new FakeClock(1409702151000000000L), new ObjectMapper(), Locale.US, TimeZone.getTimeZone("America/Los_Angeles"), /* tracesToKeep */ 3, false); try { assumeTrue("Can make the root directory read-only", tmpDir.getRoot().setReadOnly()); listener.outputTrace(new BuildId("BUILD_ID")); fail("Expected an exception."); } catch (HumanReadableException e) { assertEquals( "Unable to write trace file: java.nio.file.AccessDeniedException: " + projectFilesystem.resolve(BuckConstant.BUCK_OUTPUT_PATH), e.getMessage()); } finally { tmpDir.getRoot().setWritable(true); } }
@Ignore( "Test is ignored because currently it is not possible to register two block extensions in same instance. This may require deep changes on Asciidoctor Extensions API") @Test public void extensions_should_be_correctly_added() throws IOException { Asciidoctor asciidoctor = JRubyAsciidoctor.create(); // To avoid registering the same extension over and over for all tests, service is instantiated // manually. new ArrowsAndBoxesExtension().register(asciidoctor); Options options = options() .inPlace(false) .toFile(new File(testFolder.getRoot(), "rendersample.html")) .safe(SafeMode.UNSAFE) .get(); asciidoctor.renderFile(classpath.getResource("arrows-and-boxes-example.ad"), options); File renderedFile = new File(testFolder.getRoot(), "rendersample.html"); Document doc = Jsoup.parse(renderedFile, "UTF-8"); Element arrowsJs = doc.select("script[src=http://www.headjump.de/javascripts/arrowsandboxes.js").first(); assertThat(arrowsJs, is(notNullValue())); Element arrowsCss = doc.select("link[href=http://www.headjump.de/stylesheets/arrowsandboxes.css").first(); assertThat(arrowsCss, is(notNullValue())); Element arrowsAndBoxes = doc.select("pre[class=arrows-and-boxes").first(); assertThat(arrowsAndBoxes, is(notNullValue())); }
/** End-to-end installation test. */ private void doTestAutoInstallation(String id, String fullversion) throws Exception { Assume.assumeTrue( "this is a really time consuming test, so only run it when we really want", Boolean.getBoolean("jenkins.testJDKInstaller")); retrieveUpdateCenterData(); JDKInstaller installer = new JDKInstaller(id, true); JDK jdk = new JDK( "test", tmp.getRoot().getAbsolutePath(), Arrays.asList(new InstallSourceProperty(Arrays.<ToolInstaller>asList(installer)))); j.jenkins.getJDKs().add(jdk); FreeStyleProject p = j.createFreeStyleProject(); p.setJDK(jdk); p.getBuildersList().add(new Shell("java -fullversion\necho $JAVA_HOME")); FreeStyleBuild b = j.buildAndAssertSuccess(p); @SuppressWarnings("deprecation") String log = b.getLog(); System.out.println(log); // make sure it runs with the JDK that just got installed assertTrue(log.contains(fullversion)); assertTrue(log.contains(tmp.getRoot().getAbsolutePath())); }
/** * Setup to do for each unit test. * * @throws IOException if there's an error accessing the local file system */ @Before public void setUp() throws IOException { srcMetastore = new MockHiveMetastoreClient(); destMetastore = new MockHiveMetastoreClient(); srcLocalTmp.create(); destLocalTmp.create(); final Path srcFsRoot = new Path("file://" + srcLocalTmp.getRoot().getAbsolutePath()); final Path destFsRoot = new Path("file://" + destLocalTmp.getRoot().getAbsolutePath()); srcWarehouseRoot = new Path(makeFileUri(srcLocalTmp), "warehouse"); destWarehouseRoot = new Path(makeFileUri(destLocalTmp), "warehouse"); srcWarehouseRoot.getFileSystem(conf).mkdirs(srcWarehouseRoot); destWarehouseRoot.getFileSystem(conf).mkdirs(destWarehouseRoot); LOG.info(String.format("src root: %s, dest root: %s", srcWarehouseRoot, destWarehouseRoot)); final Path srcTmp = new Path(makeFileUri(this.srcLocalTmp), "tmp"); final Path destTmp = new Path(makeFileUri(this.destLocalTmp), "tmp"); srcCluster = new MockCluster("src_cluster", srcMetastore, srcFsRoot, srcTmp); destCluster = new MockCluster("dest_cluster", destMetastore, destFsRoot, destTmp); // Disable checking of modified times as the local filesystem does not // support this directoryCopier = new DirectoryCopier(conf, destCluster.getTmpDir(), false); }
@Test public void tryLock() { assertThat(temp.getRoot().list()).isEmpty(); lock.tryLock(); assertThat(temp.getRoot().toPath().resolve(".sonar_lock")).exists(); lock.unlock(); }
@Test public void testCopyColumnsToDirectory() throws Exception { this.setup.groupBySetup(); String uriTemplate = Paths.get(folder.getRoot().toURI()).toUri().toString(); SQLResponse response = execute( "copy characters (name, details['job']) to DIRECTORY ?", new Object[] {uriTemplate}); assertThat(response.cols().length, is(0)); assertThat(response.rowCount(), is(7L)); List<String> lines = new ArrayList<>(7); DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(folder.getRoot().toURI()), "*.json"); for (Path entry : stream) { lines.addAll(Files.readAllLines(entry, StandardCharsets.UTF_8)); } Path path = Paths.get(folder.getRoot().toURI().resolve("characters_0_.json")); assertTrue(path.toFile().exists()); assertThat(lines.size(), is(7)); boolean foundJob = false; boolean foundName = false; for (String line : lines) { foundName = foundName || line.contains("Arthur Dent"); foundJob = foundJob || line.contains("Sandwitch Maker"); assertThat(line.split(",").length, is(2)); assertThat(line.trim(), startsWith("[")); assertThat(line.trim(), endsWith("]")); } assertTrue(foundJob); assertTrue(foundName); }
private Resource createFile(String path, String content) throws IOException { final File file = new File(folder.getRoot(), path); file.getParentFile().mkdirs(); final Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); writer.write(content); writer.close(); return new FileResource(folder.getRoot(), path); }
@Before public void setUpProject() throws IOException { orchestrator.resetData(); orchestrator .getServer() .restoreProfile(FileLocation.ofClasspath("/duplication/xoo-duplication-profile.xml")); FileUtils.copyDirectory(ItUtils.projectDir(PROJECT_DIR), temp.getRoot()); projectDir = temp.getRoot(); }
@Test public void testDirectoryOrdering() throws IOException { createFile("src1/org/jacoco/example/Test.java", "AAA"); locator.add(new FileResource(folder.getRoot(), "src1")); createFile("src2/org/jacoco/example/Test.java", "BBB"); locator.add(new FileResource(folder.getRoot(), "src2")); createFile("src3/org/jacoco/example/Test.java", "CCC"); locator.add(new FileResource(folder.getRoot(), "src3")); final Reader source = locator.getSourceFile("org/jacoco/example", "Test.java"); assertContent("AAA", source); }
@Test public void testExportToDirectory() throws Exception { closeFileHandlesInEtc(); resetInitialState(); String response = console.runCommand(EXPORT_COMMAND + " \"" + temporaryFolder.getRoot() + "\""); assertThat( String.format("Exporting current configurations to %s.", temporaryFolder.toString()), response, containsString("Successfully exported all configurations.")); assertExportContents(temporaryFolder.getRoot().toPath()); }
@Test public void differentContexts() throws Exception { ContextManager cm = new ContextManager( vfs, new ReloadingClassLoader() { @Override public ClassLoader getClassLoader() { return ClassLoader.getSystemClassLoader(); } }); cm.setContextConfig( new ContextsConfig() { @Override public ContextConfig getContextConfig(String context) { if (context.equals("CX1")) { return new ContextConfig(uri1.toString(), true); } else if (context.equals("CX2")) { return new ContextConfig(uri2.toString(), true); } return null; } }); FileObject testDir = vfs.resolveFile(folder1.getRoot().toURI().toString()); FileObject[] dirContents = testDir.getChildren(); ClassLoader cl1 = cm.getClassLoader("CX1"); FileObject[] files = ((VFSClassLoader) cl1).getFileObjects(); Assert.assertArrayEquals(createFileSystems(dirContents), files); FileObject testDir2 = vfs.resolveFile(folder2.getRoot().toURI().toString()); FileObject[] dirContents2 = testDir2.getChildren(); ClassLoader cl2 = cm.getClassLoader("CX2"); FileObject[] files2 = ((VFSClassLoader) cl2).getFileObjects(); Assert.assertArrayEquals(createFileSystems(dirContents2), files2); Class<?> defaultContextClass = cl1.loadClass("test.HelloWorld"); Object o1 = defaultContextClass.newInstance(); Assert.assertEquals("Hello World!", o1.toString()); Class<?> myContextClass = cl2.loadClass("test.HelloWorld"); Object o2 = myContextClass.newInstance(); Assert.assertEquals("Hello World!", o2.toString()); Assert.assertFalse(defaultContextClass.equals(myContextClass)); cm.removeUnusedContexts(new HashSet<String>()); }
@Test public void whenDatabaseTuningFilePresentInDefaultLocationShouldLoadItEvenIfNotSpecified() throws IOException { File emptyPropertyFile = PropertyFileBuilder.builder(folder.getRoot()).build(); DatabaseTuningPropertyFileBuilder.builder(folder.getRoot()).build(); PropertyFileConfigurator configurator = new PropertyFileConfigurator(emptyPropertyFile); assertEquals( "25M", configurator .getDatabaseTuningProperties() .get(GraphDatabaseSettings.nodestore_mapped_memory_size.name())); }
/** * Initializes the test. * * @throws Exception if some errors were occurred */ @Before public void setUp() throws Exception { conf = new Configuration(true); if (format instanceof Configurable) { ((Configurable) format).setConf(conf); } mapping = new File(temp.getRoot(), "mapping").getCanonicalFile(); temporary = new File(temp.getRoot(), "temporary").getCanonicalFile(); localtemp = new File(temp.getRoot(), "localtemp").getCanonicalFile(); profile = new HadoopDataSourceProfile( conf, "testing", "testing", new Path(mapping.toURI()), new Path(temporary.toURI())); context = new OutputAttemptContext("tx", "atmpt", profile.getId(), new Counter()); }
@Test public void testFirstCopy() throws IOException { createTempFiles(); KenwoodUsb kenwoodUsb = new KenwoodUsb(tempSourceFolder.getRoot(), tempTargetFolder.getRoot()); kenwoodUsb.copy(); assertEquals( "Wrong number of sub-directories in the target directory", 4, tempTargetFolder.getRoot().list().length); assertEquals( "Wrong number of files in the target directory", MUSIC_FILE_NUMBER, FileUtils.listFiles(tempTargetFolder.getRoot(), null, true).size()); }
@Test public void canCompressTraces() throws IOException { ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmpDir.getRoot().toPath()); ChromeTraceBuildListener listener = new ChromeTraceBuildListener( projectFilesystem, new FakeClock(1409702151000000000L), new ObjectMapper(), Locale.US, TimeZone.getTimeZone("America/Los_Angeles"), /* tracesToKeep */ 1, true); listener.outputTrace(new BuildId("BUILD_ID")); Path tracePath = Paths.get("buck-out/log/traces/build.2014-09-02.16-55-51.BUILD_ID.trace.gz"); assertTrue(projectFilesystem.exists(tracePath)); BufferedReader reader = new BufferedReader( new InputStreamReader( new GZIPInputStream(projectFilesystem.newFileInputStream(tracePath)))); List<?> elements = new Gson().fromJson(reader, List.class); assertThat(elements, notNullValue()); }
@Test public void sanitizeSymlinkedWorkingDirectory() throws IOException { TemporaryFolder folder = new TemporaryFolder(); folder.create(); // Setup up a symlink to our working directory. Path symlinkedRoot = folder.getRoot().toPath().resolve("symlinked-root"); java.nio.file.Files.createSymbolicLink(symlinkedRoot, tmp.getRootPath()); // Run the build, setting PWD to the above symlink. Typically, this causes compilers to use // the symlinked directory, even though it's not the right project root. Map<String, String> envCopy = Maps.newHashMap(System.getenv()); envCopy.put("PWD", symlinkedRoot.toString()); workspace .runBuckCommandWithEnvironmentAndContext( tmp.getRootPath(), Optional.<NGContext>absent(), Optional.<BuckEventListener>absent(), Optional.of(ImmutableMap.copyOf(envCopy)), "build", "//:simple#default,static") .assertSuccess(); // Verify that we still sanitized this path correctly. Path lib = workspace.getPath("buck-out/gen/simple#default,static/libsimple.a"); String contents = Files.asByteSource(lib.toFile()).asCharSource(Charsets.ISO_8859_1).read(); assertFalse(lib.toString(), contents.contains(tmp.getRootPath().toString())); assertFalse(lib.toString(), contents.contains(symlinkedRoot.toString())); folder.delete(); }
@Test public void testCorrectSettingOfMaxSlots() throws Exception { File confFile = tmp.newFile("flink-conf.yaml"); File jarFile = tmp.newFile("test.jar"); new CliFrontend(tmp.getRoot().getAbsolutePath()); String[] params = new String[] {"-yn", "2", "-ys", "3", jarFile.getAbsolutePath()}; RunOptions runOptions = CliFrontendParser.parseRunCommand(params); FlinkYarnSessionCli yarnCLI = new TestCLI("y", "yarn"); AbstractYarnClusterDescriptor descriptor = yarnCLI.createDescriptor("", runOptions.getCommandLine()); // each task manager has 3 slots but the parallelism is 7. Thus the slots should be increased. Assert.assertEquals(3, descriptor.getTaskManagerSlots()); Assert.assertEquals(2, descriptor.getTaskManagerCount()); Configuration config = new Configuration(); CliFrontend.setJobManagerAddressInConfig(config, new InetSocketAddress("test", 9000)); ClusterClient client = new TestingYarnClusterClient(descriptor, config); Assert.assertEquals(6, client.getMaxSlots()); }
@Test public void testAnalyzeAll4() throws IOException { createClassfile("bin1", AnalyzerTest.class); final int count = analyzer.analyzeAll(folder.getRoot()); assertEquals(1, count); assertEquals(Collections.singleton("org/jacoco/core/analysis/AnalyzerTest"), classes); }
@Test public void testClose_cannotDelete() throws Exception { File file = new File(tempFolder.getRoot(), "testClose_cannotDelete") { int deleteCalls = 0; @Override public boolean delete() { if (deleteCalls == 0) { deleteCalls++; return false; } else { return super.delete(); } } }; assertTrue(file.createNewFile()); assertTrue(file.exists()); PurgeOnCloseFileInputStream purgeOnCloseFileInputStream = new PurgeOnCloseFileInputStream(file); purgeOnCloseFileInputStream.close(); assertTrue(file.exists()); assertTrue(file.setReadable(true)); assertTrue(file.setWritable(true)); assertTrue(file.delete()); }
@Test public void testGenerateUniqueOperationIds() { final File output = folder.getRoot(); final Swagger swagger = new SwaggerParser().read("src/test/resources/2_0/duplicateOperationIds.yaml"); CodegenConfig codegenConfig = new JavaClientCodegen(); codegenConfig.setOutputDir(output.getAbsolutePath()); ClientOptInput clientOptInput = new ClientOptInput().opts(new ClientOpts()).swagger(swagger).config(codegenConfig); DefaultGenerator generator = new DefaultGenerator(); generator.opts(clientOptInput); Map<String, List<CodegenOperation>> paths = generator.processPaths(swagger.getPaths()); Set<String> opIds = new HashSet<String>(); for (String path : paths.keySet()) { List<CodegenOperation> ops = paths.get(path); for (CodegenOperation op : ops) { assertFalse(opIds.contains(op.operationId)); opIds.add(op.operationId); } } }
@Test public void testExpiration() throws Exception { // negative time to make sure it is expired on the second call cache = new PersistentCache(tmp.getRoot().toPath(), -100, mock(Logger.class)); assertCacheHit(false); assertCacheHit(false); }
@Test public void testReconfigure() throws Exception { cache = new PersistentCache(tmp.getRoot().toPath(), Long.MAX_VALUE, mock(Logger.class)); assertCacheHit(false); assertCacheHit(true); File root = tmp.getRoot(); FileUtils.deleteQuietly(root); // should re-create cache directory and start using the cache cache.reconfigure(); assertThat(root).exists(); assertCacheHit(false); assertCacheHit(true); }
@AfterClass public static void teardown() throws Exception { // Unset FLINK_CONF_DIR, as it might change the behavior of other tests Map<String, String> map = new HashMap<>(System.getenv()); map.remove(CliFrontend.ENV_CONFIG_DIRECTORY); TestBaseUtils.setEnv(map); // When we are on travis, we copy the tmp files of JUnit (containing the MiniYARNCluster log // files) // to <flinkRoot>/target/flink-yarn-tests-*. // The files from there are picked up by the ./tools/travis_watchdog.sh script // to upload them to Amazon S3. if (isOnTravis()) { File target = new File("../target" + yarnConfiguration.get(TEST_CLUSTER_NAME_KEY)); if (!target.mkdirs()) { LOG.warn("Error creating dirs to {}", target); } File src = tmp.getRoot(); LOG.info( "copying the final files from {} to {}", src.getAbsolutePath(), target.getAbsolutePath()); try { FileUtils.copyDirectoryToDirectory(src, target); } catch (IOException e) { LOG.warn( "Error copying the final files from {} to {}: msg: {}", src.getAbsolutePath(), target.getAbsolutePath(), e.getMessage(), e); } } }
@Before public void setup() { String pwdFull = new File(".").getAbsolutePath(); this.pwd = pwdFull.substring(0, pwdFull.length() - 2); this.testDir = temp.getRoot().getAbsolutePath(); correctCommand = "cegma --genome " + pwd + "/assembly.fa --output " + testDir + "/cegma-output --threads 16 2>&1"; correctFullCommand = "cd " + testDir + "; CEGMATMP=" + testDir + "/temp; " + "sed 's/>/>seq_/g' " + pwd + "/assembly.fa > " + testDir + "/assembly.fa.mod.fa; " + "cegma --genome " + testDir + "/assembly.fa.mod.fa --output " + testDir + "/cegma-output --threads 16 2>&1" + "; cd " + pwd; }
@Before public void setUp() throws Exception { assumeThat(TD_API_KEY, not(isEmptyOrNullString())); projectDir = folder.getRoot().toPath().toAbsolutePath().normalize(); config = folder.newFile().toPath(); Files.write(config, asList("secrets.td.apikey = " + TD_API_KEY)); outfile = projectDir.resolve("outfile"); client = TDClient.newBuilder(false).setApiKey(TD_API_KEY).build(); database = "tmp_" + UUID.randomUUID().toString().replace('-', '_'); client.createDatabase(database); table = "test"; String insertJobId = client.submit( TDJobRequest.newPrestoQuery(database, "create table " + table + " as select 1")); TestUtils.expect(Duration.ofMinutes(5), jobSuccess(client, insertJobId)); String selectCountJobId = client.submit(TDJobRequest.newPrestoQuery(database, "select count(*) from " + table)); TestUtils.expect(Duration.ofMinutes(5), jobSuccess(client, selectCountJobId)); List<ArrayNode> result = downloadResult(selectCountJobId); assertThat(result.get(0).get(0).asInt(), is(1)); }
@Before public void setup() throws Exception { vfs = getVFS(); folder1.create(); folder2.create(); FileUtils.copyURLToFile( this.getClass().getResource("/HelloWorld.jar"), folder1.newFile("HelloWorld.jar")); FileUtils.copyURLToFile( this.getClass().getResource("/HelloWorld.jar"), folder2.newFile("HelloWorld.jar")); uri1 = new File(folder1.getRoot(), "HelloWorld.jar").toURI(); uri2 = folder2.getRoot().toURI(); }
@Test public void testCreateFileWithDirectories() throws IOException { final IMultiReportOutput output = new FileMultiReportOutput(folder.getRoot()); final OutputStream stream = output.createFile("a/b/c/test"); stream.write(1); stream.write(2); stream.write(3); stream.close(); output.close(); final InputStream actual = new FileInputStream(new File(folder.getRoot(), "a/b/c/test")); assertEquals(1, actual.read()); assertEquals(2, actual.read()); assertEquals(3, actual.read()); assertEquals(-1, actual.read()); }
@Test public void testWithoutDecode() throws IOException { File testFile = new File(folder.getRoot(), "testFileNoDecode.txt"); FileUtils.writeStringToFile(testFile, FILEDATA); List<Text> output = ShellUtil.scanFile(testFile.getAbsolutePath(), false); assertEquals(ImmutableList.of(new Text("line1"), new Text("line2")), output); }