Skip to content
Merged
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
55 changes: 29 additions & 26 deletions presto-native-execution/presto_cpp/main/tests/TaskInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,62 @@
#include "presto_cpp/main/common/tests/test_json.h"
#include "presto_cpp/main/connectors/PrestoToVeloxConnector.h"

using namespace facebook;
using namespace facebook::presto::protocol;
using namespace facebook::presto;

class TaskInfoTest : public ::testing::Test {};
class TaskInfoTest : public ::testing::Test {
protected:
void SetUp() override {
registerPrestoToVeloxConnector(
std::make_unique<facebook::presto::HivePrestoToVeloxConnector>("hive"));
}

void TearDown() override {
unregisterPrestoToVeloxConnector("hive");
}
};

const std::string BASE_DATA_PATH = "/github/presto-trunk/presto-native-execution/presto_cpp/main/tests/data/";

TEST_F(TaskInfoTest, duration) {
double thrift = 0;
facebook::presto::thrift::toThrift(Duration(123, TimeUnit::MILLISECONDS), thrift);
thrift::toThrift(protocol::Duration(123, protocol::TimeUnit::MILLISECONDS), thrift);
ASSERT_EQ(thrift, 123);
}

TEST_F(TaskInfoTest, binaryMetadataUpdates) {
std::string str = slurp(getDataPath(BASE_DATA_PATH, "MetadataUpdates.json"));
json j = json::parse(str);
registerPrestoToVeloxConnector(std::make_unique<facebook::presto::HivePrestoToVeloxConnector>("hive"));
MetadataUpdates metadataUpdates = j;
protocol::MetadataUpdates metadataUpdates = j;
std::unique_ptr<std::string> thriftMetadataUpdates = std::make_unique<std::string>();
facebook::presto::thrift::toThrift(metadataUpdates, *thriftMetadataUpdates);
thrift::toThrift(metadataUpdates, *thriftMetadataUpdates);

json thriftJson = json::parse(*thriftMetadataUpdates);
ASSERT_EQ(j, thriftJson);

presto::unregisterPrestoToVeloxConnector("hive");
}

TEST_F(TaskInfoTest, taskInfo) {
std::string str = slurp(getDataPath(BASE_DATA_PATH, "TaskInfo.json"));
json j = json::parse(str);
registerPrestoToVeloxConnector(std::make_unique<facebook::presto::HivePrestoToVeloxConnector>("hive"));
TaskInfo taskInfo = j;
facebook::presto::thrift::TaskInfo thriftTaskInfo;
facebook::presto::thrift::toThrift(taskInfo, thriftTaskInfo);
protocol::TaskInfo taskInfo = j;
thrift::TaskInfo thriftTaskInfo;
thrift::toThrift(taskInfo, thriftTaskInfo);

json thriftJson = json::parse(*thriftTaskInfo.metadataUpdates()->metadataUpdates());
ASSERT_EQ(taskInfo.metadataUpdates, thriftJson);
ASSERT_EQ(thriftTaskInfo.needsPlan(), false);
ASSERT_EQ(thriftTaskInfo.outputBuffers()->buffers()->size(), 2);
ASSERT_EQ(thriftTaskInfo.outputBuffers()->buffers()[0].bufferId()->id(), 100);
ASSERT_EQ(thriftTaskInfo.outputBuffers()->buffers()[1].bufferId()->id(), 200);
ASSERT_EQ(thriftTaskInfo.stats()->blockedReasons()->count(facebook::presto::thrift::BlockedReason::WAITING_FOR_MEMORY), 1);
ASSERT_EQ(thriftTaskInfo.stats()->blockedReasons()->count(thrift::BlockedReason::WAITING_FOR_MEMORY), 1);
ASSERT_EQ(thriftTaskInfo.stats()->runtimeStats()->metrics()->size(), 2);
ASSERT_EQ(thriftTaskInfo.stats()->runtimeStats()->metrics()["test_metric1"].sum(), 123);
ASSERT_EQ(thriftTaskInfo.stats()->runtimeStats()->metrics()["test_metric2"].name(), "test_metric2");

presto::unregisterPrestoToVeloxConnector("hive");
}

