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

Fixed FileHandleTest.localFile test #28

Closed
Closed
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
20 changes: 15 additions & 5 deletions velox/connectors/hive/FileHandleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,37 @@

#include "velox/connectors/hive/FileHandle.h"

#include <string>
#include "gtest/gtest.h"
#include "velox/common/caching/SimpleLRUCache.h"
#include "velox/common/file/File.h"
#include "velox/common/memory/Arena.h"

#include "gtest/gtest.h"

using namespace facebook::velox;

TEST(FileHandle, localFile) {
TEST(FileHandleTest, localFile) {
// TODO: use the appropriate test directory.
const char filename[] = "/tmp/test";
remove(filename);
// Use unique name for each process/thread execution to prevent cross
// process/thread race condition
auto pid = getpid();
auto tid = pthread_self();
const std::string filename =
"/tmp/test" + std::to_string(pid) + "_" + std::to_string(tid);
remove(filename.data());

{
LocalWriteFile writeFile(filename);
writeFile.append("foo");
}

FileHandleFactory factory(
std::make_unique<SimpleLRUCache<std::string, FileHandle>>(1000),
std::make_unique<FileHandleGenerator>());
auto fileHandle = factory.generate(filename);
ASSERT_EQ(fileHandle->file->size(), 3);
Arena arena;
ASSERT_EQ(fileHandle->file->pread(0, 3, &arena), "foo");

// Clean up
remove(filename.data());
}