summaryrefslogtreecommitdiff
path: root/python/test/Ice/blobject/Client.py
blob: 64846c2702f92cf5a0564d24b348746adff410dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2018 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
#
# **********************************************************************

from TestHelper import TestHelper
TestHelper.loadSlice('Test.ice')
import sys
import Ice
import Test
import RouterI


def test(b):
    if not b:
        raise RuntimeError('test assertion failed')


class Client(TestHelper):

    def allTests(self, communicator, sync):
        hello = Test.HelloPrx.checkedCast(communicator.stringToProxy("test:default -p 12010"))
        hello.sayHello(False)
        hello.sayHello(False, {"_fwd": "o"})
        test(hello.add(10, 20) == 30)
        try:
            hello.raiseUE()
            test(False)
        except Test.UE:
            pass

        try:
            Test.HelloPrx.checkedCast(communicator.stringToProxy("unknown:default -p 12010 -t 10000"))
            test(False)
        except Ice.ObjectNotExistException:
            pass

        # First try an object at a non-existent endpoint.
        try:
            Test.HelloPrx.checkedCast(communicator.stringToProxy("missing:default -p 12000 -t 10000"))
            test(False)
        except Ice.UnknownLocalException as e:
            test(e.unknown.find('ConnectionRefusedException'))
            if sync:
                hello.shutdown()

    def run(self, args):

        properties = self.createTestProperties(args)
        properties.setProperty('Ice.Warn.Dispatch', '0')
        with self.initialize(properties=properties) as communicator:
            router = RouterI.RouterI(communicator, False)
            sys.stdout.write("testing async blobject... ")
            sys.stdout.flush()
            self.allTests(communicator, False)
            print("ok")
            router.destroy()

        with self.initialize(properties=properties) as communicator:
            router = RouterI.RouterI(communicator, True)
            sys.stdout.write("testing sync blobject... ")
            sys.stdout.flush()
            self.allTests(communicator, True)
            print("ok")
            router.destroy()