TEST_F(TaskInfoTest, taskId) {
TaskId taskId = "queryId.1.2.3.4";
facebook::presto::thrift::TaskId thriftTaskId;
facebook::presto::thrift::toThrift(taskId, thriftTaskId);
protocol::TaskId taskId = "queryId.1.2.3.4";
thrift::TaskId thriftTaskId;
thrift::toThrift(taskId, thriftTaskId);

ASSERT_EQ(thriftTaskId.stageExecutionId()->stageId()->queryId(), "queryId");
ASSERT_EQ(thriftTaskId.stageExecutionId()->stageId()->id(), 1);
Expand All @@ -83,9 +86,9 @@ TEST_F(TaskInfoTest, taskId) {
TEST_F(TaskInfoTest, operatorStatsEmptyBlockedReason) {
std::string str = slurp(getDataPath(BASE_DATA_PATH, "OperatorStatsEmptyBlockedReason.json"));
json j = json::parse(str);
OperatorStats operatorStats = j;
facebook::presto::thrift::OperatorStats thriftOperatorStats;
facebook::presto::thrift::toThrift(operatorStats, thriftOperatorStats);
protocol::OperatorStats operatorStats = j;
thrift::OperatorStats thriftOperatorStats;
thrift::toThrift(operatorStats, thriftOperatorStats);

ASSERT_EQ(thriftOperatorStats.blockedReason().has_value(), false);
ASSERT_EQ(thriftOperatorStats.blockedWall(), 80);
Expand All @@ -95,9 +98,9 @@ TEST_F(TaskInfoTest, operatorStatsEmptyBlockedReason) {
TEST_F(TaskInfoTest, operatorStats) {
std::string str = slurp(getDataPath(BASE_DATA_PATH, "OperatorStats.json"));
json j = json::parse(str);
OperatorStats operatorStats = j;
facebook::presto::thrift::OperatorStats thriftOperatorStats;
facebook::presto::thrift::toThrift(operatorStats, thriftOperatorStats);
protocol::OperatorStats operatorStats = j;
thrift::OperatorStats thriftOperatorStats;
thrift::toThrift(operatorStats, thriftOperatorStats);

ASSERT_EQ(thriftOperatorStats.blockedReason(), facebook::presto::thrift::BlockedReason::WAITING_FOR_MEMORY);
ASSERT_EQ(thriftOperatorStats.blockedReason(), thrift::BlockedReason::WAITING_FOR_MEMORY);
}
45 changes: 22 additions & 23 deletions presto-native-execution/presto_cpp/main/tests/TaskStatusTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
#include "presto_cpp/main/thrift/ProtocolToThrift.h"
#include "presto_cpp/main/common/tests/test_json.h"

using namespace facebook;
using namespace facebook::presto::protocol;
using namespace facebook::presto;

class TaskStatusTest : public ::testing::Test {};

TEST_F(TaskStatusTest, lifeSpan) {
std::string str = R"("Group1001")";

json j = json::parse(str);
Lifespan lifeSpan = j;
facebook::presto::thrift::Lifespan thriftLifespan;
facebook::presto::thrift::toThrift(lifeSpan, thriftLifespan);
protocol::Lifespan lifeSpan = j;
thrift::Lifespan thriftLifespan;
thrift::toThrift(lifeSpan, thriftLifespan);

ASSERT_EQ(thriftLifespan.grouped(), true);
ASSERT_EQ(thriftLifespan.groupId(), 1001);
Expand All @@ -42,13 +41,13 @@ TEST_F(TaskStatusTest, errorCode) {
})";

json j = json::parse(str);
ErrorCode errorCode = j;
facebook::presto::thrift::ErrorCode thriftErrorCode;
facebook::presto::thrift::toThrift(errorCode, thriftErrorCode);
protocol::ErrorCode errorCode = j;
thrift::ErrorCode thriftErrorCode;
thrift::toThrift(errorCode, thriftErrorCode);

ASSERT_EQ(thriftErrorCode.code(), 1234);
ASSERT_EQ(thriftErrorCode.name(), "name");
ASSERT_EQ(thriftErrorCode.type(), facebook::presto::thrift::ErrorType::INTERNAL_ERROR);
ASSERT_EQ(thriftErrorCode.type(), thrift::ErrorType::INTERNAL_ERROR);
ASSERT_EQ(thriftErrorCode.retriable(), false);
}

Expand All @@ -73,16 +72,16 @@ TEST_F(TaskStatusTest, executionFailureInfoOptionalFieldsEmpty) {
})";

json j = json::parse(str);
ExecutionFailureInfo executionFailureInfo = j;
facebook::presto::thrift::ExecutionFailureInfo thriftExecutionFailureInfo;
facebook::presto::thrift::toThrift(executionFailureInfo, thriftExecutionFailureInfo);
protocol::ExecutionFailureInfo executionFailureInfo = j;
thrift::ExecutionFailureInfo thriftExecutionFailureInfo;
thrift::toThrift(executionFailureInfo, thriftExecutionFailureInfo);

ASSERT_EQ(thriftExecutionFailureInfo.type(), "type");
ASSERT_EQ(thriftExecutionFailureInfo.errorLocation()->columnNumber(), 2);
ASSERT_EQ(thriftExecutionFailureInfo.remoteHost()->hostPortString(), "localhost:8080");
ASSERT_EQ(thriftExecutionFailureInfo.errorCode()->type(), facebook::presto::thrift::ErrorType::INTERNAL_ERROR);
ASSERT_EQ(thriftExecutionFailureInfo.errorCode()->type(), thrift::ErrorType::INTERNAL_ERROR);
ASSERT_EQ(thriftExecutionFailureInfo.errorCode()->retriable(), false);
ASSERT_EQ(thriftExecutionFailureInfo.errorCause(), facebook::presto::thrift::ErrorCause::EXCEEDS_BROADCAST_MEMORY_LIMIT);
ASSERT_EQ(thriftExecutionFailureInfo.errorCause(), thrift::ErrorCause::EXCEEDS_BROADCAST_MEMORY_LIMIT);
ASSERT_EQ(thriftExecutionFailureInfo.cause(), nullptr);
ASSERT_EQ(thriftExecutionFailureInfo.suppressed()->size(), 0);
}
Expand All @@ -91,18 +90,18 @@ TEST_F(TaskStatusTest, executionFailureInfoOptionalFieldsNonempty) {
std::string str = slurp(getDataPath("/github/presto-trunk/presto-native-execution/presto_cpp/main/tests/data/", "ExecutionFailureInfo.json"));

json j = json::parse(str);
ExecutionFailureInfo executionFailureInfo = j;
facebook::presto::thrift::ExecutionFailureInfo thriftExecutionFailureInfo;
facebook::presto::thrift::toThrift(executionFailureInfo, thriftExecutionFailureInfo);
protocol::ExecutionFailureInfo executionFailureInfo = j;
thrift::ExecutionFailureInfo thriftExecutionFailureInfo;
thrift::toThrift(executionFailureInfo, thriftExecutionFailureInfo);

ASSERT_EQ((*thriftExecutionFailureInfo.cause()).type(), "cause");
ASSERT_EQ((*thriftExecutionFailureInfo.cause()).errorCause(), facebook::presto::thrift::ErrorCause::UNKNOWN);
ASSERT_EQ((*thriftExecutionFailureInfo.cause()).errorCode()->type(), facebook::presto::thrift::ErrorType::INSUFFICIENT_RESOURCES);
ASSERT_EQ((*thriftExecutionFailureInfo.cause()).errorCause(), thrift::ErrorCause::UNKNOWN);
ASSERT_EQ((*thriftExecutionFailureInfo.cause()).errorCode()->type(), thrift::ErrorType::INSUFFICIENT_RESOURCES);
ASSERT_EQ((*thriftExecutionFailureInfo.cause()).errorCode()->retriable(), true);
ASSERT_EQ((*thriftExecutionFailureInfo.suppressed())[0].type(), "suppressed1");
ASSERT_EQ((*thriftExecutionFailureInfo.suppressed())[0].errorCause(), facebook::presto::thrift::ErrorCause::LOW_PARTITION_COUNT);
ASSERT_EQ((*thriftExecutionFailureInfo.suppressed())[0].errorCode()->type(), facebook::presto::thrift::ErrorType::EXTERNAL);
ASSERT_EQ((*thriftExecutionFailureInfo.suppressed())[0].errorCause(), thrift::ErrorCause::LOW_PARTITION_COUNT);
ASSERT_EQ((*thriftExecutionFailureInfo.suppressed())[0].errorCode()->type(), thrift::ErrorType::EXTERNAL);
ASSERT_EQ((*thriftExecutionFailureInfo.suppressed())[1].type(), "suppressed2");
ASSERT_EQ((*thriftExecutionFailureInfo.suppressed())[1].errorCause(), facebook::presto::thrift::ErrorCause::EXCEEDS_BROADCAST_MEMORY_LIMIT);
ASSERT_EQ((*thriftExecutionFailureInfo.suppressed())[1].errorCode()->type(), facebook::presto::thrift::ErrorType::INTERNAL_ERROR);
ASSERT_EQ((*thriftExecutionFailureInfo.suppressed())[1].errorCause(), thrift::ErrorCause::EXCEEDS_BROADCAST_MEMORY_LIMIT);
ASSERT_EQ((*thriftExecutionFailureInfo.suppressed())[1].errorCode()->type(), thrift::ErrorType::INTERNAL_ERROR);
}
Loading
Loading