Skip to content

Commit

Permalink
Removing dependency on local Alluxio cluster from REST API test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsimsa committed May 10, 2016
1 parent f8eba01 commit 0a3aae3
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 359 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public LocalAlluxioMaster getMaster() {
} }


/** /**
* @return the hostname of the master * @return the hostname of the cluster
*/ */
public String getMasterHostname() { public String getHostname() {
return mHostname; return mHostname;
} }


Expand Down
88 changes: 41 additions & 47 deletions tests/src/test/java/alluxio/master/AlluxioMasterRestApiTest.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import alluxio.WorkerStorageTierAssoc; import alluxio.WorkerStorageTierAssoc;
import alluxio.master.block.BlockMaster; import alluxio.master.block.BlockMaster;
import alluxio.metrics.MetricsSystem; import alluxio.metrics.MetricsSystem;
import alluxio.rest.TestCaseFactory; import alluxio.rest.TestCase;
import alluxio.underfs.UnderFileSystem; import alluxio.underfs.UnderFileSystem;
import alluxio.util.CommonUtils; import alluxio.util.CommonUtils;
import alluxio.wire.WorkerInfo; import alluxio.wire.WorkerInfo;
Expand Down Expand Up @@ -63,6 +63,8 @@ public final class AlluxioMasterRestApiTest {
private static final Map<String, String> NO_PARAMS = new HashMap<>(); private static final Map<String, String> NO_PARAMS = new HashMap<>();
private AlluxioMaster mAlluxioMaster; private AlluxioMaster mAlluxioMaster;
private BlockMaster mBlockMaster; private BlockMaster mBlockMaster;
private String mHostname;
private int mPort;


@Rule @Rule
private LocalAlluxioClusterResource mResource = new LocalAlluxioClusterResource(); private LocalAlluxioClusterResource mResource = new LocalAlluxioClusterResource();
Expand All @@ -73,6 +75,8 @@ public void before() {
Whitebox.setInternalState(AlluxioMaster.class, "sAlluxioMaster", mAlluxioMaster); Whitebox.setInternalState(AlluxioMaster.class, "sAlluxioMaster", mAlluxioMaster);
mBlockMaster = PowerMockito.mock(BlockMaster.class); mBlockMaster = PowerMockito.mock(BlockMaster.class);
Whitebox.setInternalState(mAlluxioMaster, "mBlockMaster", mBlockMaster); Whitebox.setInternalState(mAlluxioMaster, "mBlockMaster", mBlockMaster);
mHostname = mResource.get().getHostname();
mPort = mResource.get().getMaster().getWebLocalPort();
} }


private String getEndpoint(String suffix) { private String getEndpoint(String suffix) {
Expand All @@ -85,9 +89,8 @@ public void getCapacityBytesTest() throws Exception {
long capacityBytes = random.nextLong(); long capacityBytes = random.nextLong();
Mockito.doReturn(capacityBytes).when(mBlockMaster).getCapacityBytes(); Mockito.doReturn(capacityBytes).when(mBlockMaster).getCapacityBytes();


TestCaseFactory new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_CAPACITY_BYTES),
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_CAPACITY_BYTES), NO_PARAMS, "GET", capacityBytes).run();
NO_PARAMS, "GET", capacityBytes, mResource).run();
} }


@Test @Test
Expand All @@ -96,9 +99,8 @@ public void getUsedBytesTest() throws Exception {
long usedBytes = random.nextLong(); long usedBytes = random.nextLong();
Mockito.doReturn(usedBytes).when(mBlockMaster).getUsedBytes(); Mockito.doReturn(usedBytes).when(mBlockMaster).getUsedBytes();


TestCaseFactory new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_USED_BYTES),
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_USED_BYTES), NO_PARAMS, "GET", usedBytes).run();
NO_PARAMS, "GET", usedBytes, mResource).run();
} }


