Skip to content

Commit

Permalink
Speed up client unit tests P1.
Browse files Browse the repository at this point in the history
  • Loading branch information
haoyuan committed Dec 24, 2014
1 parent 7b86436 commit 360aff0
Show file tree
Hide file tree
Showing 6 changed files with 499 additions and 401 deletions.
11 changes: 10 additions & 1 deletion core/src/test/java/tachyon/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static int createByteFile(TachyonFS tfs, String fileName, WriteType op, i
throws IOException {
return createByteFile(tfs, new TachyonURI(fileName), op, len);
}

/**
* Create a simple file with <code>len</code> bytes.
*
Expand Down Expand Up @@ -148,4 +148,13 @@ public static List<String> listFiles(TachyonFS tfs, String path) throws IOExcept

return res;
}

/**
* Creates a unique path based off the caller.
*/
public static final String uniqPath() {
StackTraceElement caller = new Throwable().getStackTrace()[1];
long time = System.nanoTime();
return "/" + caller.getClassName() + "/" + caller.getMethodName() + "/" + time;
}
}
44 changes: 24 additions & 20 deletions core/src/test/java/tachyon/client/BlockInStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import java.io.IOException;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import tachyon.TestUtils;
Expand All @@ -33,33 +33,34 @@ public class BlockInStreamTest {
private static final int MEAN = (MIN_LEN + MAX_LEN) / 2;
private static final int DELTA = 33;

private LocalTachyonCluster mLocalTachyonCluster = null;
private TachyonFS mTfs = null;
private static LocalTachyonCluster sLocalTachyonCluster = null;
private static TachyonFS sTfs = null;

@After
public final void after() throws Exception {
mLocalTachyonCluster.stop();
@AfterClass
public static final void afterClass() throws Exception {
sLocalTachyonCluster.stop();
System.clearProperty("tachyon.user.quota.unit.bytes");
}

@Before
public final void before() throws IOException {
@BeforeClass
public static final void beforeClass() throws IOException {
System.setProperty("tachyon.user.quota.unit.bytes", "1000");
mLocalTachyonCluster = new LocalTachyonCluster(10000);
mLocalTachyonCluster.start();
mTfs = mLocalTachyonCluster.getClient();
sLocalTachyonCluster = new LocalTachyonCluster(10000);
sLocalTachyonCluster.start();
sTfs = sLocalTachyonCluster.getClient();
}

/**
* Test <code>void read()</code>.
*/
@Test
public void readTest1() throws IOException {
String uniqPath = TestUtils.uniqPath();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : WriteType.values()) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(sTfs, uniqPath + "/file_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = sTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
if (k == 0) {
Expand Down Expand Up @@ -107,11 +108,12 @@ public void readTest1() throws IOException {
*/
@Test
public void readTest2() throws IOException {
String uniqPath = TestUtils.uniqPath();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : WriteType.values()) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(sTfs, uniqPath + "/file_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = sTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
if (k == 0) {
Expand Down Expand Up @@ -143,11 +145,12 @@ public void readTest2() throws IOException {
*/
@Test
public void readTest3() throws IOException {
String uniqPath = TestUtils.uniqPath();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : WriteType.values()) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(sTfs, uniqPath + "/file_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = sTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
if (k == 0) {
Expand Down Expand Up @@ -179,11 +182,12 @@ public void readTest3() throws IOException {
*/
@Test
public void skipTest() throws IOException {
String uniqPath = TestUtils.uniqPath();
for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
for (WriteType op : WriteType.values()) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(sTfs, uniqPath + "/file_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = sTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
Assert.assertTrue(is instanceof BlockInStream);
Expand Down
65 changes: 36 additions & 29 deletions core/src/test/java/tachyon/client/FileInStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import java.io.IOException;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand All @@ -36,38 +36,39 @@ public class FileInStreamTest {
private static final int MEAN = (MIN_LEN + MAX_LEN) / 2;
private static final int DELTA = 33;

private LocalTachyonCluster mLocalTachyonCluster = null;
private TachyonFS mTfs = null;
private static LocalTachyonCluster sLocalTachyonCluster = null;
private static TachyonFS sTfs = null;

@Rule
public ExpectedException thrown = ExpectedException.none();

@After
public final void after() throws Exception {
mLocalTachyonCluster.stop();
@AfterClass
public static final void afterClass() throws Exception {
sLocalTachyonCluster.stop();
System.clearProperty("tachyon.user.quota.unit.bytes");
System.clearProperty("tachyon.user.default.block.size.byte");
}

@Before
public final void before() throws IOException {
@BeforeClass
public static final void beforeClass() throws IOException {
System.setProperty("tachyon.user.quota.unit.bytes", "1000");
System.setProperty("tachyon.user.default.block.size.byte", String.valueOf(BLOCK_SIZE));
mLocalTachyonCluster = new LocalTachyonCluster(10000);
mLocalTachyonCluster.start();
mTfs = mLocalTachyonCluster.getClient();
sLocalTachyonCluster = new LocalTachyonCluster(10000);
sLocalTachyonCluster.start();
sTfs = sLocalTachyonCluster.getClient();
}

/**
* Test <code>void read()</code>.
*/
@Test
public void readTest1() throws IOException {
String uniqPath = TestUtils.uniqPath();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : WriteType.values()) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(sTfs, uniqPath + "/file_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = sTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
Assert.assertTrue(is instanceof FileInStream);
Expand Down Expand Up @@ -107,11 +108,12 @@ public void readTest1() throws IOException {
*/
@Test
public void readTest2() throws IOException {
String uniqPath = TestUtils.uniqPath();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : WriteType.values()) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(sTfs, uniqPath + "/file_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = sTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
Assert.assertTrue(is instanceof FileInStream);
Expand All @@ -135,11 +137,12 @@ public void readTest2() throws IOException {
*/
@Test
public void readTest3() throws IOException {
String uniqPath = TestUtils.uniqPath();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : WriteType.values()) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(sTfs, uniqPath + "/file_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = sTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
Assert.assertTrue(is instanceof FileInStream);
Expand All @@ -163,11 +166,12 @@ public void readTest3() throws IOException {
*/
@Test
public void readEndOfFileTest() throws IOException {
String uniqPath = TestUtils.uniqPath();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : WriteType.values()) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(sTfs, uniqPath + "/file_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = sTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
Assert.assertTrue(is instanceof FileInStream);
Expand All @@ -194,11 +198,12 @@ public void readEndOfFileTest() throws IOException {
*/
@Test
public void seekExceptionTest1() throws IOException {
String uniqPath = TestUtils.uniqPath();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : WriteType.values()) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(sTfs, uniqPath + "/file_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = sTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));

Expand All @@ -224,12 +229,12 @@ public void seekExceptionTest1() throws IOException {
public void seekExceptionTest2() throws IOException {
thrown.expect(IOException.class);
thrown.expectMessage("Seek position is past EOF");

String uniqPath = TestUtils.uniqPath();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : WriteType.values()) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(sTfs, uniqPath + "/file_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = sTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));

Expand All @@ -246,11 +251,12 @@ public void seekExceptionTest2() throws IOException {
*/
@Test
public void seekTest() throws IOException {
String uniqPath = TestUtils.uniqPath();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : WriteType.values()) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(sTfs, uniqPath + "/file_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = sTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));

Expand All @@ -271,11 +277,12 @@ public void seekTest() throws IOException {
*/
@Test
public void skipTest() throws IOException {
String uniqPath = TestUtils.uniqPath();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : WriteType.values()) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(sTfs, uniqPath + "/file_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = sTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
Assert.assertTrue(is instanceof FileInStream);
Expand Down
Loading

0 comments on commit 360aff0

Please sign in to comment.