16 #include <gtest/gtest.h> 17 #include <gmock/gmock.h> 34 std::this_thread::sleep_for(std::chrono::milliseconds(500));
55 test_publisher = std::make_shared<SimpleTestPublisher>();
59 EXPECT_EQ(0, test_publisher->getPublishAttempts());
60 EXPECT_EQ(0, test_publisher->getPublishSuccesses());
61 EXPECT_EQ(0.0f, test_publisher->getPublishSuccessPercentage());
62 EXPECT_EQ(std::chrono::milliseconds(0), test_publisher->getLastPublishDuration());
66 test_publisher.reset();
84 std::string data(
"They're taking the hobbits to Isengard!");
85 auto status = test_publisher->attemptPublish(data);
88 EXPECT_FALSE(test_publisher->canPublish());
89 EXPECT_EQ(0, test_publisher->getPublishAttempts());
90 EXPECT_EQ(std::chrono::milliseconds(0), test_publisher->getLastPublishDuration());
99 std::string data(
"They're taking the hobbits to Isengard!");
101 bool b = test_publisher->start();
103 EXPECT_TRUE(test_publisher->canPublish());
105 auto status = test_publisher->attemptPublish(data);
107 EXPECT_EQ(1, test_publisher->getPublishAttempts());
108 EXPECT_EQ(1, test_publisher->getPublishSuccesses());
109 EXPECT_EQ(100.0f, test_publisher->getPublishSuccessPercentage());
110 EXPECT_LT(std::chrono::milliseconds(0), test_publisher->getLastPublishDuration());
119 std::string data(
"They're taking the hobbits to Isengard!");
121 bool b = test_publisher->start();
123 EXPECT_TRUE(test_publisher->canPublish());
125 auto status = test_publisher->attemptPublish(data);
128 EXPECT_EQ(1, test_publisher->getPublishAttempts());
129 EXPECT_EQ(1, test_publisher->getPublishSuccesses());
130 EXPECT_EQ(100.0f, test_publisher->getPublishSuccessPercentage());
131 EXPECT_LT(std::chrono::milliseconds(0), test_publisher->getLastPublishDuration());
134 test_publisher->setShouldSucceed(
false);
135 status = test_publisher->attemptPublish(data);
138 EXPECT_EQ(2, test_publisher->getPublishAttempts());
139 EXPECT_EQ(1, test_publisher->getPublishSuccesses());
140 EXPECT_EQ(50.0f, test_publisher->getPublishSuccessPercentage());
141 EXPECT_LT(std::chrono::milliseconds(0), test_publisher->getLastPublishDuration());
151 std::string data(
"They're taking the hobbits to Isengard!");
153 bool b = test_publisher->start();
155 EXPECT_TRUE(test_publisher->canPublish());
161 std::this_thread::sleep_for(std::chrono::milliseconds(200));
162 b = test_publisher->shutdown();
165 EXPECT_EQ(data, test_publisher->last_data);
170 auto status = test_publisher->attemptPublish(data);
173 EXPECT_LT(std::chrono::milliseconds(0), test_publisher->getLastPublishDuration());
174 EXPECT_FALSE(test_publisher->canPublish());
void setShouldSucceed(bool nv)
~SimpleTestPublisher() override=default
std::shared_ptr< SimpleTestPublisher > test_publisher
Aws::DataFlow::UploadStatus attemptPublish(std::string &data) override
Aws::DataFlow::UploadStatus publishData(std::string &data) override
TEST_F(PublisherTest, Sanity)