From common-commits-return-80349-archive-asf-public=cust-asf.ponee.io@hadoop.apache.org Thu Mar 22 22:21:17 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 872CD18076D for ; Thu, 22 Mar 2018 22:21:16 +0100 (CET) Received: (qmail 31265 invoked by uid 500); 22 Mar 2018 21:21:06 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 29628 invoked by uid 99); 22 Mar 2018 21:21:05 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Mar 2018 21:21:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A0678F6779; Thu, 22 Mar 2018 21:21:04 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jhc@apache.org To: common-commits@hadoop.apache.org Date: Thu, 22 Mar 2018 21:21:32 -0000 Message-Id: <1153c2b753c8455d81d88a185a71f356@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [29/52] [abbrv] hadoop git commit: HDFS-10796: libhdfs++: Previous commit was missing test/hdfs_ioservice_test.cc, adding it. HDFS-10796: libhdfs++: Previous commit was missing test/hdfs_ioservice_test.cc, adding it. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/a30cf6a3 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/a30cf6a3 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/a30cf6a3 Branch: refs/heads/HDFS-8707 Commit: a30cf6a369770381df4b3fb23d059749dbf6c4cf Parents: fbff671 Author: James Authored: Sun Dec 11 10:52:39 2016 -0500 Committer: James Clampffer Committed: Thu Mar 22 17:19:47 2018 -0400 ---------------------------------------------------------------------- .../libhdfspp/tests/hdfs_ioservice_test.cc | 103 +++++++++++++++++++ 1 file changed, 103 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/a30cf6a3/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/hdfs_ioservice_test.cc ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/hdfs_ioservice_test.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/hdfs_ioservice_test.cc new file mode 100644 index 0000000..a03f275 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/hdfs_ioservice_test.cc @@ -0,0 +1,103 @@ +/** + * 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 "common/hdfs_ioservice.h" + +#include +#include +#include +#include + +#include + +using ::testing::_; +using ::testing::InvokeArgument; +using ::testing::Return; + +using namespace hdfs; + +// Make sure IoService spins up specified number of threads +TEST(IoServiceTest, InitThreads) { +#ifndef DISABLE_CONCURRENT_WORKERS + std::shared_ptr service = std::static_pointer_cast(IoService::MakeShared()); + EXPECT_NE(service, nullptr); + + unsigned int thread_count = 4; + unsigned int result_thread_count = service->InitWorkers(thread_count); + EXPECT_EQ(thread_count, result_thread_count); + + service->Stop(); +#else + #pragma message("DISABLE_CONCURRENT_WORKERS is defined so hdfs_ioservice_test will compile out the InitThreads test") +#endif +} + +// Make sure IoService defaults to logical thread count +TEST(IoServiceTest, InitDefaultThreads) { +#ifndef DISABLE_CONCURRENT_WORKERS + std::shared_ptr service = std::static_pointer_cast(IoService::MakeShared()); + EXPECT_NE(service, nullptr); + + unsigned int thread_count = std::thread::hardware_concurrency(); + unsigned int result_thread_count = service->InitDefaultWorkers(); + EXPECT_EQ(thread_count, result_thread_count); + + service->Stop(); +#else + #pragma message("DISABLE_CONCURRENT_WORKERS is defined so hdfs_ioservice_test will compile out the InitDefaultThreads test") +#endif +} + + +// Check IoService::PostTask +TEST(IoServiceTest, SimplePost) { + std::shared_ptr service = std::static_pointer_cast(IoService::MakeShared()); + EXPECT_NE(service, nullptr); + + unsigned int thread_count = std::thread::hardware_concurrency(); + unsigned int result_thread_count = service->InitDefaultWorkers(); +#ifndef DISABLE_CONCURRENT_WORKERS + EXPECT_EQ(thread_count, result_thread_count); +#else + (void)thread_count; + (void)result_thread_count; +#endif + // Like with the C synchronous shims a promise/future is needed to block until the async call completes. + auto promise = std::make_shared>(); + std::future future = promise->get_future(); + + // this will get invoked on a worker thread + std::function example_callback = [promise](){ + promise->set_value("hello from IoService"); + }; + service->PostTask(example_callback); + + // block until worker thread finishes + std::string result = future.get(); + EXPECT_EQ(result, "hello from IoService"); + + service->Stop(); + +} + +int main(int argc, char *argv[]) { + // The following line must be executed to initialize Google Mock + // (and Google Test) before running the tests. + ::testing::InitGoogleMock(&argc, argv); + return RUN_ALL_TESTS(); +} --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org