コード例 #1
0
 def test_create_delete_workspace(self):
     y = Zenoh.login(ZSERVER)
     admin = y.admin()
     stid = '123'
     admin.add_storage(stid, {'selector': '/myzenoh/**'})
     time.sleep(1)  # TODO remove
     workspace = y.workspace('/myzenoh')
     self.assertEqual(workspace.path, Path('/myzenoh'))
     admin.remove_storage(stid)
     y.logout()
コード例 #2
0
 def test_create_delete_storage(self):
     y = Zenoh.login(ZSERVER)
     admin = y.admin()
     stid = '123'
     res1 = admin.add_storage(stid, {'selector': '/myzenoh/**'})
     time.sleep(1)  # TODO remove
     res2 = admin.remove_storage(stid)
     y.logout()
     self.assertTrue(res1)
     self.assertTrue(res2)
コード例 #3
0
 def test_put_get_remove(self):
     y = Zenoh.login(ZSERVER)
     admin = y.admin()
     stid = '123'
     admin.add_storage(stid, {'selector': '/myzenoh/**'})
     time.sleep(1)  # TODO remove
     workspace = y.workspace('/myzenoh')
     d = Value('hello!', encoding=Encoding.STRING)
     self.assertTrue(workspace.put('/myzenoh/key1', d))
     data = workspace.get('/myzenoh/key1')[0]
     self.assertEqual(data.get_value(), d)
     self.assertEqual(data.get_path(), '/myzenoh/key1')
     self.assertTrue(workspace.remove('/myzenoh/key1'))
     self.assertEqual(workspace.get('/myzenoh/key1'), [])
     admin.remove_storage(stid)
     y.logout()
コード例 #4
0
    def test__big_put_get_remove(self):
        y = Zenoh.login('127.0.0.1')
        admin = y.admin()
        stid = '123'
        admin.add_storage(stid, {'selector': '/myzenoh/**'})
        time.sleep(1)  # TODO remove
        workspace = y.workspace('/myzenoh')

        for i in range(0, 100):
            v = 'x{}'.format(i) * 512
            workspace.put('/myzenoh/big/{}'.format(i),
                          Value(v, encoding=Encoding.STRING))

        dataset = workspace.get('/myzenoh/big/**')
        self.assertEqual(len(dataset), 100)
        admin.remove_storage(stid)
        y.logout()
コード例 #5
0
    def test_eval(self):
        y = Zenoh.login(ZSERVER)
        admin = y.admin()
        stid = '123'
        admin.add_storage(stid, {'selector': '/myzenoh/**'})
        time.sleep(1)  # TODO remove
        workspace = y.workspace('/myzenoh')

        def cb(path, args):
            return Value('{} World!'.format(args['hello']),
                         encoding=Encoding.STRING)

        workspace.register_eval('/myzenoh/key1', cb)
        dataset = workspace.get('/myzenoh/key1?(hello=mondo)')
        self.assertEqual(dataset[0].get_path(), '/myzenoh/key1')
        self.assertEqual(dataset[0].get_value(),
                         Value('mondo World!', encoding=Encoding.STRING))
        workspace.unregister_eval('/myzenoh/key1')
        admin.remove_storage(stid)
        y.logout()
コード例 #6
0
    def test_sub_remove(self):
        y = Zenoh.login(ZSERVER)
        admin = y.admin()
        stid = '123'
        admin.add_storage(stid, {'selector': '/myzenoh/**'})
        time.sleep(1)  # TODO remove
        workspace = y.workspace('/myzenoh')
        local_var = mvar.MVar()
        workspace.put('/myzenoh/key1', Value('123', encoding=Encoding.STRING))

        def cb(kvs):
            self.assertEqual(kvs[0].get_path(), '/myzenoh/key1')
            self.assertEqual(kvs[0].get_kind(), ChangeKind.REMOVE)
            local_var.put(kvs)

        sid = workspace.subscribe('/myzenoh/key1', cb)
        workspace.remove('/myzenoh/key1')
        self.assertTrue(workspace.unsubscribe(sid))
        admin.remove_storage(stid)
        y.logout()
コード例 #7
0
                                 description='Produces float values')
parser.add_argument('--path',
                    '-p',
                    dest='path',
                    default='/zenoh/examples/native/float',
                    type=str,
                    help='the path representing the float resource')

parser.add_argument(
    '--locator',
    '-l',
    dest='locator',
    default=None,
    type=str,
    help='The locator to be used to boostrap the zenoh session.'
    ' By default dynamic discovery is used')

args = parser.parse_args()

# zenoh code  --- --- --- --- --- --- --- --- --- --- ---
z = Zenoh.login(args.locator)
w = z.workspace()

while (True):
    v = input("Insert value (\'.\' to exit): ")
    if v != '.':
        w.put(args.path, float(v))
    else:
        z.logout()
        break
コード例 #8
0
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
#   ADLINK zenoh team, <*****@*****.**>

import sys
from zenoh import Zenoh, Selector, Path, Workspace, Encoding, Value

selector = '/demo/example/**'
if len(sys.argv) > 1:
    selector = sys.argv[1]

locator = None
if len(sys.argv) > 2:
    locator = sys.argv[2]

print('Login to Zenoh (locator={})...'.format(locator))
z = Zenoh.login(locator)

print('Use Workspace on "/"')
w = z.workspace('/')

print('Get from {}'.format(selector))
for data in w.get(selector):
    print('  {} : {}'.format(data.path, data.value))

z.logout()
コード例 #9
0
 def test_create_close_api(self):
     y = Zenoh.login(ZSERVER)
     self.assertTrue(y.rt.running)
     y.logout()
     self.assertFalse(y.rt.running)