Skip to content

Commit

Permalink
adding a rudimentary integration test that specifies localhost as the…
Browse files Browse the repository at this point in the history
… server to write.
  • Loading branch information
yuzhu committed Sep 19, 2015
1 parent ed6f7cc commit 5c387a9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
21 changes: 10 additions & 11 deletions clients/unshaded/src/main/java/tachyon/client/ClientOptions.java
Expand Up @@ -17,7 +17,6 @@


import tachyon.Constants; import tachyon.Constants;
import tachyon.conf.TachyonConf; import tachyon.conf.TachyonConf;
import tachyon.thrift.NetAddress;


/** /**
* Represents the set of operation specific configuration options a user can pass into a Tachyon * Represents the set of operation specific configuration options a user can pass into a Tachyon
Expand All @@ -36,7 +35,7 @@ public static class Builder {
/** How this operation should interact with the under storage */ /** How this operation should interact with the under storage */
private UnderStorageType mUnderStorageType; private UnderStorageType mUnderStorageType;
/** Worker location to write data, if not possible, the operation will fail */ /** Worker location to write data, if not possible, the operation will fail */
private NetAddress mLocation; private String mHostname;


/** /**
* @param conf Tachyon configuration * @param conf Tachyon configuration
Expand All @@ -47,15 +46,15 @@ public Builder(TachyonConf conf) {
conf.getEnum(Constants.USER_DEFAULT_TACHYON_STORAGE_TYPE, TachyonStorageType.class); conf.getEnum(Constants.USER_DEFAULT_TACHYON_STORAGE_TYPE, TachyonStorageType.class);
mUnderStorageType = mUnderStorageType =
conf.getEnum(Constants.USER_DEFAULT_UNDER_STORAGE_TYPE, UnderStorageType.class); conf.getEnum(Constants.USER_DEFAULT_UNDER_STORAGE_TYPE, UnderStorageType.class);
mLocation = null; mHostname = null;
} }


/** /**
* @param location the location to use * @param hostname the hostname to use
* @return the builder * @return the builder
*/ */
public Builder setLocation(NetAddress location) { public Builder setLocation(String hostname) {
mLocation = location; mHostname = hostname;
return this; return this;
} }


Expand Down Expand Up @@ -111,7 +110,7 @@ public ClientOptions build() {
private final long mBlockSize; private final long mBlockSize;
private final TachyonStorageType mTachyonStorageType; private final TachyonStorageType mTachyonStorageType;
private final UnderStorageType mUnderStorageType; private final UnderStorageType mUnderStorageType;
private final NetAddress mLocation; private final String mHostname;


/** /**
* @return the default <code>ClientOptions</code> * @return the default <code>ClientOptions</code>
Expand All @@ -124,7 +123,7 @@ private ClientOptions(ClientOptions.Builder builder) {
mBlockSize = builder.mBlockSize; mBlockSize = builder.mBlockSize;
mTachyonStorageType = builder.mTachyonStorageType; mTachyonStorageType = builder.mTachyonStorageType;
mUnderStorageType = builder.mUnderStorageType; mUnderStorageType = builder.mUnderStorageType;
mLocation = builder.mLocation; mHostname = builder.mHostname;
} }


/** /**
Expand All @@ -149,9 +148,9 @@ public UnderStorageType getUnderStorageType() {
} }


/** /**
* @return the location * @return the Hostname
*/ */
public NetAddress getLocation() { public String getHostname() {
return mLocation; return mHostname;
} }
} }
Expand Up @@ -31,7 +31,6 @@
import tachyon.client.UnderStorageType; import tachyon.client.UnderStorageType;
import tachyon.client.block.BlockStoreContext; import tachyon.client.block.BlockStoreContext;
import tachyon.client.block.BufferedBlockOutStream; import tachyon.client.block.BufferedBlockOutStream;
import tachyon.thrift.NetAddress;
import tachyon.underfs.UnderFileSystem; import tachyon.underfs.UnderFileSystem;
import tachyon.util.io.PathUtils; import tachyon.util.io.PathUtils;
import tachyon.worker.WorkerClient; import tachyon.worker.WorkerClient;
Expand All @@ -56,7 +55,7 @@ public final class FileOutStream extends OutputStream implements Cancelable {


private boolean mCanceled; private boolean mCanceled;
private boolean mClosed; private boolean mClosed;
private NetAddress mLocation; private String mHostname;
private boolean mShouldCacheCurrentBlock; private boolean mShouldCacheCurrentBlock;
private BufferedBlockOutStream mCurrentBlockOutStream; private BufferedBlockOutStream mCurrentBlockOutStream;
private List<BufferedBlockOutStream> mPreviousBlockOutStreams; private List<BufferedBlockOutStream> mPreviousBlockOutStreams;
Expand Down Expand Up @@ -90,7 +89,7 @@ public FileOutStream(long fileId, ClientOptions options) throws IOException {
} }
mClosed = false; mClosed = false;
mCanceled = false; mCanceled = false;
mLocation = options.getLocation(); mHostname = options.getHostname();
mShouldCacheCurrentBlock = mTachyonStorageType.isStore(); mShouldCacheCurrentBlock = mTachyonStorageType.isStore();
} }


