17 #include <gtest/gtest.h> 45 std::lock_guard<std::recursive_mutex> lk(
mtx);
60 test_batcher = std::make_shared<TestBatcher>();
61 test_batcher->start();
66 test_batcher->shutdown();
81 EXPECT_EQ(0u, test_batcher->getCurrentBatchSize());
87 test_batcher->setMaxAllowableBatchSize(new_max);
88 EXPECT_EQ(new_max, test_batcher->getMaxAllowableBatchSize());
90 for(
size_t i=0; i<new_max; i++) {
91 test_batcher->batchData(i);
92 EXPECT_EQ(i+1, test_batcher->getCurrentBatchSize());
95 test_batcher->batchData(42);
96 EXPECT_EQ(0u, test_batcher->getCurrentBatchSize());
97 EXPECT_EQ(0, test_batcher->pub_called);
103 test_batcher->setTriggerBatchSize(new_max);
104 EXPECT_EQ(new_max, test_batcher->getTriggerBatchSize());
106 for(
size_t i=0; i<new_max-1; i++) {
107 test_batcher->batchData(i);
108 EXPECT_EQ(i+1, test_batcher->getCurrentBatchSize());
111 test_batcher->batchData(42);
112 EXPECT_EQ(0u, test_batcher->getCurrentBatchSize());
113 EXPECT_EQ(1, test_batcher->pub_called);
130 EXPECT_THROW(test_batcher->setMaxAllowableBatchSize(0), std::invalid_argument);
131 EXPECT_NO_THROW(test_batcher->setMaxAllowableBatchSize(max));
132 EXPECT_EQ(max, test_batcher->getMaxAllowableBatchSize());
135 EXPECT_THROW(test_batcher->setTriggerBatchSize(0), std::invalid_argument);
136 EXPECT_THROW(test_batcher->setTriggerBatchSize(trigger + max), std::invalid_argument);
137 EXPECT_NO_THROW(test_batcher->setTriggerBatchSize(trigger));
138 EXPECT_EQ(trigger, test_batcher->getTriggerBatchSize());
140 EXPECT_THROW(
TestBatcher(100, 200), std::invalid_argument);
bool publishBatchedData() override
static void validateConfigurableSizes(size_t batch_max_queue_size, size_t batch_trigger_publish_size)
static const size_t kDefaultTriggerSize
std::shared_ptr< TestBatcher > test_batcher
static const size_t kDefaultMaxBatchSize
TEST_F(DataBatcherTest, Sanity)
TestBatcher(size_t max_allowable_batch_size=DataBatcher::kDefaultMaxBatchSize, size_t publish_trigger_size=DataBatcher::kDefaultTriggerSize)