MCPcopy Create free account
hub / github.com/apache/brpc / ReducerTest_window

Function ReducerTest_window

test/bvar_reducer_unittest.cpp:194–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192}
193
194void ReducerTest_window() {
195 bvar::Adder<int> c1;
196 bvar::Maxer<int> c2;
197 bvar::Miner<int> c3;
198 bvar::Window<bvar::Adder<int> > w1(&c1, 1);
199 bvar::Window<bvar::Adder<int> > w2(&c1, 2);
200 bvar::Window<bvar::Adder<int> > w3(&c1, 3);
201 bvar::Window<bvar::Maxer<int> > w4(&c2, 1);
202 bvar::Window<bvar::Maxer<int> > w5(&c2, 2);
203 bvar::Window<bvar::Maxer<int> > w6(&c2, 3);
204 bvar::Window<bvar::Miner<int> > w7(&c3, 1);
205 bvar::Window<bvar::Miner<int> > w8(&c3, 2);
206 bvar::Window<bvar::Miner<int> > w9(&c3, 3);
207
208#if !BRPC_WITH_GLOG
209 logging::StringSink log_str;
210 logging::LogSink* old_sink = logging::SetLogSink(&log_str);
211 c2.get_value();
212 ASSERT_EQ(&log_str, logging::SetLogSink(old_sink));
213 ASSERT_NE(std::string::npos, log_str.find(
214 "You should not call Reducer<int, bvar::detail::MaxTo<int>>"
215 "::get_value() when a Window<> is used because the operator"
216 " does not have inverse."));
217#endif
218 const int N = 6000;
219 int count = 0;
220 int total_count = 0;
221 int64_t last_time = butil::cpuwide_time_us();
222 for (int i = 1; i <= N; ++i) {
223 c1 << 1;
224 c2 << N - i;
225 c3 << i;
226 ++count;
227 ++total_count;
228 int64_t now = butil::cpuwide_time_us();
229 if (now - last_time >= 1000000L) {
230 last_time = now;
231 ASSERT_EQ(total_count, c1.get_value());
232 LOG(INFO) << "c1=" << total_count
233 << " count=" << count
234 << " w1=" << w1
235 << " w2=" << w2
236 << " w3=" << w3
237 << " w4=" << w4
238 << " w5=" << w5
239 << " w6=" << w6
240 << " w7=" << w7
241 << " w8=" << w8
242 << " w9=" << w9;
243 count = 0;
244 } else {
245 usleep(950);
246 }
247 }
248}
249
250TEST_F(ReducerTest, window) {
251 ReducerTest_window();

Callers 1

TEST_FFunction · 0.85

Calls 4

SetLogSinkFunction · 0.85
cpuwide_time_usFunction · 0.85
get_valueMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected