/** Tests {@link FileOutStream#write(byte[], int, int)}. */ @Test public void writeTest3() throws Exception { String uniqPath = PathUtils.uniqPath(); for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) { for (CreateFileOptions op : getOptionSet()) { writeTest3Util(new AlluxioURI(uniqPath + "/file_" + k + "_" + op.hashCode()), k, op); } } }
/** * Tests writing to a file for longer than HEARTBEAT_INTERVAL_MS to make sure the sessionId * doesn't change. Tracks [ALLUXIO-171]. */ @Test public void longWrite() throws Exception { AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath()); final int length = 2; FileOutStream os = mFileSystem.createFile( filePath, CreateFileOptions.defaults().setWriteType(WriteType.THROUGH)); os.write((byte) 0); Thread.sleep(Configuration.getInt(PropertyKey.USER_HEARTBEAT_INTERVAL_MS) * 2); os.write((byte) 1); os.close(); checkWrite(filePath, UnderStorageType.SYNC_PERSIST, length, length); }
/** Tests writing to a file and specify the location to be localhost. */ @Test public void writeSpecifyLocal() throws Exception { AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath()); final int length = 2; FileOutStream os = mFileSystem.createFile( filePath, CreateFileOptions.defaults() .setWriteType(WriteType.CACHE_THROUGH) .setLocationPolicy(new LocalFirstPolicy())); os.write((byte) 0); os.write((byte) 1); os.close(); checkWrite(filePath, UnderStorageType.SYNC_PERSIST, length, length); }
/** * Tests if out-of-order writes are possible. Writes could be out-of-order when the following are * both true: - a "large" write (over half the internal buffer size) follows a smaller write. - * the "large" write does not cause the internal buffer to overflow. */ @Test public void outOfOrderWrite() throws Exception { AlluxioURI filePath = new AlluxioURI(PathUtils.uniqPath()); FileOutStream os = mFileSystem.createFile( filePath, CreateFileOptions.defaults().setWriteType(WriteType.MUST_CACHE)); // Write something small, so it is written into the buffer, and not directly to the file. os.write((byte) 0); // A length greater than 0.5 * BUFFER_BYTES and less than BUFFER_BYTES. int length = (BUFFER_BYTES * 3) / 4; // Write a large amount of data (larger than BUFFER_BYTES/2, but will not overflow the buffer. os.write(BufferUtils.getIncreasingByteArray(1, length)); os.close(); checkWrite(filePath, UnderStorageType.NO_PERSIST, length + 1, length + 1); }