Skip to content

Commit

Permalink
modification on BlockHandlerLocalTest and WorkerStorageTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingfei committed Dec 22, 2014
1 parent 8e923e6 commit d44f126
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 45 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/tachyon/client/TachyonFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ synchronized void completeFile(int fid) throws IOException {
* @return the local temporary folder for the user or null if unable to allocate one.
* @throws IOException
*/
synchronized String createAndGetUserLocalTempFolder(long storageDirId) throws IOException {
public synchronized String createAndGetUserLocalTempFolder(long storageDirId) throws IOException {
String userTempFolder = mWorkerClient.getUserTempFolder();

if (StringUtils.isBlank(userTempFolder)) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/tachyon/worker/WorkerStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void run() {
storageDirIds[k] = lockBlock(Users.CHECKPOINT_USER_ID, StorageDirId.unknownId(),
blockId);
if (StorageDirId.isUnknown(storageDirIds[k])) {
throw new FileDoesNotExistException("Block doesn't exist!");
throw new IOException("Block doesn't exist!");
}
}
OutputStream os =
Expand Down
88 changes: 45 additions & 43 deletions core/src/test/java/tachyon/worker/BlockHandlerLocalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
import org.junit.Before;
import org.junit.Test;

import tachyon.TachyonURI;
import tachyon.TestUtils;
import tachyon.client.TachyonFS;
import tachyon.client.TachyonFile;
import tachyon.client.WriteType;
import tachyon.master.LocalTachyonCluster;
import tachyon.util.CommonUtils;

public class BlockHandlerLocalTest {

private LocalTachyonCluster mLocalTachyonCluster = null;
private TachyonFS mTfs = null;

@After
public final void after() throws Exception {
mLocalTachyonCluster.stop();
Expand All @@ -47,48 +48,49 @@ public final void before() throws IOException {
mTfs = mLocalTachyonCluster.getClient();
}

// @Test
// public void directByteBufferWriteTest() throws IOException {
// ByteBuffer buf = ByteBuffer.allocateDirect(100);
// buf.put(TestUtils.getIncreasingByteArray(100));
//
// int fileId = mTfs.createFile(new TachyonURI("/root/testFile"));
// long blockId = mTfs.getBlockId(fileId, 0);
// long storageDirId = mTfs.requestSpace(100);
// String localFolder = mTfs.createAndGetUserLocalTempFolder(storageDirId);
// String filename = CommonUtils.concat(localFolder, blockId);
// BlockHandler handler = BlockHandler.get(filename);
// try {
// handler.append(0, buf);
// mTfs.cacheBlock(blockId);
// TachyonFile file = mTfs.getFile(fileId);
// long fileLen = file.length();
// Assert.assertEquals(100, fileLen);
// } finally {
// handler.close();
// }
// return;
// }
//
// @Test
// public void heapByteBufferwriteTest() throws IOException {
// int fileId = mTfs.createFile(new TachyonURI("/root/testFile"));
// long blockId = mTfs.getBlockId(fileId, 0);
// String localFolder = mTfs.createAndGetUserLocalTempFolder().getPath();
// String filename = CommonUtils.concat(localFolder, blockId);
// BlockHandler handler = BlockHandler.get(filename);
// byte[] buf = TestUtils.getIncreasingByteArray(100);
// try {
// handler.append(0, ByteBuffer.wrap(buf));
// mTfs.cacheBlock(blockId);
// TachyonFile file = mTfs.getFile(fileId);
// long fileLen = file.length();
// Assert.assertEquals(100, fileLen);
// } finally {
// handler.close();
// }
// return;
// }
@Test
public void directByteBufferWriteTest() throws IOException {
ByteBuffer buf = ByteBuffer.allocateDirect(100);
buf.put(TestUtils.getIncreasingByteArray(100));

int fileId = mTfs.createFile(new TachyonURI("/root/testFile"));
long blockId = mTfs.getBlockId(fileId, 0);
long storageDirId = mTfs.requestSpace(100);
String tempFolder = mTfs.createAndGetUserLocalTempFolder(storageDirId);
String filename = CommonUtils.concat(tempFolder, blockId);
BlockHandler handler = BlockHandler.get(filename);
try {
handler.append(0, buf);
mTfs.cacheBlock(storageDirId, blockId);
TachyonFile file = mTfs.getFile(fileId);
long fileLen = file.length();
Assert.assertEquals(100, fileLen);
} finally {
handler.close();
}
return;
}

@Test
public void heapByteBufferwriteTest() throws IOException {
int fileId = mTfs.createFile(new TachyonURI("/root/testFile"));
long blockId = mTfs.getBlockId(fileId, 0);
long storageDirId = mTfs.requestSpace(100);
String tempFolder = mTfs.createAndGetUserLocalTempFolder(storageDirId);
String filename = CommonUtils.concat(tempFolder, blockId);
BlockHandler handler = BlockHandler.get(filename);
byte[] buf = TestUtils.getIncreasingByteArray(100);
try {
handler.append(0, ByteBuffer.wrap(buf));
mTfs.cacheBlock(storageDirId, blockId);
TachyonFile file = mTfs.getFile(fileId);
long fileLen = file.length();
Assert.assertEquals(100, fileLen);
} finally {
handler.close();
}
return;
}

@Test
public void readExceptionTest() throws IOException {
Expand Down

0 comments on commit d44f126

Please sign in to comment.