Expand Down Expand Up @@ -231,12 +230,8 @@ private void getNextBlock() throws IOException {
} }


if (mTachyonStorageType.isStore()) { if (mTachyonStorageType.isStore()) {
String hostname = null;
if (null != mLocation) {
hostname = mLocation.getHost();
}
mCurrentBlockOutStream = mCurrentBlockOutStream =
mContext.getTachyonBlockStore().getOutStream(getNextBlockId(), mBlockSize, hostname); mContext.getTachyonBlockStore().getOutStream(getNextBlockId(), mBlockSize, mHostname);
mShouldCacheCurrentBlock = true; mShouldCacheCurrentBlock = true;
} }
} }
Expand Down
Expand Up @@ -43,6 +43,7 @@
import tachyon.underfs.UnderFileSystemCluster; import tachyon.underfs.UnderFileSystemCluster;
import tachyon.util.io.BufferUtils; import tachyon.util.io.BufferUtils;
import tachyon.util.io.PathUtils; import tachyon.util.io.PathUtils;
import tachyon.util.network.NetworkAddressUtils;
import tachyon.worker.WorkerContext; import tachyon.worker.WorkerContext;


/** /**
Expand All @@ -61,6 +62,7 @@ public class FileOutStreamIntegrationTest {
private static ClientOptions sWriteBoth; private static ClientOptions sWriteBoth;
private static ClientOptions sWriteTachyon; private static ClientOptions sWriteTachyon;
private static ClientOptions sWriteUnderStore; private static ClientOptions sWriteUnderStore;
private static ClientOptions sWriteLocal;


private TachyonFileSystem mTfs = null; private TachyonFileSystem mTfs = null;
private TachyonConf mMasterTachyonConf; private TachyonConf mMasterTachyonConf;
Expand Down Expand Up @@ -105,6 +107,10 @@ public final void before() throws Exception {
sWriteUnderStore = sWriteUnderStore =
new ClientOptions.Builder(mMasterTachyonConf).setStorageTypes(TachyonStorageType new ClientOptions.Builder(mMasterTachyonConf).setStorageTypes(TachyonStorageType
.NO_STORE, UnderStorageType.PERSIST).setBlockSize(BLOCK_SIZE_BYTES).build(); .NO_STORE, UnderStorageType.PERSIST).setBlockSize(BLOCK_SIZE_BYTES).build();
sWriteLocal =
new ClientOptions.Builder(mMasterTachyonConf).setStorageTypes(TachyonStorageType.STORE,
UnderStorageType.PERSIST).setBlockSize(BLOCK_SIZE_BYTES)
.setLocation(NetworkAddressUtils.getLocalHostName(ClientContext.getConf())).build();
} }


@BeforeClass @BeforeClass
Expand Down Expand Up @@ -218,6 +224,23 @@ private void writeTest3Util(TachyonURI filePath, ClientOptions op, int len) thro
checkWrite(filePath, op.getUnderStorageType(), len, len / 2 * 2); checkWrite(filePath, op.getUnderStorageType(), len, len / 2 * 2);
} }


/**
* Test writing to a file and specify the location to be localhost.
*
* @throws IOException
* @throws InterruptedException
*/
@Test
public void writeSpecifyLocalTest() throws IOException, InterruptedException {
TachyonURI filePath = new TachyonURI(PathUtils.uniqPath());
int len = 2;
FileOutStream os = mTfs.getOutStream(filePath, sWriteLocal);
os.write((byte) 0);
os.write((byte) 1);
os.close();
checkWrite(filePath, sWriteLocal.getUnderStorageType(), len, len);
}

/** /**
* Test writing to a file for longer than HEARTBEAT_INTERVAL_MS to make sure the sessionId doesn't * Test writing to a file for longer than HEARTBEAT_INTERVAL_MS to make sure the sessionId doesn't
* change. Tracks [TACHYON-171]. * change. Tracks [TACHYON-171].
Expand Down

0 comments on commit 5c387a9

Please sign in to comment.