blob: aafebb8ad8bd7b7aa3aa2c555f62218df65f2ed4 [file] [log] [blame]
Tommy Carpenter21f659c2020-02-26 14:12:54 -05001"""
2Test 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
22import time
23import json
Tommy Carpenter21f659c2020-02-26 14:12:54 -050024from ricxappframe.xapp_frame import Xapp
25
Tommy Carpenter21f659c2020-02-26 14:12:54 -050026
Tommy Carpenterf9cd5cc2020-03-09 13:46:37 -040027def entry(self):
28 my_ns = "myxapp"
29 number = 0
30 while True:
31 # test healthcheck
32 print("Healthy? {}".format(xapp.healthcheck()))
Tommy Carpenter21f659c2020-02-26 14:12:54 -050033
Tommy Carpenterf9cd5cc2020-03-09 13:46:37 -040034 # rmr send to default handler
35 self.rmr_send(json.dumps({"sup": number}).encode(), 6660666)
Tommy Carpenter21f659c2020-02-26 14:12:54 -050036
Tommy Carpenterf9cd5cc2020-03-09 13:46:37 -040037 # 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 Carpenter21f659c2020-02-26 14:12:54 -050041
Tommy Carpenterf9cd5cc2020-03-09 13:46:37 -040042 # store it in SDL and read it back; delete and read
43 self.sdl_set(my_ns, "numba", number)
Tommy Carpenter0f8305b2020-03-18 10:34:28 -040044 self.logger.info(self.sdl_get(my_ns, "numba"))
45 self.logger.info(self.sdl_find_and_get(my_ns, "num"))
Tommy Carpenterf9cd5cc2020-03-09 13:46:37 -040046 self.sdl_delete(my_ns, "numba")
Tommy Carpenter0f8305b2020-03-18 10:34:28 -040047 self.logger.info(self.sdl_get(my_ns, "numba"))
Tommy Carpenterf9cd5cc2020-03-09 13:46:37 -040048
49 # rmr receive
50 for (summary, sbuf) in self.rmr_get_messages():
Tommy Carpenter0f8305b2020-03-18 10:34:28 -040051 # summary is a dict that contains bytes so we can't use json.dumps on it so we have no good way to turn this into a string to use the logger unfortunately
52 # print is more "verbose" than the ric logger
53 # if you try to log this you will get: TypeError: Object of type bytes is not JSON serializable
Tommy Carpenterf9cd5cc2020-03-09 13:46:37 -040054 print(summary)
55 self.rmr_free(sbuf)
56
57 time.sleep(2)
Tommy Carpenter21f659c2020-02-26 14:12:54 -050058
59
Tommy Carpenterf9cd5cc2020-03-09 13:46:37 -040060xapp = Xapp(entrypoint=entry, rmr_port=4564, use_fake_sdl=True)
Tommy Carpenter21f659c2020-02-26 14:12:54 -050061xapp.run()