Skip to content

Commit

Permalink
Port MasterClientIntegrationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
cc committed Sep 2, 2015
1 parent 55a55da commit b82bf3d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 39 deletions.
Expand Up @@ -15,7 +15,6 @@


package tachyon.master.next; package tachyon.master.next;


import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
Expand All @@ -27,25 +26,21 @@
import org.junit.Test; import org.junit.Test;


import tachyon.Constants; import tachyon.Constants;
import tachyon.client.FileSystemMasterClient;
import tachyon.conf.TachyonConf; import tachyon.conf.TachyonConf;
import tachyon.master.LocalTachyonCluster;
import tachyon.master.MasterClient;
import tachyon.master.MasterInfo;
import tachyon.thrift.NoWorkerException;


/** /**
* Though its name indicates that it provides the tests for {@link tachyon.master.MasterClient}, * Though its name indicates that it provides the tests for {@link tachyon.master.MasterClient},
* this class is more like unit-testing the internal implementation of tachyon Master via a * this class is more like unit-testing the internal implementation of tachyon Master via a
* {@link tachyon.master.MasterClient}, and thus it depends on many components in tachyon.master. As a result, we * {@link tachyon.master.MasterClient}, and thus it depends on many components in tachyon.master.
* place MasterClient in tachyon-common and this test in tachyon-integration-tests. * As a result, we place MasterClient in tachyon-common and this test in tachyon-integration-tests.
* *
* <p> * <p>
* TODO: Rename this class. * TODO: Rename this class.
* *
*/ */
public class MasterClientIntegrationTest { public class MasterClientIntegrationTest {
private tachyon.master.LocalTachyonCluster mLocalTachyonCluster = null; private LocalTachyonCluster mLocalTachyonCluster = null;
private MasterInfo mMasterInfo = null;
private final ExecutorService mExecutorService = Executors.newFixedThreadPool(2); private final ExecutorService mExecutorService = Executors.newFixedThreadPool(2);
private TachyonConf mMasterTachyonConf = null; private TachyonConf mMasterTachyonConf = null;


Expand All @@ -60,45 +55,45 @@ public final void before() throws Exception {
mLocalTachyonCluster = new LocalTachyonCluster(1000, 1000, Constants.GB); mLocalTachyonCluster = new LocalTachyonCluster(1000, 1000, Constants.GB);
mLocalTachyonCluster.start(); mLocalTachyonCluster.start();
mMasterTachyonConf = mLocalTachyonCluster.getMasterTachyonConf(); mMasterTachyonConf = mLocalTachyonCluster.getMasterTachyonConf();
mMasterInfo = mLocalTachyonCluster.getMasterInfo();
} }


@Test @Test
public void openCloseTest() throws TException, IOException { public void openCloseTest() throws TException, IOException {
MasterClient masterClient = FileSystemMasterClient fsMasterClient = new FileSystemMasterClient(
new MasterClient(mMasterInfo.getMasterAddress(), mExecutorService, mMasterTachyonConf); mLocalTachyonCluster.getMaster().getAddress(), mExecutorService, mMasterTachyonConf);
Assert.assertFalse(masterClient.isConnected()); Assert.assertFalse(fsMasterClient.isConnected());
masterClient.connect(); fsMasterClient.connect();
Assert.assertTrue(masterClient.isConnected()); Assert.assertTrue(fsMasterClient.isConnected());
masterClient.user_createFile("/file", "", Constants.DEFAULT_BLOCK_SIZE_BYTE, true); fsMasterClient.createFile("/file", Constants.DEFAULT_BLOCK_SIZE_BYTE, true);
Assert.assertTrue(masterClient.getFileStatus(-1, "/file") != null); Assert.assertTrue(fsMasterClient.getFileInfo(fsMasterClient.getFileId("/file")) != null);
masterClient.disconnect(); fsMasterClient.disconnect();
Assert.assertFalse(masterClient.isConnected()); Assert.assertFalse(fsMasterClient.isConnected());
masterClient.connect(); fsMasterClient.connect();
Assert.assertTrue(masterClient.isConnected()); Assert.assertTrue(fsMasterClient.isConnected());
Assert.assertTrue(masterClient.getFileStatus(-1, "/file") != null); Assert.assertTrue(fsMasterClient.getFileInfo(fsMasterClient.getFileId("/file")) != null);
masterClient.close(); fsMasterClient.close();
} }


@Test(timeout = 3000, expected = FileNotFoundException.class) @Test(timeout = 3000, expected = IOException.class)
public void user_getClientBlockInfoReturnsOnError() throws TException, IOException { public void user_getClientBlockInfoReturnsOnError() throws IOException {
// This test was created to show that an infinite loop occurs. // This test was created to show that an infinite loop occurs.
// The timeout will protect against this, and the change was to throw a IOException // The timeout will protect against this, and the change was to throw a IOException
// in the cases we don't want to disconnect from master // in the cases we don't want to disconnect from master
MasterClient masterClient = FileSystemMasterClient fsMasterClient = new FileSystemMasterClient(
new MasterClient(mMasterInfo.getMasterAddress(), mExecutorService, mMasterTachyonConf); mLocalTachyonCluster.getMaster().getAddress(), mExecutorService, mMasterTachyonConf);
masterClient.user_getClientBlockInfo(Long.MAX_VALUE); fsMasterClient.getFileInfo(Long.MAX_VALUE);
masterClient.close(); fsMasterClient.close();
} }


@Test(timeout = 3000, expected = NoWorkerException.class) // TODO: Cannot find counterpart for {@link MasterClient#user_getWorker} in new master clients
public void user_getWorkerReturnsWhenNotLocal() throws Exception { //@Test(timeout = 3000, expected = NoWorkerException.class)
// This test was created to show that an infinite loop occurs. //public void user_getWorkerReturnsWhenNotLocal() throws Exception {
// The timeout will protect against this, and the change was to throw a IOException // // This test was created to show that an infinite loop occurs.
// in the cases we don't want to disconnect from master // // The timeout will protect against this, and the change was to throw a IOException
MasterClient masterClient = // // in the cases we don't want to disconnect from master
new MasterClient(mMasterInfo.getMasterAddress(), mExecutorService, mMasterTachyonConf); // MasterClient masterClient =
masterClient.user_getWorker(false, "host.doesnotexist.fail"); // new MasterClient(mMasterInfo.getMasterAddress(), mExecutorService, mMasterTachyonConf);
masterClient.close(); // masterClient.user_getWorker(false, "host.doesnotexist.fail");
} // masterClient.close();
//}
} }
Expand Up @@ -17,6 +17,7 @@


import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress;


import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
Expand Down Expand Up @@ -205,6 +206,13 @@ public void cleanupUnderfs() throws IOException {
System.clearProperty("tachyon.underfs.address"); System.clearProperty("tachyon.underfs.address");
} }


/**
* Get the externally resolvable address of the master (used by unit test only).
*/
public InetSocketAddress getAddress() {
return mTachyonMaster.getMasterAddress();
}

/** /**
* Get the actual bind hostname on RPC service (used by unit test only). * Get the actual bind hostname on RPC service (used by unit test only).
* *
Expand Down
7 changes: 7 additions & 0 deletions servers/src/main/java/tachyon/master/next/TachyonMaster.java
Expand Up @@ -174,6 +174,13 @@ public TachyonConf getTachyonConf() {
return mTachyonConf; return mTachyonConf;
} }


/**
* Get the externally resolvable address of this master.
*/
public InetSocketAddress getMasterAddress() {
return mMasterAddress;
}

/** /**
* Get the actual bind hostname on RPC service (used by unit test only). * Get the actual bind hostname on RPC service (used by unit test only).
*/ */
Expand Down

0 comments on commit b82bf3d

Please sign in to comment.