Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | 1x 1x 1x 1x 1x 1x 4x 1x 10x 10x 30x 30x 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x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | // Copyright (c) ZeroC, Inc.
import { Ice } from "@zeroc/ice";
import { Test } from "./Test.js";
import { TestHelper, test } from "../../Common/TestHelper.js";
const ArrayUtil = Ice.ArrayUtil;
const isConnectionFailed = (defaultProtocol, ex) => (defaultProtocol === "tcp" && ex instanceof Ice.ConnectionRefusedException) ||
(defaultProtocol !== "tcp" && ex instanceof Ice.ConnectFailedException) ||
ex instanceof Ice.ConnectTimeoutException;
function shuffle(values) {
for (let i = values.length; i > 0; --i) {
const e = values[i - 1];
const rand = Math.floor(Math.random() * i);
values[i - 1] = values[rand];
values[rand] = e;
}
}
export class Client extends TestHelper {
async allTests() {
async function createTestIntfPrx(adapters) {
let endpoints = [];
let obj = null;
for (const adapter of adapters) {
obj = await adapter.getTestIntf();
test(obj !== null);
endpoints = endpoints.concat(obj.ice_getEndpoints());
}
if (obj === null) {
throw new Error("no object adapter");
}
return Test.TestIntfPrx.uncheckedCast(obj.ice_endpoints(endpoints));
}
async function deactivate(communicator, adapters) {
for (const adapter of adapters) {
await communicator.deactivateObjectAdapter(adapter);
}
}
const out = this.getWriter();
let communicator = this.communicator();
const properties = communicator.getProperties().clone();
const defaultProtocol = properties.getIceProperty("Ice.Default.Protocol");
const ref = `communicator:${this.getTestEndpoint()}`;
let com = new Test.RemoteCommunicatorPrx(communicator, ref);
out.write("testing binding with single endpoint... ");
{
const adapter = await com.createObjectAdapter("Adapter", "default");
test(adapter !== null);
const test1 = await adapter.getTestIntf();
test(test1 !== null);
const test2 = await adapter.getTestIntf();
test(test2 !== null);
test((await test1.ice_getConnection()) === (await test2.ice_getConnection()));
await test1.ice_ping();
await test2.ice_ping();
await com.deactivateObjectAdapter(adapter);
const test3 = Test.TestIntfPrx.uncheckedCast(test1);
test((await test3.ice_getConnection()) === (await test1.ice_getConnection()));
test((await test3.ice_getConnection()) === (await test2.ice_getConnection()));
try {
await test3.ice_ping();
test(false);
}
catch (ex) {
if (ex instanceof Ice.Exception) {
test(isConnectionFailed(defaultProtocol, ex), ex);
}
else {
throw ex;
}
}
}
out.writeLine("ok");
await communicator.destroy();
[communicator] = this.initialize(properties);
com = new Test.RemoteCommunicatorPrx(communicator, ref);
out.write("testing binding with multiple endpoints... ");
{
const adapters = (await Promise.all([
com.createObjectAdapter("Adapter11", "default"),
com.createObjectAdapter("Adapter12", "default"),
com.createObjectAdapter("Adapter13", "default"),
]));
//
// Ensure that when a connection is opened it's reused for new
// proxies and that all endpoints are eventually tried.
//
let names = ["Adapter11", "Adapter12", "Adapter13"];
while (names.length > 0) {
const adpts = ArrayUtil.clone(adapters);
const test1 = await createTestIntfPrx(adpts);
shuffle(adpts);
const test2 = await createTestIntfPrx(adpts);
shuffle(adpts);
const test3 = await createTestIntfPrx(adpts);
await test1.ice_ping();
test((await test1.ice_getConnection()) == (await test2.ice_getConnection()));
test((await test2.ice_getConnection()) == (await test3.ice_getConnection()));
const name = await test1.getAdapterName();
const index = names.indexOf(name);
if (index !== -1) {
names.splice(index, 1);
}
const conn = await test1.ice_getConnection();
await conn.close();
}
//
// Ensure that the proxy correctly caches the connection (we
// always send the request over the same connection.)
//
{
for (const adpt of adapters) {
const prx = await adpt.getTestIntf();
await prx.ice_ping();
}
const t = await createTestIntfPrx(adapters);
const name = await t.getAdapterName();
const nRetry = 10;
let i;
for (i = 0; i < nRetry && (await t.getAdapterName()) == name; i++)
;
test(i == nRetry);
for (const adpt of adapters) {
const prx = await adpt.getTestIntf();
const conn = await prx.ice_getConnection();
await conn.close();
}
}
// Deactivate a remote adapter and ensure that we can still establish the connection to the remaining
// adapters.
await com.deactivateObjectAdapter(adapters[0]);
names = ["Adapter12", "Adapter13"];
while (names.length > 0) {
const adpts = ArrayUtil.clone(adapters);
const test1 = await createTestIntfPrx(adpts);
shuffle(adpts);
const test2 = await createTestIntfPrx(adpts);
shuffle(adpts);
const test3 = await createTestIntfPrx(adpts);
test((await test1.ice_getConnection()) == (await test2.ice_getConnection()));
test((await test2.ice_getConnection()) == (await test3.ice_getConnection()));
const name = await test1.getAdapterName();
const index = names.indexOf(name);
if (index !== -1) {
names.splice(index, 1);
}
const conn = await test1.ice_getConnection();
await conn.close();
}
// Deactivate an adapter and ensure that we can still establish the connection to the remaining adapter.
await com.deactivateObjectAdapter(adapters[2]);
const obj = await createTestIntfPrx(adapters);
test((await obj.getAdapterName()) == "Adapter12");
await deactivate(com, adapters);
}
out.writeLine("ok");
await communicator.destroy();
[communicator] = this.initialize(properties);
com = new Test.RemoteCommunicatorPrx(communicator, ref);
// Firefox has a configuration that causes failed connections to be delayed on retry
// (network.websocket.delay-failed-reconnects=true by default), so we prefer to disable this test with Firefox.
if (typeof navigator === "undefined" || navigator.userAgent.indexOf("Firefox") === -1) {
out.write("testing binding with multiple random endpoints... ");
const adapters = (await Promise.all([
com.createObjectAdapter("AdapterRandom11", "default"),
com.createObjectAdapter("AdapterRandom12", "default"),
com.createObjectAdapter("AdapterRandom13", "default"),
com.createObjectAdapter("AdapterRandom14", "default"),
com.createObjectAdapter("AdapterRandom15", "default"),
]));
let count = 20;
let adapterCount = adapters.length;
while (--count > 0) {
const proxies = [];
if (count == 1) {
await com.deactivateObjectAdapter(adapters[4]);
--adapterCount;
}
for (let i = 0; i < proxies.length; ++i) {
let adpts = new Array(Math.floor(Math.random() * adapters.length));
if (adpts.length == 0) {
adpts = new Array(1);
}
for (let j = 0; j < adpts.length; ++j) {
adpts[j] = adapters[Math.floor(Math.random() * adapters.length)];
}
proxies[i] = await createTestIntfPrx(ArrayUtil.clone(adpts));
}
for (let i = 0; i < proxies.length; i++) {
proxies[i].getAdapterName().catch(() => {
// ignore exception
});
}
for (let i = 0; i < proxies.length; i++) {
try {
await proxies[i].ice_ping();
}
catch (ex) {
test(ex instanceof Ice.LocalException, ex);
}
}
const connections = [];
for (let i = 0; i < proxies.length; i++) {
if (proxies[i].ice_getCachedConnection() !== null) {
if (connections.indexOf(proxies[i].ice_getCachedConnection()) === -1) {
connections.push(proxies[i].ice_getCachedConnection());
}
}
}
test(connections.length <= adapterCount);
for (const a of adapters) {
try {
const prx = await a.getTestIntf();
const conn = await prx.ice_getConnection();
await conn.close();
}
catch (ex) {
// Expected if adapter is down.
test(ex instanceof Ice.LocalException, ex);
}
}
}
out.writeLine("ok");
}
await communicator.destroy();
[communicator] = this.initialize(properties);
com = new Test.RemoteCommunicatorPrx(communicator, ref);
out.write("testing random endpoint selection... ");
{
const adapters = (await Promise.all([
com.createObjectAdapter("Adapter21", "default"),
com.createObjectAdapter("Adapter22", "default"),
com.createObjectAdapter("Adapter23", "default"),
]));
let obj = await createTestIntfPrx(adapters);
test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random);
let names = ["Adapter21", "Adapter22", "Adapter23"];
while (names.length > 0) {
const index = names.indexOf(await obj.getAdapterName());
if (index !== -1) {
names.splice(index, 1);
}
const conn = await obj.ice_getConnection();
await conn.close();
}
obj = Test.TestIntfPrx.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Random));
test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Random);
names = ["Adapter21", "Adapter22", "Adapter23"];
while (names.length > 0) {
const index = names.indexOf(await obj.getAdapterName());
if (index !== -1) {
names.splice(index, 1);
}
const conn = await obj.ice_getConnection();
await conn.close();
}
await deactivate(com, adapters);
}
out.writeLine("ok");
await communicator.destroy();
[communicator] = this.initialize(properties);
com = new Test.RemoteCommunicatorPrx(communicator, ref);
out.write("testing ordered endpoint selection... ");
{
let adapters = (await Promise.all([
com.createObjectAdapter("Adapter31", "default"),
com.createObjectAdapter("Adapter32", "default"),
com.createObjectAdapter("Adapter33", "default"),
]));
let obj = await createTestIntfPrx(adapters);
obj = Test.TestIntfPrx.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered));
test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered);
const nRetry = 3;
//
// Ensure that endpoints are tried in order by deactivating the adapters
// one after the other.
//
let i;
for (i = 0; i < nRetry && (await obj.getAdapterName()) == "Adapter31"; i++)
;
test(i == nRetry);
await com.deactivateObjectAdapter(adapters[0]);
for (i = 0; i < nRetry && (await obj.getAdapterName()) == "Adapter32"; i++)
;
test(i == nRetry);
await com.deactivateObjectAdapter(adapters[1]);
for (i = 0; i < nRetry && (await obj.getAdapterName()) == "Adapter33"; i++)
;
test(i == nRetry);
await com.deactivateObjectAdapter(adapters[2]);
try {
await obj.getAdapterName();
}
catch (ex) {
if (ex instanceof Ice.Exception) {
test(isConnectionFailed(defaultProtocol, ex), ex);
}
else {
throw ex;
}
}
const endpoints = obj.ice_getEndpoints();
adapters = [];
// Now, re-activate the adapters with the same endpoints in the opposite order.
let adapter = await com.createObjectAdapter("Adapter36", endpoints[2].toString());
adapters.push(adapter);
for (i = 0; i < nRetry && (await obj.getAdapterName()) == "Adapter36"; i++)
;
test(i == nRetry);
let conn = await obj.ice_getConnection();
await conn.close();
adapter = await com.createObjectAdapter("Adapter35", endpoints[1].toString());
adapters.push(adapter);
for (i = 0; i < nRetry && (await obj.getAdapterName()) == "Adapter35"; i++)
;
test(i == nRetry);
conn = await obj.ice_getConnection();
await conn.close();
adapter = await com.createObjectAdapter("Adapter34", endpoints[0].toString());
adapters.push(adapter);
for (i = 0; i < nRetry && (await obj.getAdapterName()) == "Adapter34"; i++)
;
test(i == nRetry);
await deactivate(com, adapters);
}
out.writeLine("ok");
await communicator.destroy();
[communicator] = this.initialize(properties);
com = new Test.RemoteCommunicatorPrx(communicator, ref);
out.write("testing per request binding with single endpoint... ");
{
const adapter = await com.createObjectAdapter("Adapter41", "default");
test(adapter !== null);
let test1 = await adapter.getTestIntf();
test(test1 !== null);
test1 = test1.ice_connectionCached(false);
let test2 = await adapter.getTestIntf();
test(test2 !== null);
test2 = test2.ice_connectionCached(false);
test(!test1.ice_isConnectionCached());
test(!test2.ice_isConnectionCached());
const connection1 = await test1.ice_getConnection();
const connection2 = await test2.ice_getConnection();
test(connection1 == connection2);
await test1.ice_ping();
await com.deactivateObjectAdapter(adapter);
const test3 = Test.TestIntfPrx.uncheckedCast(test1);
try {
test((await test3.ice_getConnection()) == (await test1.ice_getConnection()));
test(false);
}
catch (ex) {
if (ex instanceof Ice.Exception) {
test(isConnectionFailed(defaultProtocol, ex), ex);
}
else {
throw ex;
}
}
}
out.writeLine("ok");
await communicator.destroy();
[communicator] = this.initialize(properties);
com = new Test.RemoteCommunicatorPrx(communicator, ref);
out.write("testing per request binding with multiple endpoints... ");
{
const adapters = (await Promise.all([
com.createObjectAdapter("Adapter51", "default"),
com.createObjectAdapter("Adapter52", "default"),
com.createObjectAdapter("Adapter53", "default"),
]));
const obj = Test.TestIntfPrx.uncheckedCast((await createTestIntfPrx(adapters)).ice_connectionCached(false));
test(!obj.ice_isConnectionCached());
let names = ["Adapter51", "Adapter52", "Adapter53"];
while (names.length > 0) {
const name = await obj.getAdapterName();
const index = names.indexOf(name);
if (index !== -1) {
names.splice(index, 1);
}
}
await com.deactivateObjectAdapter(adapters[0]);
names = ["Adapter52", "Adapter53"];
while (names.length > 0) {
const name = await obj.getAdapterName();
const index = names.indexOf(name);
if (index !== -1) {
names.splice(index, 1);
}
}
await com.deactivateObjectAdapter(adapters[2]);
test((await obj.getAdapterName()) == "Adapter52");
await deactivate(com, adapters);
}
out.writeLine("ok");
if (typeof navigator === "undefined" || navigator.userAgent.indexOf("Firefox") === -1) {
//
// Firefox adds a delay on websocket failed reconnects that causes this test to take too
// much time to complete.
//
// You can set network.websocket.delay-failed-reconnects to false in Firefox about:config
// to disable this behavior
//
await communicator.destroy();
[communicator] = this.initialize(properties);
com = new Test.RemoteCommunicatorPrx(communicator, ref);
out.write("testing per request binding and ordered endpoint selection... ");
let adapters = (await Promise.all([
com.createObjectAdapter("Adapter61", "default"),
com.createObjectAdapter("Adapter62", "default"),
com.createObjectAdapter("Adapter63", "default"),
]));
let obj = await createTestIntfPrx(adapters);
obj = Test.TestIntfPrx.uncheckedCast(obj.ice_endpointSelection(Ice.EndpointSelectionType.Ordered));
test(obj.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered);
obj = Test.TestIntfPrx.uncheckedCast(obj.ice_connectionCached(false));
test(!obj.ice_isConnectionCached());
const nRetry = 3;
let i;
// Ensure that endpoints are tried in order by deactivating the adapters one after the other.
for (i = 0; i < nRetry && (await obj.getAdapterName()) == "Adapter61"; i++)
;
test(i == nRetry);
await com.deactivateObjectAdapter(adapters[0]);
for (i = 0; i < nRetry && (await obj.getAdapterName()) == "Adapter62"; i++)
;
test(i == nRetry);
await com.deactivateObjectAdapter(adapters[1]);
for (i = 0; i < nRetry && (await obj.getAdapterName()) == "Adapter63"; i++)
;
test(i == nRetry);
com.deactivateObjectAdapter(adapters[2]);
try {
await obj.getAdapterName();
}
catch (ex) {
if (ex instanceof Ice.Exception) {
test(isConnectionFailed(defaultProtocol, ex), ex);
}
else {
throw ex;
}
}
const endpoints = obj.ice_getEndpoints();
adapters = [];
// Now, re-activate the adapters with the same endpoints in the opposite order.
let adapter = await com.createObjectAdapter("Adapter66", endpoints[2].toString());
adapters.push(adapter);
for (i = 0; i < nRetry && (await obj.getAdapterName()) == "Adapter66"; i++)
;
test(i == nRetry);
adapter = await com.createObjectAdapter("Adapter65", endpoints[1].toString());
adapters.push(adapter);
for (i = 0; i < nRetry && (await obj.getAdapterName()) == "Adapter65"; i++)
;
test(i == nRetry);
adapter = await com.createObjectAdapter("Adapter64", endpoints[0].toString());
adapters.push(adapter);
for (i = 0; i < nRetry && (await obj.getAdapterName()) == "Adapter64"; i++)
;
test(i == nRetry);
await deactivate(com, adapters);
out.writeLine("ok");
}
await com.shutdown();
}
async run(args) {
let communicator = null;
try {
[communicator, args] = this.initialize(args);
await this.allTests();
}
finally {
if (communicator) {
await communicator.destroy();
}
}
}
}
|