Skip to content

Commit

Permalink
Revert "reuse cluster for TFsShellTest and made each test isolated"
Browse files Browse the repository at this point in the history
  • Loading branch information
haoyuan committed Dec 23, 2014
1 parent bf829b0 commit 20f9217
Show file tree
Hide file tree
Showing 7 changed files with 413 additions and 525 deletions.
9 changes: 0 additions & 9 deletions core/src/test/java/tachyon/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,4 @@ 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: 32 additions & 41 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.AfterClass;
import org.junit.After;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand All @@ -36,39 +36,38 @@ public class FileInStreamTest {
private static final int MEAN = (MIN_LEN + MAX_LEN) / 2;
private static final int DELTA = 33;

private static LocalTachyonCluster CLUSTER = null;
private static TachyonFS TFS = null;
private LocalTachyonCluster mLocalTachyonCluster = null;
private TachyonFS mTfs = null;

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

@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));
CLUSTER = new LocalTachyonCluster(10000);
CLUSTER.start();
TFS = CLUSTER.getClient();
}

@AfterClass
public static final void after() throws Exception {
CLUSTER.stop();
@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 {
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();
}

/**
* 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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = TFS.getFile(fileId);
TachyonFile file = mTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
Assert.assertTrue(is instanceof FileInStream);
Expand Down Expand Up @@ -108,12 +107,11 @@ 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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = TFS.getFile(fileId);
TachyonFile file = mTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
Assert.assertTrue(is instanceof FileInStream);
Expand All @@ -137,12 +135,11 @@ 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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = TFS.getFile(fileId);
TachyonFile file = mTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
Assert.assertTrue(is instanceof FileInStream);
Expand All @@ -166,12 +163,11 @@ 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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = TFS.getFile(fileId);
TachyonFile file = mTfs.getFile(fileId);
InStream is =
(k < MEAN ? file.getInStream(ReadType.CACHE) : file.getInStream(ReadType.NO_CACHE));
Assert.assertTrue(is instanceof FileInStream);
Expand All @@ -198,12 +194,11 @@ 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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

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

Expand All @@ -230,13 +225,11 @@ 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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

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

Expand All @@ -253,12 +246,11 @@ 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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

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

Expand All @@ -279,12 +271,11 @@ 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(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

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

import com.google.common.collect.ImmutableSet;
import org.junit.AfterClass;
import org.junit.After;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand All @@ -37,39 +36,41 @@ public class LocalBlockInStreamTest {
private static final int MAX_LEN = 255;
private static final int DELTA = 33;

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);
private LocalTachyonCluster mLocalTachyonCluster = null;
private TachyonFS mTfs = null;
private Set<WriteType> mWriteCacheType;

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

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

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

mWriteCacheType = new HashSet<WriteType>();
mWriteCacheType.add(WriteType.MUST_CACHE);
mWriteCacheType.add(WriteType.CACHE_THROUGH);
}

/**
* 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 : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = TFS.getFile(fileId);
TachyonFile file = mTfs.getFile(fileId);
InStream is = file.getInStream(ReadType.NO_CACHE);
if (k == 0) {
Assert.assertTrue(is instanceof EmptyBlockInStream);
Expand Down Expand Up @@ -118,12 +119,11 @@ 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 : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = TFS.getFile(fileId);
TachyonFile file = mTfs.getFile(fileId);
InStream is = file.getInStream(ReadType.NO_CACHE);
if (k == 0) {
Assert.assertTrue(is instanceof EmptyBlockInStream);
Expand Down Expand Up @@ -156,12 +156,11 @@ 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 : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = TFS.getFile(fileId);
TachyonFile file = mTfs.getFile(fileId);
InStream is = file.getInStream(ReadType.NO_CACHE);
if (k == 0) {
Assert.assertTrue(is instanceof EmptyBlockInStream);
Expand Down Expand Up @@ -197,12 +196,11 @@ 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 : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = TFS.getFile(fileId);
TachyonFile file = mTfs.getFile(fileId);
InStream is = file.getInStream(ReadType.NO_CACHE);
if (k == 0) {
Assert.assertTrue(is instanceof EmptyBlockInStream);
Expand Down Expand Up @@ -233,13 +231,11 @@ 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 : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = TFS.getFile(fileId);
TachyonFile file = mTfs.getFile(fileId);
InStream is = file.getInStream(ReadType.NO_CACHE);
if (k == 0) {
Assert.assertTrue(is instanceof EmptyBlockInStream);
Expand All @@ -260,12 +256,11 @@ 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 : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = TFS.getFile(fileId);
TachyonFile file = mTfs.getFile(fileId);
InStream is = file.getInStream(ReadType.NO_CACHE);
if (k == 0) {
Assert.assertTrue(is instanceof EmptyBlockInStream);
Expand All @@ -289,12 +284,11 @@ 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 : WRITE_TYPES) {
int fileId = TestUtils.createByteFile(TFS, path + "/root/testFile_" + k + "_" + op, op, k);
for (WriteType op : mWriteCacheType) {
int fileId = TestUtils.createByteFile(mTfs, "/root/testFile_" + k + "_" + op, op, k);

TachyonFile file = TFS.getFile(fileId);
TachyonFile file = mTfs.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 20f9217

Please sign in to comment.