Try a DoExchange echo server.
()
| 2285 | |
| 2286 | |
| 2287 | def test_doexchange_echo(): |
| 2288 | """Try a DoExchange echo server.""" |
| 2289 | data = pa.Table.from_arrays([ |
| 2290 | pa.array(range(0, 10 * 1024)) |
| 2291 | ], names=["a"]) |
| 2292 | batches = data.to_batches(max_chunksize=512) |
| 2293 | |
| 2294 | with ExchangeFlightServer() as server, \ |
| 2295 | FlightClient(("localhost", server.port)) as client: |
| 2296 | descriptor = flight.FlightDescriptor.for_command(b"echo") |
| 2297 | writer, reader = client.do_exchange(descriptor) |
| 2298 | with writer: |
| 2299 | # Read/write metadata before starting data. |
| 2300 | for i in range(10): |
| 2301 | buf = str(i).encode("utf-8") |
| 2302 | writer.write_metadata(buf) |
| 2303 | chunk = reader.read_chunk() |
| 2304 | assert chunk.data is None |
| 2305 | assert chunk.app_metadata == buf |
| 2306 | |
| 2307 | # Now write data without metadata. |
| 2308 | writer.begin(data.schema) |
| 2309 | num_batches = 0 |
| 2310 | for batch in batches: |
| 2311 | writer.write_batch(batch) |
| 2312 | assert reader.schema == data.schema |
| 2313 | chunk = reader.read_chunk() |
| 2314 | assert chunk.data == batch |
| 2315 | assert chunk.app_metadata is None |
| 2316 | num_batches += 1 |
| 2317 | assert reader.stats.num_record_batches == num_batches |
| 2318 | |
| 2319 | # And write data with metadata. |
| 2320 | for i, batch in enumerate(batches): |
| 2321 | buf = str(i).encode("utf-8") |
| 2322 | writer.write_with_metadata(batch, buf) |
| 2323 | chunk = reader.read_chunk() |
| 2324 | assert chunk.data == batch |
| 2325 | assert chunk.app_metadata == buf |
| 2326 | num_batches += 1 |
| 2327 | assert reader.stats.num_record_batches == num_batches |
| 2328 | |
| 2329 | |
| 2330 | def test_doexchange_echo_v4(): |
nothing calls this directly
no test coverage detected