summaryrefslogtreecommitdiff
path: root/csharp/test/Ice/servantLocator/ServantLocatorI.cs
blob: 6c10e36fbc54a3e2d359892d6f9f2f58ffa65283 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// **********************************************************************
//
// Copyright (c) 2003-2017 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.
//
// **********************************************************************

using System;
using Test;
using Ice;

public sealed class ServantLocatorI : Ice.ServantLocator
{
    public ServantLocatorI(String category)
    {
        _category = category;
        _deactivated = false;
        _requestId = -1;
    }
    
    ~ServantLocatorI()
    {
        lock(this)
        {
            test(_deactivated);
        }
    }
    
    private static void test(bool b)
    {
        if(!b)
        {
            throw new System.Exception();
        }
    }
    
    public Ice.Object locate(Ice.Current current, out object cookie)
    {
        lock(this)
        {
            test(!_deactivated);
        }
        
        test(current.id.category.Equals(_category) || _category.Length == 0);
        
        if(current.id.name.Equals("unknown"))
        {
            cookie = null;
            return null;
        }

        test(current.id.name.Equals("locate") || current.id.name.Equals("finished"));
        if(current.id.name.Equals("locate"))
        {
            exception(current);
        }

        //
        // Ensure locate() is only called once per request.
        //
        test(_requestId == -1);
        _requestId = current.requestId;

        cookie = new CookieI();

        return new TestI();
    }
    
    public void finished(Ice.Current current, Ice.Object servant, System.Object cookie)
    {
        lock(this)
        {
            test(!_deactivated);
        }

        //
        // Ensure finished() is only called once per request.
        //
        test(_requestId == current.requestId);
        _requestId = -1;
        
        test(current.id.category.Equals(_category)  || _category.Length == 0);
        test(current.id.name.Equals("locate") || current.id.name.Equals("finished"));
        
        if(current.id.name.Equals("finished"))
        {
            exception(current);
        }

        Cookie co = (Cookie) cookie;
        test(co.message().Equals("blahblah"));
    }
    
    public void deactivate(string category)
    {
        lock(this)
        {
            test(!_deactivated);
        
            _deactivated = true;
        }
    }
    
    private void exception(Ice.Current current)
    {
        if(current.operation.Equals("ice_ids"))
        {
            throw new Test.TestIntfUserException();
        }
        else if(current.operation.Equals("requestFailedException"))
        {
            throw new ObjectNotExistException();
        }
        else if(current.operation.Equals("unknownUserException"))
        {
            UnknownUserException ex = new UnknownUserException();
            ex.unknown = "reason";
            throw ex;
        }
        else if(current.operation.Equals("unknownLocalException"))
        {
            UnknownLocalException ex = new UnknownLocalException();
            ex.unknown = "reason";
            throw ex;
        }
        else if(current.operation.Equals("unknownException"))
        {
            UnknownException ex = new UnknownException();
            ex.unknown = "reason";
            throw ex;
        }
        else if(current.operation.Equals("userException"))
        {
            throw new TestIntfUserException();
        }
        else if(current.operation.Equals("localException"))
        {
            SocketException ex = new SocketException();
            ex.error = 0;
            throw ex;
        }
        else if(current.operation.Equals("csException"))
        {
            throw new System.Exception("message");
        }
        else if(current.operation.Equals("unknownExceptionWithServantException"))
        {
            throw new UnknownException("reason");
        }
        else if(current.operation.Equals("impossibleException"))
        {
            throw new Test.TestIntfUserException(); // Yes, it really is meant to be TestIntfException.
        }
        else if(current.operation.Equals("intfUserException"))
        {
            throw new Test.TestImpossibleException(); // Yes, it really is meant to be TestImpossibleException.
        }
        else if(current.operation.Equals("asyncResponse"))
        {
            throw new Test.TestImpossibleException();
        }
        else if(current.operation.Equals("asyncException"))
        {
            throw new Test.TestImpossibleException();
        }
    }

    private bool _deactivated;
    private string _category;
    private int _requestId;
}