private void write(FileSystem alluxioClient) throws IOException, AlluxioException { FileOutStream fileOutStream = createFile(alluxioClient, mFilePath, mDeleteIfExists); long startTimeMs = CommonUtils.getCurrentMs(); try (DataOutputStream os = new DataOutputStream(fileOutStream)) { os.writeInt(mLength); for (int i = 0; i < mLength; i++) { os.writeInt(i); } } LOG.info(FormatUtils.formatTimeTakenMs(startTimeMs, "writeFile to file " + mFilePath)); }
private void writeFile(FileSystem fileSystem) throws IOException, AlluxioException { ByteBuffer buf = ByteBuffer.allocate(NUMBERS * 4); buf.order(ByteOrder.nativeOrder()); for (int k = 0; k < NUMBERS; k++) { buf.putInt(k); } LOG.debug("Writing data..."); long startTimeMs = CommonUtils.getCurrentMs(); FileOutStream os = fileSystem.createFile(mFilePath, mWriteOptions); os.write(buf.array()); os.close(); LOG.info(FormatUtils.formatTimeTakenMs(startTimeMs, "writeFile to file " + mFilePath)); }
private boolean readFile(FileSystem fileSystem) throws IOException, AlluxioException { boolean pass = true; LOG.debug("Reading data..."); final long startTimeMs = CommonUtils.getCurrentMs(); FileInStream is = fileSystem.openFile(mFilePath, mReadOptions); ByteBuffer buf = ByteBuffer.allocate((int) is.remaining()); is.read(buf.array()); buf.order(ByteOrder.nativeOrder()); for (int k = 0; k < NUMBERS; k++) { pass = pass && (buf.getInt() == k); } is.close(); LOG.info(FormatUtils.formatTimeTakenMs(startTimeMs, "readFile file " + mFilePath)); return pass; } }
private boolean read(FileSystem alluxioClient) throws IOException, AlluxioException { OpenFilePOptions options = OpenFilePOptions.newBuilder().setReadType(mReadType.toProto()).build(); boolean pass = true; long startTimeMs = CommonUtils.getCurrentMs(); try (DataInputStream input = new DataInputStream(alluxioClient.openFile(mFilePath, options))) { int length = input.readInt(); for (int i = 0; i < length; i++) { if (input.readInt() != i) { pass = false; break; } } } LOG.info(FormatUtils.formatTimeTakenMs(startTimeMs, "readFile file " + mFilePath)); return pass; } }
/** * Tests the {@link FormatUtils#formatTimeTakenMs(long, String)} method. */ @Test public void formatTimeTakenMs() { class TestCase { Pattern mExpected; String mInputMessage; public TestCase(String expectedRE, String inputMessage) { mExpected = Pattern.compile(expectedRE); mInputMessage = inputMessage; } } List<TestCase> testCases = new ArrayList<>(); testCases.add(new TestCase("^Task A took (.*) ms.$", "Task A")); testCases.add(new TestCase("^Task B took (.*) ms.$", "Task B")); long delta = 100; for (TestCase testCase : testCases) { String result = FormatUtils.formatTimeTakenMs(CommonUtils.getCurrentMs() - delta, testCase.mInputMessage); Matcher match = testCase.mExpected.matcher(result); Assert.assertTrue(match.matches()); Assert.assertTrue(delta <= Long.parseLong(match.group(1))); Assert.assertTrue(Long.parseLong(match.group(1)) <= 2 * delta); } }
private void write(FileSystem alluxioClient) throws IOException, AlluxioException { FileOutStream fileOutStream = createFile(alluxioClient, mFilePath, mDeleteIfExists); long startTimeMs = CommonUtils.getCurrentMs(); try (DataOutputStream os = new DataOutputStream(fileOutStream)) { os.writeInt(mLength); for (int i = 0; i < mLength; i++) { os.writeInt(i); } } LOG.info(FormatUtils.formatTimeTakenMs(startTimeMs, "writeFile to file " + mFilePath)); }
private void writeFile(FileSystem fileSystem) throws IOException, AlluxioException { ByteBuffer buf = ByteBuffer.allocate(NUMBERS * 4); buf.order(ByteOrder.nativeOrder()); for (int k = 0; k < NUMBERS; k++) { buf.putInt(k); } LOG.debug("Writing data..."); long startTimeMs = CommonUtils.getCurrentMs(); FileOutStream os = fileSystem.createFile(mFilePath, mWriteOptions); os.write(buf.array()); os.close(); LOG.info(FormatUtils.formatTimeTakenMs(startTimeMs, "writeFile to file " + mFilePath)); }
private boolean readFile(FileSystem fileSystem) throws IOException, AlluxioException { boolean pass = true; LOG.debug("Reading data..."); final long startTimeMs = CommonUtils.getCurrentMs(); FileInStream is = fileSystem.openFile(mFilePath, mReadOptions); ByteBuffer buf = ByteBuffer.allocate((int) is.remaining()); is.read(buf.array()); buf.order(ByteOrder.nativeOrder()); for (int k = 0; k < NUMBERS; k++) { pass = pass && (buf.getInt() == k); } is.close(); LOG.info(FormatUtils.formatTimeTakenMs(startTimeMs, "readFile file " + mFilePath)); return pass; } }
private boolean read(FileSystem alluxioClient) throws IOException, AlluxioException { OpenFileOptions options = OpenFileOptions.defaults().setReadType(mReadType); boolean pass = true; long startTimeMs = CommonUtils.getCurrentMs(); try (DataInputStream input = new DataInputStream(alluxioClient.openFile(mFilePath, options))) { int length = input.readInt(); for (int i = 0; i < length; i++) { if (input.readInt() != i) { pass = false; break; } } } LOG.info(FormatUtils.formatTimeTakenMs(startTimeMs, "readFile file " + mFilePath)); return pass; } }
/** * Creates the files for this example. */ public static void createFiles() throws AlluxioException, IOException { final long startTimeMs = CommonUtils.getCurrentMs(); for (int k = 0; k < sFiles; k++) { sFileSystem.createFile(new AlluxioURI(sFileName + (k + sBaseFileNumber))).close(); LOG.info(FormatUtils.formatTimeTakenMs(startTimeMs, "createFile")); } }