@Test @Test
Expand All @@ -109,9 +111,8 @@ public void getFreeBytesTest() throws Exception {
Mockito.doReturn(capacityBytes).when(mBlockMaster).getCapacityBytes(); Mockito.doReturn(capacityBytes).when(mBlockMaster).getCapacityBytes();
Mockito.doReturn(usedBytes).when(mBlockMaster).getUsedBytes(); Mockito.doReturn(usedBytes).when(mBlockMaster).getUsedBytes();


TestCaseFactory new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_FREE_BYTES),
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_FREE_BYTES), NO_PARAMS, NO_PARAMS, "GET", capacityBytes - usedBytes).run();
"GET", capacityBytes - usedBytes, mResource).run();
} }


@Test @Test
Expand All @@ -120,9 +121,8 @@ public void getWorkerCountTest() throws Exception {
int workerCount = random.nextInt(); int workerCount = random.nextInt();
Mockito.doReturn(workerCount).when(mBlockMaster).getWorkerCount(); Mockito.doReturn(workerCount).when(mBlockMaster).getWorkerCount();


TestCaseFactory new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_WORKER_COUNT),
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_WORKER_COUNT), NO_PARAMS, NO_PARAMS, "GET", workerCount).run();
"GET", workerCount, mResource).run();


Mockito.verify(mBlockMaster).getWorkerCount(); Mockito.verify(mBlockMaster).getWorkerCount();
} }
Expand All @@ -137,9 +137,9 @@ public void getWorkerInfoListTest() throws Exception {
} }
Mockito.doReturn(workerInfos).when(mBlockMaster).getWorkerInfoList(); Mockito.doReturn(workerInfos).when(mBlockMaster).getWorkerInfoList();


TestCaseFactory new TestCase(mHostname, mPort,
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_WORKER_INFO_LIST), getEndpoint(AlluxioMasterRestServiceHandler.GET_WORKER_INFO_LIST), NO_PARAMS, "GET",
NO_PARAMS, "GET", workerInfos, mResource).run(); workerInfos).run();


Mockito.verify(mBlockMaster).getWorkerInfoList(); Mockito.verify(mBlockMaster).getWorkerInfoList();
} }
Expand Down Expand Up @@ -169,9 +169,8 @@ public void getConfigurationTest() throws Exception {
Configuration configuration = mockConfiguration(); Configuration configuration = mockConfiguration();
Mockito.doReturn(properties).when(configuration).getInternalProperties(); Mockito.doReturn(properties).when(configuration).getInternalProperties();


TestCaseFactory new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_CONFIGURATION),
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_CONFIGURATION), NO_PARAMS, "GET", propertyMap).run();
NO_PARAMS, "GET", propertyMap, mResource).run();


Mockito.verify(configuration).getInternalProperties(); Mockito.verify(configuration).getInternalProperties();
} }
Expand All @@ -183,9 +182,8 @@ public void getRpcAddressTest() throws Exception {
random.nextInt(8080) + 1); random.nextInt(8080) + 1);
Mockito.doReturn(address).when(mAlluxioMaster).getMasterAddress(); Mockito.doReturn(address).when(mAlluxioMaster).getMasterAddress();


TestCaseFactory new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_RPC_ADDRESS),
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_RPC_ADDRESS), NO_PARAMS, NO_PARAMS, "GET", address.toString()).run();
"GET", address.toString(), mResource).run();


Mockito.verify(mAlluxioMaster).getMasterAddress(); Mockito.verify(mAlluxioMaster).getMasterAddress();
} }
Expand Down Expand Up @@ -224,8 +222,8 @@ public void getMetricsTest() throws Exception {
gauges.put(filesPinnedProperty, filesPinnedGauge); gauges.put(filesPinnedProperty, filesPinnedGauge);
Mockito.doReturn(gauges).when(metricRegistry).getGauges(); Mockito.doReturn(gauges).when(metricRegistry).getGauges();


TestCaseFactory.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_METRICS), new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_METRICS),
NO_PARAMS, "GET", metricsMap, mResource).run(); NO_PARAMS, "GET", metricsMap).run();


Mockito.verify(metricRegistry).getCounters(); Mockito.verify(metricRegistry).getCounters();
Mockito.verify(metricRegistry).getGauges(); Mockito.verify(metricRegistry).getGauges();
Expand All @@ -238,9 +236,8 @@ public void getStartTimeMsTest() throws Exception {
long startTime = random.nextLong(); long startTime = random.nextLong();
Mockito.doReturn(startTime).when(mAlluxioMaster).getStartTimeMs(); Mockito.doReturn(startTime).when(mAlluxioMaster).getStartTimeMs();


TestCaseFactory new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_START_TIME_MS),
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_START_TIME_MS), NO_PARAMS, "GET", startTime).run();
NO_PARAMS, "GET", startTime, mResource).run();
} }


@Test @Test
Expand All @@ -249,17 +246,16 @@ public void getUptimeMsTest() throws Exception {
long uptime = random.nextLong(); long uptime = random.nextLong();
Mockito.doReturn(uptime).when(mAlluxioMaster).getUptimeMs(); Mockito.doReturn(uptime).when(mAlluxioMaster).getUptimeMs();


TestCaseFactory new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_UPTIME_MS),
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_UPTIME_MS), NO_PARAMS, NO_PARAMS, "GET", uptime).run();
"GET", uptime, mResource).run();


Mockito.verify(mAlluxioMaster).getUptimeMs(); Mockito.verify(mAlluxioMaster).getUptimeMs();
} }


@Test @Test
public void getVersionTest() throws Exception { public void getVersionTest() throws Exception {
TestCaseFactory.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_VERSION), new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_VERSION),
NO_PARAMS, "GET", Version.VERSION, mResource).run(); NO_PARAMS, "GET", Version.VERSION).run();
} }


private UnderFileSystem mockUfs() { private UnderFileSystem mockUfs() {
Expand All @@ -281,9 +277,9 @@ public void getUfsCapacityBytesTest() throws Exception {
Mockito.doReturn(capacity).when(ufs).getSpace(Mockito.anyString(), Mockito.eq( Mockito.doReturn(capacity).when(ufs).getSpace(Mockito.anyString(), Mockito.eq(
UnderFileSystem.SpaceType.SPACE_TOTAL)); UnderFileSystem.SpaceType.SPACE_TOTAL));


TestCaseFactory new TestCase(mHostname, mPort,
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_UFS_CAPACITY_BYTES), getEndpoint(AlluxioMasterRestServiceHandler.GET_UFS_CAPACITY_BYTES), NO_PARAMS, "GET",
NO_PARAMS, "GET", capacity, mResource).run(); capacity).run();
} }


@Test @Test
Expand All @@ -295,9 +291,8 @@ public void getUfsUsedBytesTest() throws Exception {
Mockito.doReturn(usedBytes).when(ufs).getSpace(Mockito.anyString(), Mockito.eq( Mockito.doReturn(usedBytes).when(ufs).getSpace(Mockito.anyString(), Mockito.eq(
UnderFileSystem.SpaceType.SPACE_USED)); UnderFileSystem.SpaceType.SPACE_USED));


TestCaseFactory new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_UFS_USED_BYTES),
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_UFS_USED_BYTES), NO_PARAMS, "GET", usedBytes).run();
NO_PARAMS, "GET", usedBytes, mResource).run();
} }


@Test @Test
Expand All @@ -309,9 +304,8 @@ public void getUfsFreeBytesTest() throws Exception {
Mockito.doReturn(freeBytes).when(ufs).getSpace(Mockito.anyString(), Mockito.eq( Mockito.doReturn(freeBytes).when(ufs).getSpace(Mockito.anyString(), Mockito.eq(
UnderFileSystem.SpaceType.SPACE_FREE)); UnderFileSystem.SpaceType.SPACE_FREE));


TestCaseFactory new TestCase(mHostname, mPort, getEndpoint(AlluxioMasterRestServiceHandler.GET_UFS_FREE_BYTES),
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_UFS_FREE_BYTES), NO_PARAMS, "GET", freeBytes).run();
NO_PARAMS, "GET", freeBytes, mResource).run();
} }


