-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HDFS-16472. Make HDFS setrep tool cross platform (#4130)
* The source files for hdfs_setrep uses getopt for parsing the command line arguments. * getopt is available only on Linux and thus, isn't cross platform. * We need to replace getopt with boost::program_options to make this tool cross platform.
- Loading branch information
1 parent
34b3275
commit 4ef1d3e
Showing
11 changed files
with
617 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...oject/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/tools/hdfs-setrep-mock.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* 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 <functional> | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <gmock/gmock.h> | ||
#include <gtest/gtest.h> | ||
|
||
#include "hdfs-setrep-mock.h" | ||
#include "hdfs-tool-tests.h" | ||
|
||
namespace hdfs::tools::test { | ||
SetrepMock::~SetrepMock() = default; | ||
|
||
void SetrepMock::SetExpectations( | ||
std::function<std::unique_ptr<SetrepMock>()> test_case, | ||
const std::vector<std::string> &args) const { | ||
// Get the pointer to the function that defines the test case | ||
const auto test_case_func = | ||
test_case.target<std::unique_ptr<SetrepMock> (*)()>(); | ||
ASSERT_NE(test_case_func, nullptr); | ||
|
||
// Set the expected method calls and their corresponding arguments for each | ||
// test case | ||
if (*test_case_func == &CallHelp<SetrepMock>) { | ||
EXPECT_CALL(*this, HandleHelp()).Times(1).WillOnce(testing::Return(true)); | ||
return; | ||
} | ||
|
||
if (*test_case_func == &PassPermissionsAndAPath<SetrepMock>) { | ||
const auto number = args[0]; | ||
const auto path = args[1]; | ||
EXPECT_CALL(*this, HandlePath(path, number)) | ||
.Times(1) | ||
.WillOnce(testing::Return(true)); | ||
} | ||
} | ||
} // namespace hdfs::tools::test |
68 changes: 68 additions & 0 deletions
68
...roject/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/tools/hdfs-setrep-mock.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* 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 LIBHDFSPP_TOOLS_HDFS_SETREP_MOCK | ||
#define LIBHDFSPP_TOOLS_HDFS_SETREP_MOCK | ||
|
||
#include <functional> | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <gmock/gmock.h> | ||
|
||
#include "hdfs-setrep.h" | ||
|
||
namespace hdfs::tools::test { | ||
/** | ||
* {@class SetrepMock} is an {@class Setrep} whereby it mocks the | ||
* HandleHelp and HandlePath methods for testing their functionality. | ||
*/ | ||
class SetrepMock : public hdfs::tools::Setrep { | ||
public: | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
SetrepMock(const int argc, char **argv) : Setrep(argc, argv) {} | ||
|
||
// Abiding to the Rule of 5 | ||
SetrepMock(const SetrepMock &) = delete; | ||
SetrepMock(SetrepMock &&) = delete; | ||
SetrepMock &operator=(const SetrepMock &) = delete; | ||
SetrepMock &operator=(SetrepMock &&) = delete; | ||
~SetrepMock() override; | ||
|
||
/** | ||
* Defines the methods and the corresponding arguments that are expected | ||
* to be called on this instance of {@link HdfsTool} for the given test case. | ||
* | ||
* @param test_case An {@link std::function} object that points to the | ||
* function defining the test case | ||
* @param args The arguments that are passed to this test case | ||
*/ | ||
void SetExpectations(std::function<std::unique_ptr<SetrepMock>()> test_case, | ||
const std::vector<std::string> &args = {}) const; | ||
|
||
MOCK_METHOD(bool, HandleHelp, (), (const, override)); | ||
|
||
MOCK_METHOD(bool, HandlePath, (const std::string &, const std::string &), | ||
(const, override)); | ||
}; | ||
} // namespace hdfs::tools::test | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ject/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/hdfs-setrep/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
add_library(hdfs_setrep_lib STATIC $<TARGET_OBJECTS:hdfs_tool_obj> hdfs-setrep.cc) | ||
target_include_directories(hdfs_setrep_lib PRIVATE ../../tools ${Boost_INCLUDE_DIRS}) | ||
target_link_libraries(hdfs_setrep_lib PRIVATE Boost::boost Boost::program_options tools_common hdfspp_static) | ||
|
||
add_executable(hdfs_setrep main.cc) | ||
target_include_directories(hdfs_setrep PRIVATE ../../tools) | ||
target_link_libraries(hdfs_setrep PRIVATE hdfs_setrep_lib) | ||
|
||
install(TARGETS hdfs_setrep RUNTIME DESTINATION bin) |
Oops, something went wrong.