use of alluxio.client.block.RemoteBlockInStream in project alluxio by Alluxio.
the class RemoteBlockInStreamIntegrationTest method readTest5.
/**
* Tests {@link RemoteBlockInStream#read(byte[])}. Read from remote data server.
*/
@Test
public void readTest5() throws Exception {
String uniqPath = PathUtils.uniqPath();
for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + k);
FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteAlluxio, k);
long blockId = mFileSystem.getStatus(uri).getBlockIds().get(0);
BlockInfo info = AlluxioBlockStore.create().getInfo(blockId);
WorkerNetAddress workerAddr = info.getLocations().get(0).getWorkerAddress();
RemoteBlockInStream is = RemoteBlockInStream.create(info.getBlockId(), info.getLength(), workerAddr, FileSystemContext.INSTANCE, InStreamOptions.defaults());
byte[] ret = new byte[k];
int start = 0;
while (start < k) {
int read = is.read(ret);
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(start, read, ret));
start += read;
}
is.close();
Assert.assertTrue(mFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
}
}
use of alluxio.client.block.RemoteBlockInStream in project alluxio by Alluxio.
the class RemoteBlockInStreamIntegrationTest method readTest4.
/**
* Tests {@link RemoteBlockInStream#read()}. Read from remote data server.
*/
@Test
public void readTest4() throws Exception {
String uniqPath = PathUtils.uniqPath();
for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + k);
FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteAlluxio, k);
long blockId = mFileSystem.getStatus(uri).getBlockIds().get(0);
AlluxioBlockStore blockStore = AlluxioBlockStore.create();
BlockInfo info = blockStore.getInfo(blockId);
WorkerNetAddress workerAddr = info.getLocations().get(0).getWorkerAddress();
RemoteBlockInStream is = RemoteBlockInStream.create(info.getBlockId(), info.getLength(), workerAddr, FileSystemContext.INSTANCE, InStreamOptions.defaults());
byte[] ret = new byte[k];
int value = is.read();
int cnt = 0;
while (value != -1) {
Assert.assertTrue(value >= 0);
Assert.assertTrue(value < 256);
ret[cnt++] = (byte) value;
value = is.read();
}
Assert.assertEquals(cnt, k);
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
Assert.assertTrue(mFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
}
}
use of alluxio.client.block.RemoteBlockInStream in project alluxio by Alluxio.
the class RemoteBlockInStreamIntegrationTest method readTest6.
/**
* Tests {@link RemoteBlockInStream#read(byte[], int, int)}. Read from remote data server.
*/
@Test
public void readTest6() throws Exception {
String uniqPath = PathUtils.uniqPath();
for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + k);
FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteAlluxio, k);
long blockId = mFileSystem.getStatus(uri).getBlockIds().get(0);
BlockInfo info = AlluxioBlockStore.create().getInfo(blockId);
WorkerNetAddress workerAddr = info.getLocations().get(0).getWorkerAddress();
RemoteBlockInStream is = RemoteBlockInStream.create(info.getBlockId(), info.getLength(), workerAddr, FileSystemContext.INSTANCE, InStreamOptions.defaults());
byte[] ret = new byte[k / 2];
int start = 0;
while (start < k / 2) {
int read = is.read(ret, 0, (k / 2) - start);
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(start, read, ret));
start += read;
}
is.close();
Assert.assertTrue(mFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
}
}
use of alluxio.client.block.RemoteBlockInStream in project alluxio by Alluxio.
the class RemoteBlockInStreamIntegrationTest method remoteReadLock.
/**
* Tests remote read stream lock in {@link RemoteBlockInStream}.
*/
@Test
public void remoteReadLock() throws Exception {
HeartbeatScheduler.await(HeartbeatContext.WORKER_BLOCK_SYNC, 10, TimeUnit.SECONDS);
String uniqPath = PathUtils.uniqPath();
for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + k);
FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteAlluxio, k);
HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
long blockId = mFileSystem.getStatus(uri).getBlockIds().get(0);
BlockInfo info = AlluxioBlockStore.create().getInfo(blockId);
WorkerNetAddress workerAddr = info.getLocations().get(0).getWorkerAddress();
RemoteBlockInStream is = RemoteBlockInStream.create(info.getBlockId(), info.getLength(), workerAddr, FileSystemContext.INSTANCE, InStreamOptions.defaults());
Assert.assertEquals(0, is.read());
mFileSystem.delete(uri);
HeartbeatScheduler.execute(HeartbeatContext.WORKER_BLOCK_SYNC);
// The file has been deleted.
Assert.assertFalse(mFileSystem.exists(uri));
// Look! We can still read the deleted file since we have a lock!
byte[] ret = new byte[k / 2];
Assert.assertEquals(k / 2, is.read(ret, 0, k / 2));
is.close();
Assert.assertFalse(mFileSystem.exists(uri));
// Try to create an in stream again, and it should fail.
RemoteBlockInStream is2 = null;
try {
is2 = RemoteBlockInStream.create(info.getBlockId(), info.getLength(), workerAddr, FileSystemContext.INSTANCE, InStreamOptions.defaults());
} catch (IOException e) {
Assert.assertTrue(e.getCause() instanceof BlockDoesNotExistException);
} finally {
if (is2 != null) {
is2.close();
}
}
}
}
Aggregations