hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhuvnesh2...@apache.org
Subject [02/48] incubator-hawq git commit: HAWQ-618. Import libhdfs3 library for internal management and LICENSE modified
Date Mon, 04 Apr 2016 05:09:06 GMT
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bc0904ab/depends/libhdfs3/test/unit/TestRpcChannel.cpp
----------------------------------------------------------------------
diff --git a/depends/libhdfs3/test/unit/TestRpcChannel.cpp b/depends/libhdfs3/test/unit/TestRpcChannel.cpp
new file mode 100644
index 0000000..1d6f8cc
--- /dev/null
+++ b/depends/libhdfs3/test/unit/TestRpcChannel.cpp
@@ -0,0 +1,443 @@
+/********************************************************************
+ * Copyright (c) 2013 - 2014, Pivotal Inc.
+ * All rights reserved.
+ *
+ * Author: Zhanwei Wang
+ ********************************************************************/
+/********************************************************************
+ * 2014 -
+ * open source under Apache License Version 2.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 "Atomic.h"
+#include "ClientNamenodeProtocol.pb.h"
+#include "Exception.h"
+#include "ExceptionInternal.h"
+#include "IpcConnectionContext.pb.h"
+#include "Logger.h"
+#include "MockBufferedSocketReader.h"
+#include "MockRpcClient.h"
+#include "MockRpcRemoteCall.h"
+#include "MockSocket.h"
+#include "rpc/RpcChannel.h"
+#include "RpcHeader.pb.h"
+#include "TestUtil.h"
+#include "Thread.h"
+#include "UnitTestUtils.h"
+
+#include <google/protobuf/io/coded_stream.h>
+
+using namespace Hdfs;
+using namespace Hdfs::Mock;
+using namespace Hdfs::Internal;
+using namespace testing;
+using namespace ::google::protobuf;
+using namespace ::google::protobuf::io;
+
+RpcChannelKey BuildKey() {
+    RpcAuth auth;
+    RpcProtocolInfo protocol(0, "test", "kind");
+    RpcServerInfo server("unknown token server", "unknown server", "unknown port");
+    Config conf;
+    SessionConfig session(conf);
+    RpcConfig rpcConf(session);
+    return RpcChannelKey(auth, protocol, server, rpcConf);
+}
+
+static RpcConfig & GetConfig(RpcChannelKey & key) {
+    return const_cast<RpcConfig &>(key.getConf());
+}
+
+static uint32_t GetCallId(uint32_t start) {
+    static Hdfs::Internal::atomic<uint32_t> id(start);
+    return id++;
+}
+
+static void BuildResponse(uint32_t id,
+                          RpcResponseHeaderProto::RpcStatusProto status, const char * errClass,
+                          const char * errMsg, ::google::protobuf::Message * resp, std::vector<char> & output) {
+    WriteBuffer buffer;
+    RpcResponseHeaderProto respHeader;
+    respHeader.set_callid(id);
+    respHeader.set_status(status);
+
+    if (errClass != NULL) {
+        respHeader.set_exceptionclassname(errClass);
+    }
+
+    if (errMsg != NULL) {
+        respHeader.set_errormsg(errMsg);
+    }
+
+    int size = respHeader.ByteSize();
+    int totalSize = size + CodedOutputStream::VarintSize32(size);
+
+    if (resp != NULL) {
+        size = resp->ByteSize();
+        totalSize += size + CodedOutputStream::VarintSize32(size);
+    }
+
+    buffer.writeBigEndian(totalSize);
+    size = respHeader.ByteSize();
+    buffer.writeVarint32(size);
+    respHeader.SerializeToArray(buffer.alloc(size), size);
+
+    if (resp != NULL) {
+        size = resp->ByteSize();
+        buffer.writeVarint32(size);
+        resp->SerializeToArray(buffer.alloc(size), size);
+    }
+
+    output.resize(buffer.getDataSize(0));
+    memcpy(&output[0], buffer.getBuffer(0), buffer.getDataSize(0));
+}
+
+TEST(TestRpcChannel, TestConnectFailure) {
+    RpcChannelKey key = BuildKey();
+    MockRpcClient client;
+    EXPECT_CALL(client, getClientId()).Times(AnyNumber()).WillRepeatedly(Return(""));
+    MockSocket * sock = new MockSocket();
+    MockBufferedSocketReader * in = new MockBufferedSocketReader();
+    GetConfig(key).setMaxRetryOnConnect(2);
+    EXPECT_CALL(*sock, connect(An<const char *>(), An<const char *>(), _)).Times(2).WillOnce(
+        InvokeWithoutArgs(bind(&InvokeThrow<Hdfs::HdfsNetworkException>,
+                               "test expected connect failed",
+                               static_cast<bool *>(NULL)))).WillOnce(
+                                   InvokeWithoutArgs(
+                                       bind(&InvokeThrow<Hdfs::HdfsTimeoutException>,
+                                            "test expected connect timeout",
+                                            static_cast<bool *>(NULL))));
+    EXPECT_CALL(*sock, close()).Times(2);
+    RpcChannelImpl channel(key, sock, in, client);
+    EXPECT_THROW(DebugException(channel.connect()), Hdfs::HdfsTimeoutException);
+}
+
+TEST(TestRpcChannel, TestConnectSuccess) {
+    RpcChannelKey key = BuildKey();
+    MockRpcClient client;
+    EXPECT_CALL(client, getClientId()).Times(AnyNumber()).WillRepeatedly(Return(""));
+    MockSocket * sock = new MockSocket();
+    MockBufferedSocketReader * in = new MockBufferedSocketReader();
+    GetConfig(key).setMaxRetryOnConnect(1);
+    EXPECT_CALL(*sock, connect(An<const char *>(), An<const char *>(), _)).Times(1);
+    EXPECT_CALL(*sock, close()).Times(1);
+    EXPECT_CALL(*sock, setNoDelay(_)).Times(1);
+    EXPECT_CALL(*sock, writeFully(_, _, _)).Times(2);
+    RpcChannelImpl channel(key, sock, in, client);
+    EXPECT_NO_THROW(DebugException(channel.connect()));
+    EXPECT_TRUE(channel.available);
+}
+
+TEST(TestRpcChannel, TestCancelPendingCall) {
+    RpcChannelKey key = BuildKey();
+    MockRpcClient client;
+    EXPECT_CALL(client, getClientId()).Times(AnyNumber()).WillRepeatedly(Return(""));
+    MockSocket * sock = new MockSocket();
+    MockBufferedSocketReader * in = new MockBufferedSocketReader();
+    RpcRemoteCallPtr call = RpcRemoteCallPtr(
+                                new MockRpcRemoteCall(RpcCall(false, "", NULL, NULL), 0, ""));
+    EXPECT_CALL(*sock, close()).Times(1);
+    EXPECT_CALL(*static_cast<MockRpcRemoteCall *>(call.get()), cancel(_)).Times(1);
+    RpcChannelImpl channel(key, sock, in, client);
+    channel.available = true;
+    channel.pendingCalls[call->getIdentity()] = call;
+
+    try {
+        THROW(HdfsNetworkException, "expected exception");
+    } catch (...) {
+        Hdfs::Internal::lock_guard<Hdfs::Internal::mutex> lock(channel.writeMut);
+        EXPECT_NO_THROW(DebugException(channel.cleanupPendingCalls(Hdfs::current_exception())));
+    }
+}
+
+TEST(TestRpcChannel, TestCheckResponse_InvalidResponse) {
+    RpcChannelKey key = BuildKey();
+    MockRpcClient client;
+    EXPECT_CALL(client, getClientId()).Times(AnyNumber()).WillRepeatedly(Return(""));
+    MockSocket * sock = new MockSocket();
+    MockBufferedSocketReader * in = new MockBufferedSocketReader();
+    EXPECT_CALL(*in, readBigEndianInt32(_)).Times(1).WillOnce(Return(100));
+    EXPECT_CALL(*in, readVarint32(_)).Times(1).WillOnce(Return(0));
+    EXPECT_CALL(*in, readFully(_, _, _)).Times(1);
+    EXPECT_CALL(client, isRunning()).Times(AnyNumber()).WillRepeatedly(
+        Return(true));
+    EXPECT_CALL(*sock, close()).Times(1);
+    RpcChannelImpl channel(key, sock, in, client);
+    channel.available = true;
+    EXPECT_THROW(channel.readOneResponse(false), HdfsRpcException);
+}
+
+TEST(TestRpcChannel, TestCheckResponse_InvalidCallId) {
+    std::vector<char> resp;
+    BuildResponse(0, RpcResponseHeaderProto_RpcStatusProto_SUCCESS, NULL, NULL, NULL, resp);
+    RpcChannelKey key = BuildKey();
+    MockRpcClient client;
+    EXPECT_CALL(client, getClientId()).Times(AnyNumber()).WillRepeatedly(Return(""));
+    MockSocket * sock = new MockSocket();
+    BufferedSocketReaderImpl * in = new BufferedSocketReaderImpl(*sock, resp);
+    EXPECT_CALL(*sock, close()).Times(1);
+    EXPECT_CALL(client, isRunning()).Times(AnyNumber()).WillRepeatedly(
+        Return(true));
+    RpcChannelImpl channel(key, sock, in, client);
+    channel.available = true;
+    EXPECT_THROW(channel.readOneResponse(false), HdfsRpcException);
+}
+
+TEST(TestRpcChannel, TestCheckResponse_SendPing) {
+    RpcChannelKey key = BuildKey();
+    MockRpcClient client;
+    EXPECT_CALL(client, getClientId()).Times(AnyNumber()).WillRepeatedly(Return(""));
+    MockSocket * sock = new MockSocket();
+    MockBufferedSocketReader * in = new MockBufferedSocketReader();
+    GetConfig(key).setMaxRetryOnConnect(1);
+    GetConfig(key).setMaxIdleTime(1000);
+    GetConfig(key).setPingTimeout(400);
+    EXPECT_CALL(*sock, close()).Times(1);
+    EXPECT_CALL(*sock, writeFully(_, _, _)).Times(1);
+    EXPECT_CALL(*in, poll(_)).Times(2).WillOnce(
+        InvokeWithoutArgs(bind(&InvokeWaitAndReturn<bool>, 500, false, 0))).WillOnce(
+            InvokeWithoutArgs(
+                bind(&InvokeThrowAndReturn<HdfsNetworkException, bool>,
+                     "expected exception", static_cast<bool *>(NULL),
+                     false)));
+    EXPECT_CALL(client, isRunning()).Times(AnyNumber()).WillRepeatedly(
+        Return(true));
+    RpcChannelImpl channel(key, sock, in, client);
+    channel.lastActivity = steady_clock::now();
+    channel.available = true;
+    EXPECT_THROW(channel.checkOneResponse(), HdfsNetworkException);
+}
+
+TEST(TestRpcChannel, TestCheckResponse_ErrorResponse) {
+    std::vector<char> resp;
+    const char * errClass = "test error class";
+    const char * errMsg = "test error message";
+    BuildResponse(0, RpcResponseHeaderProto_RpcStatusProto_ERROR, errClass, errMsg, NULL, resp);
+    RpcChannelKey key = BuildKey();
+    MockRpcClient client;
+    EXPECT_CALL(client, getClientId()).Times(AnyNumber()).WillRepeatedly(Return(""));
+    MockSocket * sock = new MockSocket();
+    BufferedSocketReaderImpl * in = new BufferedSocketReaderImpl(*sock, resp);
+    RpcRemoteCallPtr call = RpcRemoteCallPtr(
+                                new MockRpcRemoteCall(RpcCall(false, "", NULL, NULL), 0, ""));
+    EXPECT_CALL(client, isRunning()).Times(AnyNumber()).WillRepeatedly(
+        Return(true));
+    EXPECT_CALL(*sock, close()).Times(1);
+    EXPECT_CALL(*static_cast<MockRpcRemoteCall *>(call.get()), cancel(_)).Times(1);
+    RpcChannelImpl channel(key, sock, in, client);
+    channel.available = true;
+    channel.pendingCalls[call->getIdentity()] = call;
+    EXPECT_NO_THROW(DebugException(channel.readOneResponse(false)));
+}
+
+TEST(TestRpcChannel, TestCheckResponse_FatalResponse1) {
+    std::vector<char> resp;
+    const char * errMsg = "test fatal message";
+    BuildResponse(0, RpcResponseHeaderProto_RpcStatusProto_FATAL, NULL, errMsg, NULL, resp);
+    RpcChannelKey key = BuildKey();
+    MockRpcClient client;
+    EXPECT_CALL(client, getClientId()).Times(AnyNumber()).WillRepeatedly(Return(""));
+    MockSocket * sock = new MockSocket();
+    BufferedSocketReaderImpl * in = new BufferedSocketReaderImpl(*sock, resp);
+    EXPECT_CALL(client, isRunning()).Times(AnyNumber()).WillRepeatedly(
+        Return(true));
+    EXPECT_CALL(*sock, close()).Times(1);
+    RpcChannelImpl channel(key, sock, in, client);
+    channel.available = true;
+    EXPECT_THROW(DebugException(channel.readOneResponse(false)), HdfsRpcException);
+}
+
+TEST(TestRpcChannel, TestCheckResponse_FatalResponse2) {
+    std::vector<char> resp;
+    const char * errClass = "org.apache.hadoop.ipc.StandbyException";
+    const char * errMsg = "test fatal message";
+    BuildResponse(0, RpcResponseHeaderProto_RpcStatusProto_FATAL, errClass, errMsg, NULL, resp);
+    RpcChannelKey key = BuildKey();
+    MockRpcClient client;
+    EXPECT_CALL(client, getClientId()).Times(AnyNumber()).WillRepeatedly(Return(""));
+    MockSocket * sock = new MockSocket();
+    BufferedSocketReaderImpl * in = new BufferedSocketReaderImpl(*sock, resp);
+    EXPECT_CALL(client, isRunning()).Times(AnyNumber()).WillRepeatedly(
+        Return(true));
+    EXPECT_CALL(*sock, close()).Times(1);
+    RpcChannelImpl channel(key, sock, in, client);
+    channel.available = true;
+    EXPECT_THROW(DebugException(channel.readOneResponse(false)), NameNodeStandbyException);
+}
+
+TEST(TestRpcChannel, TestInvoke_RetryIdempotent) {
+    std::vector<char> respBody;
+    MockRpcClient client;
+    uint32_t callid = 2;
+    EXPECT_CALL(client, getClientId()).Times(AnyNumber()).WillRepeatedly(Return(""));
+    EXPECT_CALL(client, getCallId()).Times(AnyNumber()).WillRepeatedly(Return(callid));
+    MkdirsRequestProto request;
+    MkdirsResponseProto response, resp;
+    request.set_src("src");
+    request.set_createparent(true);
+    request.mutable_masked()->set_perm(0600u);
+    resp.set_result(true);
+    BuildResponse(callid, RpcResponseHeaderProto_RpcStatusProto_SUCCESS, NULL, NULL, &resp, respBody);
+    MockSocket * sock = new MockSocket();
+    RpcChannelKey key = BuildKey();
+    BufferedSocketReaderImpl * in = new BufferedSocketReaderImpl(*sock, respBody);
+    EXPECT_CALL(client, isRunning()).Times(AnyNumber()).WillRepeatedly(
+        Return(true));
+    EXPECT_CALL(*sock, connect(An<const char *>(), An<const char *>(), _)).Times(1);
+    EXPECT_CALL(*sock, setNoDelay(_)).Times(1);
+    EXPECT_CALL(*sock, close()).Times(AtLeast(2));
+    EXPECT_CALL(*sock, writeFully(_, _, _)).Times(4).WillOnce(
+        InvokeWithoutArgs(
+            bind(&InvokeThrow<HdfsNetworkConnectException>,
+                 "expected exception", static_cast<bool *>(NULL)))).WillRepeatedly(
+                     InvokeWithoutArgs(&InvokeDoNothing));
+    RpcChannelImpl channel(key, sock, in, client);
+    channel.available = true;
+    channel.addRef();
+    EXPECT_NO_THROW(DebugException(channel.invoke(RpcCall(true, "mkdirs", &request, &response))));
+    channel.close(false);
+}
+
+static void InvokeConcurrently(RpcChannelImpl * channel) {
+    MkdirsRequestProto request;
+    MkdirsResponseProto response;
+    request.set_src("src");
+    request.set_createparent(true);
+    request.mutable_masked()->set_perm(0600u);
+    channel->addRef();
+    EXPECT_THROW(DebugException(channel->invoke(RpcCall(true, "mkdirs", &request, &response))),
+                 HdfsRpcException);
+    channel->close(false);
+}
+
+TEST(TestRpcChannel, TestInvokeConcurrently_FatalError) {
+    bool throwError = false;
+    MockRpcClient client;
+    EXPECT_CALL(client, getClientId()).Times(AnyNumber()).WillRepeatedly(Return(""));
+    EXPECT_CALL(client, getCallId()).Times(AnyNumber()).WillRepeatedly(
+        InvokeWithoutArgs(bind(GetCallId, 0)));
+    RpcChannelKey key = BuildKey();
+    MockSocket * sock = new MockSocket();
+    MockBufferedSocketReader * in = new MockBufferedSocketReader();
+    EXPECT_CALL(client, isRunning()).Times(AnyNumber()).WillRepeatedly(
+        Return(true));
+    EXPECT_CALL(*in, poll(_)).Times(AnyNumber()).WillRepeatedly(
+        InvokeWithoutArgs(
+            bind(&InvokeThrowAndReturn<HdfsNetworkException, bool>,
+                 "expected exception", &throwError, false)));
+    EXPECT_CALL(*sock, writeFully(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        InvokeWithoutArgs(&InvokeDoNothing));
+    EXPECT_CALL(*sock, close()).Times(AnyNumber());
+    EXPECT_CALL(*sock, setNoDelay(_)).Times(AnyNumber());
+    RpcChannelImpl channel(key, sock, in, client);
+    EXPECT_CALL(*sock, connect(An<const char *>(), An<const char *>(), _)).Times(
+        AnyNumber()).WillRepeatedly(Assign(&channel.available, true));
+    std::vector<std::shared_ptr<thread> > threads;
+    int numOfThread = 50;
+
+    for (int i = 0; i < numOfThread; ++i) {
+        threads.push_back(
+            std::shared_ptr<thread>(
+                new thread(InvokeConcurrently, &channel)));
+    }
+
+    sleep_for(seconds(5));
+    throwError = true;
+
+    for (size_t i = 0; i < threads.size(); ++i) {
+        threads[i]->join();
+    }
+}
+
+TEST(TestRpcChannel, TestInvokeConcurrently_ClientExit) {
+    bool clientIsRunning = true;
+    MockRpcClient client;
+    EXPECT_CALL(client, getClientId()).Times(AnyNumber()).WillRepeatedly(Return(""));
+    RpcChannelKey key = BuildKey();
+    MockSocket * sock = new MockSocket();
+    MockBufferedSocketReader * in = new MockBufferedSocketReader();
+    EXPECT_CALL(client, isRunning()).Times(AnyNumber()).WillRepeatedly(
+        ReturnPointee(&clientIsRunning));
+    EXPECT_CALL(*in, poll(_)).Times(AnyNumber()).WillRepeatedly(Return(false));
+    EXPECT_CALL(*sock, writeFully(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        InvokeWithoutArgs(&InvokeDoNothing));
+    EXPECT_CALL(*sock, close()).Times(AnyNumber());
+    RpcChannelImpl channel(key, sock, in, client);
+    channel.available = true;
+    std::vector<std::shared_ptr<thread> > threads;
+    EXPECT_CALL(client, getCallId()).Times(AnyNumber()).WillRepeatedly(
+        InvokeWithoutArgs(bind(GetCallId, 0)));
+    int numOfThread = 50;
+
+    for (int i = 0; i < numOfThread; ++i) {
+        threads.push_back(
+            std::shared_ptr<thread>(
+                new thread(InvokeConcurrently, &channel)));
+    }
+
+    for (int i = 0 ; i < 5; ++i) {
+        channel.checkIdle();
+        sleep_for(seconds(1));
+    }
+
+    clientIsRunning = false;
+
+    for (size_t i = 0; i < threads.size(); ++i) {
+        threads[i]->join();
+    }
+}
+
+
+static void TestTimeout(RpcChannelImpl & channel, RpcCall & call) {
+    try {
+        channel.invoke(call);
+    } catch (const HdfsRpcException & e) {
+        Hdfs::rethrow_if_nested(e);
+    }
+}
+
+TEST(TestRpcChannel, TestTimeout) {
+    MockRpcClient client;
+    EXPECT_CALL(client, getClientId()).Times(AnyNumber()).WillRepeatedly(Return(""));
+    EXPECT_CALL(client, getCallId()).Times(AnyNumber()).WillRepeatedly(InvokeWithoutArgs(bind(GetCallId, 0)));
+    RpcChannelKey key = BuildKey();
+    GetConfig(key).setRpcTimeout(1000);
+    MockSocket * sock = new MockSocket();
+    MockBufferedSocketReader * in = new MockBufferedSocketReader();
+    EXPECT_CALL(client, isRunning()).Times(AnyNumber()).WillRepeatedly(Return(true));
+    EXPECT_CALL(*sock, writeFully(_, _, _)).Times(AnyNumber()).WillRepeatedly(Return());
+    EXPECT_CALL(*sock, close()).Times(AnyNumber()).WillRepeatedly(Return());
+    EXPECT_CALL(*in, poll(_)).Times(AnyNumber()).WillRepeatedly(Return(false));
+    RpcChannelImpl channel(key, sock, in, client);
+    channel.available = true;
+    ++channel.refs;
+    MkdirsRequestProto request;
+    MkdirsResponseProto response;
+    request.set_src("src");
+    request.set_createparent(true);
+    request.mutable_masked()->set_perm(0600u);
+    RpcCall call(false, "mkdirs", &request, &response);
+    EXPECT_THROW(TestTimeout(channel, call), HdfsTimeoutException);
+    --channel.refs;
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bc0904ab/depends/libhdfs3/test/unit/TestRpcClient.cpp
----------------------------------------------------------------------
diff --git a/depends/libhdfs3/test/unit/TestRpcClient.cpp b/depends/libhdfs3/test/unit/TestRpcClient.cpp
new file mode 100644
index 0000000..a2e8d25
--- /dev/null
+++ b/depends/libhdfs3/test/unit/TestRpcClient.cpp
@@ -0,0 +1,110 @@
+/********************************************************************
+ * Copyright (c) 2013 - 2014, Pivotal Inc.
+ * All rights reserved.
+ *
+ * Author: Zhanwei Wang
+ ********************************************************************/
+/********************************************************************
+ * 2014 -
+ * open source under Apache License Version 2.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 "Exception.h"
+#include "MockBufferedSocketReader.h"
+#include "MockRpcChannel.h"
+#include "MockSocket.h"
+#include "rpc/RpcClient.h"
+#include "TestRpcChannelStub.h"
+#include "UnitTestUtils.h"
+#include "XmlConfig.h"
+
+using namespace Hdfs;
+using namespace Hdfs::Mock;
+using namespace Hdfs::Internal;
+using namespace testing;
+
+class MockRpcChannelStub: public TestRpcChannelStub {
+public:
+    MOCK_METHOD2(getChannel, RpcChannel * (
+                     RpcChannelKey key, RpcClient & c));
+};
+
+static RpcChannelKey BuildKey() {
+    RpcAuth auth;
+    RpcProtocolInfo protocol(0, "test", "kind");
+    RpcServerInfo server("unknown token service", "unknown server", "unknown port");
+    Config conf;
+    SessionConfig session(conf);
+    RpcConfig rpcConf(session);
+    return RpcChannelKey(auth, protocol, server, rpcConf);
+}
+
+static RpcConfig & GetConfig(RpcChannelKey & key) {
+    return const_cast<RpcConfig &>(key.getConf());
+}
+
+TEST(TestRpcClient, TestInvoke_CreateChannelFailure) {
+    RpcAuth auth;
+    RpcProtocolInfo protocol(0, "test", "kind");
+    RpcServerInfo server("unknown token service", "unknown server", "unknown port");
+    Config conf;
+    SessionConfig session(conf);
+    RpcConfig rpcConf(session);
+    MockRpcChannelStub stub;
+    RpcClientImpl client;
+    client.stub = &stub;
+    EXPECT_CALL(stub, getChannel(_, _)).Times(1).WillOnce(
+        InvokeWithoutArgs(
+            bind(&InvokeThrowAndReturn<HdfsIOException, RpcChannel *>,
+                 "create channel failed.", static_cast<bool *>(NULL),
+                 static_cast<RpcChannel *>(NULL))));
+    EXPECT_THROW(client.getChannel(auth, protocol, server, rpcConf),
+                 HdfsRpcException);
+}
+
+TEST(TestRpcClient, TestCleanupIdleChannel) {
+    RpcAuth auth;
+    RpcProtocolInfo protocol(0, "test", "kind");
+    RpcServerInfo server("unknown token service", "unknown server", "unknown port");
+    Config conf;
+    SessionConfig session(conf);
+    RpcConfig rpcConf(session);
+    MockRpcChannelStub stub;
+    RpcClientImpl client;
+    client.stub = &stub;
+    RpcChannelKey key = BuildKey();
+    GetConfig(key).setMaxIdleTime(10000);
+    GetConfig(key).setPingTimeout(900);
+    MockSocket * sock = new MockSocket();
+    MockBufferedSocketReader * in = new MockBufferedSocketReader();
+    RpcChannelImpl * channel = new RpcChannelImpl(key, sock, in, client);
+    EXPECT_CALL(stub, getChannel(_, _)).Times(1).WillOnce(Return(channel));
+    channel->lastActivity = channel->lastIdle = steady_clock::now();
+    channel->available = true;
+    EXPECT_CALL(*sock, close()).Times(AtLeast(1));
+    EXPECT_CALL(*sock, writeFully(_, _, _)).Times(AtLeast(1));
+    sleep_for(seconds(1));
+    EXPECT_NO_THROW(client.getChannel(auth, protocol, server, rpcConf));
+    EXPECT_TRUE(channel->refs == 1);
+    channel->close(false);
+    sleep_for(seconds(3));
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bc0904ab/depends/libhdfs3/test/unit/TestSessionConfig.cpp
----------------------------------------------------------------------
diff --git a/depends/libhdfs3/test/unit/TestSessionConfig.cpp b/depends/libhdfs3/test/unit/TestSessionConfig.cpp
new file mode 100644
index 0000000..503e6ef
--- /dev/null
+++ b/depends/libhdfs3/test/unit/TestSessionConfig.cpp
@@ -0,0 +1,39 @@
+/********************************************************************
+ * Copyright (c) 2013 - 2014, Pivotal Inc.
+ * All rights reserved.
+ *
+ * Author: Zhanwei Wang
+ ********************************************************************/
+/********************************************************************
+ * 2014 -
+ * open source under Apache License Version 2.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 "SessionConfig.h"
+#include "XmlConfig.h"
+
+using namespace Hdfs;
+using namespace Hdfs::Internal;
+
+TEST(TestSessionConfig, TestSelect) {
+    Config conf;
+    SessionConfig session(conf);
+    ASSERT_STREQ("hdfs://localhost:9000", session.getDefaultUri().c_str());
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bc0904ab/depends/libhdfs3/test/unit/TestSocket.cpp
----------------------------------------------------------------------
diff --git a/depends/libhdfs3/test/unit/TestSocket.cpp b/depends/libhdfs3/test/unit/TestSocket.cpp
new file mode 100644
index 0000000..b3cdb2d
--- /dev/null
+++ b/depends/libhdfs3/test/unit/TestSocket.cpp
@@ -0,0 +1,456 @@
+/********************************************************************
+ * Copyright (c) 2013 - 2014, Pivotal Inc.
+ * All rights reserved.
+ *
+ * Author: Zhanwei Wang
+ ********************************************************************/
+/********************************************************************
+ * 2014 -
+ * open source under Apache License Version 2.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 <errno.h>
+#include <netdb.h>
+#include <sys/socket.h>
+
+#include "Exception.h"
+#include "ExceptionInternal.h"
+#include "MockOperationCanceledCallback.h"
+#include "MockSockCall.h"
+#include "MockSystem.h"
+#include "network/TcpSocket.h"
+#include "Thread.h"
+#include "UnitTestUtils.h"
+
+using namespace Hdfs;
+using namespace Hdfs::Mock;
+using namespace Hdfs::Internal;
+using namespace MockSystem;
+using namespace testing;
+
+class TestSocket: public ::testing::Test {
+public:
+    virtual void SetUp() {
+        MockSockSysCallObj = &syscall;
+    }
+
+    virtual void TearDown() {
+        MockSockSysCallObj = NULL;
+        ChecnOperationCanceledCallback = function<bool(void)>();
+    }
+
+public:
+    MockSockSysCall syscall;
+};
+
+static int32_t ReadAction(int sock, void * buffer, int32_t size, int flag,
+                          const void * target, int32_t tsize) {
+    assert(size >= tsize);
+    memcpy(buffer, target, tsize);
+    return tsize;
+}
+
+static int32_t WriteAction(int sock, const void * buffer, int32_t size,
+                           int flag, void * target, int32_t tsize) {
+    int32_t retval = size < tsize ? size : tsize;
+    memcpy(target, buffer, tsize);
+    return retval;
+}
+
+TEST_F(TestSocket, ConnectFailure_Socket) {
+    struct addrinfo addr;
+    TcpSocketImpl sock;
+    EXPECT_CALL(syscall, socket(_, _, _)).Times(1).WillOnce(Return(-1));
+    EXPECT_THROW(sock.connect(&addr, "host", "port", 1000),
+                 HdfsNetworkException);
+}
+
+TEST_F(TestSocket, ConnectFailure_Fcntl) {
+    struct addrinfo addr;
+    TcpSocketImpl sock;
+    EXPECT_CALL(syscall, socket(_, _, _)).Times(2).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, close(_)).Times(2).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(2).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, setsockopt(_,_,_,_,_)).Times(AnyNumber()).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, fcntl(_, _, _)).Times(3).WillOnce(Return(-1)).WillOnce(
+        Return(0)).WillOnce(Return(-1));
+    EXPECT_THROW(sock.connect(&addr, "host", "port", 1000),
+                 HdfsNetworkException);
+    EXPECT_THROW(sock.connect(&addr, "host", "port", 1000),
+                 HdfsNetworkException);
+}
+
+#ifdef SO_NOSIGPIPE
+TEST_F(TestSocket, ConnectFailure_Setsockopt) {
+    struct addrinfo addr;
+    TcpSocketImpl sock;
+    EXPECT_CALL(syscall, socket(_, _, _)).Times(1).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, close(_)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, fcntl(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, setsockopt(_, _, _, _, _)).Times(1).WillOnce(
+        Return(-1));
+    EXPECT_THROW(sock.connect(&addr, "host", "port", 1000),
+                 HdfsNetworkException);
+}
+#endif
+
+TEST_F(TestSocket, ConnectFailure_ConnectRefused) {
+    struct addrinfo addr;
+    TcpSocketImpl sock;
+    EXPECT_CALL(syscall, socket(_, _, _)).Times(1).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, close(_)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, fcntl(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, setsockopt(_, _, _, _, _)).Times(AnyNumber()).WillOnce(
+        Return(0));
+    EXPECT_CALL(syscall, connect(_, _, _)).Times(1).WillOnce(
+        SetErrnoAndReturn(ECONNREFUSED, -1));
+    EXPECT_THROW(sock.connect(&addr, "host", "port", 1000),
+                 HdfsNetworkException);
+}
+
+TEST_F(TestSocket, ConnectFailure_ConnectInterupted) {
+    struct addrinfo addr;
+    TcpSocketImpl sock;
+    MockOperationCanceledCallback * mockCancelObj =
+        new MockOperationCanceledCallback;
+    MockCancelObject * mockCancel = mockCancelObj;
+    EXPECT_CALL(syscall, socket(_, _, _)).Times(2).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, close(_)).Times(2).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(2).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, fcntl(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, setsockopt(_, _, _, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, connect(_, _, _)).Times(3).WillOnce(
+        SetErrnoAndReturn(EINTR, -1)).WillOnce(SetErrnoAndReturn(EINTR, -1)).WillOnce(
+            SetErrnoAndReturn(ECONNREFUSED, -1));
+    EXPECT_CALL(*mockCancelObj, check()).Times(2).WillOnce(Return(true)).WillOnce(
+        Return(false));
+    ChecnOperationCanceledCallback = bind(&MockCancelObject::canceled,
+                                          mockCancel);
+    EXPECT_THROW(sock.connect(&addr, "host", "port", 1000), HdfsCanceled);
+    EXPECT_THROW(sock.connect(&addr, "host", "port", 1000),
+                 HdfsNetworkException);
+    delete mockCancelObj;
+}
+
+TEST_F(TestSocket, ConnectFailure_Poll) {
+    struct addrinfo addr;
+    TcpSocketImpl sock;
+    EXPECT_CALL(syscall, socket(_, _, _)).Times(2).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, close(_)).Times(2).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(2).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, fcntl(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, setsockopt(_, _, _, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, connect(_, _, _)).Times(2).WillRepeatedly(
+        SetErrnoAndReturn(EINPROGRESS, -1));
+    EXPECT_CALL(syscall, poll(_, _, _)).Times(2).WillOnce(
+        SetErrnoAndReturn(EAGAIN, -1)).WillOnce(Return(0));
+    EXPECT_THROW(sock.connect(&addr, "host", "port", 1000),
+                 HdfsNetworkException);
+    EXPECT_THROW(sock.connect(&addr, "host", "port", 1000), HdfsTimeoutException);
+}
+
+TEST_F(TestSocket, ConnectFailure_Timeout) {
+    struct addrinfo addr;
+    TcpSocketImpl sock;
+    EXPECT_CALL(syscall, socket(_, _, _)).Times(2).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, close(_)).Times(2).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(2).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, fcntl(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, setsockopt(_, _, _, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, connect(_, _, _)).Times(2).WillOnce(
+        SetErrnoAndReturn(ETIMEDOUT, -1)).WillOnce(
+            SetErrnoAndReturn(EINPROGRESS, -1));
+    EXPECT_CALL(syscall, poll(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(1));
+    EXPECT_CALL(syscall, getpeername(_, _, _)).Times(1).WillOnce(Return(-1));
+    EXPECT_CALL(syscall, recv(_, _, _, _)).Times(1).WillOnce(
+        SetErrnoAndReturn(ETIMEDOUT, -1));
+    EXPECT_THROW(sock.connect(&addr, "host", "port", 1000), HdfsTimeoutException);
+    EXPECT_THROW(sock.connect(&addr, "host", "port", 1000), HdfsTimeoutException);
+}
+
+TEST_F(TestSocket, ConnectFailure_ConnectFailed) {
+    struct addrinfo addr;
+    TcpSocketImpl sock;
+    EXPECT_CALL(syscall, socket(_, _, _)).Times(1).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, close(_)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, fcntl(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, setsockopt(_, _, _, _, _)).Times(AnyNumber()).WillOnce(
+        Return(0));
+    EXPECT_CALL(syscall, connect(_, _, _)).Times(1).WillOnce(
+        SetErrnoAndReturn(EINPROGRESS, -1));
+    EXPECT_CALL(syscall, poll(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(1));
+    EXPECT_CALL(syscall, getpeername(_, _, _)).Times(1).WillOnce(Return(-1));
+    EXPECT_CALL(syscall, recv(_, _, _, _)).Times(1).WillOnce(
+        SetErrnoAndReturn(ECONNREFUSED, -1));
+    EXPECT_THROW(sock.connect(&addr, "host", "port", 1000),
+                 HdfsNetworkException);
+}
+
+TEST_F(TestSocket, ConnectSuccess) {
+    struct addrinfo addr;
+    TcpSocketImpl sock;
+    EXPECT_CALL(syscall, socket(_, _, _)).Times(1).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, close(_)).Times(1);
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, fcntl(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, setsockopt(_, _, _, _, _)).Times(AnyNumber()).WillOnce(
+        Return(0));
+    EXPECT_CALL(syscall, connect(_, _, _)).Times(1).WillOnce(
+        SetErrnoAndReturn(EINPROGRESS, -1));
+    EXPECT_CALL(syscall, poll(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(1));
+    EXPECT_CALL(syscall, getpeername(_, _, _)).Times(1).WillOnce(Return(0));
+    EXPECT_CALL(syscall, recv(_, _, _, _)).Times(0);
+    EXPECT_NO_THROW(sock.connect(&addr, "host", "port", 1000));
+}
+
+TEST_F(TestSocket, ConnectMultiAddrFailure_Getaddrinfo) {
+    TcpSocketImpl sock;
+    EXPECT_CALL(syscall, getaddrinfo(_, _, _, _)).Times(1).WillOnce(
+        Return(EAI_MEMORY));
+    EXPECT_CALL(syscall, freeaddrinfo(_)).Times(0);
+    EXPECT_THROW(sock.connect("host", "port", 1000), HdfsNetworkException);
+}
+
+TEST_F(TestSocket, ConnectMultiAddrFailure_ThrowLastError) {
+    TcpSocketImpl sock;
+    struct addrinfo addr[2];
+    addr[0].ai_next = &addr[1];
+    addr[1].ai_next = NULL;
+    EXPECT_CALL(syscall, getaddrinfo(_, _, _, _)).Times(1).WillOnce(
+        DoAll(SetArgPointee<3>(&addr[0]), Return(0)));
+    EXPECT_CALL(syscall, freeaddrinfo(_)).Times(1).WillOnce(Return());
+    EXPECT_CALL(syscall, socket(_, _, _)).Times(1).WillRepeatedly(
+        SetErrnoAndReturn(ENFILE, -1));
+    EXPECT_THROW(sock.connect("host", "port", 1000), HdfsNetworkException);
+}
+
+TEST_F(TestSocket, ConnectMultiAddrFailure_Canceled) {
+    TcpSocketImpl sock;
+    struct addrinfo addr[2];
+    addr[0].ai_next = &addr[1];
+    addr[1].ai_next = NULL;
+    MockOperationCanceledCallback * mockCancelObj =
+        new MockOperationCanceledCallback;
+    MockCancelObject * mockCancel = mockCancelObj;
+    EXPECT_CALL(syscall, getaddrinfo(_, _, _, _)).Times(1).WillOnce(
+        DoAll(SetArgPointee<3>(&addr[0]), Return(0)));
+    EXPECT_CALL(syscall, freeaddrinfo(_)).Times(1).WillOnce(Return());
+    EXPECT_CALL(*mockCancelObj, check()).Times(1).WillOnce(Return(true));
+    ChecnOperationCanceledCallback = bind(&MockCancelObject::canceled,
+                                          mockCancel);
+    EXPECT_THROW(sock.connect("host", "port", 1000), HdfsCanceled);
+    delete mockCancelObj;
+}
+
+TEST_F(TestSocket, ConnectMultiAddrFailure_Timeout) {
+    TcpSocketImpl sock;
+    struct addrinfo addr[2];
+    addr[0].ai_next = &addr[1];
+    addr[1].ai_next = NULL;
+    EXPECT_CALL(syscall, getaddrinfo(_, _, _, _)).Times(2).WillRepeatedly(
+        DoAll(SetArgPointee<3>(&addr[0]), Return(0)));
+    EXPECT_CALL(syscall, freeaddrinfo(_)).Times(2).WillRepeatedly(Return());
+    EXPECT_CALL(syscall, socket(_, _, _)).Times(3).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, fcntl(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, setsockopt(_, _, _, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, poll(_, _, _)).Times(AnyNumber()).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, close(_)).Times(3);
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(3).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, connect(_, _, _)).Times(3).WillRepeatedly(
+        SetErrnoAndReturn(EINPROGRESS, -1));
+    EXPECT_THROW(sock.connect("host", "port", 0), HdfsTimeoutException);
+    sock.close();
+    EXPECT_THROW(sock.connect("host", "port", 900), HdfsTimeoutException);
+}
+
+TEST_F(TestSocket, ConnectMultiAddrSuccessfully) {
+    TcpSocketImpl sock;
+    EXPECT_CALL(syscall, socket(_, _, _)).Times(1).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, close(_)).Times(1);
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, fcntl(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, setsockopt(_, _, _, _, _)).Times(AnyNumber()).WillOnce(
+        Return(0));
+    EXPECT_CALL(syscall, connect(_, _, _)).Times(1).WillOnce(
+        SetErrnoAndReturn(EINPROGRESS, -1));
+    EXPECT_CALL(syscall, poll(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(1));
+    EXPECT_CALL(syscall, getpeername(_, _, _)).Times(1).WillOnce(Return(0));
+    EXPECT_CALL(syscall, recv(_, _, _, _)).Times(0);
+    struct addrinfo addr[2];
+    addr[0].ai_next = &addr[1];
+    addr[1].ai_next = NULL;
+    EXPECT_CALL(syscall, getaddrinfo(_, _, _, _)).Times(1).WillRepeatedly(
+        DoAll(SetArgPointee<3>(&addr[0]), Return(0)));
+    EXPECT_CALL(syscall, freeaddrinfo(_)).Times(1).WillRepeatedly(Return());
+    EXPECT_NO_THROW(sock.connect("host", "port", 0));
+}
+
+TEST_F(TestSocket, ConnectMultiAddrFinallySuccess) {
+    TcpSocketImpl sock;
+    EXPECT_CALL(syscall, socket(_, _, _)).Times(2).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, close(_)).Times(2);
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(2).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, fcntl(_, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, setsockopt(_, _, _, _, _)).Times(AnyNumber()).WillRepeatedly(
+        Return(0));
+    EXPECT_CALL(syscall, connect(_, _, _)).Times(2).WillRepeatedly(
+        SetErrnoAndReturn(EINPROGRESS, -1));
+    EXPECT_CALL(syscall, poll(_, _, _)).Times(AnyNumber()).WillOnce(
+        Return(0)).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, getpeername(_, _, _)).Times(1).WillOnce(Return(0));
+    struct addrinfo addr[2];
+    addr[0].ai_next = &addr[1];
+    addr[1].ai_next = NULL;
+    EXPECT_CALL(syscall, getaddrinfo(_, _, _, _)).Times(1).WillRepeatedly(
+        DoAll(SetArgPointee<3>(&addr[0]), Return(0)));
+    EXPECT_CALL(syscall, freeaddrinfo(_)).Times(1).WillRepeatedly(Return());
+    EXPECT_NO_THROW(sock.connect("host", "port", 1000));
+}
+
+TEST_F(TestSocket, ReadFailure) {
+    TcpSocketImpl sock;
+    sock.sock = 1;
+    char buffer[128];
+    EXPECT_CALL(syscall, close(_)).Times(1);
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, recv(_, _, _, _)).Times(3).WillOnce(
+        SetErrnoAndReturn(EINTR, -1)).WillOnce(SetErrnoAndReturn(EBADF, -1)).WillOnce(
+            Return(0));
+    EXPECT_THROW(sock.read(buffer, sizeof(buffer)), HdfsNetworkException);
+    EXPECT_THROW(sock.read(buffer, sizeof(buffer)), HdfsEndOfStream);
+}
+
+TEST_F(TestSocket, ReadSuccess) {
+    TcpSocketImpl sock;
+    sock.sock = 1;
+    char buffer[128];
+    EXPECT_CALL(syscall, close(_)).Times(1);
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, recv(_, _, _, _)).Times(1).WillOnce(
+        Return(sizeof(buffer)));
+    EXPECT_EQ(static_cast<int32_t>(sizeof(buffer)), sock.read(buffer, sizeof(buffer)));
+}
+
+TEST_F(TestSocket, ReadFullyFailure) {
+    TcpSocketImpl sock;
+    sock.sock = 1;
+    char buffer[128];
+    EXPECT_CALL(syscall, close(_)).Times(1);
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, poll(_, _, _)).Times(2).WillOnce(Return(0)).WillOnce(
+        Invoke(bind(&InvokeWaitAndReturn<int>, 1000, 0, 0)));
+    EXPECT_CALL(syscall, recv(_, _, _, _)).Times(0);
+    EXPECT_THROW(sock.readFully(buffer, sizeof(buffer), 0), HdfsTimeoutException);
+    EXPECT_THROW(sock.readFully(buffer, sizeof(buffer), 500), HdfsTimeoutException);
+}
+
+TEST_F(TestSocket, ReadFullySuccess) {
+    TcpSocketImpl sock;
+    sock.sock = 1;
+    char buffer[128];
+    char target[] = "hello world";
+    int32_t tsize = sizeof(target) / 2;
+    void * t1 = target, *t2 = target + tsize;
+    EXPECT_CALL(syscall, close(_)).Times(1);
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, poll(_, _, _)).Times(2).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, recv(_, _, _, _)).Times(2).WillOnce(
+        Invoke(bind(&ReadAction, _1, _2, _3, _4, t1, tsize))).WillOnce(
+            Invoke(bind(&ReadAction, _1, _2, _3, _4, t2, tsize)));
+    memset(buffer, 0, sizeof(buffer));
+    EXPECT_NO_THROW(sock.readFully(buffer, sizeof(target), 500));
+    EXPECT_STREQ(target, buffer);
+}
+
+TEST_F(TestSocket, WriteFailure) {
+    TcpSocketImpl sock;
+    sock.sock = 1;
+    char buffer[128];
+    EXPECT_CALL(syscall, close(_)).Times(1);
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, send(_, _, _, _)).Times(2).WillOnce(
+        SetErrnoAndReturn(EINTR, -1)).WillOnce(
+            SetErrnoAndReturn(EBADF, -1));
+    EXPECT_THROW(sock.write(buffer, sizeof(buffer)), HdfsNetworkException);
+}
+
+TEST_F(TestSocket, WriteSuccess) {
+    TcpSocketImpl sock;
+    sock.sock = 1;
+    char buffer[128];
+    EXPECT_CALL(syscall, close(_)).Times(1);
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, send(_, _, _, _)).Times(1).WillOnce(
+        Return(sizeof(buffer)));
+    EXPECT_EQ(static_cast<int32_t>(sizeof(buffer)), sock.write(buffer, sizeof(buffer)));
+}
+
+TEST_F(TestSocket, WriteFullyFailure) {
+    TcpSocketImpl sock;
+    sock.sock = 1;
+    char buffer[128];
+    EXPECT_CALL(syscall, close(_)).Times(1);
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, poll(_, _, _)).Times(2).WillOnce(Return(0)).WillOnce(
+        Invoke(bind(&InvokeWaitAndReturn<int>, 1000, 0, 0)));
+    EXPECT_CALL(syscall, send(_, _, _, _)).Times(0);
+    EXPECT_THROW(sock.writeFully(buffer, sizeof(buffer), 0), HdfsTimeoutException);
+    EXPECT_THROW(sock.writeFully(buffer, sizeof(buffer), 500), HdfsTimeoutException);
+}
+
+TEST_F(TestSocket, WriteFullySuccess) {
+    TcpSocketImpl sock;
+    sock.sock = 1;
+    char buffer[128];
+    char target[] = "hello world";
+    int32_t tsize = (sizeof(target) + 1) / 2;
+    void * b1 = buffer, *b2 = buffer + tsize;
+    EXPECT_CALL(syscall, close(_)).Times(1);
+    EXPECT_CALL(syscall, shutdown(_, _)).Times(1).WillRepeatedly(Return(0));
+    EXPECT_CALL(syscall, poll(_, _, _)).Times(2).WillRepeatedly(Return(1));
+    EXPECT_CALL(syscall, send(_, _, _, _)).Times(2).WillOnce(
+        Invoke(bind(&WriteAction, _1, _2, _3, _4, b1, tsize))).WillOnce(
+            Invoke(bind(&WriteAction, _1, _2, _3, _4, b2, tsize)));
+    memset(buffer, 0, sizeof(buffer));
+    EXPECT_NO_THROW(sock.writeFully(target, sizeof(target), 500));
+    EXPECT_STREQ(target, buffer);
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bc0904ab/depends/libhdfs3/test/unit/TestXmlConfig.cpp
----------------------------------------------------------------------
diff --git a/depends/libhdfs3/test/unit/TestXmlConfig.cpp b/depends/libhdfs3/test/unit/TestXmlConfig.cpp
new file mode 100644
index 0000000..3f8b265
--- /dev/null
+++ b/depends/libhdfs3/test/unit/TestXmlConfig.cpp
@@ -0,0 +1,72 @@
+/********************************************************************
+ * Copyright (c) 2013 - 2014, Pivotal Inc.
+ * All rights reserved.
+ *
+ * Author: Zhanwei Wang
+ ********************************************************************/
+/********************************************************************
+ * 2014 -
+ * open source under Apache License Version 2.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 "Exception.h"
+#include "XmlConfig.h"
+
+#ifndef DATA_DIR
+#define DATA_DIR ""
+#endif
+
+using namespace Hdfs;
+
+TEST(TestXmlConfig, TestParse) {
+    EXPECT_NO_THROW({ Config conf(DATA_DIR"hdfs-default.xml"); });
+}
+
+TEST(TestXmlConfig, ParseBadFile) {
+    EXPECT_THROW({ Config conf("path not exist"); }, HdfsBadConfigFoumat);
+    EXPECT_THROW({ Config conf(DATA_DIR"invalid.xml"); }, HdfsBadConfigFoumat);
+}
+
+TEST(TestXmlConfig, TestGetValue) {
+    Config conf(DATA_DIR"unit-config.xml");
+    EXPECT_STREQ("TestString", conf.getString("TestString"));
+    EXPECT_STREQ("TestString", conf.getString("NOT EXIST", "TestString"));
+    EXPECT_EQ(123456, conf.getInt32("TestInt32"));
+    EXPECT_EQ(123456, conf.getInt32("NOT EXIST", 123456));
+    EXPECT_THROW(conf.getInt32("TestInt32Invalid"), HdfsConfigNotFound);
+    EXPECT_THROW(conf.getInt32("TestInt32OverFlow"), HdfsConfigNotFound);
+    EXPECT_EQ(12345678901ll, conf.getInt64("TestInt64"));
+    EXPECT_EQ(12345678901ll, conf.getInt64("NOT EXIST", 12345678901ll));
+    EXPECT_THROW(conf.getInt64("TestInt64Invalid"), HdfsConfigNotFound);
+    EXPECT_THROW(conf.getInt64("TestInt64OverFlow"), HdfsConfigNotFound);
+    EXPECT_DOUBLE_EQ(123.456, conf.getDouble("TestDouble"));
+    EXPECT_DOUBLE_EQ(123.456, conf.getDouble("NOT EXIST", 123.456));
+    EXPECT_THROW(conf.getDouble("TestDoubleInvalid"), HdfsConfigNotFound);
+    EXPECT_THROW(conf.getDouble("TestDoubleOverflow"), HdfsConfigNotFound);
+    EXPECT_THROW(conf.getDouble("TestDoubleUnderflow"), HdfsConfigNotFound);
+    EXPECT_TRUE(conf.getBool("TestTrue1"));
+    EXPECT_TRUE(conf.getBool("TestTrue2"));
+    EXPECT_TRUE(conf.getBool("NOT EXIST", true));
+    EXPECT_FALSE(conf.getBool("TestFalse1"));
+    EXPECT_FALSE(conf.getBool("TestFalse2"));
+    EXPECT_FALSE(conf.getBool("NOT EXIST", false));
+    EXPECT_THROW(conf.getBool("TestBoolInvalid"), HdfsConfigNotFound);
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bc0904ab/depends/libhdfs3/test/unit/UnitTestInputStream.cpp
----------------------------------------------------------------------
diff --git a/depends/libhdfs3/test/unit/UnitTestInputStream.cpp b/depends/libhdfs3/test/unit/UnitTestInputStream.cpp
new file mode 100644
index 0000000..2b75d49
--- /dev/null
+++ b/depends/libhdfs3/test/unit/UnitTestInputStream.cpp
@@ -0,0 +1,224 @@
+/********************************************************************
+ * Copyright (c) 2013 - 2014, Pivotal Inc.
+ * All rights reserved.
+ *
+ * Author: Zhanwei Wang
+ ********************************************************************/
+/********************************************************************
+ * 2014 -
+ * open source under Apache License Version 2.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 "client/InputStreamImpl.h"
+#include "client/FileSystem.h"
+#include "MockFileSystemInter.h"
+#include "TestDatanodeStub.h"
+#include "MockDatanode.h"
+#include "server/ExtendedBlock.h"
+#include "XmlConfig.h"
+#include <string>
+
+using namespace Hdfs::Internal;
+using namespace Hdfs::Mock;
+using namespace testing;
+using ::testing::AtLeast;
+
+class TestInputSteam: public ::testing::Test {
+
+public:
+    TestInputSteam() {
+    }
+    ~TestInputSteam() {
+    }
+
+protected:
+    MockFileSystemInter fs;
+    InputStreamImpl ins;
+};
+
+class MockLocatedBlocks: public LocatedBlocks {
+public:
+    MOCK_CONST_METHOD0(getFileLength, int64_t ());
+    MOCK_METHOD1(setFileLength, void (int64_t fileLength));
+    MOCK_CONST_METHOD0(isLastBlockComplete, bool ());
+    MOCK_METHOD1(setIsLastBlockComplete, void (bool lastBlockComplete));
+    MOCK_METHOD0(getLastBlock, shared_ptr<LocatedBlock> ());
+    MOCK_METHOD1(setLastBlock, void (const LocatedBlock & lastBlock));
+    MOCK_CONST_METHOD0(isUnderConstruction, bool ());
+    MOCK_METHOD1(setUnderConstruction, void (bool underConstruction));
+    MOCK_METHOD1(findBlock, LocatedBlock * (int64_t position));
+    MOCK_METHOD0(getBlocks, std::vector<LocatedBlock> & ());
+    MOCK_METHOD1(setLastBlock, void(shared_ptr<LocatedBlock>));
+};
+
+class MockDatanodeStub: public TestDatanodeStub {
+public:
+    MOCK_METHOD0(getDatanode, shared_ptr<MockDatanode>());
+
+};
+
+TEST(InputStreamTest, ReadBlockLength_Success) {
+    InputStreamImpl ins;
+    LocatedBlock b;
+    shared_ptr<MockDatanode> datanode(new MockDatanode());
+    MockDatanodeStub stub;
+    std::vector<DatanodeInfo> dfv;
+    DatanodeInfo df;
+    dfv.push_back(df);
+    b.locs = dfv;
+    ins.stub = &stub;
+    EXPECT_CALL(stub, getDatanode()).Times(1).WillOnce(Return(datanode));
+    EXPECT_CALL(*datanode, getReplicaVisibleLength(_)).Times(1).WillOnce(Return(2));
+    EXPECT_NO_THROW(ins.readBlockLength(b));
+}
+
+TEST(InputStreamTest, ReadBlockLength_Fail) {
+    InputStreamImpl ins;
+    shared_ptr<MockDatanode> datanode(new MockDatanode());
+    MockDatanodeStub stub;
+    LocatedBlock b;
+    std::vector<DatanodeInfo> dfv;
+    DatanodeInfo df1;
+    dfv.push_back(df1);
+    b.locs = dfv;
+    ins.stub = &stub;
+    EXPECT_CALL(stub, getDatanode()).Times(1).WillOnce(Return(datanode));
+    EXPECT_CALL(*datanode, getReplicaVisibleLength(_)).Times(1).WillOnce(Return(-1));
+    EXPECT_EQ(ins.readBlockLength(b), -1);
+}
+
+TEST(InputStreamTest, ReadBlockLength_FailTry) {
+    InputStreamImpl ins;
+    shared_ptr<MockDatanode> datanode(new MockDatanode());
+    MockDatanodeStub stub;
+    LocatedBlock b;
+    std::vector<DatanodeInfo> dfv;
+    DatanodeInfo df1;
+    DatanodeInfo df2;
+    dfv.push_back(df1);
+    dfv.push_back(df2);
+    b.locs = dfv;
+    ins.stub = &stub;
+    EXPECT_CALL(stub, getDatanode()).Times(2).WillOnce(Return(datanode)).WillOnce(Return(datanode));
+    EXPECT_CALL(*datanode, getReplicaVisibleLength(_)).Times(2).WillOnce(Return(-1)).WillOnce(
+        Return(0));
+    EXPECT_EQ(ins.readBlockLength(b), 0);
+}
+
+TEST(InputStreamTest, ReadBlockLength_ThrowTry) {
+    InputStreamImpl ins;
+    shared_ptr<MockDatanode> datanode(new MockDatanode());
+    MockDatanodeStub stub;
+    LocatedBlock b;
+    std::vector<DatanodeInfo> dfv;
+    DatanodeInfo df1;
+    DatanodeInfo df2;
+    dfv.push_back(df1);
+    dfv.push_back(df2);
+    b.locs = dfv;
+    ins.stub = &stub;
+    Hdfs::ReplicaNotFoundException e("test", "test", 2, "test");
+    EXPECT_CALL(stub, getDatanode()).Times(2).WillOnce(Return(datanode)).WillOnce(Return(datanode));
+    EXPECT_CALL(*datanode, getReplicaVisibleLength(_)).Times(2).WillOnce(Throw(e)).WillOnce(
+        Return(0));
+    EXPECT_EQ(ins.readBlockLength(b), 0);
+}
+
+TEST(InputStreamTest, UpdateBlockInfos_LastComplete) {
+    MockFileSystemInter * fs = new MockFileSystemInter;
+    MockLocatedBlocks * lbs = new MockLocatedBlocks();
+    InputStreamImpl ins;
+    ins.filesystem = shared_ptr<FileSystemInter>(fs);
+    ins.maxGetBlockInfoRetry = 1;
+    ins.lastBlockBeingWrittenLength = 1;
+    ins.lbs = shared_ptr < MockLocatedBlocks > (lbs);
+    EXPECT_CALL(*fs, getBlockLocations(_, _, _, _)).WillOnce(Return());
+    EXPECT_CALL(*lbs, isLastBlockComplete()).WillOnce(Return(true));
+    EXPECT_NO_THROW(ins.updateBlockInfos());
+    EXPECT_EQ(ins.lastBlockBeingWrittenLength, 0);
+}
+
+TEST(InputStreamTest, UpdateBlockInfos_NotLastComplete) {
+    MockFileSystemInter * fs = new MockFileSystemInter;
+    MockLocatedBlocks * lbs = new MockLocatedBlocks();
+    InputStreamImpl ins;
+    ins.filesystem = shared_ptr<FileSystemInter>(fs);
+    ins.maxGetBlockInfoRetry = 1;
+    ins.lastBlockBeingWrittenLength = 1;
+    ins.lbs = shared_ptr < MockLocatedBlocks > (lbs);
+    shared_ptr<MockDatanode> datanode(new MockDatanode());
+    MockDatanodeStub stub;
+    ins.stub = &stub;
+    shared_ptr<LocatedBlock> block(new LocatedBlock);
+    std::vector<DatanodeInfo> dfv;
+    DatanodeInfo df;
+    dfv.push_back(df);
+    block->setLocations(dfv);
+    EXPECT_CALL(*fs, getBlockLocations(_, _, _, _)).WillOnce(Return());
+    EXPECT_CALL(*lbs, isLastBlockComplete()).WillOnce(Return(false));
+    EXPECT_CALL(*lbs, getLastBlock()).WillOnce(Return(block));
+    EXPECT_CALL(stub, getDatanode()).Times(1).WillOnce(Return(datanode));
+    EXPECT_CALL(*datanode, getReplicaVisibleLength(_)).WillOnce(Return(2));
+    EXPECT_NO_THROW(ins.updateBlockInfos());
+    EXPECT_GT(ins.lastBlockBeingWrittenLength, 0);
+}
+
+TEST(InputStreamTest, UpdateBlockInfos_TrowAndTry) {
+    MockFileSystemInter * fs = new MockFileSystemInter;
+    MockLocatedBlocks * lbs = new MockLocatedBlocks();
+    InputStreamImpl ins;
+    ins.filesystem = shared_ptr<FileSystemInter>(fs);
+    ins.maxGetBlockInfoRetry = 2;
+    ins.lastBlockBeingWrittenLength = 1;
+    ins.lbs = shared_ptr < MockLocatedBlocks > (lbs);
+    Hdfs::HdfsRpcException e("test", "test", 2, "test");
+    EXPECT_CALL(*fs, getBlockLocations(_, _, _, _)).Times(2).WillOnce(Throw(e)).WillOnce(
+        Throw(e));
+    EXPECT_THROW(ins.updateBlockInfos(), Hdfs::HdfsRpcException);
+}
+
+TEST(InputStreamTest, ChoseBestNode_Success) {
+    InputStreamImpl ins;
+    LocatedBlock * lb = new LocatedBlock();
+    std::vector<DatanodeInfo> dfv;
+    DatanodeInfo df1;
+    DatanodeInfo df2;
+    dfv.push_back(df1);
+    dfv.push_back(df2);
+    lb->locs = dfv;
+    ins.curBlock = shared_ptr < LocatedBlock > (lb);
+    EXPECT_NO_THROW(ins.choseBestNode());
+}
+
+TEST(InputStreamTest, SetupBlockReader_Failed) {
+    InputStreamImpl ins;
+    LocatedBlock * lb = new LocatedBlock();
+    std::vector<DatanodeInfo> dfv;
+    DatanodeInfo df1;
+    DatanodeInfo df2;
+    dfv.push_back(df1);
+    dfv.push_back(df2);
+    lb->locs = dfv;
+    ins.curBlock = shared_ptr < LocatedBlock > (lb);
+    ins.failedNodes = dfv;
+    EXPECT_THROW(ins.setupBlockReader(false), Hdfs::HdfsIOException);
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bc0904ab/depends/libhdfs3/test/unit/UnitTestMain.cpp
----------------------------------------------------------------------
diff --git a/depends/libhdfs3/test/unit/UnitTestMain.cpp b/depends/libhdfs3/test/unit/UnitTestMain.cpp
new file mode 100644
index 0000000..b8299de
--- /dev/null
+++ b/depends/libhdfs3/test/unit/UnitTestMain.cpp
@@ -0,0 +1,38 @@
+/********************************************************************
+ * Copyright (c) 2013 - 2014, Pivotal Inc.
+ * All rights reserved.
+ *
+ * Author: Zhanwei Wang
+ ********************************************************************/
+/********************************************************************
+ * 2014 -
+ * open source under Apache License Version 2.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"
+
+int main(int argc, char ** argv) {
+    ::testing::InitGoogleTest(&argc, argv);
+#ifdef DATA_DIR
+    if (0 != chdir(DATA_DIR)) {
+        abort();
+    }
+#endif
+    return RUN_ALL_TESTS();
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bc0904ab/depends/libhdfs3/test/unit/UnitTestOutputStream.cpp
----------------------------------------------------------------------
diff --git a/depends/libhdfs3/test/unit/UnitTestOutputStream.cpp b/depends/libhdfs3/test/unit/UnitTestOutputStream.cpp
new file mode 100644
index 0000000..0748e6f
--- /dev/null
+++ b/depends/libhdfs3/test/unit/UnitTestOutputStream.cpp
@@ -0,0 +1,410 @@
+/********************************************************************
+ * Copyright (c) 2013 - 2014, Pivotal Inc.
+ * All rights reserved.
+ *
+ * Author: Zhanwei Wang
+ ********************************************************************/
+/********************************************************************
+ * 2014 -
+ * open source under Apache License Version 2.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 "client/FileSystem.h"
+#include "client/FileSystemImpl.h"
+#include "client/FileSystemInter.h"
+#include "client/OutputStream.h"
+#include "client/OutputStreamImpl.h"
+#include "client/Packet.h"
+#include "client/Pipeline.h"
+#include "DateTime.h"
+#include "MockFileSystemInter.h"
+#include "MockLeaseRenewer.h"
+#include "MockPipeline.h"
+#include "NamenodeStub.h"
+#include "server/ExtendedBlock.h"
+#include "TestDatanodeStub.h"
+#include "TestUtil.h"
+#include "Thread.h"
+#include "XmlConfig.h"
+
+#include <string>
+
+using namespace Hdfs;
+using namespace Internal;
+using namespace Hdfs::Mock;
+using namespace testing;
+using ::testing::AtLeast;
+
+#define BASE_DIR "test/"
+
+class TestOutputStream: public ::testing::Test {
+public:
+    TestOutputStream() {
+        renewer = MakeMockLeaseRenewer();
+    }
+
+    ~TestOutputStream() {
+        ResetMockLeaseRenewer(renewer);
+    }
+
+protected:
+    shared_ptr<LeaseRenewer> renewer;
+    MockFileSystemInter fs;
+    OutputStreamImpl ous;
+};
+
+class MockPipelineStub: public PipelineStub {
+public:
+    MOCK_METHOD0(getPipeline, shared_ptr<MockPipeline> ());
+};
+
+class MockNamenodeStub: public NamenodeStub {
+public:
+    MOCK_METHOD0(getNamenode, MockNamenode * ());
+};
+
+static void LeaseRenew(int flag) {
+    Config conf;
+    FileStatus fileinfo;
+    fileinfo.setBlocksize(2048);
+    fileinfo.setLength(1024);
+    shared_ptr<LocatedBlock> lastBlock(new LocatedBlock);
+    lastBlock->setNumBytes(0);
+    std::pair<shared_ptr<LocatedBlock>, shared_ptr<FileStatus> > lastBlockWithStatus;
+    lastBlockWithStatus.first = lastBlock;
+    lastBlockWithStatus.second = shared_ptr<FileStatus>(new FileStatus(fileinfo));
+    MockNamenodeStub stub;
+    SessionConfig sconf(conf);
+    shared_ptr<MockFileSystemInter> myfs(new MockFileSystemInter());
+    EXPECT_CALL(*myfs, getConf()).Times(1).WillOnce(ReturnRef(sconf));
+    //EXPECT_CALL(stub, getNamenode()).Times(1).WillOnce(Return(nn));
+    OutputStreamImpl leaseous;
+
+    if (flag & Append) {
+        EXPECT_CALL(*myfs, append(_)).Times(1).WillOnce(Return(lastBlockWithStatus));
+    } else {
+        EXPECT_CALL(*myfs, create(_, _, _, _, _, _)).Times(1);
+    }
+
+    EXPECT_CALL(*myfs, complete(_, _)).Times(1).WillOnce(Return(true));
+    EXPECT_CALL(GetMockLeaseRenewer(), StartRenew(_)).Times(1);
+    EXPECT_CALL(GetMockLeaseRenewer(), StopRenew(_)).Times(1);
+    EXPECT_CALL(*myfs, getStandardPath(_)).Times(1);
+    EXPECT_NO_THROW(DebugException(leaseous.open(myfs, BASE_DIR"testrenewlease", flag, 0644, true, 0, 2048)));
+    EXPECT_NO_THROW(leaseous.close());
+};
+
+static void heartBeatSender(int flag) {
+    OutputStreamImpl ous;
+    shared_ptr<MockPipeline> pipeline(new MockPipeline());
+    MockPipelineStub stub;
+    ous.stub = &stub;
+    MockFileSystemInter * fs = new MockFileSystemInter;
+    FileStatus fileinfo;
+    fileinfo.setBlocksize(2048);
+    fileinfo.setLength(1024);
+    Config conf;
+    const SessionConfig sessionConf(conf);
+    shared_ptr<LocatedBlock> lastBlock(new LocatedBlock);
+    lastBlock->setNumBytes(0);
+    std::pair<shared_ptr<LocatedBlock>, shared_ptr<FileStatus> > lastBlockWithStatus;
+    lastBlockWithStatus.first = lastBlock;
+    lastBlockWithStatus.second = shared_ptr<FileStatus>(new FileStatus(fileinfo));
+    EXPECT_CALL(*fs, getStandardPath(_)).Times(1).WillOnce(Return("/testheartBeat"));
+    EXPECT_CALL(*fs, getConf()).Times(1).WillOnce(ReturnRef(sessionConf));
+
+    if (flag & Append) {
+        EXPECT_CALL(*fs, append(_)).Times(1).WillOnce(Return(lastBlockWithStatus));
+    } else {
+        EXPECT_CALL(*fs, create(_, _, _, _, _, _)).Times(1);
+    }
+
+    EXPECT_CALL(*fs, registerOpenedOutputStream()).Times(1);
+    EXPECT_NO_THROW(ous.open(shared_ptr<FileSystemInter>(fs), "testheartBeat", flag, 0644, false, 3, 1024 * 1024));
+    char buffer[20];
+    Hdfs::FillBuffer(buffer, sizeof(buffer), 0);
+    EXPECT_NO_THROW(ous.append(buffer, sizeof(buffer)));
+    EXPECT_CALL(stub, getPipeline()).Times(1).WillOnce(Return(pipeline));
+    EXPECT_CALL(*pipeline, send(_)).Times(3);
+    EXPECT_CALL(*pipeline, flush()).Times(1);
+    EXPECT_NO_THROW(ous.flush());
+    sleep_for(seconds(21));
+    EXPECT_CALL(*pipeline, close(_)).Times(1).WillOnce(Return(lastBlock));
+    EXPECT_CALL(*fs, fsync(_)).Times(1);
+    EXPECT_CALL(*fs, complete(_, _)).Times(1).WillOnce(Return(true));
+    EXPECT_CALL(*fs, unregisterOpenedOutputStream()).Times(1);
+    EXPECT_NO_THROW(ous.close());
+}
+
+static void heartBeatSenderThrow(int flag) {
+    OutputStreamImpl ous;
+    shared_ptr<MockPipeline> pipeline(new MockPipeline());
+    MockPipelineStub stub;
+    ous.stub = &stub;
+    MockFileSystemInter * fs = new MockFileSystemInter;
+    FileStatus fileinfo;
+    fileinfo.setBlocksize(2048);
+    fileinfo.setLength(1024);
+    Config conf;
+    const SessionConfig sessionConf(conf);
+    shared_ptr<LocatedBlock> lastBlock(new LocatedBlock);
+    HdfsIOException e("test", "test", 3, "test");
+    lastBlock->setNumBytes(0);
+    std::pair<shared_ptr<LocatedBlock>, shared_ptr<FileStatus> > lastBlockWithStatus;
+    lastBlockWithStatus.first = lastBlock;
+    lastBlockWithStatus.second = shared_ptr<FileStatus>(new FileStatus(fileinfo));
+    EXPECT_CALL(*fs, getStandardPath(_)).Times(1).WillOnce(Return("/testheartBeat"));
+    EXPECT_CALL(*fs, getConf()).Times(1).WillOnce(ReturnRef(sessionConf));
+
+    if (flag & Append) {
+        EXPECT_CALL(*fs, append(_)).Times(1).WillOnce(Return(lastBlockWithStatus));
+    } else {
+        EXPECT_CALL(*fs, create(_, _, _, _, _, _)).Times(1);
+    }
+
+    EXPECT_CALL(*fs, registerOpenedOutputStream()).Times(1);
+    EXPECT_NO_THROW(ous.open(shared_ptr<FileSystemInter>(fs), "testheartBeat", flag, 0644, false, 3, 1024 * 1024));
+    char buffer[20];
+    Hdfs::FillBuffer(buffer, sizeof(buffer), 0);
+    EXPECT_NO_THROW(ous.append(buffer, sizeof(buffer)));
+    EXPECT_CALL(stub, getPipeline()).Times(1).WillOnce(Return(pipeline));
+    EXPECT_CALL(*pipeline, send(_)).Times(2).WillOnce(Return()).WillOnce(Throw(e));
+    EXPECT_CALL(*pipeline, flush()).Times(1);
+    EXPECT_NO_THROW(ous.flush());
+    sleep_for(seconds(11));
+    EXPECT_CALL(*pipeline, close(_)).Times(1).WillOnce(Return(lastBlock));
+    EXPECT_CALL(*fs, fsync(_)).Times(1);
+    EXPECT_CALL(*fs, complete(_, _)).Times(1).WillOnce(Return(true));
+    EXPECT_CALL(*fs, unregisterOpenedOutputStream()).Times(1);
+    EXPECT_NO_THROW(ous.close());
+}
+
+TEST_F(TestOutputStream, LeaseRenewForAppend_Success) {
+    LeaseRenew(Create | Append);
+}
+
+TEST_F(TestOutputStream, LeaseRenewForCreate_Success) {
+    LeaseRenew(Create);
+}
+
+TEST_F(TestOutputStream, DISABLED_heartBeatSenderForAppend_Success) {
+    heartBeatSender(Create | Append);
+}
+
+TEST_F(TestOutputStream, DISABLED_heartBeatSenderForCreate_Success) {
+    heartBeatSender(Create);
+}
+
+TEST_F(TestOutputStream, DISABLED_heartBeatSenderForCreate_Throw) {
+    heartBeatSenderThrow(Create);
+}
+
+TEST_F(TestOutputStream, DISABLED_heartBeatSenderForAppend_Throw) {
+    heartBeatSenderThrow(Create | Append);
+}
+
+TEST_F(TestOutputStream, openForCreate_Success) {
+    OutputStreamImpl ous;
+    MockFileSystemInter * fs = new MockFileSystemInter;
+    Config conf;
+    const SessionConfig sessionConf(conf);
+    EXPECT_CALL(*fs, getStandardPath(_)).Times(1).WillOnce(Return("/testopen"));
+    EXPECT_CALL(*fs, getConf()).Times(1).WillOnce(ReturnRef(sessionConf));
+    EXPECT_CALL(*fs, create(_, _, _, _, _, _)).Times(1);
+    EXPECT_CALL(GetMockLeaseRenewer(), StartRenew(_)).Times(1);
+    EXPECT_CALL(GetMockLeaseRenewer(), StopRenew(_)).Times(1);
+    EXPECT_NO_THROW(ous.open(shared_ptr<FileSystemInter>(fs), "testopen", Create, 0644, false, 3, 1024 * 1024));
+    EXPECT_CALL(*fs, complete(_, _)).Times(1).WillOnce(Return(true));
+    EXPECT_NO_THROW(ous.close());
+}
+
+TEST_F(TestOutputStream, registerForCreate_Success) {
+    OutputStreamImpl ous;
+    MockFileSystemInter * fs = new MockFileSystemInter;
+    Config conf;
+    const SessionConfig sessionConf(conf);
+    EXPECT_CALL(*fs, getStandardPath(_)).Times(1).WillOnce(Return("/testregiester"));
+    EXPECT_CALL(*fs, getConf()).Times(1).WillOnce(ReturnRef(sessionConf));
+    EXPECT_CALL(*fs, create(_, _, _, _, _, _)).Times(1);
+    EXPECT_CALL(GetMockLeaseRenewer(), StartRenew(_)).Times(1);
+    EXPECT_CALL(GetMockLeaseRenewer(), StopRenew(_)).Times(1);
+    EXPECT_NO_THROW(ous.open(shared_ptr<FileSystemInter>(fs), "testregiester", Create, 0644, false, 3, 1024 * 1024));
+    EXPECT_CALL(*fs, complete(_, _)).Times(1).WillOnce(Return(true));
+    EXPECT_NO_THROW(ous.close());
+}
+
+TEST_F(TestOutputStream, registerForAppend_Success) {
+    OutputStreamImpl ous;
+    MockFileSystemInter * fs = new MockFileSystemInter;
+    Config conf;
+    const SessionConfig sessionConf(conf);
+    FileStatus fileinfo;
+    fileinfo.setBlocksize(2048);
+    fileinfo.setLength(1024);
+    shared_ptr<LocatedBlock> lastBlock(new LocatedBlock);
+    lastBlock->setNumBytes(0);
+    std::pair<shared_ptr<LocatedBlock>, shared_ptr<FileStatus> > lastBlockWithStatus;
+    lastBlockWithStatus.first = lastBlock;
+    lastBlockWithStatus.second = shared_ptr<FileStatus>(new FileStatus(fileinfo));
+    EXPECT_CALL(*fs, getStandardPath(_)).Times(1).WillOnce(Return("/testregiester"));
+    EXPECT_CALL(*fs, getConf()).Times(1).WillOnce(ReturnRef(sessionConf));
+    EXPECT_CALL(*fs, append(_)).Times(1).WillOnce(Return(lastBlockWithStatus));
+    EXPECT_CALL(GetMockLeaseRenewer(), StartRenew(_)).Times(1);
+    EXPECT_CALL(GetMockLeaseRenewer(), StopRenew(_)).Times(1);
+    EXPECT_NO_THROW(ous.open(shared_ptr<FileSystemInter>(fs), "testregiester", Append, 0644, false, 0, 0));
+    EXPECT_CALL(*fs, complete(_, _)).Times(1).WillOnce(Return(true));
+    EXPECT_NO_THROW(ous.close());
+}
+
+TEST_F(TestOutputStream, openForCreate_Fail) {
+    OutputStreamImpl ous;
+    MockFileSystemInter * fs = new MockFileSystemInter;
+    Config conf;
+    const SessionConfig sessionConf(conf);
+    HdfsIOException e("test", "test", 2, "test");
+    EXPECT_CALL(*fs, getStandardPath(_)).Times(1).WillOnce(Return("/testopen"));
+    EXPECT_CALL(*fs, getConf()).Times(1).WillOnce(ReturnRef(sessionConf));
+    EXPECT_CALL(*fs, create(_, _, _, _, _, _)).Times(1).WillOnce(Throw(e));
+    EXPECT_THROW(ous.open(shared_ptr<FileSystemInter>(fs), "testopen", Create, 0644, false, 3, 1024 * 1024), HdfsIOException);
+}
+
+
+TEST_F(TestOutputStream, openForAppend_Success) {
+    OutputStreamImpl ous;
+    MockFileSystemInter * fs = new MockFileSystemInter;
+    Config conf;
+    const SessionConfig sessionConf(conf);
+    FileStatus fileinfo;
+    fileinfo.setBlocksize(2048);
+    fileinfo.setLength(1024);
+    shared_ptr<LocatedBlock> lastBlock(new LocatedBlock);
+    lastBlock->setNumBytes(0);
+    std::pair<shared_ptr<LocatedBlock>, shared_ptr<FileStatus> > lastBlockWithStatus;
+    lastBlockWithStatus.first = lastBlock;
+    lastBlockWithStatus.second = shared_ptr<FileStatus>(new FileStatus(fileinfo));
+    EXPECT_CALL(*fs, getStandardPath(_)).Times(1).WillOnce(Return("/testopen"));
+    EXPECT_CALL(*fs, getConf()).Times(1).WillOnce(ReturnRef(sessionConf));
+    EXPECT_CALL(*fs, append(_)).Times(1).WillOnce(Return(lastBlockWithStatus));
+    EXPECT_CALL(GetMockLeaseRenewer(), StartRenew(_)).Times(1);
+    EXPECT_CALL(GetMockLeaseRenewer(), StopRenew(_)).Times(1);
+    EXPECT_NO_THROW(ous.open(shared_ptr<FileSystemInter>(fs), "testopen", Append, 0644, false, 0, 0));
+    EXPECT_CALL(*fs, complete(_, _)).Times(1).WillOnce(Return(true));
+    EXPECT_NO_THROW(ous.close());
+}
+
+TEST_F(TestOutputStream, openForAppend_Fail) {
+    OutputStreamImpl ous;
+    MockFileSystemInter * fs = new MockFileSystemInter;
+    Config conf;
+    const SessionConfig sessionConf(conf);
+    FileStatus fileinfo;
+    fileinfo.setBlocksize(2048);
+    fileinfo.setLength(1024);
+    EXPECT_CALL(*fs, getStandardPath(_)).Times(1).WillOnce(Return("/testopen"));
+    EXPECT_CALL(*fs, getConf()).Times(1).WillOnce(ReturnRef(sessionConf));
+    EXPECT_CALL(*fs, append(_)).Times(1).WillOnce(Throw(FileNotFoundException("test", "test", 2, "test")));
+    EXPECT_THROW(ous.open(shared_ptr<FileSystemInter>(fs), "testopen", Append, 0644, false, 0, 0), FileNotFoundException);
+}
+
+TEST_F(TestOutputStream, append_Success) {
+    OutputStreamImpl ous;
+    shared_ptr<MockPipeline> pipelineStub(new MockPipeline());
+    MockPipelineStub stub;
+    ous.stub = &stub;
+    MockFileSystemInter * fs = new MockFileSystemInter;
+    FileStatus fileinfo;
+    fileinfo.setBlocksize(2048);
+    fileinfo.setLength(1024);
+    Config conf;
+    const SessionConfig sessionConf(conf);
+    shared_ptr<LocatedBlock> lastBlock(new LocatedBlock);
+    lastBlock->setNumBytes(0);
+    std::pair<shared_ptr<LocatedBlock>, shared_ptr<FileStatus> > lastBlockWithStatus;
+    lastBlockWithStatus.first = lastBlock;
+    lastBlockWithStatus.second = shared_ptr<FileStatus>(new FileStatus(fileinfo));
+    EXPECT_CALL(*fs, getStandardPath(_)).Times(1).WillOnce(Return("/testopen"));
+    EXPECT_CALL(*fs, getConf()).Times(1).WillOnce(ReturnRef(sessionConf));
+    EXPECT_CALL(*fs, append(_)).Times(1).WillOnce(Return(lastBlockWithStatus));
+    EXPECT_CALL(GetMockLeaseRenewer(), StartRenew(_)).Times(1);
+    EXPECT_CALL(GetMockLeaseRenewer(), StopRenew(_)).Times(1);
+    EXPECT_NO_THROW(ous.open(shared_ptr<FileSystemInter>(fs), "testopen", Create | Append, 0644, false, 3, 2048));
+    char buffer[4096 + 523];
+    Hdfs::FillBuffer(buffer, sizeof(buffer), 0);
+    EXPECT_CALL(stub, getPipeline()).Times(3).WillOnce(Return(pipelineStub)).WillOnce(Return(pipelineStub)).WillOnce(Return(pipelineStub));
+    EXPECT_CALL(*pipelineStub, send(_)).Times(4);
+    EXPECT_CALL(*pipelineStub, close(_)).Times(2).WillOnce(Return(lastBlock)).WillOnce(Return(lastBlock));
+    EXPECT_CALL(*fs, fsync(_)).Times(2);
+    EXPECT_NO_THROW(ous.append(buffer, sizeof(buffer)));
+    EXPECT_CALL(*pipelineStub, close(_)).Times(1).WillOnce(Return(lastBlock));
+    EXPECT_CALL(*fs, fsync(_)).Times(1);
+    EXPECT_CALL(*fs, complete(_, _)).Times(1).WillOnce(Return(true));
+    EXPECT_NO_THROW(ous.close());
+}
+
+TEST_F(TestOutputStream, flush_Success) {
+    OutputStreamImpl ous;
+    shared_ptr<MockPipeline> pipelineStub(new MockPipeline());
+    MockPipelineStub stub;
+    ous.stub = &stub;
+    MockFileSystemInter * fs = new MockFileSystemInter;
+    FileStatus fileinfo;
+    fileinfo.setBlocksize(2048);
+    fileinfo.setLength(1024);
+    Config conf;
+    const SessionConfig sessionConf(conf);
+    shared_ptr<LocatedBlock> lastBlock(new LocatedBlock);
+    HdfsIOException e("test", "test", 3, "test");
+    lastBlock->setNumBytes(0);
+    std::pair<shared_ptr<LocatedBlock>, shared_ptr<FileStatus> > lastBlockWithStatus;
+    lastBlockWithStatus.first = lastBlock;
+    lastBlockWithStatus.second = shared_ptr<FileStatus>(new FileStatus(fileinfo));
+    EXPECT_CALL(*fs, getStandardPath(_)).Times(1).WillOnce(Return("/testflush"));
+    EXPECT_CALL(*fs, getConf()).Times(1).WillOnce(ReturnRef(sessionConf));
+    EXPECT_CALL(*fs, append(_)).Times(1).WillOnce(Return(lastBlockWithStatus));
+    EXPECT_CALL(GetMockLeaseRenewer(), StartRenew(_)).Times(1);
+    EXPECT_CALL(GetMockLeaseRenewer(), StopRenew(_)).Times(1);
+    EXPECT_NO_THROW(ous.open(shared_ptr<FileSystemInter>(fs), "testflush", Create | Append, 0644, false, 3, 1024 * 1024));
+    char buffer[20];
+    Hdfs::FillBuffer(buffer, sizeof(buffer), 0);
+    EXPECT_NO_THROW(ous.append(buffer, sizeof(buffer)));
+    EXPECT_CALL(stub, getPipeline()).Times(1).WillOnce(Return(pipelineStub));
+    EXPECT_CALL(*pipelineStub, send(_)).Times(1);
+    EXPECT_CALL(*pipelineStub, flush()).Times(1);
+    EXPECT_NO_THROW(ous.flush());
+    EXPECT_CALL(*pipelineStub, close(_)).Times(1).WillOnce(Return(lastBlock));
+    EXPECT_CALL(*fs, fsync(_)).Times(1);
+    EXPECT_CALL(*fs, complete(_, _)).Times(1).WillOnce(Return(true));
+    EXPECT_NO_THROW(ous.close());
+}
+
+TEST_F(TestOutputStream, ValidateFirstBadLink) {
+    EXPECT_NO_THROW(PipelineImpl::checkBadLinkFormat(""));
+    EXPECT_NO_THROW(PipelineImpl::checkBadLinkFormat("8.8.8.8:1234"));
+    EXPECT_NO_THROW(PipelineImpl::checkBadLinkFormat("2001:0db8:85a3:0000:0000:8a2e:0370:7334:50010"));
+    EXPECT_THROW(PipelineImpl::checkBadLinkFormat("3"), HdfsException);
+    EXPECT_THROW(PipelineImpl::checkBadLinkFormat("8.8.8.8"), HdfsException);
+    EXPECT_THROW(PipelineImpl::checkBadLinkFormat("8.8.8.8:"), HdfsException);
+    EXPECT_THROW(PipelineImpl::checkBadLinkFormat("8.8.8.888:50010"), HdfsException);
+    EXPECT_THROW(PipelineImpl::checkBadLinkFormat("8.8.8.8:500101"), HdfsException);
+    EXPECT_THROW(PipelineImpl::checkBadLinkFormat("8.8.8.8:50010a"), HdfsException);
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bc0904ab/depends/libhdfs3/test/unit/UnitTestUtils.h
----------------------------------------------------------------------
diff --git a/depends/libhdfs3/test/unit/UnitTestUtils.h b/depends/libhdfs3/test/unit/UnitTestUtils.h
new file mode 100644
index 0000000..e1bc3ad
--- /dev/null
+++ b/depends/libhdfs3/test/unit/UnitTestUtils.h
@@ -0,0 +1,69 @@
+/********************************************************************
+ * Copyright (c) 2013 - 2014, Pivotal Inc.
+ * All rights reserved.
+ *
+ * Author: Zhanwei Wang
+ ********************************************************************/
+/********************************************************************
+ * 2014 - 
+ * open source under Apache License Version 2.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.
+ */
+#ifndef _HDFS_LIBHDFS3_TEST_UNIT_UNITTESTUTILS_H_
+#define _HDFS_LIBHDFS3_TEST_UNIT_UNITTESTUTILS_H_
+
+#include "DateTime.h"
+#include "ExceptionInternal.h"
+
+namespace Hdfs {
+namespace Internal {
+
+template<typename T>
+void InvokeThrow(const char * str, bool * trigger) {
+    if (!trigger || *trigger) {
+        THROW(T, "%s", str);
+    }
+}
+
+template<typename T, typename R>
+R InvokeThrowAndReturn(const char * str, bool * trigger, R ret) {
+    if (!trigger || *trigger) {
+        THROW(T, "%s", str);
+    }
+
+    return ret;
+}
+
+template<typename R>
+R InvokeWaitAndReturn(int timeout, R ret, int ec) {
+    if (timeout > 0) {
+        sleep_for(milliseconds(timeout));
+    }
+
+    errno = ec;
+    return ret;
+}
+
+static inline void InvokeDoNothing() {
+
+}
+
+}
+}
+#endif /* _HDFS_LIBHDFS3_TEST_UNIT_UNITTESTUTILS_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bc0904ab/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 47f1bbb..f802686 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,6 +44,14 @@
               <exclude>depends/libyarn/CMake/FindBoost.cmake</exclude>
               <exclude>depends/libyarn/CMake/FindGSasl.cmake</exclude>
               <exclude>depends/libyarn/CMake/FindKERBEROS.cmake</exclude>