@Test @Test
Expand All @@ -327,9 +321,9 @@ public void getCapacityBytesOnTiersTest() throws Exception {
} }
Mockito.doReturn(capacityBytesOnTiers).when(mBlockMaster).getTotalBytesOnTiers(); Mockito.doReturn(capacityBytesOnTiers).when(mBlockMaster).getTotalBytesOnTiers();


TestCaseFactory new TestCase(mHostname, mPort,
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_CAPACITY_BYTES_ON_TIERS), getEndpoint(AlluxioMasterRestServiceHandler.GET_CAPACITY_BYTES_ON_TIERS), NO_PARAMS, "GET",
NO_PARAMS, "GET", capacityBytesOnTiers, mResource).run(); capacityBytesOnTiers).run();


Mockito.verify(mBlockMaster).getTotalBytesOnTiers(); Mockito.verify(mBlockMaster).getTotalBytesOnTiers();
} }
Expand All @@ -347,9 +341,9 @@ public void getUsedBytesOnTiersTest() throws Exception {
} }
Mockito.doReturn(usedBytesOnTiers).when(mBlockMaster).getUsedBytesOnTiers(); Mockito.doReturn(usedBytesOnTiers).when(mBlockMaster).getUsedBytesOnTiers();


TestCaseFactory new TestCase(mHostname, mPort,
.newMasterTestCase(getEndpoint(AlluxioMasterRestServiceHandler.GET_USED_BYTES_ON_TIERS), getEndpoint(AlluxioMasterRestServiceHandler.GET_USED_BYTES_ON_TIERS), NO_PARAMS, "GET",
NO_PARAMS, "GET", usedBytesOnTiers, mResource).run(); usedBytesOnTiers).run();


