Skip to content

Commit

Permalink
Merge pull request Alluxio#570 from dcapwell/testSpeedupImprovments
Browse files Browse the repository at this point in the history
reuse cluster for TFsShellTest and made each test isolated
  • Loading branch information
haoyuan committed Dec 23, 2014
2 parents 6820214 + b55ad8a commit bf829b0
Show file tree
Hide file tree
Showing 7 changed files with 525 additions and 413 deletions.
9 changes: 9 additions & 0 deletions core/src/test/java/tachyon/TestUtils.java
Original file line number Diff line number Diff line change
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 uniqFile() {
StackTraceElement caller = new Throwable().getStackTrace()[1];
long time = System.nanoTime();
return "/" + caller.getClassName() + "/" + caller.getMethodName() + "/" + time;
}
}
73 changes: 41 additions & 32 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 CLUSTER = null;
private static TachyonFS TFS = null;

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

@After
public final void after() throws Exception {
mLocalTachyonCluster.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 before() 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();
CLUSTER = new LocalTachyonCluster(10000);
CLUSTER.start();
TFS = CLUSTER.getClient();
}

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

/**
* Test <code>void read()</code>.
*/
@Test
public void readTest1() throws IOException {
final String path = TestUtils.uniqFile();
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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = TFS.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 {
final String path = TestUtils.uniqFile();
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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = TFS.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 {
final String path = TestUtils.uniqFile();
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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = TFS.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 {
final String path = TestUtils.uniqFile();
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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = TFS.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 {
final String path = TestUtils.uniqFile();
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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

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

Expand All @@ -225,11 +230,13 @@ public void seekExceptionTest2() throws IOException {
thrown.expect(IOException.class);
thrown.expectMessage("Seek position is past EOF");

final String path = TestUtils.uniqFile();

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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

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

Expand All @@ -246,11 +253,12 @@ public void seekExceptionTest2() throws IOException {
*/
@Test
public void seekTest() throws IOException {
final String path = TestUtils.uniqFile();
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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

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

Expand All @@ -271,11 +279,12 @@ public void seekTest() throws IOException {
*/
@Test
public void skipTest() throws IOException {
final String path = TestUtils.uniqFile();
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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = TFS.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
Assert.assertTrue(is instanceof FileInStream);
Expand Down
86 changes: 46 additions & 40 deletions core/src/test/java/tachyon/client/LocalBlockInStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
import java.util.HashSet;
import java.util.Set;

import org.junit.After;
import com.google.common.collect.ImmutableSet;
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,41 +37,39 @@ public class LocalBlockInStreamTest {
private static final int MAX_LEN = 255;
private static final int DELTA = 33;

private LocalTachyonCluster mLocalTachyonCluster = null;
private TachyonFS mTfs = null;
private Set<WriteType> mWriteCacheType;
private static LocalTachyonCluster CLUSTER = null;
private static TachyonFS TFS = null;
private static final ImmutableSet<WriteType> WRITE_TYPES =
ImmutableSet.of(WriteType.MUST_CACHE, WriteType.CACHE_THROUGH);

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

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

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

mWriteCacheType = new HashSet<WriteType>();
mWriteCacheType.add(WriteType.MUST_CACHE);
mWriteCacheType.add(WriteType.CACHE_THROUGH);
@AfterClass
public static final void after() throws Exception {
CLUSTER.stop();
System.clearProperty("tachyon.user.quota.unit.bytes");
}

/**
* Test <code>void read()</code>.
*/
@Test
public void readTest1() throws IOException {
final String path = TestUtils.uniqFile();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = TFS.getFile(fileId);
InStream is = file.getInStream(ReadType.NO_CACHE);
if (k == 0) {
Assert.assertTrue(is instanceof EmptyBlockInStream);
Expand Down Expand Up @@ -119,11 +118,12 @@ public void readTest1() throws IOException {
*/
@Test
public void readTest2() throws IOException {
final String path = TestUtils.uniqFile();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = TFS.getFile(fileId);
InStream is = file.getInStream(ReadType.NO_CACHE);
if (k == 0) {
Assert.assertTrue(is instanceof EmptyBlockInStream);
Expand Down Expand Up @@ -156,11 +156,12 @@ public void readTest2() throws IOException {
*/
@Test
public void readTest3() throws IOException {
final String path = TestUtils.uniqFile();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = TFS.getFile(fileId);
InStream is = file.getInStream(ReadType.NO_CACHE);
if (k == 0) {
Assert.assertTrue(is instanceof EmptyBlockInStream);
Expand Down Expand Up @@ -196,11 +197,12 @@ public void readTest3() throws IOException {
*/
@Test
public void seekExceptionTest1() throws IOException {
final String path = TestUtils.uniqFile();
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = TFS.getFile(fileId);
InStream is = file.getInStream(ReadType.NO_CACHE);
if (k == 0) {
Assert.assertTrue(is instanceof EmptyBlockInStream);
Expand Down Expand Up @@ -231,11 +233,13 @@ public void seekExceptionTest2() throws IOException {
thrown.expect(IOException.class);
thrown.expectMessage("Seek position is past buffer limit");

final String path = TestUtils.uniqFile();

for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = TFS.getFile(fileId);
InStream is = file.getInStream(ReadType.NO_CACHE);
if (k == 0) {
Assert.assertTrue(is instanceof EmptyBlockInStream);
Expand All @@ -256,11 +260,12 @@ public void seekExceptionTest2() throws IOException {
*/
@Test
public void seekTest() throws IOException {
final String path = TestUtils.uniqFile();
for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = TFS.getFile(fileId);
InStream is = file.getInStream(ReadType.NO_CACHE);
if (k == 0) {
Assert.assertTrue(is instanceof EmptyBlockInStream);
Expand All @@ -284,11 +289,12 @@ public void seekTest() throws IOException {
*/
@Test
public void skipTest() throws IOException {
final String path = TestUtils.uniqFile();
for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = mTfs.getFile(fileId);
TachyonFile file = TFS.getFile(fileId);
InStream is = file.getInStream(ReadType.CACHE);
Assert.assertTrue(is instanceof LocalBlockInStream);
Assert.assertEquals(k / 2, is.skip(k / 2));
Expand Down
Loading

0 comments on commit bf829b0

Please sign in to comment.