blob: 23373babd715d0639db47efd4794ce00df6bdb06 (
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
import Foundation
import Ice
import TestCommon
class TestI: TestIntf {
init() {}
func transient(current: Ice.Current) throws {
let communicator = current.adapter!.getCommunicator()
let adapter = try communicator.createObjectAdapterWithEndpoints(name: "TransientTestAdapter",
endpoints: "default")
try adapter.activate()
adapter.destroy()
}
func deactivate(current: Ice.Current) throws {
current.adapter!.deactivate()
Thread.sleep(forTimeInterval: 0.1)
}
}
class CookieI: Cookie {
func message() -> String {
return "blahblah"
}
}
class RouterI: Ice.Router {
func getClientProxy(current _: Ice.Current) throws -> (returnValue: ObjectPrx?, hasRoutingTable: Bool?) {
return (nil, false)
}
func addProxies(proxies _: [ObjectPrx?], current _: Current) throws -> [ObjectPrx?] {
return []
}
func getServerProxy(current: Ice.Current) throws -> Ice.ObjectPrx? {
let prx =
try current.adapter!.getCommunicator().stringToProxy("dummy:tcp -h localhost -p \(_nextPort) -t 30000")
_nextPort += 1
return prx
}
var _nextPort: Int32 = 23456
}
class ServantLocatorI: Ice.ServantLocator {
var _helper: TestHelper
var _deactivated: Bool
var _router = RouterI()
var _lock = os_unfair_lock()
init(helper: TestHelper) {
_deactivated = false
_helper = helper
}
deinit {
precondition(_deactivated)
}
func locate(_ current: Ice.Current) throws -> (returnValue: Disp?, cookie: AnyObject?) {
try withLock(&_lock) {
try _helper.test(!_deactivated)
}
if current.id.name == "router" {
return (RouterDisp(_router), CookieI())
}
try _helper.test(current.id.category == "")
try _helper.test(current.id.name == "test")
return (TestIntfDisp(TestI()), CookieI())
}
func finished(curr current: Ice.Current, servant _: Ice.Disp, cookie: Swift.AnyObject?) throws {
try withLock(&_lock) {
try _helper.test(!_deactivated)
}
if current.id.name == "router" {
return
}
try _helper.test((cookie as! Cookie).message() == "blahblah")
}
func deactivate(_: String) {
do {
try withLock(&_lock) {
try _helper.test(!_deactivated)
_deactivated = true
}
} catch {
fatalError("\(error)")
}
}
}
|