MCPcopy Create free account
hub / github.com/apache/arrow / TestPauseThenStop

Function TestPauseThenStop

cpp/src/arrow/acero/source_node_test.cc:113–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111// backpressure is applied to the source node.
112template <typename ThisNode>
113void TestPauseThenStop() {
114 ASSERT_OK(ThisNode::Register());
115
116 // number of batches, number of batches to pass before pausing, batch size
117 constexpr int num_batches = 10, num_pass = 2, batch_size = 1;
118 // the above constants can be changed subject to the following restrictions
119 // to ensure that the test works
120 ASSERT_GE(num_pass, 1); // must pass at least one batch before pausing
121 ASSERT_GT(num_batches, num_pass); // must have more batches after pausing
122 auto t_schema = schema({field("time", int32()), field("value", int32())});
123 ASSERT_OK_AND_ASSIGN(auto t_batches,
124 MakeIntegerBatches({[](int row) -> int64_t { return row; },
125 [](int row) -> int64_t { return row + 1; }},
126 t_schema, num_batches, batch_size));
127
128 Declaration t_src = {
129 "source", SourceNodeOptions(t_batches.schema,
130 MakeDelayedGen(t_batches, "t_src", /*delay_sec=*/0.5,
131 /*noisy=*/false))};
132 Declaration ctrl = {
133 ThisNode::kFactoryName, {t_src}, PauseThenStopNodeOptions(num_pass)};
134
135 ASSERT_OK_AND_ASSIGN(std::unique_ptr<RecordBatchReader> batch_reader,
136 DeclarationToReader(ctrl, /*use_threads=*/false));
137
138 if (!ThisNode::kPlanExitsEarly) {
139 int64_t total_length = 0;
140 for (;;) {
141 ASSERT_OK_AND_ASSIGN(auto batch, batch_reader->Next());
142 if (!batch) {
143 break;
144 }
145 total_length += batch->num_rows();
146 }
147 ASSERT_EQ(static_cast<int64_t>(num_pass * batch_size), total_length);
148 } else {
149 for (int i = 0; i < num_pass - 1; i++) {
150 ASSERT_OK_AND_ASSIGN(auto batch, batch_reader->Next());
151 ASSERT_TRUE(batch);
152 }
153 ASSERT_RAISES(Cancelled, batch_reader->Next());
154 }
155}
156
157TEST(SourceNode, PauseThenStopInput) { TestPauseThenStop<PauseThenStopInputNode>(); }
158

Callers

nothing calls this directly

Calls 10

RegisterFunction · 0.85
SourceNodeOptionsClass · 0.85
MakeDelayedGenFunction · 0.85
DeclarationToReaderFunction · 0.85
ASSERT_OK_AND_ASSIGNFunction · 0.70
schemaFunction · 0.50
fieldFunction · 0.50
num_rowsMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected