diff options
author | Mark Spruiell <mes@zeroc.com> | 2016-12-09 15:18:08 -0800 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2016-12-09 15:18:08 -0800 |
commit | 3b7e9f99b61538e0bbd6f07deeb7f7cb12013ed5 (patch) | |
tree | a8edbf5d1043527cc50880b34ee83458ed7e4855 /python/test/Ice/operations/ServerAMD.py | |
parent | Merge remote-tracking branch 'origin/3.6' (diff) | |
download | ice-3b7e9f99b61538e0bbd6f07deeb7f7cb12013ed5.tar.bz2 ice-3b7e9f99b61538e0bbd6f07deeb7f7cb12013ed5.tar.xz ice-3b7e9f99b61538e0bbd6f07deeb7f7cb12013ed5.zip |
ICE-7138 - new Python AMI mapping based on futures and modified AMD mapping
Diffstat (limited to 'python/test/Ice/operations/ServerAMD.py')
-rwxr-xr-x | python/test/Ice/operations/ServerAMD.py | 356 |
1 files changed, 184 insertions, 172 deletions
diff --git a/python/test/Ice/operations/ServerAMD.py b/python/test/Ice/operations/ServerAMD.py index 05777bad2d7..3204be386dc 100755 --- a/python/test/Ice/operations/ServerAMD.py +++ b/python/test/Ice/operations/ServerAMD.py @@ -8,7 +8,11 @@ # # ********************************************************************** -import os, sys, traceback, threading +import os, sys, traceback, threading, time + +haveConcurrentFuture = sys.version_info.major > 3 or (sys.version_info.major == 3 and sys.version_info.minor >= 5) +if haveConcurrentFuture: + import concurrent.futures import Ice slice_dir = Ice.getSliceDir() @@ -23,18 +27,20 @@ def test(b): if not b: raise RuntimeError('test assertion failed') -class Thread_opVoid(threading.Thread): - def __init__(self, cb): +class FutureThread(threading.Thread): + def __init__(self, f, r): threading.Thread.__init__(self) - self.cb = cb + self.future = f + self.result = r def run(self): - self.cb.ice_response() + time.sleep(0.01) + self.future.set_result(self.result) class MyDerivedClassI(Test.MyDerivedClass): def __init__(self): - self.opVoidThread = None - self.opVoidThreadLock = threading.Lock() + self.threads = [] + self.threadLock = threading.Lock() self.lock = threading.Lock() self.opByteSOnewayCount = 0 @@ -54,56 +60,63 @@ class MyDerivedClassI(Test.MyDerivedClass): test(current.mode == Ice.OperationMode.Nonmutating) return Test.MyDerivedClass.ice_id(self, current) - def shutdown_async(self, cb, current=None): - self.opVoidThreadLock.acquire() - if self.opVoidThread: - self.opVoidThread.join() - self.opVoidThread = None - self.opVoidThreadLock.release() + def shutdown(self, current=None): + with self.threadLock: + for thread in self.threads: + thread.join() + self.threads = [] current.adapter.getCommunicator().shutdown() - cb.ice_response() - def opVoid_async(self, cb, current=None): + def opVoid(self, current=None): test(current.mode == Ice.OperationMode.Normal) - self.opVoidThreadLock.acquire() - if self.opVoidThread: - self.opVoidThread.join() - self.opVoidThread = None + f = Ice.Future() + + with self.threadLock: + thread = FutureThread(f, None) + self.threads.append(thread) + thread.start() - self.opVoidThread = Thread_opVoid(cb) - self.opVoidThread.start() - self.opVoidThreadLock.release() + return f - def opByte_async(self, cb, p1, p2, current=None): - cb.ice_response(p1, p1 ^ p2) + def opByte(self, p1, p2, current=None): + # Test the ability to use another Future type + if haveConcurrentFuture: + f = concurrent.futures.Future() + with self.threadLock: + thread = FutureThread(f, (p1, p1 ^ p2)) + self.threads.append(thread) + thread.start() + else: + f = Ice.Future.completed((p1, p1 ^ p2)) + return f - def opBool_async(self, cb, p1, p2, current=None): - cb.ice_response(p2, p1) + def opBool(self, p1, p2, current=None): + return Ice.Future.completed((p2, p1)) - def opShortIntLong_async(self, cb, p1, p2, p3, current=None): - cb.ice_response(p3, p1, p2, p3) + def opShortIntLong(self, p1, p2, p3, current=None): + return Ice.Future.completed((p3, p1, p2, p3)) - def opFloatDouble_async(self, cb, p1, p2, current=None): - cb.ice_response(p2, p1, p2) + def opFloatDouble(self, p1, p2, current=None): + return Ice.Future.completed((p2, p1, p2)) - def opString_async(self, cb, p1, p2, current=None): - cb.ice_response(p1 + " " + p2, p2 + " " + p1) + def opString(self, p1, p2, current=None): + return Ice.Future.completed((p1 + " " + p2, p2 + " " + p1)) - def opMyEnum_async(self, cb, p1, current=None): - cb.ice_response(Test.MyEnum.enum3, p1) + def opMyEnum(self, p1, current=None): + return Ice.Future.completed((Test.MyEnum.enum3, p1)) - def opMyClass_async(self, cb, p1, current=None): + def opMyClass(self, p1, current=None): p2 = p1 p3 = Test.MyClassPrx.uncheckedCast(current.adapter.createProxy(Ice.stringToIdentity("noSuchIdentity"))) - cb.ice_response(Test.MyClassPrx.uncheckedCast(current.adapter.createProxy(current.id)), p2, p3) + return Ice.Future.completed((Test.MyClassPrx.uncheckedCast(current.adapter.createProxy(current.id)), p2, p3)) - def opStruct_async(self, cb, p1, p2, current=None): + def opStruct(self, p1, p2, current=None): p1.s.s = "a new string" - cb.ice_response(p2, p1) + return Ice.Future.completed((p2, p1)) - def opByteS_async(self, cb, p1, p2, current=None): + def opByteS(self, p1, p2, current=None): if sys.version_info[0] == 2: # By default sequence<byte> maps to a string. p3 = map(ord, p1) @@ -113,323 +126,322 @@ class MyDerivedClassI(Test.MyDerivedClass): else: p3 = bytes(reversed(p1)) r = p1 + p2 - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opBoolS_async(self, cb, p1, p2, current=None): + def opBoolS(self, p1, p2, current=None): p3 = p1[0:] p3.extend(p2) r = p1[0:] r.reverse(); - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opShortIntLongS_async(self, cb, p1, p2, p3, current=None): + def opShortIntLongS(self, p1, p2, p3, current=None): p4 = p1[0:] p5 = p2[0:] p5.reverse() p6 = p3[0:] p6.extend(p3) - cb.ice_response(p3, p4, p5, p6) + return Ice.Future.completed((p3, p4, p5, p6)) - def opFloatDoubleS_async(self, cb, p1, p2, current=None): + def opFloatDoubleS(self, p1, p2, current=None): p3 = p1[0:] p4 = p2[0:] p4.reverse() r = p2[0:] r.extend(p1) - cb.ice_response(r, p3, p4) + return Ice.Future.completed((r, p3, p4)) - def opStringS_async(self, cb, p1, p2, current=None): + def opStringS(self, p1, p2, current=None): p3 = p1[0:] p3.extend(p2) r = p1[0:] r.reverse() - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opByteSS_async(self, cb, p1, p2, current=None): + def opByteSS(self, p1, p2, current=None): p3 = p1[0:] p3.reverse() r = p1[0:] r.extend(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opBoolSS_async(self, cb, p1, p2, current=None): + def opBoolSS(self, p1, p2, current=None): p3 = p1[0:] p3.extend(p2) r = p1[0:] r.reverse() - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opShortIntLongSS_async(self, cb, p1, p2, p3, current=None): + def opShortIntLongSS(self, p1, p2, p3, current=None): p4 = p1[0:] p5 = p2[0:] p5.reverse() p6 = p3[0:] p6.extend(p3) - cb.ice_response(p3, p4, p5, p6) + return Ice.Future.completed((p3, p4, p5, p6)) - def opFloatDoubleSS_async(self, cb, p1, p2, current=None): + def opFloatDoubleSS(self, p1, p2, current=None): p3 = p1[0:] p4 = p2[0:] p4.reverse() r = p2[0:] r.extend(p2) - cb.ice_response(r, p3, p4) + return Ice.Future.completed((r, p3, p4)) - def opStringSS_async(self, cb, p1, p2, current=None): + def opStringSS(self, p1, p2, current=None): p3 = p1[0:] p3.extend(p2) r = p2[0:] r.reverse() - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opStringSSS_async(self, cb, p1, p2, current=None): + def opStringSSS(self, p1, p2, current=None): p3 = p1[0:] p3.extend(p2) r = p2[0:] r.reverse() - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opByteBoolD_async(self, cb, p1, p2, current=None): + def opByteBoolD(self, p1, p2, current=None): p3 = p1.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opShortIntD_async(self, cb, p1, p2, current=None): + def opShortIntD(self, p1, p2, current=None): p3 = p1.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opLongFloatD_async(self, cb, p1, p2, current=None): + def opLongFloatD(self, p1, p2, current=None): p3 = p1.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opStringStringD_async(self, cb, p1, p2, current=None): + def opStringStringD(self, p1, p2, current=None): p3 = p1.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opStringMyEnumD_async(self, cb, p1, p2, current=None): + def opStringMyEnumD(self, p1, p2, current=None): p3 = p1.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opMyEnumStringD_async(self, cb, p1, p2, current=None): + def opMyEnumStringD(self, p1, p2, current=None): p3 = p1.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opMyStructMyEnumD_async(self, cb, p1, p2, current=None): + def opMyStructMyEnumD(self, p1, p2, current=None): p3 = p1.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opByteBoolDS_async(self, cb, p1, p2, current=None): + def opByteBoolDS(self, p1, p2, current=None): p3 = p2[0:] p3.extend(p1) r = p1[::-1] - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opShortIntDS_async(self, cb, p1, p2, current=None): + def opShortIntDS(self, p1, p2, current=None): p3 = p2[0:] p3.extend(p1) r = p1[::-1] - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opLongFloatDS_async(self, cb, p1, p2, current=None): + def opLongFloatDS(self, p1, p2, current=None): p3 = p2[0:] p3.extend(p1) r = p1[::-1] - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opStringStringDS_async(self, cb, p1, p2, current=None): + def opStringStringDS(self, p1, p2, current=None): p3 = p2[0:] p3.extend(p1) r = p1[::-1] - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opStringMyEnumDS_async(self, cb, p1, p2, current=None): + def opStringMyEnumDS(self, p1, p2, current=None): p3 = p2[0:] p3.extend(p1) r = p1[::-1] - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opMyEnumStringDS_async(self, cb, p1, p2, current=None): + def opMyEnumStringDS(self, p1, p2, current=None): p3 = p2[0:] p3.extend(p1) r = p1[::-1] - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opMyStructMyEnumDS_async(self, cb, p1, p2, current=None): + def opMyStructMyEnumDS(self, p1, p2, current=None): p3 = p2[0:] p3.extend(p1) r = p1[::-1] - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opByteByteSD_async(self, cb, p1, p2, current=None): + def opByteByteSD(self, p1, p2, current=None): p3 = p2.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opBoolBoolSD_async(self, cb, p1, p2, current=None): + def opBoolBoolSD(self, p1, p2, current=None): p3 = p2.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opShortShortSD_async(self, cb, p1, p2, current=None): + def opShortShortSD(self, p1, p2, current=None): p3 = p2.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opIntIntSD_async(self, cb, p1, p2, current=None): + def opIntIntSD(self, p1, p2, current=None): p3 = p2.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opLongLongSD_async(self, cb, p1, p2, current=None): + def opLongLongSD(self, p1, p2, current=None): p3 = p2.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opStringFloatSD_async(self, cb, p1, p2, current=None): + def opStringFloatSD(self, p1, p2, current=None): p3 = p2.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opStringDoubleSD_async(self, cb, p1, p2, current=None): + def opStringDoubleSD(self, p1, p2, current=None): p3 = p2.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opStringStringSD_async(self, cb, p1, p2, current=None): + def opStringStringSD(self, p1, p2, current=None): p3 = p2.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opMyEnumMyEnumSD_async(self, cb, p1, p2, current=None): + def opMyEnumMyEnumSD(self, p1, p2, current=None): p3 = p2.copy() r = p1.copy() r.update(p2) - cb.ice_response(r, p3) + return Ice.Future.completed((r, p3)) - def opIntS_async(self, cb, s, current=None): - cb.ice_response([-x for x in s]) + def opIntS(self, s, current=None): + return Ice.Future.completed([-x for x in s]) - def opByteSOneway_async(self, cb, s, current=None): - self.lock.acquire() - self.opByteSOnewayCount += 1 - self.lock.release() - cb.ice_response() + def opByteSOneway(self, s, current=None): + with self.lock: + self.opByteSOnewayCount += 1 + return Ice.Future.completed(None) - def opByteSOnewayCallCount_async(self, cb, current=None): - self.lock.acquire() - count = self.opByteSOnewayCount - self.opByteSOnewayCount = 0 - self.lock.release() - cb.ice_response(count) + def opByteSOnewayCallCount(self, current=None): + with self.lock: + count = self.opByteSOnewayCount + self.opByteSOnewayCount = 0 + return Ice.Future.completed(count) - def opDoubleMarshaling_async(self, cb, p1, p2, current=None): + def opDoubleMarshaling(self, p1, p2, current=None): d = 1278312346.0 / 13.0; test(p1 == d) for i in p2: test(i == d) - cb.ice_response() + return Ice.Future.completed(None) - def opContext_async(self, cb, current=None): - cb.ice_response(current.ctx) + def opContext(self, current=None): + return Ice.Future.completed(current.ctx) - def opIdempotent_async(self, cb, current=None): + def opIdempotent(self, current=None): test(current.mode == Ice.OperationMode.Idempotent) - cb.ice_response() + return Ice.Future.completed(None) - def opNonmutating_async(self, cb, current=None): + def opNonmutating(self, current=None): test(current.mode == Ice.OperationMode.Nonmutating) - cb.ice_response() + return Ice.Future.completed(None) - def opDerived_async(self, cb, current=None): - cb.ice_response() + def opDerived(self, current=None): + return Ice.Future.completed(None) - def opByte1_async(self, cb, value, current=None): - cb.ice_response(value) + def opByte1(self, value, current=None): + return Ice.Future.completed(value) - def opShort1_async(self, cb, value, current=None): - cb.ice_response(value) + def opShort1(self, value, current=None): + return Ice.Future.completed(value) - def opInt1_async(self, cb, value, current=None): - cb.ice_response(value) + def opInt1(self, value, current=None): + return Ice.Future.completed(value) - def opLong1_async(self, cb, value, current=None): - cb.ice_response(value) + def opLong1(self, value, current=None): + return Ice.Future.completed(value) - def opFloat1_async(self, cb, value, current=None): - cb.ice_response(value) + def opFloat1(self, value, current=None): + return Ice.Future.completed(value) - def opDouble1_async(self, cb, value, current=None): - cb.ice_response(value) + def opDouble1(self, value, current=None): + return Ice.Future.completed(value) - def opString1_async(self, cb, value, current=None): - cb.ice_response(value) + def opString1(self, value, current=None): + return Ice.Future.completed(value) - def opStringS1_async(self, cb, value, current=None): - cb.ice_response(value) + def opStringS1(self, value, current=None): + return Ice.Future.completed(value) - def opByteBoolD1_async(self, cb, value, current=None): - cb.ice_response(value) + def opByteBoolD1(self, value, current=None): + return Ice.Future.completed(value) - def opStringS2_async(self, cb, value, current=None): - cb.ice_response(value) + def opStringS2(self, value, current=None): + return Ice.Future.completed(value) - def opByteBoolD2_async(self, cb, value, current=None): - cb.ice_response(value) + def opByteBoolD2(self, value, current=None): + return Ice.Future.completed(value) - def opMyClass1_async(self, cb, value, current=None): - return cb.ice_response(value) + def opMyClass1(self, value, current=None): + return Ice.Future.completed(value) - def opMyStruct1_async(self, cb, value, current=None): - return cb.ice_response(value) + def opMyStruct1(self, value, current=None): + return Ice.Future.completed(value) - def opStringLiterals_async(self, cb, current=None): - return cb.ice_response([ + def opStringLiterals(self, current=None): + return Ice.Future.completed([ Test.s0, Test.s1, Test.s2, Test.s3, Test.s4, Test.s5, Test.s6, Test.s7, Test.s8, Test.s9, Test.s10, - Test.sw0, Test.sw1, Test.sw2, Test.sw3, Test.sw4, Test.sw5, Test.sw6, Test.sw7, Test.sw8, Test.sw9, Test.sw10, + Test.sw0, Test.sw1, Test.sw2, Test.sw3, Test.sw4, Test.sw5, Test.sw6, Test.sw7, Test.sw8, Test.sw9, + Test.sw10, Test.ss0, Test.ss1, Test.ss2, Test.ss3, Test.ss4, Test.ss5, Test.su0, Test.su1, Test.su2]) - def opWStringLiterals_async(self, cb, current=None): - return self.opStringLiterals_async(cb, current) + def opWStringLiterals(self, current=None): + return self.opStringLiterals(current) - def opMStruct1_async(self, cb, current): - cb.ice_response(Test.Structure()) + def opMStruct1(self, current): + return Ice.Future.completed(Test.Structure()) - def opMStruct2_async(self, cb, p1, current): - cb.ice_response(p1, p1) + def opMStruct2(self, p1, current): + return Ice.Future.completed((p1, p1)) - def opMSeq1_async(self, cb, current): - cb.ice_response([]) + def opMSeq1(self, current): + return Ice.Future.completed([]) - def opMSeq2_async(self, cb, p1, current): - cb.ice_response(p1, p1) + def opMSeq2(self, p1, current): + return Ice.Future.completed((p1, p1)) - def opMDict1_async(self, cb, current): - cb.ice_response({}) + def opMDict1(self, current): + return Ice.Future.completed({}) - def opMDict2_async(self, cb, p1, current): - cb.ice_response(p1, p1) + def opMDict2(self, p1, current): + return Ice.Future.completed((p1, p1)) def run(args, communicator): communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010:udp") |