~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/jinterface/test/jinterface_SUITE_data/MboxSendReceive.java

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * %CopyrightBegin%
 
3
 *
 
4
 * Copyright Ericsson AB 2004-2010. All Rights Reserved.
 
5
 *
 
6
 * The contents of this file are subject to the Erlang Public License,
 
7
 * Version 1.1, (the "License"); you may not use this file except in
 
8
 * compliance with the License. You should have received a copy of the
 
9
 * Erlang Public License along with this software. If not, it can be
 
10
 * retrieved online at http://www.erlang.org/.
 
11
 *
 
12
 * Software distributed under the License is distributed on an "AS IS"
 
13
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
 * the License for the specific language governing rights and limitations
 
15
 * under the License.
 
16
 *
 
17
 * %CopyrightEnd%
 
18
 */
 
19
 
 
20
import com.ericsson.otp.erlang.*;
 
21
 
 
22
class MboxSendReceive {
 
23
 
 
24
    /*
 
25
      Implements test case jinterface_SUITE:mbox_send_receive/1
 
26
 
 
27
      Test OtpMbox.send(...) and OtpMbox.receive(...)
 
28
     */
 
29
 
 
30
    private static final boolean dbg = true;
 
31
    private static final int recTime = 2000;
 
32
 
 
33
    private static final int java_erlang_send_receive = 1;
 
34
    private static final int java_internal_send_receive_same_node = 2;
 
35
    private static final int java_internal_send_receive_different_nodes = 3;
 
36
    private static final int java_internal_send_receive_self = 4;
 
37
 
 
38
    public static void main(String argv[]) {
 
39
 
 
40
        String cookie = argv[0];
 
41
        String erlNode = argv[1];
 
42
 
 
43
        OtpErlangObject[] msgArray = new OtpErlangObject[2];
 
44
        msgArray[1] = new OtpErlangAtom("hello world");
 
45
        OtpErlangTuple msg = null;
 
46
 
 
47
        try {
 
48
            // Initiate: create javanode and mboxes
 
49
            OtpNode node = new OtpNode("javanode",cookie);
 
50
            OtpMbox mbox = node.createMbox();
 
51
            OtpMbox mbox2 = node.createMbox("java_echo_server2");
 
52
 
 
53
            // Send the pid of mbox to erlang and wait for test case
 
54
            // instruction: {TestCaseTag, Pid}
 
55
            mbox.send("erl_send_receive_server", erlNode, mbox.self());
 
56
            OtpErlangObject o = mbox.receive(recTime);
 
57
            if (o == null) System.exit(1);
 
58
            OtpErlangTuple testCase = (OtpErlangTuple)o;
 
59
            dbg("mbox received " + testCase);
 
60
            int tag = (int)((OtpErlangLong)testCase.elementAt(0)).longValue();
 
61
            OtpErlangPid erlangPid = (OtpErlangPid)testCase.elementAt(1);
 
62
 
 
63
            switch (tag) {
 
64
 
 
65
            case java_erlang_send_receive:
 
66
 
 
67
                // Test1 (happened during initiation):
 
68
                // Send mbox pid to erlang process with registered name.
 
69
                // Erlang process sent back its pid to the mbox pid.
 
70
 
 
71
                // Test2: Register name and sent it to the erlang pid. Erlang
 
72
                // process shall send message back to my registered name.
 
73
 
 
74
                mbox.registerName("java_echo_server");
 
75
                msgArray[0] = getNameNode("java_echo_server",node);
 
76
                msg = new OtpErlangTuple(msgArray);
 
77
 
 
78
                dbg("java_echo_server sending " + msg);
 
79
                mbox.send(erlangPid,msg);
 
80
 
 
81
                o = mbox.receive(recTime);
 
82
                dbg("java_echo_server received " + o);
 
83
                if (o == null) System.exit(2);
 
84
                if (!((OtpErlangAtom)o).equals(msgArray[1])) System.exit(3);
 
85
 
 
86
                // Test3: Same as Test2, but using a new mbox2 which
 
87
                // got its name already when it is created - i.e. not
 
88
                // using mbox.registerName
 
89
                msgArray[0] = getNameNode("java_echo_server2",node);
 
90
                msg = new OtpErlangTuple(msgArray);
 
91
 
 
92
                dbg("java_echo_server2 sending " + msg);
 
93
                mbox2.send(erlangPid,msg);
 
94
 
 
95
                o = mbox2.receive(recTime);
 
96
                dbg("java_echo_server received " + o);
 
97
                if (o == null) System.exit(4);
 
98
                if (!((OtpErlangAtom)o).equals(msgArray[1])) System.exit(5);
 
99
 
 
100
                break;
 
101
 
 
102
            case java_internal_send_receive_same_node:
 
103
 
 
104
                // Test1: Sending message between mboxes on same node
 
105
                // given registered name and node without host.
 
106
                mbox.send("java_echo_server2","javanode",msgArray[1]);
 
107
                o = mbox2.receive(recTime);
 
108
                dbg("Mbox at same node: " + o);
 
109
                if (o == null) System.exit(6);
 
110
                if(!((OtpErlangAtom)o).equals(msgArray[1])) System.exit(7);
 
111
 
 
112
                // Test2: Sending message between mboxes on same node
 
113
                // given registered name and node with host.
 
114
                mbox.send("java_echo_server2",mbox2.self().node(),msgArray[1]);
 
115
                o = mbox2.receive(recTime);
 
116
                dbg("Mbox at same node: " + o);
 
117
                if (o == null) System.exit(8);
 
118
                if(!((OtpErlangAtom)o).equals(msgArray[1])) System.exit(9);
 
119
 
 
120
                // Test3: Sending message between mboxes on same node
 
121
                // given registered name but not node.
 
122
                mbox.send("java_echo_server2",msgArray[1]);
 
123
                o = mbox2.receive(recTime);
 
124
                dbg("Mbox at same node: " + o);
 
125
                if (o == null) System.exit(10);
 
126
                if(!((OtpErlangAtom)o).equals(msgArray[1])) System.exit(11);
 
127
 
 
128
                // Test4: Sending message between mboxes on same node
 
129
                // given pid.
 
130
                mbox.send(mbox2.self(),msgArray[1]);
 
131
                o = mbox2.receive(recTime);
 
132
                dbg("Mbox at same node: " + o);
 
133
                if (o == null) System.exit(12);
 
134
                if(!((OtpErlangAtom)o).equals(msgArray[1])) System.exit(13);
 
135
 
 
136
                break;
 
137
 
 
138
            case java_internal_send_receive_different_nodes:
 
139
 
 
140
                OtpNode node2 = new OtpNode("javanode2", cookie);
 
141
                OtpMbox mboxOtherNode = node2.createMbox("mboxOtherNode");
 
142
 
 
143
                // Test1: Sending message between mboxes on different
 
144
                // nodes given registered name and node without host.
 
145
                mbox.send("mboxOtherNode","javanode2",msgArray[1]);
 
146
                o = mboxOtherNode.receive(recTime);
 
147
                dbg("Mbox at same node: " + o);
 
148
                if (o == null) System.exit(14);
 
149
                if(!((OtpErlangAtom)o).equals(msgArray[1])) System.exit(15);
 
150
 
 
151
                // Test2: Sending message between mboxes on different
 
152
                // nodes given registered name and node with host.
 
153
                mbox.send("mboxOtherNode",mboxOtherNode.self().node(),
 
154
                          msgArray[1]);
 
155
                o = mboxOtherNode.receive(recTime);
 
156
                dbg("Mbox at same node: " + o);
 
157
                if (o == null) System.exit(16);
 
158
                if(!((OtpErlangAtom)o).equals(msgArray[1])) System.exit(17);
 
159
 
 
160
                // Test3: Sending message between mboxes on different
 
161
                // nodes given pid.
 
162
                mbox.send(mboxOtherNode.self(),msgArray[1]);
 
163
                o = mboxOtherNode.receive(recTime);
 
164
                dbg("Mbox at same node: " + o);
 
165
                if (o == null) System.exit(18);
 
166
                if(!((OtpErlangAtom)o).equals(msgArray[1])) System.exit(19);
 
167
 
 
168
                break;
 
169
 
 
170
 
 
171
            case java_internal_send_receive_self:
 
172
 
 
173
                // Test1: Sending message to myself given registered
 
174
                // name and node without host.
 
175
                mbox2.send("java_echo_server2","javanode",msgArray[1]);
 
176
                o = mbox2.receive(recTime);
 
177
                dbg("Self: " + o);
 
178
                if (o == null) System.exit(18);
 
179
                if(!((OtpErlangAtom)o).equals(msgArray[1])) System.exit(19);
 
180
 
 
181
                // Test2: Sending message to myself given registered
 
182
                // name and node with host.
 
183
                mbox2.send("java_echo_server2",mbox2.self().node(),msgArray[1]);
 
184
                o = mbox2.receive(recTime);
 
185
                dbg("Self: " + o);
 
186
                if (o == null) System.exit(20);
 
187
                if(!((OtpErlangAtom)o).equals(msgArray[1])) System.exit(21);
 
188
 
 
189
                // Test3: Sending message to myself given registered
 
190
                // name but not host.
 
191
                mbox2.send("java_echo_server2",msgArray[1]);
 
192
                o = mbox2.receive(recTime);
 
193
                dbg("Self: " + o);
 
194
                if (o == null) System.exit(22);
 
195
                if(!((OtpErlangAtom)o).equals(msgArray[1])) System.exit(23);
 
196
 
 
197
                // Test4: Sending message to myself given pid.
 
198
                mbox2.send(mbox2.self(),msgArray[1]);
 
199
                o = mbox2.receive(recTime);
 
200
                dbg("Self: " + o);
 
201
                if (o == null) System.exit(24);
 
202
                if(!((OtpErlangAtom)o).equals(msgArray[1])) System.exit(25);
 
203
 
 
204
                break;
 
205
 
 
206
            }
 
207
 
 
208
            // Closing erl_send_receive_server by sending the atom 'done' to it.
 
209
            mbox.send(erlangPid,new OtpErlangAtom("done"));
 
210
        }
 
211
        catch (Exception e) {
 
212
            System.out.println("" + e);
 
213
            System.exit(26);
 
214
        }
 
215
    }
 
216
 
 
217
    private static OtpErlangTuple getNameNode(String mboxName,OtpNode node) {
 
218
        OtpErlangObject[] array = {new OtpErlangAtom(mboxName),
 
219
                                   new OtpErlangAtom(node.node())};
 
220
        return new OtpErlangTuple(array);
 
221
 
 
222
    }
 
223
 
 
224
    private static void dbg(String str) {
 
225
        if (dbg) System.out.println(str);
 
226
    }
 
227
 
 
228
 
 
229
}