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

Function test_doexchange_echo

python/pyarrow/tests/test_flight.py:2249–2289  ·  view source on GitHub ↗

Try a DoExchange echo server.

()

Source from the content-addressed store, hash-verified

2247
2248
2249def test_doexchange_echo():
2250 """Try a DoExchange echo server."""
2251 data = pa.Table.from_arrays([
2252 pa.array(range(0, 10 * 1024))
2253 ], names=["a"])
2254 batches = data.to_batches(max_chunksize=512)
2255
2256 with ExchangeFlightServer() as server, \
2257 FlightClient(("localhost", server.port)) as client:
2258 descriptor = flight.FlightDescriptor.for_command(b"echo")
2259 writer, reader = client.do_exchange(descriptor)
2260 with writer:
2261 # Read/write metadata before starting data.
2262 for i in range(10):
2263 buf = str(i).encode("utf-8")
2264 writer.write_metadata(buf)
2265 chunk = reader.read_chunk()
2266 assert chunk.data is None
2267 assert chunk.app_metadata == buf
2268
2269 # Now write data without metadata.
2270 writer.begin(data.schema)
2271 num_batches = 0
2272 for batch in batches:
2273 writer.write_batch(batch)
2274 assert reader.schema == data.schema
2275 chunk = reader.read_chunk()
2276 assert chunk.data == batch
2277 assert chunk.app_metadata is None
2278 num_batches += 1
2279 assert reader.stats.num_record_batches == num_batches
2280
2281 # And write data with metadata.
2282 for i, batch in enumerate(batches):
2283 buf = str(i).encode("utf-8")
2284 writer.write_with_metadata(batch, buf)
2285 chunk = reader.read_chunk()
2286 assert chunk.data == batch
2287 assert chunk.app_metadata == buf
2288 num_batches += 1
2289 assert reader.stats.num_record_batches == num_batches
2290
2291
2292def test_doexchange_echo_v4():

Callers

nothing calls this directly

Calls 8

FlightClientClass · 0.90
to_batchesMethod · 0.80
write_batchMethod · 0.80
arrayMethod · 0.45
do_exchangeMethod · 0.45
encodeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected