summaryrefslogtreecommitdiff
path: root/python/test/Ice/ami/TestI.py
blob: 75deb1d08b6c51a0e4012570fbfe473eea9a4072 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# **********************************************************************
#
# Copyright (c) 2003-2016 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.
#
# **********************************************************************

import Ice, Test, threading, time

class TestIntfI(Test._TestIntfDisp):
    def __init__(self):
        self._cond = threading.Condition()
        self._batchCount = 0
        self._pending = []

    def op(self, current=None):
        pass

    def opWithResult(self, current=None):
        return 15

    def opWithUE(self, current=None):
        raise Test.TestIntfException()

    def opWithPayload(self, bytes, current=None):
        pass

    def opBatch(self, current=None):
        with self._cond:
            self._batchCount += 1
            self._cond.notify()

    def opBatchCount(self, current=None):
        with self._cond:
            return self._batchCount

    def waitForBatch(self, count, current=None):
        with self._cond:
            while self._batchCount < count:
                self._cond.wait(5)
            result = count == self._batchCount
            self._batchCount = 0
            return result

    def close(self, mode, current=None):
        current.con.close(Ice.ConnectionClose.valueOf(mode.value))

    def sleep(self, ms, current=None):
        time.sleep(ms / 1000.0)

    def startDispatch(self, current=None):
        f = Ice.Future()
        with self._cond:
            self._pending.append(f)
        return f

    def finishDispatch(self, current=None):
        with self._cond:
            for f in self._pending:
                f.set_result(None)
            self._pending = []

    def shutdown(self, current=None):
        #
        # Just in case a request arrived late.
        #
        with self._cond:
            for f in self._pending:
                f.set_result(None)
        current.adapter.getCommunicator().shutdown()

    def supportsAMD(self, current=None):
        return True

    def supportsFunctionalTests(self, current=None):
        return False

class TestIntfControllerI(Test._TestIntfControllerDisp):
    def __init__(self, adapter):
        self._adapter = adapter

    def holdAdapter(self, current=None):
        self._adapter.hold()

    def resumeAdapter(self, current=None):
        self._adapter.activate()