Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hdfs): Fix the failed unit tests in velox_hdfs_file_test #11884

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class HdfsFileSystemTest : public testing::Test {
miniCluster = std::make_shared<filesystems::test::HdfsMiniCluster>();
miniCluster->start();
auto tempFile = createFile();
miniCluster->addFile(tempFile->getPath(), destinationPath);
miniCluster->addFile(tempFile->getPath(), fullDestinationPath);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

#include <boost/process.hpp>

#include "HdfsMiniCluster.h"

namespace facebook::velox::filesystems::test {
Expand Down Expand Up @@ -77,6 +79,14 @@ HdfsMiniCluster::HdfsMiniCluster() {
}

void HdfsMiniCluster::addFile(std::string source, std::string destination) {
std::cout << "Starting to add file from " << source << " to " << destination << std::endl;

std::ostringstream output;
std::ostringstream error;

boost::process::ipstream outStream;
boost::process::ipstream errStream;

auto filePutProcess = std::make_shared<boost::process::child>(
env_,
exePath_,
Expand All @@ -85,13 +95,36 @@ void HdfsMiniCluster::addFile(std::string source, std::string destination) {
filesystemUrl,
filePutOption,
source,
destination);
bool isExited =
filePutProcess->wait_for(std::chrono::duration<int, std::milli>(5000));
if (!isExited) {
VELOX_FAIL(
"Failed to add file to hdfs, exit code: {}",
filePutProcess->exit_code());
destination,
boost::process::std_out > outStream,
boost::process::std_err > errStream);

std::cout << "Process started with PID: " << filePutProcess->id() << std::endl;

std::string line;
while (outStream && std::getline(outStream, line) && !line.empty())
output << line << std::endl;

while (errStream && std::getline(errStream, line) && !line.empty())
error << line << std::endl;

bool isExited = filePutProcess->wait_for(std::chrono::duration<int, std::milli>(5000));

if (isExited) {
int exitCode = filePutProcess->exit_code();
std::cout << "Process exited with code: " << exitCode << std::endl;
std::cout << "Process output: " << output.str() << std::endl;
std::cout << "Process error: " << error.str() << std::endl;

if (exitCode != 0) {
std::cerr << "Failed to add file to hdfs, exit code: " << exitCode << ", error: " << error.str() << std::endl;
throw std::runtime_error("Failed to add file to hdfs, exit code: " + std::to_string(exitCode));
}
} else {
std::cerr << "Failed to add file to hdfs, process did not exit in time" << std::endl;
filePutProcess->terminate();
std::cerr << "Process terminated" << std::endl;
throw std::runtime_error("Failed to add file to hdfs, process did not exit in time");
}
}

Expand Down
Loading