Mockito.verify(mBlockMaster).getUsedBytesOnTiers(); Mockito.verify(mBlockMaster).getUsedBytesOnTiers();
} }
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/java/alluxio/master/PinIntegrationTest.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class PinIntegrationTest {
public final void before() throws Exception { public final void before() throws Exception {
mFileSystem = mLocalAlluxioClusterResource.get().getClient(); mFileSystem = mLocalAlluxioClusterResource.get().getClient();
mFSMasterClient = new FileSystemMasterClient( mFSMasterClient = new FileSystemMasterClient(
new InetSocketAddress(mLocalAlluxioClusterResource.get().getMasterHostname(), new InetSocketAddress(mLocalAlluxioClusterResource.get().getHostname(),
mLocalAlluxioClusterResource.get().getMasterPort()), mLocalAlluxioClusterResource.get().getMasterPort()),
mLocalAlluxioClusterResource.get().getWorkerConf()); mLocalAlluxioClusterResource.get().getWorkerConf());
mSetPinned = SetAttributeOptions.defaults().setPinned(true); mSetPinned = SetAttributeOptions.defaults().setPinned(true);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void startCluster(String bindHost) throws Exception {
private void connectServices() throws IOException, ConnectionFailedException { private void connectServices() throws IOException, ConnectionFailedException {
// connect Master RPC service // connect Master RPC service
mBlockMasterClient = mBlockMasterClient =
new BlockMasterClient(new InetSocketAddress(mLocalAlluxioCluster.getMasterHostname(), new BlockMasterClient(new InetSocketAddress(mLocalAlluxioCluster.getHostname(),
mLocalAlluxioCluster.getMasterPort()), mMasterConfiguration); mLocalAlluxioCluster.getMasterPort()), mMasterConfiguration);
mBlockMasterClient.connect(); mBlockMasterClient.connect();


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import alluxio.Constants; import alluxio.Constants;
import alluxio.LocalAlluxioClusterResource; import alluxio.LocalAlluxioClusterResource;
import alluxio.master.AlluxioMaster; import alluxio.master.AlluxioMaster;
import alluxio.rest.TestCaseFactory; import alluxio.rest.TestCase;
import alluxio.wire.BlockInfo; import alluxio.wire.BlockInfo;
import alluxio.wire.BlockInfoTest; import alluxio.wire.BlockInfoTest;


Expand All @@ -41,6 +41,8 @@
public class BlockMasterClientRestApiTest { public class BlockMasterClientRestApiTest {
private static final Map<String, String> NO_PARAMS = new HashMap<>(); private static final Map<String, String> NO_PARAMS = new HashMap<>();
private BlockMaster mBlockMaster; private BlockMaster mBlockMaster;
private String mHostname;
private int mPort;


@Rule @Rule
private LocalAlluxioClusterResource mResource = new LocalAlluxioClusterResource(); private LocalAlluxioClusterResource mResource = new LocalAlluxioClusterResource();
Expand All @@ -53,6 +55,8 @@ public void before() throws Exception {
BlockMaster blockMaster = Whitebox.getInternalState(alluxioMaster, "mBlockMaster"); BlockMaster blockMaster = Whitebox.getInternalState(alluxioMaster, "mBlockMaster");
blockMaster.stop(); blockMaster.stop();
Whitebox.setInternalState(alluxioMaster, "mBlockMaster", mBlockMaster); Whitebox.setInternalState(alluxioMaster, "mBlockMaster", mBlockMaster);
mHostname = mResource.get().getHostname();
mPort = mResource.get().getMaster().getWebLocalPort();
} }


private String getEndpoint(String suffix) { private String getEndpoint(String suffix) {
Expand All @@ -61,16 +65,14 @@ private String getEndpoint(String suffix) {


@Test @Test
public void serviceNameTest() throws Exception { public void serviceNameTest() throws Exception {
TestCaseFactory new TestCase(mHostname, mPort, getEndpoint(BlockMasterClientRestServiceHandler.SERVICE_NAME),
.newMasterTestCase(getEndpoint(BlockMasterClientRestServiceHandler.SERVICE_NAME), NO_PARAMS, NO_PARAMS, "GET", Constants.BLOCK_MASTER_CLIENT_SERVICE_NAME).run();
"GET", Constants.BLOCK_MASTER_CLIENT_SERVICE_NAME, mResource).run();
} }


@Test @Test
public void serviceVersionTest() throws Exception { public void serviceVersionTest() throws Exception {
TestCaseFactory new TestCase(mHostname, mPort, getEndpoint(BlockMasterClientRestServiceHandler.SERVICE_VERSION),
.newMasterTestCase(getEndpoint(BlockMasterClientRestServiceHandler.SERVICE_VERSION), NO_PARAMS, "GET", Constants.BLOCK_MASTER_CLIENT_SERVICE_VERSION).run();
NO_PARAMS, "GET", Constants.BLOCK_MASTER_CLIENT_SERVICE_VERSION, mResource).run();
} }


@Test @Test
Expand All @@ -81,9 +83,8 @@ public void getBlockInfoTest() throws Exception {
BlockInfo blockInfo = BlockInfoTest.createRandom(); BlockInfo blockInfo = BlockInfoTest.createRandom();
Mockito.doReturn(blockInfo).when(mBlockMaster).getBlockInfo(Mockito.anyLong()); Mockito.doReturn(blockInfo).when(mBlockMaster).getBlockInfo(Mockito.anyLong());


TestCaseFactory new TestCase(mHostname, mPort, getEndpoint(BlockMasterClientRestServiceHandler.GET_BLOCK_INFO),
.newMasterTestCase(getEndpoint(BlockMasterClientRestServiceHandler.GET_BLOCK_INFO), params, params, "GET", blockInfo).run();
"GET", blockInfo, mResource).run();


Mockito.verify(mBlockMaster).getBlockInfo(Mockito.anyLong()); Mockito.verify(mBlockMaster).getBlockInfo(Mockito.anyLong());
} }
Expand Down
Loading

0 comments on commit 0a3aae3

Please sign in to comment.