public static void testWrite() throws Exception { FileSystem fs = cluster.getFileSystem(); long tStart = System.currentTimeMillis(); bench.writeTest(fs); long execTime = System.currentTimeMillis() - tStart; bench.analyzeResult(fs, TestType.TEST_TYPE_WRITE, execTime); }
@Test(timeout = 6000) public void testAppend() throws Exception { FileSystem fs = cluster.getFileSystem(); long tStart = System.currentTimeMillis(); bench.appendTest(fs); long execTime = System.currentTimeMillis() - tStart; bench.analyzeResult(fs, TestType.TEST_TYPE_APPEND, execTime); }
@Test(timeout = 3000) public void testReadSkip() throws Exception { FileSystem fs = cluster.getFileSystem(); long tStart = System.currentTimeMillis(); bench.getConf().setLong("test.io.skip.size", 1); bench.randomReadTest(fs); long execTime = System.currentTimeMillis() - tStart; bench.analyzeResult(fs, TestType.TEST_TYPE_READ_SKIP, execTime); }
@Test(timeout = 3000) public void testReadBackward() throws Exception { FileSystem fs = cluster.getFileSystem(); long tStart = System.currentTimeMillis(); bench.getConf().setLong("test.io.skip.size", -DEFAULT_BUFFER_SIZE); bench.randomReadTest(fs); long execTime = System.currentTimeMillis() - tStart; bench.analyzeResult(fs, TestType.TEST_TYPE_READ_BACKWARD, execTime); }
private void analyzeResult(FileSystem fs, TestType testType, long execTime) throws IOException { analyzeResult(fs, testType, execTime, DEFAULT_RES_FILE_NAME); }
@Override // Tool public int run(String[] args) throws IOException { TestType testType = null; int bufferSize = DEFAULT_BUFFER_SIZE; long nrBytes = 1 * MEGA; int nrFiles = 1; long skipSize = 0; String resFileName = DEFAULT_RES_FILE_NAME; String compressionClass = null; boolean isSequential = false; String version = TestDFSIO.class.getSimpleName() + ".1.7"; LOG.info(version); if (args.length == 0) { System.err.println("Missing arguments."); return -1; } for (int i = 0; i < args.length; i++) { // parse command line if (args[i].startsWith("-read")) { testType = TestType.TEST_TYPE_READ; } else if (args[i].equals("-write")) { testType = TestType.TEST_TYPE_WRITE; } else if (args[i].equals("-append")) { testType = TestType.TEST_TYPE_APPEND; } else if (args[i].equals("-random")) { if (testType != TestType.TEST_TYPE_READ) return -1; testType = TestType.TEST_TYPE_READ_RANDOM; } else if (args[i].equals("-backward")) { if (testType != TestType.TEST_TYPE_READ) return -1; testType = TestType.TEST_TYPE_READ_BACKWARD; } else if (args[i].equals("-skip")) { if (testType != TestType.TEST_TYPE_READ) return -1; testType = TestType.TEST_TYPE_READ_SKIP; } else if (args[i].equals("-clean")) { testType = TestType.TEST_TYPE_CLEANUP; } else if (args[i].startsWith("-seq")) { isSequential = true; } else if (args[i].startsWith("-compression")) { compressionClass = args[++i]; } else if (args[i].equals("-nrFiles")) { nrFiles = Integer.parseInt(args[++i]); } else if (args[i].equals("-fileSize") || args[i].equals("-size")) { nrBytes = parseSize(args[++i]); } else if (args[i].equals("-skipSize")) { skipSize = parseSize(args[++i]); } else if (args[i].equals("-bufferSize")) { bufferSize = Integer.parseInt(args[++i]); } else if (args[i].equals("-resFile")) { resFileName = args[++i]; } else { System.err.println("Illegal argument: " + args[i]); return -1; } } if (testType == null) return -1; if (testType == TestType.TEST_TYPE_READ_BACKWARD) skipSize = -bufferSize; else if (testType == TestType.TEST_TYPE_READ_SKIP && skipSize == 0) skipSize = bufferSize; LOG.info("nrFiles = " + nrFiles); LOG.info("nrBytes (MB) = " + toMB(nrBytes)); LOG.info("bufferSize = " + bufferSize); if (skipSize > 0) LOG.info("skipSize = " + skipSize); LOG.info("baseDir = " + getBaseDir(config)); if (compressionClass != null) { config.set("test.io.compression.class", compressionClass); LOG.info("compressionClass = " + compressionClass); } config.setInt("test.io.file.buffer.size", bufferSize); config.setLong("test.io.skip.size", skipSize); config.setBoolean(DFSConfigKeys.DFS_SUPPORT_APPEND_KEY, true); FileSystem fs = FileSystem.get(config); if (isSequential) { long tStart = System.currentTimeMillis(); sequentialTest(fs, testType, nrBytes, nrFiles); long execTime = System.currentTimeMillis() - tStart; String resultLine = "Seq Test exec time sec: " + (float) execTime / 1000; LOG.info(resultLine); return 0; } if (testType == TestType.TEST_TYPE_CLEANUP) { cleanup(fs); return 0; } createControlFile(fs, nrBytes, nrFiles); long tStart = System.currentTimeMillis(); switch (testType) { case TEST_TYPE_WRITE: writeTest(fs); break; case TEST_TYPE_READ: readTest(fs); break; case TEST_TYPE_APPEND: appendTest(fs); break; case TEST_TYPE_READ_RANDOM: case TEST_TYPE_READ_BACKWARD: case TEST_TYPE_READ_SKIP: randomReadTest(fs); } long execTime = System.currentTimeMillis() - tStart; analyzeResult(fs, testType, execTime, resFileName); return 0; }