Skip to content

Commit 9a0d951

Browse files
author
Shubham
committed
Add method for outgoing message count
1 parent 7b86cfc commit 9a0d951

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

objectbox/c.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,3 +1228,7 @@ def c_array_pointer(py_list: Union[List[Any], np.ndarray], c_type):
12281228
[OBX_sync_p, c_char_p])
12291229
obx_sync_filter_variables_remove_all = c_fn_rc('obx_sync_filter_variables_remove_all',
12301230
[OBX_sync_p])
1231+
1232+
# OBX_C_API obx_err obx_sync_outgoing_message_count(OBX_sync* sync, uint64_t limit, uint64_t* out_count);
1233+
obx_sync_outgoing_message_count = c_fn_rc('obx_sync_outgoing_message_count',
1234+
[OBX_sync_p, ctypes.c_uint64, ctypes.POINTER(ctypes.c_uint64)])

objectbox/sync.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,8 @@ def remove_filter_variable(self, name: str):
273273

274274
def remove_all_filter_variables(self):
275275
c.obx_sync_filter_variables_remove_all(self.__c_sync_client_ptr)
276+
277+
def get_outgoing_message_count(self, limit: int = 0) -> int:
278+
outgoing_message_count = ctypes.c_uint64(0)
279+
c.obx_sync_outgoing_message_count(self.__c_sync_client_ptr, limit, ctypes.byref(outgoing_message_count))
280+
return outgoing_message_count.value

tests/test_sync.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,21 @@ def test_filter_variables(test_store):
5555

5656
with pytest.raises(IllegalArgumentError, match="Filter variables must have a name"):
5757
client.add_filter_variable("", "val5")
58+
59+
client.close()
60+
61+
62+
def test_outgoing_message_count(test_store):
63+
server_urls = ["ws://localhost:9999"]
64+
client = SyncClient(test_store, server_urls)
65+
66+
count = client.get_outgoing_message_count()
67+
assert count == 0
68+
69+
count_limited = client.get_outgoing_message_count(limit=10)
70+
assert count_limited == 0
71+
72+
client.close()
73+
74+
with pytest.raises(IllegalArgumentError, match='Argument "sync" must not be null'):
75+
client.get_outgoing_message_count()

0 commit comments

Comments
 (0)