diff --git a/consumer/api/python/asapo_consumer.pxd b/consumer/api/python/asapo_consumer.pxd index 692fb425be85d4490c5c57cb2d9a01636d961b9c..867139750dad8c31963e0efd8effa2525636b2dc 100644 --- a/consumer/api/python/asapo_consumer.pxd +++ b/consumer/api/python/asapo_consumer.pxd @@ -24,7 +24,7 @@ cdef extern from "asapo_wrappers.h" namespace "asapo": cdef extern from "asapo_consumer.h" namespace "asapo": cppclass FileData: - unique_ptr[uint8_t[]] release() + uint8_t[] release() pass cdef extern from "asapo_consumer.h" namespace "asapo": diff --git a/producer/api/python/asapo_producer.pxd b/producer/api/python/asapo_producer.pxd index d0a53e6cbb9536d580f152200d3acc182c36fa7d..26ec51600ede3eeb2f40553f08ffb6bc5551941b 100644 --- a/producer/api/python/asapo_producer.pxd +++ b/producer/api/python/asapo_producer.pxd @@ -26,7 +26,8 @@ cdef extern from "asapo_producer.h" namespace "asapo": cdef extern from "asapo_producer.h" namespace "asapo": cppclass FileData: - unique_ptr[uint8_t[]] release() + uint8_t[] release() + uint8_t[] get() cppclass StreamInfo: string Json(bool add_last_id) bool SetFromJson(string json_str, bool read_last_id) @@ -81,9 +82,9 @@ cdef extern from "asapo_producer.h" namespace "asapo": string Json() struct RequestCallbackPayload: GenericRequestHeader original_header + FileData data string response - cdef extern from "asapo_producer.h" namespace "asapo": cppclass RequestCallback: pass diff --git a/producer/api/python/asapo_producer.pyx.in b/producer/api/python/asapo_producer.pyx.in index 3cd30bf122922e44d594271c11df1ce364f01e47..1319d9439cf139c4284f29ace8824f03b7d0d94b 100644 --- a/producer/api/python/asapo_producer.pyx.in +++ b/producer/api/python/asapo_producer.pyx.in @@ -286,11 +286,14 @@ cdef class PyProducer: if err: throw_exception(err) return - cdef void c_callback_python(self,py_callback, RequestCallbackPayload payload, Error& err): + cdef void c_callback_python(self,py_callback, data, RequestCallbackPayload& payload, Error& err): if py_callback != None: info_str = _str(payload.original_header.Json()) info = json.loads(info_str) info['server_response'] = payload.response + if payload.data.get() != NULL: + payload.data.release() + info['data'] = data if err: py_err = python_exception_from_error(err) else: @@ -299,20 +302,20 @@ cdef class PyProducer: Py_XDECREF(<PyObject*>py_callback) cdef void c_callback(self,py_callback, RequestCallbackPayload payload, Error err) with gil: - self.c_callback_python(py_callback,payload,err) + self.c_callback_python(py_callback,None,payload,err) cdef void c_callback_ndarr(self,py_callback,nd_array,RequestCallbackPayload payload, Error err) with gil: + self.c_callback_python(py_callback,nd_array,payload,err) if nd_array is not None: if nd_array.base is not None: Py_XDECREF(<PyObject*>nd_array.base) else: Py_XDECREF(<PyObject*>nd_array) - self.c_callback_python(py_callback,payload,err) cdef void c_callback_bytesaddr(self,py_callback,bytes_array,RequestCallbackPayload payload, Error err) with gil: + self.c_callback_python(py_callback,bytes_array,payload,err) if bytes_array is not None: Py_XDECREF(<PyObject*>bytes_array) - self.c_callback_python(py_callback,payload,err) def cleanup(self): with nogil: if self.c_producer.get() is not NULL: diff --git a/tests/automatic/producer/python_api/check_linux.sh b/tests/automatic/producer/python_api/check_linux.sh index b4fea561aa03591d754d711cb942b408a1fb0691..fe5ae27138a29eecb574769e060f52b8957612db 100644 --- a/tests/automatic/producer/python_api/check_linux.sh +++ b/tests/automatic/producer/python_api/check_linux.sh @@ -41,8 +41,14 @@ sleep 1 $1 $3 $stream $beamtime_id "127.0.0.1:8400" &> out || cat out cat out -cat out | grep "successfuly sent" | wc -l | grep 13 +echo count successfully send, expect 13 +cat out | grep "successfuly sent" | wc -l | tee /dev/stderr | grep 13 +echo count same id, expect 4 +cat out | grep "already have record with same id" | wc -l | tee /dev/stderr | grep 4 +echo count duplicates, expect 4 +cat out | grep "duplicate" | wc -l | tee /dev/stderr | grep 4 +echo count data in callback, expect 3 +cat out | grep "'data':" | wc -l | tee /dev/stderr | grep 3 +echo check found local io error cat out | grep "local i/o error" -cat out | grep "already have record with same id" | wc -l | grep 4 -cat out | grep "duplicate" | wc -l | grep 4 cat out | grep "Finished successfully" diff --git a/tests/automatic/producer/python_api/check_windows.bat b/tests/automatic/producer/python_api/check_windows.bat index a0a3537efdbfcb082e9b5dcd403e421a91214c28..6127144a3add5ebaed821ed2a42d731ef57cb160 100644 --- a/tests/automatic/producer/python_api/check_windows.bat +++ b/tests/automatic/producer/python_api/check_windows.bat @@ -33,6 +33,11 @@ echo %NUM% | findstr 1 || goto error for /F %%N in ('find /C "} server warning: duplicated request" ^< "out"') do set NUM=%%N echo %NUM% | findstr 1 || goto error +for /F %%N in ("find /C 'data':") do set NUM=%%N +echo %NUM% | findstr 3 || goto error + + + findstr /I /L /C:"Finished successfully" out || goto :error goto :clean diff --git a/tests/automatic/producer/python_api/producer_api.py b/tests/automatic/producer/python_api/producer_api.py index 460a03ed12f6628d61460907106ff45c9f20dde1..dd247424c2f3eb74c33f3ec0215d01e9c1dc1bd2 100644 --- a/tests/automatic/producer/python_api/producer_api.py +++ b/tests/automatic/producer/python_api/producer_api.py @@ -26,14 +26,14 @@ def assert_eq(val, expected, name): sys.exit(1) -def callback(header, err): +def callback(payload, err): lock.acquire() # to print if isinstance(err, asapo_producer.AsapoServerWarning): - print("successfuly sent, but with warning from server: ", header, err) + print("successfuly sent, but with warning from server: ", payload, err) elif err is not None: - print("could not sent: ", header, err) + print("could not sent: ", payload, err) else: - print("successfuly sent: ", header) + print("successfuly sent: ", payload) lock.release()