private File writeYarnPropertiesFile(String contents) throws IOException { File tmpFolder = tmp.newFolder(); String currentUser = System.getProperty("user.name"); // copy .yarn-properties-<username> File testPropertiesFile = new File(tmpFolder, ".yarn-properties-" + currentUser); Files.write(testPropertiesFile.toPath(), contents.getBytes(), StandardOpenOption.CREATE); return tmpFolder.getAbsoluteFile(); } }
@Test public void testIndexDrd() throws Exception { File dir = tempFolder.newFolder(); FileUtils.writeByteArrayToFile(new File(dir, "index.drd"), new byte[]{(byte) 0x8}); Assert.assertEquals(8, SegmentUtils.getVersionFromDir(dir)); }
@Test public void testDecompressZip() throws IOException { final File tmpDir = temporaryFolder.newFolder("testDecompressZip"); final File zipFile = new File(tmpDir, testFile.getName() + ".zip"); Assert.assertFalse(zipFile.exists()); try (final ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile))) { out.putNextEntry(new ZipEntry("cool.file")); ByteStreams.copy(new FileInputStream(testFile), out); out.closeEntry(); } try (final InputStream inputStream = CompressionUtils.decompress(new FileInputStream(zipFile), zipFile.getName())) { assertGoodDataStream(inputStream); } }
@Before public void setUp() throws IOException { testDir = temporaryFolder.newFolder("testDir"); testFile = new File(testDir, "test.dat"); try (OutputStream outputStream = new FileOutputStream(testFile)) { outputStream.write(StringUtils.toUtf8(content)); } Assert.assertTrue(testFile.getParentFile().equals(testDir)); }
public static File writeYarnSiteConfigXML(Configuration yarnConf) throws IOException { tmp.create(); File yarnSiteXML = new File(tmp.newFolder().getAbsolutePath() + "/yarn-site.xml"); try (FileWriter writer = new FileWriter(yarnSiteXML)) { yarnConf.writeXml(writer); writer.flush(); } return yarnSiteXML; }
@Test public void testTopSpeedWindowingExampleITCase() throws Exception { File inputFile = temporaryFolder.newFile(); FileUtils.writeFileUtf8(inputFile, TopSpeedWindowingExampleData.CAR_DATA); final String resultPath = temporaryFolder.newFolder().toURI().toString(); TopSpeedWindowing.main(new String[] { "--input", inputFile.getAbsolutePath(), "--output", resultPath}); compareResultsByLinesInMemory(TopSpeedWindowingExampleData.TOP_SPEEDS, resultPath); } }
@Before public void setUp() throws IOException { mapper.registerSubtypes(MapLookupExtractorFactory.class); basePersistDirectory = temporaryFolder.newFolder().getAbsolutePath(); lookupSnapshotTaker = new LookupSnapshotTaker(mapper, basePersistDirectory); }
@Test(timeout = 60_000L) public void testStopBeforeStarting() throws Exception { final File directory = tempFolder.newFolder(); final RealtimeIndexTask task1 = makeRealtimeTask(null); final TestIndexerMetadataStorageCoordinator mdc = new TestIndexerMetadataStorageCoordinator(); final TaskToolbox taskToolbox = makeToolbox(task1, mdc, directory); task1.stopGracefully(taskToolbox.getConfig()); final ListenableFuture<TaskStatus> statusFuture = runTask(task1, taskToolbox); // Wait for the task to finish. final TaskStatus taskStatus = statusFuture.get(); Assert.assertEquals(TaskState.SUCCESS, taskStatus.getStatusCode()); }
@Test public void testGetExtensionFilesToLoad_non_exist_extensions_dir() throws IOException { final File tmpDir = temporaryFolder.newFolder(); Assert.assertTrue("could not create missing folder", !tmpDir.exists() || tmpDir.delete()); Assert.assertArrayEquals( "Non-exist root extensionsDir should return an empty array of File", new File[]{}, Initialization.getExtensionFilesToLoad(new ExtensionsConfig() { @Override public String getDirectory() { return tmpDir.getAbsolutePath(); } }) ); }
@Test public void shouldExtractJars() throws Exception { File sourceFile = new File(PATH_WITH_HASHES + "test-agent.jar"); File outputTmpDir = temporaryFolder.newFolder(); Set<File> files = new HashSet<>(JarUtil.extractFilesInLibDirAndReturnFiles(sourceFile, jarEntry -> jarEntry.getName().endsWith(".class"), outputTmpDir)); Set<File> actualFiles = Files.list(outputTmpDir.toPath()).map(Path::toFile).collect(Collectors.toSet()); assertEquals(files, actualFiles); assertEquals(files.size(), 2); Set<String> fileNames = files.stream().map(File::getName).collect(Collectors.toSet()); assertEquals(fileNames, new HashSet<>(Arrays.asList("ArgPrintingMain.class", "HelloWorldStreamWriter.class"))); } }
@Before public void setUp() throws IOException { cgroupDir = temporaryFolder.newFolder(); procDir = temporaryFolder.newFolder(); TestUtils.setUpCgroups(procDir, cgroupDir); cpuacctDir = new File( cgroupDir, "cpu,cpuacct/system.slice/some.service/f12ba7e0-fa16-462e-bb9d-652ccc27f0ee" ); Assert.assertTrue((cpuacctDir.isDirectory() && cpuacctDir.exists()) || cpuacctDir.mkdirs()); TestUtils.copyResource("/cpuacct.usage_all", new File(cpuacctDir, "cpuacct.usage_all")); }
@Test public void testWithRocksDbBackendFull() throws Exception { RocksDBStateBackend fullRocksDbBackend = new RocksDBStateBackend(new MemoryStateBackend(MAX_MEM_STATE_SIZE), false); fullRocksDbBackend.setDbStoragePath(tmpFolder.newFolder().getAbsolutePath()); testProgramWithBackend(fullRocksDbBackend); }
@BeforeClass public static void createHDFS() throws Exception { final File baseDir = TMP.newFolder(); Configuration hdConf = new Configuration(); hdConf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, baseDir.getAbsolutePath()); MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(hdConf); hdfsCluster = builder.build(); org.apache.hadoop.fs.FileSystem hdfs = hdfsCluster.getFileSystem(); fs = new HadoopFileSystem(hdfs); basePath = new Path(hdfs.getUri().toString() + "/tests"); }
@Test public void testGetStatisticsMultipleFilesMultiplePathsNoCachedVersion() throws IOException { final long size1 = 2077; final long size2 = 31909; final long size3 = 10; final long totalSize123 = size1 + size2 + size3; String tempDir = TestFileUtils.createTempFileDir(temporaryFolder.newFolder(), size1, size2, size3); final long size4 = 2051; final long size5 = 31902; final long size6 = 15; final long totalSize456 = size4 + size5 + size6; String tempDir2 = TestFileUtils.createTempFileDir(temporaryFolder.newFolder(), size4, size5, size6); final MultiDummyFileInputFormat format = new MultiDummyFileInputFormat(); format.setFilePaths(tempDir, tempDir2); format.configure(new Configuration()); BaseStatistics stats = format.getStatistics(null); Assert.assertEquals("The file size from the statistics is wrong.", totalSize123 + totalSize456, stats.getTotalInputSize()); }
@Test public void testVersionBin() throws Exception { File dir = tempFolder.newFolder(); FileUtils.writeByteArrayToFile(new File(dir, "version.bin"), Ints.toByteArray(9)); Assert.assertEquals(9, SegmentUtils.getVersionFromDir(dir)); }
@Test public void testDecompressBzip2() throws IOException { final File tmpDir = temporaryFolder.newFolder("testDecompressBzip2"); final File bzFile = new File(tmpDir, testFile.getName() + ".bz2"); Assert.assertFalse(bzFile.exists()); try (final OutputStream out = new BZip2CompressorOutputStream(new FileOutputStream(bzFile))) { ByteStreams.copy(new FileInputStream(testFile), out); } try (final InputStream inputStream = CompressionUtils.decompress(new FileInputStream(bzFile), bzFile.getName())) { assertGoodDataStream(inputStream); } }