+			  <exclude>depends/libhdfs3/CMake/FindBoost.cmake</exclude>
+			  <exclude>depends/libhdfs3/CMake/CodeCoverage.cmake</exclude>
+			  <exclude>depends/libhdfs3/CMake/FindGSasl.cmake</exclude>
+			  <exclude>depends/libhdfs3/CMake/FindKERBEROS.cmake</exclude>
+			  <exclude>depends/libhdfs3/CMake/FindLibUUID.cmake</exclude>
+			  <exclude>depends/libhdfs3/CMake/Functions.cmake</exclude>
+			  <exclude>depends/libhdfs3/CMake/Options.cmake</exclude>
+			  <exclude>depends/libhdfs3/CMake/Platform.cmake</exclude>
               <exclude>src/bin/gpfdist/src/gpfdist/glob.c</exclude>
               <exclude>src/bin/gpfdist/src/gpfdist/include/glob.h</exclude>
               <exclude>src/include/port/win32_msvc/glob.h</exclude>
@@ -52,6 +60,8 @@
               <!-- Google BSD license -->
               <exclude>depends/libyarn/gmock/**</exclude>
               <exclude>depends/libyarn/gtest/**</exclude>
+			  <exclude>depends/libhdfs3/gmock/**</exclude>
+			  <exclude>depends/libhdfs3/gtest/**</exclude>
 
               <!-- Oraface Project BSD license https://github.com/orafce -->
               <exclude>contrib/orafce/*</exclude>


Mime
View raw message