You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by wl...@apache.org on 2016/07/06 01:45:11 UTC
[4/5] incubator-hawq git commit: HAWQ-891. Refine libyarn codes
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/383818c2/depends/libyarn/test/unit/TestContainerManagement.cpp
----------------------------------------------------------------------
diff --git a/depends/libyarn/test/unit/TestContainerManagement.cpp b/depends/libyarn/test/unit/TestContainerManagement.cpp
deleted file mode 100644
index ffc3219..0000000
--- a/depends/libyarn/test/unit/TestContainerManagement.cpp
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include "gtest/gtest.h"
-#include "gmock/gmock.h"
-
-#include "libyarnclient/ContainerManagement.h"
-#include "MockContainerManagementProtocol.h"
-#include "TestContainerManagementStub.h"
-
-using std::map;
-using std::string;
-using std::list;
-using namespace libyarn;
-using namespace testing;
-using namespace Mock;
-
-class MockContainerManagementStub: public TestContainerManagementStub {
-public:
- MOCK_METHOD0(getContainerManagementProtocol, ContainerManagementProtocol * ());
-};
-
-TEST(TestContainerManagement,TestStartContainer){
- ContainerManagement client;
- MockContainerManagementStub stub;
- string nmHost("localhost");
- string nmPort("8032");
- string tokenService = "";
- Yarn::Config config;
- Yarn::Internal::SessionConfig sessionConfig(config);
- Yarn::Internal::UserInfo user = Yarn::Internal::UserInfo::LocalUser();
- Yarn::Internal::RpcAuth rpcAuth(user, Yarn::Internal::AuthMethod::SIMPLE);
- MockContainerManagementProtocol *protocol =new MockContainerManagementProtocol(nmHost,nmPort,tokenService,sessionConfig,rpcAuth);
-
- StringBytesMap map;
- string key("key");
- string value("value");
- map.setKey(key);
- map.setValue(value);
- list<StringBytesMap> maps;
- maps.push_back(map);
- ContainerId containerId;
- containerId.setId(501);
- list<ContainerId> containerIds;
- containerIds.push_back(containerId);
- ContainerExceptionMap exceptionMap;
- exceptionMap.setContainerId(containerId);
- SerializedException exception;
- string message("message");
- string trace("trace");
- string className("className");
- exception.setMessage(message);
- exception.setTrace(trace);
- exception.setClassName(className);
- SerializedException cause;
- string message2("message2");
- cause.setMessage(message2);
- exception.setCause(cause);
- exceptionMap.setSerializedException(exception);
- list<ContainerExceptionMap> exceptionMaps;
- exceptionMaps.push_back(exceptionMap);
- StartContainersResponse response;
- response.setServicesMetaData(maps);
- response.setSucceededRequests(containerIds);
- response.setFailedRequests(exceptionMaps);
- EXPECT_CALL(*protocol, startContainers(_)).Times(AnyNumber()).WillOnce(Return(response));
- client.stub = &stub;
- EXPECT_CALL(stub, getContainerManagementProtocol()).Times(AnyNumber()).WillOnce(Return(protocol));
-
- Container container;
- StartContainerRequest request;
- libyarn::Token nmToken;
- StartContainerResponse ret = client.startContainer(container,request,nmToken);
- list<StringBytesMap>::iterator itMap = ret.getServicesMetaData().begin();
- //EXPECT_EQ(itMap->getKey(), "key");
- //EXPECT_EQ(itMap->getValue(), "value");
-}
-
-TEST(TestContainerManagement,TestStopContainer){
- ContainerManagement client;
- MockContainerManagementStub stub;
- string nmHost("localhost");
- string nmPort("8032");
- string tokenService = "";
- Yarn::Config config;
- Yarn::Internal::SessionConfig sessionConfig(config);
- Yarn::Internal::UserInfo user = Yarn::Internal::UserInfo::LocalUser();
- Yarn::Internal::RpcAuth rpcAuth(user, Yarn::Internal::AuthMethod::SIMPLE);
- MockContainerManagementProtocol *protocol =new MockContainerManagementProtocol(nmHost,nmPort,tokenService,sessionConfig,rpcAuth);
-
- StopContainersResponseProto stopResponseProto;
- EXPECT_CALL(*protocol, stopContainers(_)).Times(AnyNumber()).WillOnce(Return(StopContainersResponse(stopResponseProto)));
- client.stub = &stub;
- EXPECT_CALL(stub, getContainerManagementProtocol()).Times(AnyNumber()).WillOnce(Return(protocol));
-
- Container container;
- libyarn::Token nmToken;
- client.stopContainer(container,nmToken);
-}
-
-TEST(TestContainerManagement,TestGetContainerStatus){
- ContainerManagement client;
- MockContainerManagementStub stub;
- string nmHost("localhost");
- string nmPort("8032");
- string tokenService = "";
- Yarn::Config config;
- Yarn::Internal::SessionConfig sessionConfig(config);
- Yarn::Internal::UserInfo user = Yarn::Internal::UserInfo::LocalUser();
- Yarn::Internal::RpcAuth rpcAuth(user, Yarn::Internal::AuthMethod::SIMPLE);
- MockContainerManagementProtocol *protocol =new MockContainerManagementProtocol(nmHost,nmPort,tokenService,sessionConfig,rpcAuth);
-
- GetContainerStatusesResponse getResponse;
- ContainerId containerId;
- containerId.setId(501);
- ContainerStatus status;
- status.setContainerId(containerId);
- list<ContainerStatus> statuses;
- statuses.push_back(status);
- getResponse.setContainerStatuses(statuses);
- EXPECT_CALL(*protocol, getContainerStatuses(_)).Times(AnyNumber()).WillOnce(Return(getResponse));
- client.stub = &stub;
- EXPECT_CALL(stub, getContainerManagementProtocol()).Times(AnyNumber()).WillOnce(Return(protocol));
-
- Container container;
- libyarn::Token nmToken;
- ContainerStatus retStatus = client.getContainerStatus(container,nmToken);
- EXPECT_EQ(status.getContainerId().getId(), 501);
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/383818c2/depends/libyarn/test/unit/TestLibYarnClient.cpp
----------------------------------------------------------------------
diff --git a/depends/libyarn/test/unit/TestLibYarnClient.cpp b/depends/libyarn/test/unit/TestLibYarnClient.cpp
deleted file mode 100644
index f922b5b..0000000
--- a/depends/libyarn/test/unit/TestLibYarnClient.cpp
+++ /dev/null
@@ -1,651 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include "gtest/gtest.h"
-#include "gmock/gmock.h"
-//#include "Thread.h"
-
-#include "libyarnclient/LibYarnClient.h"
-#include "MockApplicationMaster.h"
-#include "MockApplicationClient.h"
-#include "MockContainerManagement.h"
-#include "TestLibYarnClientStub.h"
-
-using std::string;
-using std::list;
-using std::set;
-using namespace libyarn;
-using namespace testing;
-using namespace Mock;
-
-class MockLibYarnClientStub: public TestLibYarnClientStub {
-public:
- ~MockLibYarnClientStub(){
- }
- MOCK_METHOD0(getApplicationClient, ApplicationClient* ());
- MOCK_METHOD0(getApplicationMaster, ApplicationMaster* ());
- MOCK_METHOD0(getContainerManagement, ContainerManagement* ());
-};
-
-class TestLibYarnClient: public ::testing::Test {
-public:
- TestLibYarnClient(){
- amUser = "postgres";
- rmHost = "localhost";
- rmPort = "8032";
- schedHost = "localhost";
- schedPort = "8030";
- amHost = "localhost";
- amPort = 0;
- am_tracking_url = "url";
- heartbeatInterval = 1000;
- tokenService = "";
- user = Yarn::Internal::UserInfo::LocalUser();
- }
- ~TestLibYarnClient(){
- }
-protected:
- string amUser;
- string rmHost;
- string rmPort;
- string schedHost;
- string schedPort;
- string amHost;
- int32_t amPort;
- string am_tracking_url;
- int heartbeatInterval;
- string tokenService;
- Yarn::Internal::UserInfo user;
-};
-
-static ResourceRequest BuildRequest(int requestContainer) {
- ResourceRequest resRequest;
- string host("*");
- resRequest.setResourceName(host);
- Resource capability;
- capability.setVirtualCores(1);
- capability.setMemory(1024);
- resRequest.setCapability(capability);
- resRequest.setNumContainers(requestContainer);
- resRequest.setRelaxLocality(true);
- Priority priority;
- priority.setPriority(1);
- resRequest.setPriority(priority);
- return resRequest;
-}
-
-static list<ContainerReport> BuildContainerReportList(int containerSize){
- list<ContainerReport> containerReports;
- for (int i = 0; i < containerSize; i++) {
- ContainerReport report;
- containerReports.push_back(report);
- }
- return containerReports;
-}
-static AllocateResponse BuildAllocateResponse(int containerNumber){
- AllocateResponse allocateResponse;
- allocateResponse.setResponseId(10);
- list<Container> containers;
- for (int i=0;i<containerNumber;i++){
- Container container;
- ContainerId containerId;
- containerId.setId(i+1);
- container.setId(containerId);
- containers.push_back(container);
- }
- list<NMToken> nmTokens;
- for (int i=0;i<containerNumber;i++){
- NMToken token;
- nmTokens.push_back(token);
- }
- allocateResponse.setAllocatedContainers(containers);
- allocateResponse.setNMTokens(nmTokens);
- return allocateResponse;
-}
-
-static ApplicationReport BuildApplicationReport(string passwordStr,YarnApplicationState state){
- ApplicationReport applicationReport;
- libyarn::Token token;
- string password(passwordStr);
- token.setPassword(password);
- applicationReport.setAMRMToken(token);
- applicationReport.setYarnApplicationState(state);
- return applicationReport;
-}
-
-static ApplicationID BuildApplicationID(int id){
- ApplicationID appId;
- appId.setId(id);
- return appId;
-}
-
-static RegisterApplicationMasterResponse BuildRegisterResponse(){
- RegisterApplicationMasterResponseProto responseProto;
- return RegisterApplicationMasterResponse(responseProto);
-}
-
-static StartContainerResponse BuildStartContainerResponse(){
- StartContainerResponseProto responseProto;
- return StartContainerResponse(responseProto);
-}
-
-static ContainerStatus BuildContainerStatus(int id){
- ContainerId containerId;
- containerId.setId(id);
- ContainerStatus containerStatus;
- containerStatus.setContainerId(containerId);
- return containerStatus;
-}
-
-static QueueInfo BuildQueueinfo(string queue,float capcity,int childNum){
- QueueInfo queueInfo;
- queueInfo.setQueueName(queue);
- queueInfo.setCurrentCapacity(capcity);
-
- list<QueueInfo> childQueues;
- for (int i=0;i<childNum;i++){
- QueueInfo childQueue;
- string childName("child");
- childQueue.setQueueName(childName);
- childQueue.setCurrentCapacity(capcity);
- childQueues.push_back(childQueue);
- }
- queueInfo.setChildQueues(childQueues);
- return queueInfo;
-
-}
-
-TEST_F(TestLibYarnClient,TestCreateJob){
- MockApplicationClient *appclient = new MockApplicationClient(amUser,rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- EXPECT_CALL(*appclient, getNewApplication()).Times(AnyNumber()).WillOnce(Return(BuildApplicationID(1)));
- EXPECT_CALL((*appclient),submitApplication(_)).Times(AnyNumber()).WillOnce(Return());
- EXPECT_CALL((*appclient),getApplicationReport(_)).Times(AtLeast(3))
- .WillOnce(Return(BuildApplicationReport("",YarnApplicationState::FAILED)))
- .WillOnce(Return(BuildApplicationReport("",YarnApplicationState::ACCEPTED)))
- .WillRepeatedly(Return(BuildApplicationReport("pass",YarnApplicationState::ACCEPTED)));
-
- EXPECT_CALL((*amrmclient),registerApplicationMaster(_,_,_)).Times(AnyNumber()).WillRepeatedly(Return(BuildRegisterResponse()));
- EXPECT_CALL((*amrmclient),allocate(_,_,_,_,_)).Times(AnyNumber()).WillRepeatedly(Return(BuildAllocateResponse(0)));
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
-
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval, &stub);
- string jobName("libyarn");
- string queue("default");
- string jobId("");
- int result = client.createJob(jobName,queue,jobId);
- EXPECT_EQ(result, 0);
-}
-
-TEST_F(TestLibYarnClient,TestCreateJobException){
- MockApplicationClient *appclient = new MockApplicationClient(amUser, rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- EXPECT_CALL(*appclient, getNewApplication()).Times(AnyNumber()).WillOnce(Return(BuildApplicationID(1)));
- EXPECT_CALL((*appclient),submitApplication(_)).Times(AnyNumber())
- .WillOnce(Throw(std::invalid_argument("Exist an application for the client")));
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
-
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval,&stub);
- string jobName("libyarn");
- string queue("default");
- string jobId("");
- int result = client.createJob(jobName,queue,jobId);
- EXPECT_EQ(result, 1);
-}
-
-TEST_F(TestLibYarnClient,TestCreateJobInvalidId){
- MockApplicationClient *appclient = new MockApplicationClient(amUser,rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
-
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval,&stub);
- string jobName("libyarn");
- string queue("default");
- string jobId("test");
- int result = client.createJob(jobName,queue,jobId);
- EXPECT_EQ(result,1);
-}
-
-TEST_F(TestLibYarnClient,TestAddResourceRequest){
- MockLibYarnClientStub stub;
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost,
- amPort, am_tracking_url, heartbeatInterval, &stub);
-
- Resource resource;
- resource.setMemory(1024);
- resource.setVirtualCores(1);
- string host("master");
- client.addResourceRequest(resource, 10, host, 1, true);
- list<ResourceRequest> request = client.getAskRequests();
- EXPECT_EQ(request.size(), 1);
- list<ResourceRequest>::iterator it = request.begin();
- EXPECT_EQ(it->getPriority().getPriority(), 1);
- EXPECT_EQ(it->getNumContainers(), 10);
- EXPECT_EQ(it->getRelaxLocality(), true);
- EXPECT_EQ(it->getResourceName(), host);
-}
-
-TEST_F(TestLibYarnClient,TestaddContainerRequests) {
- MockLibYarnClientStub stub;
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost,
- amPort, am_tracking_url, heartbeatInterval, &stub);
- string jobId("");
- Resource resource;
- resource.setMemory(1024);
- resource.setVirtualCores(1);
- list<struct LibYarnNodeInfo> preferred;
- int ret = client.addContainerRequests(jobId, resource, 8, preferred, 1, true);
- EXPECT_EQ(ret, 0);
- list<ResourceRequest> request = client.getAskRequests();
- list<ResourceRequest>::iterator it = request.begin();
- EXPECT_EQ(it->getPriority().getPriority(), 1);
- EXPECT_EQ(it->getNumContainers(), 8);
- EXPECT_EQ(it->getRelaxLocality(), true);
- EXPECT_EQ(it->getResourceName(), "*");
- client.clearAskRequests();
- EXPECT_EQ(client.getAskRequests().size(), 0);
-
- /* test preferred hosts */
- LibYarnNodeInfo info1("node1", NULL, 3);
- LibYarnNodeInfo info2("node2", NULL, 2);
- preferred.push_back(info1);
- preferred.push_back(info2);
- ret = client.addContainerRequests(jobId, resource, 8, preferred, 1, false);
- request = client.getAskRequests();
- for (it = request.begin(); it != request.end(); ++it) {
- if (it->getResourceName() == info1.getHost()) {
- EXPECT_EQ(it->getNumContainers(), 3);
- EXPECT_EQ(it->getRelaxLocality(), true);
- } else if (it->getResourceName() == info2.getHost()) {
- EXPECT_EQ(it->getNumContainers(), 2);
- EXPECT_EQ(it->getRelaxLocality(), true);
- } else if (it->getResourceName() == string("/default-rack")) {
- EXPECT_EQ(it->getNumContainers(), 5);
- EXPECT_EQ(it->getRelaxLocality(), false);
- } else if (it->getResourceName() == string("*")) {
- EXPECT_EQ(it->getNumContainers(), 8);
- EXPECT_EQ(it->getRelaxLocality(), false);
- } else {
- ASSERT_TRUE(false);
- }
- EXPECT_EQ(it->getCapability().getMemory(), 1024);
- EXPECT_EQ(it->getCapability().getVirtualCores(), 1);
- }
-}
-
-TEST_F(TestLibYarnClient,TestAllocateResources){
- MockApplicationClient *appclient = new MockApplicationClient(amUser,rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- EXPECT_CALL((*amrmclient),allocate(_,_,_,_,_)).Times(AnyNumber()).WillRepeatedly(Return(BuildAllocateResponse(5)));
- EXPECT_CALL((*appclient),getContainers(_)).Times(AnyNumber())
- .WillRepeatedly(Return(BuildContainerReportList(0)));
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
-
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval,&stub);
-
- string jobId("");
- list<string> blackListAdditions;
- list<string> blackListRemovals;
- ResourceRequest resRequest;
- list<Container> allocatedResourcesArray;
- int result;
-
- result = client.allocateResources(jobId, blackListAdditions, blackListRemovals,allocatedResourcesArray,5);
- EXPECT_EQ(allocatedResourcesArray.size(), 5);
- EXPECT_EQ(result,0);
-}
-
-TEST_F(TestLibYarnClient,TestAllocateResourcesRetry){
- MockApplicationClient *appclient = new MockApplicationClient(amUser, rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- EXPECT_CALL((*appclient),getContainers(_)).Times(AnyNumber())
- .WillRepeatedly(Return(BuildContainerReportList(0)));
- EXPECT_CALL((*amrmclient),allocate(_,_,_,_,_)).Times(AnyNumber())
- .WillOnce(Return(BuildAllocateResponse(5)))
- .WillOnce(Return(BuildAllocateResponse(5)))
- .WillRepeatedly(Return(BuildAllocateResponse(0)));
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
-
- LibYarnClient client(amUser,rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval,&stub);
-
- string jobId("");
- list<string> blackListAdditions;
- list<string> blackListRemovals;
- ResourceRequest resRequest;
- list<Container> allocatedResourcesArray;
- int result;
- resRequest = BuildRequest(11);
- result = client.allocateResources(jobId, blackListAdditions, blackListRemovals, allocatedResourcesArray, 2);
- EXPECT_EQ(result,0);
-}
-
-TEST_F(TestLibYarnClient,TestActiveResources){
- MockApplicationClient *appclient = new MockApplicationClient(amUser,rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
-
- LibYarnClient client(amUser,rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval,&stub);
-
- string jobId("");
- int activeContainerSize = 3;
- int64_t activeContainerIds[activeContainerSize];
- for (int i = 0;i < activeContainerSize;i++){
- activeContainerIds[i] = i;
- }
- int result = client.activeResources(jobId,activeContainerIds,activeContainerSize);
- EXPECT_EQ(result,0);
-}
-
-
-TEST_F(TestLibYarnClient,TestReleaseResources){
- MockApplicationClient *appclient = new MockApplicationClient(amUser,rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- EXPECT_CALL((*amrmclient),allocate(_,_,_,_,_)).Times(AnyNumber()).WillRepeatedly(Return(BuildAllocateResponse(5)));
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
-
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval,&stub);
-
- string jobId("");
- int releaseContainerSize = 3;
- int64_t releaseContainerIds[releaseContainerSize];
- for (int i = 0;i < releaseContainerSize;i++){
- releaseContainerIds[i] = i;
- }
- int result = client.releaseResources(jobId,releaseContainerIds,releaseContainerSize);
- EXPECT_EQ(result,0);
-}
-
-TEST_F(TestLibYarnClient,TestFinishJob){
- MockApplicationClient *appclient = new MockApplicationClient(amUser,rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- EXPECT_CALL((*amrmclient),finishApplicationMaster(_,_,_)).Times(AnyNumber()).WillRepeatedly(Return(true));
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval,&stub);
-
- string jobId("");
- int result = client.finishJob(jobId,FinalApplicationStatus::APP_SUCCEEDED);
- EXPECT_EQ(result,0);
-}
-
-TEST_F(TestLibYarnClient,TestGetApplicationReport){
- MockApplicationClient *appclient = new MockApplicationClient(amUser,rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- EXPECT_CALL((*appclient),getApplicationReport(_)).Times(AnyNumber())
- .WillRepeatedly(Return(BuildApplicationReport("pass",YarnApplicationState::ACCEPTED)));
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval,&stub);
-
- string jobId("");
- ApplicationReport applicationReport;
- int result = client.getApplicationReport(jobId,applicationReport);
- EXPECT_EQ(result,0);
-}
-
-TEST_F(TestLibYarnClient,TestGetContainerReports){
- MockApplicationClient *appclient = new MockApplicationClient(amUser,rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- int containerSize = 3;
- EXPECT_CALL((*appclient),getContainers(_)).Times(AnyNumber())
- .WillRepeatedly(Return(BuildContainerReportList(containerSize)));
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval,&stub);
-
- string jobId("");
- list<ContainerReport> reports;
- int result = client.getContainerReports(jobId,reports);
- EXPECT_EQ(result,0);
- EXPECT_EQ(int(reports.size()),containerSize);
-}
-
-TEST_F(TestLibYarnClient,TestGetContainerStatuses){
- MockApplicationClient *appclient = new MockApplicationClient(amUser,rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval,&stub);
-
- string jobId("");
- list<ContainerStatus> containerStatues;
- int containerSize = 3;
- int64_t containerIds[containerSize];
- for (int i = 0;i < containerSize;i++){
- containerIds[i] = i;
- }
- int result = client.getContainerStatuses(jobId,containerIds,containerSize,containerStatues);
- EXPECT_EQ(result,0);
- EXPECT_EQ(int(containerStatues.size()),0);
-}
-
-TEST_F(TestLibYarnClient,TestGetQueueInfo){
- MockApplicationClient *appclient = new MockApplicationClient(amUser,rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- string queue("test");
- int childNum = 2;
- float capcity = 0.5;
- QueueInfo queueInfo = BuildQueueinfo(queue,capcity,childNum);
- EXPECT_CALL((*appclient),getQueueInfo(_,_,_,_)).Times(AnyNumber())
- .WillRepeatedly(Return(queueInfo));
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval,&stub);
-
-
- QueueInfo resultQueue;
- int result = client.getQueueInfo(queue,true,true,true,resultQueue);
- EXPECT_EQ(result,0);
- EXPECT_EQ(resultQueue.getCurrentCapacity(),capcity);
- EXPECT_STREQ(resultQueue.getQueueName().c_str(),queue.c_str());
- EXPECT_EQ(int(resultQueue.getChildQueues().size()),childNum);
-}
-
-TEST_F(TestLibYarnClient,TestGetClusterNodes){
- MockApplicationClient *appclient = new MockApplicationClient(amUser,rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- list<NodeReport> nodeReports;
- int nodeSize = 3;
- for (int i=0;i<nodeSize;i++){
- NodeReport report;
- nodeReports.push_back(report);
- }
- EXPECT_CALL((*appclient),getClusterNodes(_)).Times(AnyNumber())
- .WillRepeatedly(Return(nodeReports));
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval,&stub);
-
- list<NodeState> states;
- list<NodeReport> nodeResult;
- int result = client.getClusterNodes(states,nodeResult);
- EXPECT_EQ(result,0);
- EXPECT_EQ(int(nodeResult.size()),nodeSize);
-}
-
-TEST_F(TestLibYarnClient,TestGetErrorMessage){
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval);
- EXPECT_STREQ("",client.getErrorMessage().c_str());
- client.setErrorMessage("error!");
- EXPECT_STREQ("error!",client.getErrorMessage().c_str());
-}
-
-TEST_F(TestLibYarnClient,TestGetActiveFailContainerIds){
- LibYarnClient client(amUser, rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval);
- set<int64_t> activeFailIds;
- client.getActiveFailContainerIds(activeFailIds);
- EXPECT_EQ(int(activeFailIds.size()),0);
-}
-
-TEST_F(TestLibYarnClient,TestLibYarn){
- MockApplicationClient *appclient = new MockApplicationClient(amUser,rmHost,rmHost);
- MockApplicationMaster *amrmclient = new MockApplicationMaster(schedHost,schedPort,user,tokenService);
- MockContainerManagement *nmclient = new MockContainerManagement();
- MockLibYarnClientStub stub;
-
- EXPECT_CALL(*appclient, getNewApplication()).Times(AnyNumber()).WillOnce(Return(BuildApplicationID(1)));
- EXPECT_CALL((*appclient),submitApplication(_)).Times(AnyNumber()).WillOnce(Return());
- EXPECT_CALL((*appclient),getApplicationReport(_)).Times(AtLeast(3))
- .WillOnce(Return(BuildApplicationReport("",YarnApplicationState::FAILED)))
- .WillOnce(Return(BuildApplicationReport("",YarnApplicationState::ACCEPTED)))
- .WillRepeatedly(Return(BuildApplicationReport("pass",YarnApplicationState::ACCEPTED)));
- EXPECT_CALL((*appclient),getContainers(_)).Times(AnyNumber())
- .WillRepeatedly(Return(BuildContainerReportList(0)));
-
- EXPECT_CALL((*amrmclient),registerApplicationMaster(_,_,_)).Times(AnyNumber()).WillRepeatedly(Return(BuildRegisterResponse()));
- EXPECT_CALL((*amrmclient),allocate(_,_,_,_,_)).Times(AnyNumber()).WillRepeatedly(Return(BuildAllocateResponse(5)));
- EXPECT_CALL((*amrmclient),finishApplicationMaster(_,_,_)).Times(AnyNumber()).WillRepeatedly(Return(true));
-
- EXPECT_CALL((*nmclient),startContainer(_,_,_)).Times(AnyNumber())
- .WillOnce(Throw(std::invalid_argument("startContainer Exception")))
- .WillRepeatedly(Return(BuildStartContainerResponse()));
- EXPECT_CALL((*nmclient),getContainerStatus(_,_)).Times(AnyNumber())
- .WillOnce(Return(BuildContainerStatus(2)))
- .WillOnce(Return(BuildContainerStatus(3)))
- .WillRepeatedly(Return(BuildContainerStatus(0)));
- EXPECT_CALL((*nmclient),stopContainer(_,_)).Times(AnyNumber())
- .WillRepeatedly(Return());
-
- EXPECT_CALL(stub, getApplicationClient()).Times(AnyNumber()).WillOnce(Return(appclient));
- EXPECT_CALL(stub, getApplicationMaster()).Times(AnyNumber()).WillOnce(Return(amrmclient));
- EXPECT_CALL(stub, getContainerManagement()).Times(AnyNumber()).WillOnce(Return(nmclient));
-
- LibYarnClient client(amUser,rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url,heartbeatInterval,&stub);
- string jobName("libyarn");
- string queue("default");
- string jobId("");
- int result = client.createJob(jobName,queue,jobId);
- EXPECT_EQ(result,0);
-
- list<string> blackListAdditions;
- list<string> blackListRemovals;
- ResourceRequest resRequest;
- list<Container> allocatedResourcesArray;
-
- resRequest = BuildRequest(3);
- result = client.allocateResources(jobId, blackListAdditions, blackListRemovals,allocatedResourcesArray,5);
- EXPECT_EQ(result,0);
-
- int allocatedResourceArraySize = allocatedResourcesArray.size();
- int64_t activeContainerIds[allocatedResourceArraySize];
- int64_t releaseContainerIds[allocatedResourceArraySize];
- int64_t statusContainerIds[allocatedResourceArraySize];
- int i = 0;
- for (list<Container>::iterator it = allocatedResourcesArray.begin();it != allocatedResourcesArray.end();it++){
- activeContainerIds[i] = it->getId().getId();
- if (i != 1){
- releaseContainerIds[i] = it->getId().getId();
- }
- statusContainerIds[i] = it->getId().getId();
- i++;
- }
- result = client.activeResources(jobId, activeContainerIds,allocatedResourceArraySize);
- EXPECT_EQ(result,0);
-
- set<int64_t> activeFailIds;
- result = client.getActiveFailContainerIds(activeFailIds);
- EXPECT_EQ(result,0);
- EXPECT_EQ(int(activeFailIds.size()),1);
-
- ApplicationReport report;
- result = client.getApplicationReport(jobId,report);
- EXPECT_EQ(result,0);
-
- list<ContainerStatus> containerStatues;
- result = client.getContainerStatuses(jobId,statusContainerIds,allocatedResourceArraySize,containerStatues);
- EXPECT_EQ(result,0);
- //EXPECT_EQ(int(containerStatues.size()),2);
-
- result = client.releaseResources(jobId, releaseContainerIds,allocatedResourceArraySize);
- EXPECT_EQ(result,0);
-
-
- result = client.finishJob(jobId, FinalApplicationStatus::APP_SUCCEEDED);
- EXPECT_EQ(result,0);
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/383818c2/depends/libyarn/test/unit/TestLibYarnClient/TestApplicationClient.cpp
----------------------------------------------------------------------
diff --git a/depends/libyarn/test/unit/TestLibYarnClient/TestApplicationClient.cpp b/depends/libyarn/test/unit/TestLibYarnClient/TestApplicationClient.cpp
new file mode 100644
index 0000000..b02223c
--- /dev/null
+++ b/depends/libyarn/test/unit/TestLibYarnClient/TestApplicationClient.cpp
@@ -0,0 +1,277 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <list>
+#include <string>
+
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+#include "libyarnclient/ApplicationClient.h"
+#include "MockApplicationClientProtocol.h"
+
+using std::string;
+using std::list;
+using namespace libyarn;
+using namespace testing;
+using namespace Mock;
+
+class TestApplicationClient: public ::testing::Test {
+public:
+ TestApplicationClient(){
+ string user("postgres");
+ string rmHost("localhost");
+ string rmPort("8032");
+ string tokenService = "";
+ Yarn::Config config;
+ Yarn::Internal::SessionConfig sessionConfig(config);
+ MockApplicationClientProtocol *protocol = new MockApplicationClientProtocol(user,rmHost,rmPort,tokenService, sessionConfig);
+
+ ApplicationId appId;
+ appId.setId(100);
+ appId.setClusterTimestamp(1454307175682);
+ GetNewApplicationResponse getNewApplicationResponse;
+ getNewApplicationResponse.setApplicationId(appId);
+ EXPECT_CALL((*protocol),getNewApplication(_)).Times(AnyNumber()).WillOnce(Return(getNewApplicationResponse));
+ EXPECT_CALL((*protocol),submitApplication(_)).Times(AnyNumber()).WillOnce(Return());
+
+ ApplicationReport appReport;
+ appReport.setApplicationId(appId);
+ appReport.setUser(user);
+ string queue("default");
+ string appName("hawq");
+ string hostname("master");
+ appReport.setQueue(queue);
+ appReport.setName(appName);
+ appReport.setHost(hostname);
+ appReport.setRpcPort(8090);
+ appReport.setProgress(0.5);
+ GetApplicationReportResponse appReportResponse;
+ appReportResponse.setApplicationReport(appReport);
+ EXPECT_CALL((*protocol),getApplicationReport(_)).Times(AnyNumber()).WillOnce(Return(appReportResponse));
+
+ ContainerId containerId;
+ containerId.setId(501);
+ containerId.setApplicationId(appId);
+ Resource resource;
+ resource.setMemory(1024);
+ resource.setVirtualCores(1);
+ Priority priority;
+ priority.setPriority(1);
+ ContainerReport report;
+ report.setId(containerId);
+ report.setResource(resource);
+ report.setPriority(priority);
+ list<ContainerReport> reportList;
+ reportList.push_back(report);
+ GetContainersResponse getContainersResponse;
+ getContainersResponse.setContainersReportList(reportList);
+ EXPECT_CALL((*protocol),getContainers(_)).Times(AnyNumber()).WillOnce(Return(getContainersResponse));
+
+ NodeId nodeId;
+ string nodeHost("node1");
+ nodeId.setHost(nodeHost);
+ nodeId.setPort(9983);
+ NodeReport nodeReport;
+ nodeReport.setNodeId(nodeId);
+ string rackName("default-rack");
+ nodeReport.setRackName(rackName);
+ nodeReport.setNumContainers(8);
+ Resource nodeResource;
+ nodeResource.setMemory(2048*8);
+ nodeResource.setVirtualCores(8);
+ nodeReport.setResourceCapablity(nodeResource);
+ nodeReport.setNodeState(NodeState::NS_RUNNING);
+ list<NodeReport> nodeReportList;
+ nodeReportList.push_back(nodeReport);
+ GetClusterNodesResponse getClusterNodesResponse;
+ getClusterNodesResponse.setNodeReports(nodeReportList);
+ EXPECT_CALL((*protocol),getClusterNodes(_)).Times(AnyNumber()).WillOnce(Return(getClusterNodesResponse));
+
+ QueueInfo queueInfo;
+ queueInfo.setQueueName(queue);
+ queueInfo.setCapacity(0.67);
+ queueInfo.setMaximumCapacity(0.95);
+ queueInfo.setCurrentCapacity(0.5);
+ queueInfo.setQueueState(QueueState::Q_RUNNING);
+ QueueInfo childQueue;
+ string childQueueName("hawq-queue");
+ childQueue.setQueueName(childQueueName);
+ childQueue.setCapacity(0.33);
+ childQueue.setMaximumCapacity(0.5);
+ childQueue.setCurrentCapacity(0.25);
+ list<QueueInfo> childQueueList;
+ childQueueList.push_back(childQueue);
+ queueInfo.setChildQueues(childQueueList);
+ list<ApplicationReport> appReportList;
+ appReportList.push_back(appReport);
+ queueInfo.setApplicationReports(appReportList);
+ GetQueueInfoResponse getQueueInfoResponse;
+ getQueueInfoResponse.setQueueInfo(queueInfo);
+ EXPECT_CALL((*protocol),getQueueInfo(_)).Times(AnyNumber()).WillOnce(Return(getQueueInfoResponse));
+
+ KillApplicationResponseProto killApplicationResponseProto;
+ EXPECT_CALL((*protocol),forceKillApplication(_)).Times(AnyNumber()).WillOnce(Return(KillApplicationResponse(killApplicationResponseProto)));
+
+ YarnClusterMetrics metrics;
+ metrics.setNumNodeManagers(10);
+ GetClusterMetricsResponse clusterMetricsResponse;
+ clusterMetricsResponse.setClusterMetrics(metrics);
+ EXPECT_CALL((*protocol),getClusterMetrics(_)).Times(AnyNumber()).WillOnce(Return(clusterMetricsResponse));
+
+ GetApplicationsResponse applicationsResponse;
+ applicationsResponse.setApplicationList(appReportList);
+ EXPECT_CALL((*protocol),getApplications(_)).Times(AnyNumber()).WillOnce(Return(applicationsResponse));
+
+ QueueUserACLInfo aclInfo;
+ aclInfo.setQueueName(queue);
+ list<QueueACL> queueACLList;
+ QueueACL acl1 = QueueACL::QACL_ADMINISTER_QUEUE;
+ QueueACL acl2 = QueueACL::QACL_SUBMIT_APPLICATIONS;
+ queueACLList.push_back(acl1);
+ queueACLList.push_back(acl2);
+ aclInfo.setUserAcls(queueACLList);
+ list<QueueUserACLInfo> aclInfoList;
+ aclInfoList.push_back(aclInfo);
+ GetQueueUserAclsInfoResponse queueUserAclsInfoResponse;
+ queueUserAclsInfoResponse.setUserAclsInfoList(aclInfoList);
+ EXPECT_CALL((*protocol),getQueueAclsInfo(_)).Times(AnyNumber()).WillOnce(Return(queueUserAclsInfoResponse));
+
+ client = new ApplicationClient(protocol);
+ }
+
+ ~TestApplicationClient(){
+ delete client;
+ }
+
+protected:
+ ApplicationClient *client;
+};
+
+TEST_F(TestApplicationClient, TestGetNewApplication){
+ ApplicationId response = client->getNewApplication();
+ EXPECT_EQ(response.getId(), 100);
+ EXPECT_EQ(response.getClusterTimestamp(), 1454307175682);
+}
+
+TEST_F(TestApplicationClient,TestSubmitApplication){
+ ApplicationSubmissionContext appContext;
+ client->submitApplication(appContext);
+}
+
+TEST_F(TestApplicationClient,TestGetApplicationReport){
+ ApplicationId appId;
+ ApplicationReport report = client->getApplicationReport(appId);
+ EXPECT_EQ(report.getUser(), "postgres");
+ EXPECT_EQ(report.getQueue(), "default");
+ EXPECT_EQ(report.getName(), "hawq");
+ EXPECT_EQ(report.getHost(), "master");
+ EXPECT_EQ(report.getRpcPort(), 8090);
+ EXPECT_FLOAT_EQ(report.getProgress(), 0.5);
+}
+
+TEST_F(TestApplicationClient,TestGetContainers){
+ ApplicationAttemptId appAttempId;
+ list<ContainerReport> reports = client->getContainers(appAttempId);
+ EXPECT_EQ(reports.size(), 1);
+ list<ContainerReport>::iterator it = reports.begin();
+ EXPECT_EQ(it->getId().getId(), 501);
+ EXPECT_EQ(it->getPriority().getPriority(), 1);
+ EXPECT_EQ(it->getResource().getMemory(), 1024);
+ EXPECT_EQ(it->getResource().getVirtualCores(), 1);
+}
+
+TEST_F(TestApplicationClient,TestGetClusterNodes){
+ list<NodeState> states;
+ list<NodeReport> reports = client->getClusterNodes(states);
+ EXPECT_EQ(reports.size(), 1);
+ list<NodeReport>::iterator it = reports.begin();
+ EXPECT_EQ(it->getNodeId().getHost(), "node1");
+ EXPECT_EQ(it->getNodeId().getPort(), 9983);
+ EXPECT_EQ(it->getRackName(), "default-rack");
+ EXPECT_EQ(it->getResourceCapability().getMemory(), 2048*8);
+ EXPECT_EQ(it->getResourceCapability().getVirtualCores(), 8);
+ EXPECT_EQ(it->getNodeState(), NodeState::NS_RUNNING);
+ EXPECT_EQ(it->getNumContainers(), 8);
+}
+
+TEST_F(TestApplicationClient,TestGetQueueInfo){
+ string queue = "";
+ QueueInfo queueInfo = client->getQueueInfo(queue,true,true,true);
+ EXPECT_EQ(queueInfo.getQueueName(), "default");
+ EXPECT_FLOAT_EQ(queueInfo.getCapacity(), 0.67);
+ EXPECT_FLOAT_EQ(queueInfo.getMaximumCapacity(), 0.95);
+ EXPECT_FLOAT_EQ(queueInfo.getCurrentCapacity(), 0.5);
+ EXPECT_EQ(queueInfo.getQueueState(), QueueState::Q_RUNNING);
+ list<QueueInfo> child = queueInfo.getChildQueues();
+ EXPECT_EQ(child.size(), 1);
+ list<QueueInfo>::iterator it = child.begin();
+ EXPECT_EQ(it->getQueueName(), "hawq-queue");
+ EXPECT_FLOAT_EQ(it->getCapacity(), 0.33);
+ EXPECT_FLOAT_EQ(it->getMaximumCapacity(), 0.5);
+ EXPECT_FLOAT_EQ(it->getCurrentCapacity(), 0.25);
+ list<ApplicationReport> appReportList = queueInfo.getApplicationReports();
+ list<ApplicationReport>::iterator itAppReport = appReportList.begin();
+ EXPECT_EQ(itAppReport->getApplicationId().getId(), 100);
+ EXPECT_EQ(itAppReport->getUser(), "postgres");
+}
+
+TEST_F(TestApplicationClient,TestForceKillApplication){
+ ApplicationId appId;
+ client->forceKillApplication(appId);
+}
+
+TEST_F(TestApplicationClient,TestGetClusterMetrics){
+ YarnClusterMetrics response = client->getClusterMetrics();
+ EXPECT_EQ(response.getNumNodeManagers(), 10);
+}
+
+TEST_F(TestApplicationClient,TestGetApplications){
+ list<string> applicationTypes;
+ list<YarnApplicationState> applicationStates;
+ list<ApplicationReport> reports = client->getApplications(applicationTypes,applicationStates);
+ EXPECT_EQ(reports.size(), 1);
+ list<ApplicationReport>::iterator it = reports.begin();
+ EXPECT_EQ(it->getApplicationId().getId(), 100);
+ EXPECT_EQ(it->getUser(), "postgres");
+}
+
+TEST_F(TestApplicationClient,TestGetQueueAclsInfo){
+ list<QueueUserACLInfo> response = client->getQueueAclsInfo();
+ EXPECT_EQ(response.size(), 1);
+ list<QueueUserACLInfo>::iterator it = response.begin();
+ EXPECT_EQ(it->getQueueName(), "default");
+ list<QueueACL> queueACLs = it->getUserAcls();
+ EXPECT_EQ(queueACLs.size(), 2);
+ list<QueueACL>::iterator queueACL = queueACLs.begin();
+ EXPECT_EQ(*queueACL, QueueACL::QACL_ADMINISTER_QUEUE);
+ *queueACL++;
+ EXPECT_EQ(*queueACL, QueueACL::QACL_SUBMIT_APPLICATIONS);
+}
+
+TEST_F(TestApplicationClient, TestRMInfo){
+ string rmHost("localhost");
+ string rmPort("8032");
+
+ RMInfo rmInfo = RMInfo();
+ rmInfo.setHost(rmHost);
+ rmInfo.setPort(rmPort);
+ EXPECT_EQ(rmInfo.getHost(), rmHost);
+ EXPECT_EQ(rmInfo.getPort(), rmPort);
+}
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/383818c2/depends/libyarn/test/unit/TestLibYarnClient/TestApplicationMaster.cpp
----------------------------------------------------------------------
diff --git a/depends/libyarn/test/unit/TestLibYarnClient/TestApplicationMaster.cpp b/depends/libyarn/test/unit/TestLibYarnClient/TestApplicationMaster.cpp
new file mode 100644
index 0000000..18969af
--- /dev/null
+++ b/depends/libyarn/test/unit/TestLibYarnClient/TestApplicationMaster.cpp
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <list>
+#include <string>
+
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+#include "libyarnclient/ApplicationMaster.h"
+#include "MockApplicationMasterProtocol.h"
+
+using std::string;
+using std::list;
+using namespace libyarn;
+using namespace testing;
+using namespace Mock;
+
+class TestApplicationMaster: public ::testing::Test {
+public:
+ TestApplicationMaster(){
+ string schedHost("localhost");
+ string schedPort("8032");
+ string tokenService = "";
+ Yarn::Config config;
+ Yarn::Internal::SessionConfig sessionConfig(config);
+ Yarn::Internal::UserInfo user = Yarn::Internal::UserInfo::LocalUser();
+ Yarn::Internal::RpcAuth rpcAuth(user, Yarn::Internal::AuthMethod::SIMPLE);
+ protocol = new MockApplicationMasterProtocol(schedHost,schedPort,tokenService, sessionConfig,rpcAuth);
+ client = new ApplicationMaster(protocol);
+ }
+ ~TestApplicationMaster(){
+ delete client;
+ }
+
+protected:
+ MockApplicationMasterProtocol *protocol;
+ ApplicationMaster *client;
+};
+
+TEST_F(TestApplicationMaster,TestRegisterApplicationMaster){
+ Resource resource;
+ resource.setMemory(1024*8*10);
+ resource.setVirtualCores(1*8*10);
+ string key("tokenkey");
+ ApplicationACLMap aclMap;
+ aclMap.setAccessType(ApplicationAccessType::APPACCESS_VIEW_APP);
+ string acl("acl");
+ aclMap.setAcl(acl);
+ list<ApplicationACLMap> aclMapList;
+ aclMapList.push_back(aclMap);
+ RegisterApplicationMasterResponse response;
+ response.setMaximumResourceCapability(resource);
+ response.setClientToAMTokenMasterKey(key);
+ response.setApplicationACLs(aclMapList);
+ EXPECT_CALL((*protocol),registerApplicationMaster(_)).Times(AnyNumber()).WillOnce(Return(response));
+
+ string amHost("localhost");
+ int amPort = 8032;
+ string am_tracking_url = "";
+ RegisterApplicationMasterResponse retResponse = client->registerApplicationMaster(amHost,amPort,am_tracking_url);
+ EXPECT_EQ(retResponse.getClientToAMTokenMasterKey(), "tokenkey");
+ Resource retResource = retResponse.getMaximumResourceCapability();
+ EXPECT_EQ(retResource.getMemory(), 1024*8*10);
+ EXPECT_EQ(retResource.getVirtualCores(), 1*8*10);
+ list<ApplicationACLMap> retAclMapList = retResponse.getApplicationACLs();
+ EXPECT_EQ(retAclMapList.size(), 1);
+ list<ApplicationACLMap>::iterator it = retAclMapList.begin();
+ EXPECT_EQ(it->getAccessType(), ApplicationAccessType::APPACCESS_VIEW_APP);
+ EXPECT_EQ(it->getAcl(), "acl");
+}
+
+TEST_F(TestApplicationMaster,TestAllocate){
+ Resource resource;
+ resource.setMemory(1024*8*10);
+ resource.setVirtualCores(1*8*10);
+ AllocateResponse allocateResponse;
+ allocateResponse.setAMCommand(AMCommand::AM_RESYNC);
+ allocateResponse.setResponseId(100);
+ list<Container> containers;
+ Container container;
+ ContainerId containerId;
+ containerId.setId(501);
+ container.setId(containerId);
+ NodeId nodeId;
+ string nodeHost("node1");
+ nodeId.setHost(nodeHost);
+ nodeId.setPort(9983);
+ container.setNodeId(nodeId);
+ string address("http://address");
+ container.setNodeHttpAddress(address);
+ container.setResource(resource);
+ Priority priority;
+ priority.setPriority(1);
+ container.setPriority(priority);
+ libyarn::Token token;
+ string identifier("identifier");
+ token.setIdentifier(identifier);
+ string password("password");
+ token.setPassword(password);
+ string kind("kind");
+ token.setKind(kind);
+ string service("service");
+ token.setService(service);
+ container.setContainerToken(token);
+ containers.push_back(container);
+ allocateResponse.setAllocatedContainers(containers);
+ ContainerStatus containerStatus;
+ containerStatus.setContainerId(containerId);
+ containerStatus.setContainerState(ContainerState::C_RUNNING);
+ string diagnostics("diagnostics");
+ containerStatus.setDiagnostics(diagnostics);
+ containerStatus.setExitStatus(-1000);
+ list<ContainerStatus> statuses;
+ statuses.push_back(containerStatus);
+ allocateResponse.setCompletedContainerStatuses(statuses);
+ allocateResponse.setResourceLimit(resource);
+ NodeReport nodeReport;
+ nodeReport.setNodeId(nodeId);
+ string rackName("default-rack");
+ nodeReport.setRackName(rackName);
+ nodeReport.setNumContainers(8);
+ list<NodeReport> nodeReports;
+ nodeReports.push_back(nodeReport);
+ allocateResponse.setUpdatedNodes(nodeReports);
+ allocateResponse.setNumClusterNodes(12);
+ NMToken nmToken;
+ nmToken.setNodeId(nodeId);
+ nmToken.setToken(token);
+ list<NMToken> nmTokens;
+ nmTokens.push_back(nmToken);
+ allocateResponse.setNMTokens(nmTokens);
+ EXPECT_CALL((*protocol),allocate(_)).Times(AnyNumber()).WillOnce(Return(allocateResponse));
+
+ list<ResourceRequest> asks;
+ list<ContainerId> releases;
+ ResourceBlacklistRequest blacklistRequest;
+ int32_t responseId;
+ float progress = 5;
+ AllocateResponse retResponse = client->allocate(asks,releases,blacklistRequest,responseId,progress);
+ EXPECT_EQ(retResponse.getAMCommand(), AMCommand::AM_RESYNC);
+ EXPECT_EQ(retResponse.getResponseId(), 100);
+ list<Container> retContainers = retResponse.getAllocatedContainers();
+ list<Container>::iterator it = retContainers.begin();
+ EXPECT_EQ(it->getId().getId(), 501);
+ EXPECT_EQ(it->getNodeId().getHost(), "node1");
+ EXPECT_EQ(it->getNodeId().getPort(), 9983);
+ EXPECT_EQ(it->getNodeHttpAddress(), "http://address");
+ EXPECT_EQ(it->getPriority().getPriority(), 1);
+ EXPECT_EQ(it->getResource().getMemory(), 1024*8*10);
+ EXPECT_EQ(it->getResource().getVirtualCores(), 1*8*10);
+ EXPECT_EQ(it->getContainerToken().getIdentifier(), "identifier");
+ EXPECT_EQ(it->getContainerToken().getPassword(), "password");
+ EXPECT_EQ(it->getContainerToken().getKind(), "kind");
+ EXPECT_EQ(it->getContainerToken().getService(), "service");
+ list<ContainerStatus>::iterator retStatus = retResponse.getCompletedContainersStatuses().begin();
+ EXPECT_EQ(retStatus->getContainerId().getId(), 501);
+ EXPECT_EQ(retStatus->getContainerState(), ContainerState::C_RUNNING);
+ //EXPECT_EQ(retStatus->getDiagnostics(), "diagnostics");
+ EXPECT_EQ(retStatus->getExitStatus(), -1000);
+ EXPECT_EQ(retResponse.getResourceLimit().getMemory(), 1024*8*10);
+ //list<NodeReport>::iterator report = response.getUpdatedNodes().begin();
+ //EXPECT_EQ(report->getNodeId().getHost(), "node1");
+ //list<NMToken>::iterator nmToken = response.getNMTokens().begin();
+ //EXPECT_EQ(nmToken->getNodeId().getHost(), "node1");
+ //EXPECT_EQ(nmToken->getToken().getIdentifier(), "identifier");
+ EXPECT_EQ(retResponse.getNumClusterNodes(), 12);
+}
+
+TEST_F(TestApplicationMaster,TestFinishApplicationMaster){
+ FinishApplicationMasterResponse finishApplicationMasterResponse;
+ finishApplicationMasterResponse.setIsUnregistered(true);
+ EXPECT_CALL((*protocol),finishApplicationMaster(_)).Times(AnyNumber()).WillOnce(Return(finishApplicationMasterResponse));
+ string diagnostics("");
+ string trackingUrl("");
+ FinalApplicationStatus finalstatus;
+ bool response = client->finishApplicationMaster(diagnostics,trackingUrl,finalstatus);
+ EXPECT_EQ(response,true);
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/383818c2/depends/libyarn/test/unit/TestLibYarnClient/TestContainerManagement.cpp
----------------------------------------------------------------------
diff --git a/depends/libyarn/test/unit/TestLibYarnClient/TestContainerManagement.cpp b/depends/libyarn/test/unit/TestLibYarnClient/TestContainerManagement.cpp
new file mode 100644
index 0000000..e927d68
--- /dev/null
+++ b/depends/libyarn/test/unit/TestLibYarnClient/TestContainerManagement.cpp
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <list>
+#include <map>
+#include <string>
+
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+
+#include "libyarnclient/ContainerManagement.h"
+#include "MockContainerManagementProtocol.h"
+#include "TestContainerManagementStub.h"
+
+using std::map;
+using std::string;
+using std::list;
+using namespace libyarn;
+using namespace testing;
+using namespace Mock;
+
+class MockContainerManagementStub: public TestContainerManagementStub {
+public:
+ MOCK_METHOD0(getContainerManagementProtocol, ContainerManagementProtocol * ());
+};
+
+TEST(TestContainerManagement,TestStartContainer){
+ ContainerManagement client;
+ MockContainerManagementStub stub;
+ string nmHost("localhost");
+ string nmPort("8032");
+ string tokenService = "";
+ Yarn::Config config;
+ Yarn::Internal::SessionConfig sessionConfig(config);
+ Yarn::Internal::UserInfo user = Yarn::Internal::UserInfo::LocalUser();
+ Yarn::Internal::RpcAuth rpcAuth(user, Yarn::Internal::AuthMethod::SIMPLE);
+ MockContainerManagementProtocol *protocol =new MockContainerManagementProtocol(nmHost,nmPort,tokenService,sessionConfig,rpcAuth);
+
+ StringBytesMap map;
+ string key("key");
+ string value("value");
+ map.setKey(key);
+ map.setValue(value);
+ list<StringBytesMap> maps;
+ maps.push_back(map);
+ ContainerId containerId;
+ containerId.setId(501);
+ list<ContainerId> containerIds;
+ containerIds.push_back(containerId);
+ ContainerExceptionMap exceptionMap;
+ exceptionMap.setContainerId(containerId);
+ SerializedException exception;
+ string message("message");
+ string trace("trace");
+ string className("className");
+ exception.setMessage(message);
+ exception.setTrace(trace);
+ exception.setClassName(className);
+ SerializedException cause;
+ string message2("message2");
+ cause.setMessage(message2);
+ exception.setCause(cause);
+ exceptionMap.setSerializedException(exception);
+ list<ContainerExceptionMap> exceptionMaps;
+ exceptionMaps.push_back(exceptionMap);
+ StartContainersResponse response;
+ response.setServicesMetaData(maps);
+ response.setSucceededRequests(containerIds);
+ response.setFailedRequests(exceptionMaps);
+ EXPECT_CALL(*protocol, startContainers(_)).Times(AnyNumber()).WillOnce(Return(response));
+ client.stub = &stub;
+ EXPECT_CALL(stub, getContainerManagementProtocol()).Times(AnyNumber()).WillOnce(Return(protocol));
+
+ Container container;
+ StartContainerRequest request;
+ libyarn::Token nmToken;
+ StartContainerResponse ret = client.startContainer(container,request,nmToken);
+ list<StringBytesMap>::iterator itMap = ret.getServicesMetaData().begin();
+ //EXPECT_EQ(itMap->getKey(), "key");
+ //EXPECT_EQ(itMap->getValue(), "value");
+}
+
+TEST(TestContainerManagement,TestStopContainer){
+ ContainerManagement client;
+ MockContainerManagementStub stub;
+ string nmHost("localhost");
+ string nmPort("8032");
+ string tokenService = "";
+ Yarn::Config config;
+ Yarn::Internal::SessionConfig sessionConfig(config);
+ Yarn::Internal::UserInfo user = Yarn::Internal::UserInfo::LocalUser();
+ Yarn::Internal::RpcAuth rpcAuth(user, Yarn::Internal::AuthMethod::SIMPLE);
+ MockContainerManagementProtocol *protocol =new MockContainerManagementProtocol(nmHost,nmPort,tokenService,sessionConfig,rpcAuth);
+
+ StopContainersResponseProto stopResponseProto;
+ EXPECT_CALL(*protocol, stopContainers(_)).Times(AnyNumber()).WillOnce(Return(StopContainersResponse(stopResponseProto)));
+ client.stub = &stub;
+ EXPECT_CALL(stub, getContainerManagementProtocol()).Times(AnyNumber()).WillOnce(Return(protocol));
+
+ Container container;
+ libyarn::Token nmToken;
+ client.stopContainer(container,nmToken);
+}
+
+TEST(TestContainerManagement,TestGetContainerStatus){
+ ContainerManagement client;
+ MockContainerManagementStub stub;
+ string nmHost("localhost");
+ string nmPort("8032");
+ string tokenService = "";
+ Yarn::Config config;
+ Yarn::Internal::SessionConfig sessionConfig(config);
+ Yarn::Internal::UserInfo user = Yarn::Internal::UserInfo::LocalUser();
+ Yarn::Internal::RpcAuth rpcAuth(user, Yarn::Internal::AuthMethod::SIMPLE);
+ MockContainerManagementProtocol *protocol =new MockContainerManagementProtocol(nmHost,nmPort,tokenService,sessionConfig,rpcAuth);
+
+ GetContainerStatusesResponse getResponse;
+ ContainerId containerId;
+ containerId.setId(501);
+ ContainerStatus status;
+ status.setContainerId(containerId);
+ list<ContainerStatus> statuses;
+ statuses.push_back(status);
+ getResponse.setContainerStatuses(statuses);
+ EXPECT_CALL(*protocol, getContainerStatuses(_)).Times(1).WillOnce(Return(getResponse));
+ client.stub = &stub;
+ EXPECT_CALL(stub, getContainerManagementProtocol()).Times(1).WillRepeatedly(Return(protocol));
+
+ Container container;
+ libyarn::Token nmToken;
+ ContainerStatus retStatus = client.getContainerStatus(container,nmToken);
+ EXPECT_EQ(retStatus.getContainerId().getId(), 501);
+
+ GetContainerStatusesResponse getEmptyResponse;
+ protocol =new MockContainerManagementProtocol(nmHost,nmPort,tokenService,sessionConfig,rpcAuth);
+ EXPECT_CALL(*protocol, getContainerStatuses(_)).Times(1).WillOnce(Return(getEmptyResponse));
+ EXPECT_CALL(stub, getContainerManagementProtocol()).Times(1).WillRepeatedly(Return(protocol));
+
+ retStatus = client.getContainerStatus(container, nmToken);
+ EXPECT_EQ(retStatus.getContainerId().getId(), 0);
+}
+