Skip to content

Commit

Permalink
telemetry - add new test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
SiskaPavel committed Sep 30, 2024
1 parent 6e5369b commit b8d35f9
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/telemetry/aggregator/tests/testAggSum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ TEST(AggSumTest, TestAggregate)
AggMethodSum aggMethodSum;
std::vector<Content> contents = {Scalar {true}, Scalar {5.0}};
EXPECT_THROW(aggMethodSum.aggregate(contents), TelemetryException);

}

// Test aggregation of incompatible scalar types (expect failure)
Expand Down
65 changes: 65 additions & 0 deletions src/telemetry/tests/testAggFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,69 @@ TEST(TelemetryAggFile, read)
EXPECT_EQ(uint64_t(10), std::get<uint64_t>(ArrayValueJoin[2]));
}

TEST(TelemetryAggFile, readPatternDir)
{
auto root = Directory::create();

auto dir = root->addDir("dir");
auto data0 = root->addDirs("dir/data_0/");
auto data1 = root->addDirs("dir/data_1/");
auto data2 = root->addDirs("dir/data_2/");

FileOps ops1;
ops1.read = []() { return Dict({{"packets", Scalar {uint64_t(1)}}}); };
FileOps ops2;
ops2.read = []() { return Dict({{"packets", Scalar {uint64_t(4)}}}); };
FileOps ops3;
ops3.read = []() { return Dict({{"packets", Scalar {uint64_t(10)}}}); };

auto file1 = data0->addFile("file1", ops1);
auto file2 = data1->addFile("file2", ops2);
auto file3 = data2->addFile("file3", ops3);

AggOperation aggOp1 {AggMethodType::SUM, "packets", "sumPackets"};
AggOperation aggOp2 {AggMethodType::AVG, "packets", "avgPackets"};
AggOperation aggOp3 {AggMethodType::JOIN, "packets", "joinPackets"};

auto aggFile
= root->addAggFile("aggFile", R"(data_\d+/file\d+)", {aggOp1, aggOp2, aggOp3}, dir);
const auto content = aggFile->read();

EXPECT_TRUE(std::holds_alternative<Dict>(content));

const Dict& dict = std::get<Dict>(content);
EXPECT_EQ(3, dict.size());

const Scalar& scalarValueSum = std::get<Scalar>(dict.at("sumPackets"));
EXPECT_EQ(uint64_t(15), std::get<uint64_t>(scalarValueSum));

const Scalar& scalarValueAvg = std::get<Scalar>(dict.at("avgPackets"));
EXPECT_EQ(5.00, std::get<double>(scalarValueAvg));

const Array& ArrayValueJoin = std::get<Array>(dict.at("joinPackets"));
EXPECT_EQ(3, ArrayValueJoin.size());
EXPECT_EQ(uint64_t(1), std::get<uint64_t>(ArrayValueJoin[0]));
EXPECT_EQ(uint64_t(4), std::get<uint64_t>(ArrayValueJoin[1]));
EXPECT_EQ(uint64_t(10), std::get<uint64_t>(ArrayValueJoin[2]));
}

TEST(TelemetryAggFile, readNoMatchingPattern)
{
auto root = Directory::create();

auto data0 = root->addDirs("dir/data_0/");

FileOps ops1;
ops1.read = []() { return Dict({{"packets", Scalar {uint64_t(1)}}}); };

auto file1 = data0->addFile("file1", ops1);

AggOperation aggOp1 {AggMethodType::SUM, "packets", "sumPackets"};

auto aggFile = root->addAggFile("aggFile", R"(data_\d+/file\d+)", {aggOp1});
const auto content = aggFile->read();

EXPECT_TRUE(std::holds_alternative<Scalar>(content));
}

} // namespace telemetry
20 changes: 20 additions & 0 deletions src/telemetry/tests/testDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ TEST(TelemetryDirectory, addDir)
EXPECT_EQ(info, info2);
}

/**
* @test Test creating telemetry directories recursively.
*/
TEST(TelemetryDirectory, addDirs)
{
auto root = Directory::create();

auto test = root->addDirs("info/app/test");
EXPECT_EQ("test", test->getName());
EXPECT_EQ("/info/app/test", test->getFullPath());

auto app = test->addDirs("app");
EXPECT_EQ("app", app->getName());
EXPECT_EQ("/info/app/test/app", app->getFullPath());

auto rootDir = root->addDirs("");
EXPECT_EQ("", rootDir->getName());
EXPECT_EQ("/", rootDir->getFullPath());
}

/**
* @test Test creating invalid telemetry directories.
*/
Expand Down

0 comments on commit b8d35f9

Please sign in to comment.