Skip to content

Commit

Permalink
Check for correct response.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-phaf committed Sep 8, 2023
1 parent 2e4771b commit 1e8ceea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ jobs:
run: docker compose up --exit-code-from loader

- name: Cleanup
if: always()
run: docker compose down --volumes
24 changes: 19 additions & 5 deletions examples/clients/python/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
# tested with Python 3.11
# Generate protobuf code with following command from top level directory:
# python -m grpc_tools.protoc --proto_path=datastore/protobuf datastore.proto --python_out=examples/clients/python --grpc_python_out=examples/clients/python
import os
from datetime import datetime

Expand All @@ -9,6 +11,8 @@
import datastore_pb2_grpc as dstore_grpc
import grpc

MAGIC_ID = 1234567890
MAGIC_VALUE = 123.456

def callAddTimeSeries(stub):
print('calling AddTimeSeries() ...')
Expand All @@ -24,7 +28,7 @@ def callAddTimeSeries(stub):
other3='value3',
)
request = dstore.AddTSRequest(
id=1234567890,
id=MAGIC_ID,
metadata=tsMData,
)
response = stub.AddTimeSeries(request)
Expand All @@ -42,14 +46,14 @@ def callPutObservations(stub):
obs = [
dstore.Observation(
time=timestamp,
value=123.456,
value=MAGIC_VALUE,
metadata=obsMData,
)
]
request = dstore.PutObsRequest(
tsobs=[
dstore.TSObservations(
tsid=1234567890,
tsid=MAGIC_ID,
obs=obs,
)
],
Expand All @@ -73,13 +77,23 @@ def callGetObservations(stub):
response = stub.GetObservations(request)
print(' response: {}'.format(response))

return response


if __name__ == '__main__':

with grpc.insecure_channel(f"{os.getenv('DSHOST', 'localhost')}:{os.getenv('DSPORT', '50050')}") as channel:
stub = dstore_grpc.DatastoreStub(channel)

callAddTimeSeries(stub)
callAddTimeSeries(stub)
callPutObservations(stub)
callGetObservations(stub)
response = callGetObservations(stub)

# Check response
found_at_least_one = False
for r in response.tsobs:
if r.tsid == MAGIC_ID:
for o in r.obs:
assert(o.value == MAGIC_VALUE)
found_at_least_one = True
assert found_at_least_one

0 comments on commit 1e8ceea

Please sign in to comment.