OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // | 4 // |
5 // VMOptions= | 5 // VMOptions= |
6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
9 | 9 |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 leaveRequest["request"] = "leave"; | 65 leaveRequest["request"] = "leave"; |
66 leaveRequest["sessionId"] = sessionId; | 66 leaveRequest["sessionId"] = sessionId; |
67 httpClient.post("127.0.0.1", port, "/leave") | 67 httpClient.post("127.0.0.1", port, "/leave") |
68 .then((HttpClientRequest request) { | 68 .then((HttpClientRequest request) { |
69 request.addString(json.stringify(leaveRequest)); | 69 request.addString(json.stringify(leaveRequest)); |
70 return request.close(); | 70 return request.close(); |
71 }) | 71 }) |
72 .then((HttpClientResponse response) { | 72 .then((HttpClientResponse response) { |
73 StringBuffer body = new StringBuffer(); | 73 StringBuffer body = new StringBuffer(); |
74 response.listen( | 74 response.listen( |
75 (data) => body.add(new String.fromCharCodes(data)), | 75 (data) => body.write(new String.fromCharCodes(data)), |
76 onDone: () => leaveResponseHandler(response, body.toString())); | 76 onDone: () => leaveResponseHandler(response, body.toString())); |
77 }); | 77 }); |
78 } | 78 } |
79 | 79 |
80 void receive() { | 80 void receive() { |
81 void receiveResponseHandler(response, String data) { | 81 void receiveResponseHandler(response, String data) { |
82 Expect.equals(HttpStatus.OK, response.statusCode); | 82 Expect.equals(HttpStatus.OK, response.statusCode); |
83 var responseData = json.parse(data); | 83 var responseData = json.parse(data); |
84 Expect.equals("receive", responseData["response"]); | 84 Expect.equals("receive", responseData["response"]); |
85 Expect.equals(null, responseData["disconnect"]); | 85 Expect.equals(null, responseData["disconnect"]); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 receiveRequest["sessionId"] = sessionId; | 121 receiveRequest["sessionId"] = sessionId; |
122 receiveRequest["nextMessage"] = receiveMessageNumber; | 122 receiveRequest["nextMessage"] = receiveMessageNumber; |
123 httpClient.post("127.0.0.1", port, "/receive") | 123 httpClient.post("127.0.0.1", port, "/receive") |
124 .then((HttpClientRequest request) { | 124 .then((HttpClientRequest request) { |
125 request.addString(json.stringify(receiveRequest)); | 125 request.addString(json.stringify(receiveRequest)); |
126 return request.close(); | 126 return request.close(); |
127 }) | 127 }) |
128 .then((HttpClientResponse response) { | 128 .then((HttpClientResponse response) { |
129 StringBuffer body = new StringBuffer(); | 129 StringBuffer body = new StringBuffer(); |
130 response.listen( | 130 response.listen( |
131 (data) => body.add(new String.fromCharCodes(data)), | 131 (data) => body.write(new String.fromCharCodes(data)), |
132 onDone: () => receiveResponseHandler(response, body.toString())); | 132 onDone: () => receiveResponseHandler(response, body.toString())); |
133 }); | 133 }); |
134 } | 134 } |
135 | 135 |
136 void sendMessage() { | 136 void sendMessage() { |
137 void sendResponseHandler(response, String data) { | 137 void sendResponseHandler(response, String data) { |
138 Expect.equals(HttpStatus.OK, response.statusCode); | 138 Expect.equals(HttpStatus.OK, response.statusCode); |
139 var responseData = json.parse(data); | 139 var responseData = json.parse(data); |
140 Expect.equals("message", responseData["response"]); | 140 Expect.equals("message", responseData["response"]); |
141 sendMessageNumber++; | 141 sendMessageNumber++; |
142 if (sendMessageNumber < messagesToSend) { | 142 if (sendMessageNumber < messagesToSend) { |
143 sendMessage(); | 143 sendMessage(); |
144 } else { | 144 } else { |
145 receive(); | 145 receive(); |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 Map messageRequest = new Map(); | 149 Map messageRequest = new Map(); |
150 messageRequest["request"] = "message"; | 150 messageRequest["request"] = "message"; |
151 messageRequest["sessionId"] = sessionId; | 151 messageRequest["sessionId"] = sessionId; |
152 messageRequest["message"] = "message $sendMessageNumber"; | 152 messageRequest["message"] = "message $sendMessageNumber"; |
153 httpClient.post("127.0.0.1", port, "/message") | 153 httpClient.post("127.0.0.1", port, "/message") |
154 .then((HttpClientRequest request) { | 154 .then((HttpClientRequest request) { |
155 request.addString(json.stringify(messageRequest)); | 155 request.addString(json.stringify(messageRequest)); |
156 return request.close(); | 156 return request.close(); |
157 }) | 157 }) |
158 .then((HttpClientResponse response) { | 158 .then((HttpClientResponse response) { |
159 StringBuffer body = new StringBuffer(); | 159 StringBuffer body = new StringBuffer(); |
160 response.listen( | 160 response.listen( |
161 (data) => body.add(new String.fromCharCodes(data)), | 161 (data) => body.write(new String.fromCharCodes(data)), |
162 onDone: () => sendResponseHandler(response, body.toString())); | 162 onDone: () => sendResponseHandler(response, body.toString())); |
163 }); | 163 }); |
164 } | 164 } |
165 | 165 |
166 void join() { | 166 void join() { |
167 void joinResponseHandler(response, String data) { | 167 void joinResponseHandler(response, String data) { |
168 Expect.equals(HttpStatus.OK, response.statusCode); | 168 Expect.equals(HttpStatus.OK, response.statusCode); |
169 var responseData = json.parse(data); | 169 var responseData = json.parse(data); |
170 Expect.equals("join", responseData["response"]); | 170 Expect.equals("join", responseData["response"]); |
171 sessionId = responseData["sessionId"]; | 171 sessionId = responseData["sessionId"]; |
(...skipping 10 matching lines...) Expand all Loading... |
182 joinRequest["request"] = "join"; | 182 joinRequest["request"] = "join"; |
183 joinRequest["handle"] = "test1"; | 183 joinRequest["handle"] = "test1"; |
184 httpClient.post("127.0.0.1", port, "/join") | 184 httpClient.post("127.0.0.1", port, "/join") |
185 .then((HttpClientRequest request) { | 185 .then((HttpClientRequest request) { |
186 request.addString(json.stringify(joinRequest)); | 186 request.addString(json.stringify(joinRequest)); |
187 return request.close(); | 187 return request.close(); |
188 }) | 188 }) |
189 .then((HttpClientResponse response) { | 189 .then((HttpClientResponse response) { |
190 StringBuffer body = new StringBuffer(); | 190 StringBuffer body = new StringBuffer(); |
191 response.listen( | 191 response.listen( |
192 (data) => body.add(new String.fromCharCodes(data)), | 192 (data) => body.write(new String.fromCharCodes(data)), |
193 onDone: () => joinResponseHandler(response, body.toString())); | 193 onDone: () => joinResponseHandler(response, body.toString())); |
194 }); | 194 }); |
195 } | 195 } |
196 | 196 |
197 void dispatch(message, replyTo) { | 197 void dispatch(message, replyTo) { |
198 totalClients = message.totalClients; | 198 totalClients = message.totalClients; |
199 messagesToSend = message.messagesToSend; | 199 messagesToSend = message.messagesToSend; |
200 messagesToReceive = message.messagesToReceive; | 200 messagesToReceive = message.messagesToReceive; |
201 port = message.port; | 201 port = message.port; |
202 statusPort = replyTo; | 202 statusPort = replyTo; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 TestMain testMain = new TestMain.run(10, 2); | 310 TestMain testMain = new TestMain.run(10, 2); |
311 } | 311 } |
312 | 312 |
313 | 313 |
314 void main() { | 314 void main() { |
315 testOneClient(); | 315 testOneClient(); |
316 testTwoClients(); | 316 testTwoClients(); |
317 testTwoClientsMoreMessages(); | 317 testTwoClientsMoreMessages(); |
318 testTenClients(); | 318 testTenClients(); |
319 } | 319 } |
OLD | NEW |