Tommy Carpenter | 21f659c | 2020-02-26 14:12:54 -0500 | [diff] [blame] | 1 | """ |
| 2 | Test xapp 1 |
| 3 | """ |
| 4 | # ================================================================================== |
| 5 | # Copyright (c) 2020 Nokia |
| 6 | # Copyright (c) 2020 AT&T Intellectual Property. |
| 7 | # |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | # you may not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | # ================================================================================== |
| 20 | |
| 21 | |
| 22 | import time |
| 23 | import json |
Tommy Carpenter | 21f659c | 2020-02-26 14:12:54 -0500 | [diff] [blame] | 24 | from ricxappframe.xapp_frame import Xapp |
| 25 | |
Tommy Carpenter | 21f659c | 2020-02-26 14:12:54 -0500 | [diff] [blame] | 26 | |
Tommy Carpenter | f9cd5cc | 2020-03-09 13:46:37 -0400 | [diff] [blame] | 27 | def entry(self): |
| 28 | my_ns = "myxapp" |
| 29 | number = 0 |
| 30 | while True: |
| 31 | # test healthcheck |
Lott, Christopher (cl778h) | bbc9028 | 2020-05-07 08:39:49 -0400 | [diff] [blame] | 32 | print("ping is healthy? {}".format(xapp.healthcheck())) |
Tommy Carpenter | 21f659c | 2020-02-26 14:12:54 -0500 | [diff] [blame] | 33 | |
Tommy Carpenter | f9cd5cc | 2020-03-09 13:46:37 -0400 | [diff] [blame] | 34 | # rmr send to default handler |
Lott, Christopher (cl778h) | bbc9028 | 2020-05-07 08:39:49 -0400 | [diff] [blame] | 35 | self.rmr_send(json.dumps({"ping": number}).encode(), 6660666) |
Tommy Carpenter | 21f659c | 2020-02-26 14:12:54 -0500 | [diff] [blame] | 36 | |
Tommy Carpenter | f9cd5cc | 2020-03-09 13:46:37 -0400 | [diff] [blame] | 37 | # rmr send 60000, should trigger registered callback |
| 38 | val = json.dumps({"test_send": number}).encode() |
| 39 | self.rmr_send(val, 60000) |
| 40 | number += 1 |
Tommy Carpenter | 21f659c | 2020-02-26 14:12:54 -0500 | [diff] [blame] | 41 | |
Tommy Carpenter | f9cd5cc | 2020-03-09 13:46:37 -0400 | [diff] [blame] | 42 | # store it in SDL and read it back; delete and read |
Lott, Christopher (cl778h) | bbc9028 | 2020-05-07 08:39:49 -0400 | [diff] [blame] | 43 | self.sdl_set(my_ns, "ping", number) |
| 44 | self.logger.info(self.sdl_get(my_ns, "ping")) |
| 45 | self.logger.info(self.sdl_find_and_get(my_ns, "pin")) |
| 46 | self.sdl_delete(my_ns, "ping") |
| 47 | self.logger.info(self.sdl_get(my_ns, "ping")) |
Tommy Carpenter | f9cd5cc | 2020-03-09 13:46:37 -0400 | [diff] [blame] | 48 | |
| 49 | # rmr receive |
| 50 | for (summary, sbuf) in self.rmr_get_messages(): |
Lott, Christopher (cl778h) | bbc9028 | 2020-05-07 08:39:49 -0400 | [diff] [blame] | 51 | # summary is a dict that contains bytes so we can't use json.dumps on it |
| 52 | # so we have no good way to turn this into a string to use the logger unfortunately |
Tommy Carpenter | 0f8305b | 2020-03-18 10:34:28 -0400 | [diff] [blame] | 53 | # print is more "verbose" than the ric logger |
| 54 | # if you try to log this you will get: TypeError: Object of type bytes is not JSON serializable |
Lott, Christopher (cl778h) | bbc9028 | 2020-05-07 08:39:49 -0400 | [diff] [blame] | 55 | print("ping: {0}".format(summary)) |
Tommy Carpenter | f9cd5cc | 2020-03-09 13:46:37 -0400 | [diff] [blame] | 56 | self.rmr_free(sbuf) |
| 57 | |
| 58 | time.sleep(2) |
Tommy Carpenter | 21f659c | 2020-02-26 14:12:54 -0500 | [diff] [blame] | 59 | |
| 60 | |
Tommy Carpenter | f9cd5cc | 2020-03-09 13:46:37 -0400 | [diff] [blame] | 61 | xapp = Xapp(entrypoint=entry, rmr_port=4564, use_fake_sdl=True) |
Tommy Carpenter | 21f659c | 2020-02-26 14:12:54 -0500 | [diff] [blame] | 62 | xapp.run() |