function() { out.writeLine("ok"); out.write("testing connection endpoint information... "); base = communicator.stringToProxy("test:default -p 12010"); testIntf = Test.TestIntfPrx.uncheckedCast(base); var ipinfo; return base.ice_getConnection().then( function(conn) { ipinfo = conn.getEndpoint().getInfo(); test(ipinfo.port == 12010); test(!ipinfo.compress); test(ipinfo.host == defaultHost); return testIntf.getEndpointInfoAsContext(); } ).then( function(ctx) { test(ctx.get("host") == ipinfo.host); test(ctx.get("compress") == "false"); var port = parseInt(ctx.get("port")); test(port > 0); } ); }
function() { test(communicator.stringToProxy("test").ice_locatorCacheTimeout(99).ice_getLocatorCacheTimeout() === 99); out.writeLine("ok"); out.write("testing proxy from server... "); return Test.TestIntfPrx.checkedCast(communicator.stringToProxy("test@TestAdapter")); }
function(obj) { test2 = Test.TestIntfPrx.uncheckedCast(obj.ice_connectionCached(false)); test(!test1.ice_isConnectionCached()); test(!test2.ice_isConnectionCached()); return Promise.all(test1.ice_getConnection(), test2.ice_getConnection()); }
function() { out.write("testing stringToProxy... "); var ref = "test:default -p 12010"; base = communicator.stringToProxy(ref); test(base !== null); out.writeLine("ok"); out.write("testing checked cast... "); return Test.TestIntfPrx.checkedCast(base); }
Ice.Promise.try(() => { out.write("testing stringToProxy... "); ref = "Test:default -p 12010 -t 10000"; base = communicator.stringToProxy(ref); test(base !== null); out.writeLine("ok"); out.write("testing checked cast... "); return Test.TestIntfPrx.checkedCast(base); }
function(obj) { prx = obj; prx = Test.TestIntfPrx.uncheckedCast(prx.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)); test(prx.ice_getEndpointSelection() == Ice.EndpointSelectionType.Ordered); prx = Test.TestIntfPrx.uncheckedCast(prx.ice_connectionCached(false)); test(!prx.ice_isConnectionCached()); var nRetry = 5; var f1 = function(i, idx, names) { return prx.getAdapterName().then( function(name) { test(name === names[0]); } ).then( function() { if(i < nRetry) { return f1(++i, idx, names); } else { return com.deactivateObjectAdapter(adapters[idx]).then( function() { if(names.length > 1) { names.shift(); return f1(0, ++idx, names); } } ); } }); }; return f1(0, 0, ArrayUtil.clone(names)); }
function() { var results = Array.prototype.slice.call(arguments); results.forEach( function(r) { p = r[0]; test(p); endpoints = endpoints.concat(p.ice_getEndpoints()); } ); return Test.TestIntfPrx.uncheckedCast(p.ice_endpoints(endpoints)); });
function() { if(typeof(navigator) !== 'undefined' && isSafari() && isWorker()) { out.writeLine("Test not supported with Safari web workers."); return Test.TestIntfPrx.uncheckedCast( communicator.stringToProxy("test:default -p 12010")).shutdown(); } else { return allTests(communicator, out); } }
async start() { try { let prx = await this._adapter.getTestIntf(); prx = Test.TestIntfPrx.uncheckedCast(this._communicator.stringToProxy(prx.toString())); const con = await prx.ice_getConnection(); con.setCloseCallback(connection => { this._closed = true; }); con.setHeartbeatCallback(connection => ++this._heartbeat); await this.runTestCase(this._adapter, prx); } catch(ex) { this._msg = "unexpected exception:\n" + ex.toString() + "\n" + ex.stack; } }
function(obj) { prx = obj; prx = Test.TestIntfPrx.uncheckedCast(prx.ice_endpointSelection(Ice.EndpointSelectionType.Random)); test(prx.ice_getEndpointSelection() === Ice.EndpointSelectionType.Random); names = ["Adapter21", "Adapter22", "Adapter23"]; var f1 = function() { return prx.getAdapterName().then( function(name) { if(names.indexOf(name) !== -1) { names.splice(names.indexOf(name), 1); } return prx.ice_getConnection(); } ).then( function(conn) { return conn.close(false); } ).then( function() { if(names.length > 0) { return f1(); } else { return prx; } } ); }; return f1(); },
function() { out.write("testing AsyncResult operations... "); var indirect = Test.TestIntfPrx.uncheckedCast(p.ice_adapterId("dummy")); return indirect.op().exception( function(ex, r) { try { r.throwLocalException(); } catch(ex) { test(ex instanceof Ice.NoEndpointException); } } ).then( function() { return testController.holdAdapter(); } ).then( function() { var r1 = p.op(); var r2 = null; var seq = Ice.Buffer.createNative(new Array(100000)); while((r2 = p.opWithPayload(seq)).sentSynchronously()); test(r1.sentSynchronously() && r1.isSent() && !r1.isCompleted() || !r1.sentSynchronously() && !r1.isCompleted()); test(!r2.sentSynchronously() && !r2.isCompleted()); testController.resumeAdapter(); test(r1.operation === "op"); test(r2.operation === "opWithPayload"); return r1.then( function() { test(r1.isSent()); test(r1.isCompleted()); return r2; } ).then( function() { test(r2.isSent()); test(r2.isCompleted()); } ); } ).then( function() { r = p.ice_ping(); test(r.operation === "ice_ping"); test(r.connection === null); // Expected test(r.communicator == communicator); test(r.proxy == p); // // Oneway // var p2 = p.ice_oneway(); r = p2.ice_ping(); test(r.operation === "ice_ping"); test(r.connection === null); // Expected test(r.communicator == communicator); test(r.proxy == p2); // // Batch request via proxy // p2 = p.ice_batchOneway(); p2.ice_ping(); r = p2.ice_flushBatchRequests(); test(r.operation === "ice_flushBatchRequests"); test(r.connection === null); // Expected test(r.communicator == communicator); test(r.proxy == p2); var con = p.ice_getCachedConnection(); p2 = p.ice_batchOneway(); p2.ice_ping(); r = con.flushBatchRequests(); test(r.operation === "flushBatchRequests"); test(r.connection == con); test(r.communicator == communicator); test(r.proxy === null); p2 = p.ice_batchOneway(); p2.ice_ping(); r = communicator.flushBatchRequests(); test(r.operation === "flushBatchRequests"); test(r.connection === null); test(r.communicator == communicator); test(r.proxy === null); } ).then( function() { return testController.holdAdapter(); } ).then( function() { var seq = Ice.Buffer.createNative(new Array(100024)); while((r = p.opWithPayload(seq)).sentSynchronously()); test(!r.isSent()); var r1 = p.ice_ping(); var r2 = p.ice_id(); r1.cancel(); r2.cancel(); try { r1.throwLocalException(); test(false); } catch(ex) { test(ex instanceof Ice.InvocationCanceledException); } try { r2.throwLocalException(); test(false); } catch(ex) { test(ex instanceof Ice.InvocationCanceledException); } return testController.resumeAdapter().then( function() { p.ice_ping().then( function() { test(!r1.isSent() && r1.isCompleted()); test(!r2.isSent() && r2.isCompleted()); }); }); } ).then( function() { return testController.holdAdapter(); } ).then( function() { var r1 = p.op(); var r2 = p.ice_id(); return p.ice_oneway().ice_ping().then( function() { r1.cancel(); r2.cancel(); try { r1.throwLocalException(); test(false); } catch(ex) { test(ex instanceof Ice.InvocationCanceledException); } try { r2.throwLocalException(); test(false); } catch(ex) { test(ex instanceof Ice.InvocationCanceledException); } testController.resumeAdapter(); }); } ).then( function() { out.writeLine("ok"); }); }
function() { out.writeLine("ok"); out.write("testing checked cast... "); return Test.TestIntfPrx.checkedCast(base); }
function(obj) { test1 = Test.TestIntfPrx.uncheckedCast(obj.ice_connectionCached(false)); return adapter.getTestIntf(); }
async allTests() { const out = this.getWriter(); const communicator = this.communicator(); const defaultHost = communicator.getProperties().getPropertyWithDefault("Ice.Default.Host"); out.write("testing proxy endpoint information... "); const ref = "test -t:default -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10:opaque -e 1.8 -t 100 -v ABCD"; const p1 = communicator.stringToProxy(ref); const endps = p1.ice_getEndpoints(); const endpoint = endps[0].getInfo(); const ipEndpoint = getTCPEndpointInfo(endpoint); test(ipEndpoint.host == "tcphost"); test(ipEndpoint.port == 10000); test(ipEndpoint.timeout == 1200); test(ipEndpoint.sourceAddress == "10.10.10.10"); test(ipEndpoint.compress); test(!ipEndpoint.datagram()); test(ipEndpoint.type() == Ice.TCPEndpointType && !ipEndpoint.secure() || ipEndpoint.type() == Ice.WSEndpointType && !ipEndpoint.secure() || ipEndpoint.type() == Ice.WSSEndpointType && ipEndpoint.secure()); test(ipEndpoint.type() == Ice.TCPEndpointType && endpoint instanceof Ice.TCPEndpointInfo || ipEndpoint.type() == Ice.WSEndpointType && endpoint instanceof Ice.WSEndpointInfo || ipEndpoint.type() == Ice.WSSEndpointType && endpoint instanceof Ice.WSEndpointInfo); const opaqueEndpoint = endps[1].getInfo(); test(opaqueEndpoint.rawEncoding.equals(new Ice.EncodingVersion(1, 8))); out.writeLine("ok"); out.write("testing connection endpoint information... "); const base = communicator.stringToProxy("test:" + this.getTestEndpoint()); const testIntf = Test.TestIntfPrx.uncheckedCast(base); const endpointPort = this.getTestPort(0); let conn = await base.ice_getConnection(); let ipinfo = getTCPEndpointInfo(conn.getEndpoint().getInfo()); test(ipinfo.port == endpointPort); test(!ipinfo.compress); test(ipinfo.host == defaultHost); let ctx = await testIntf.getEndpointInfoAsContext(); test(ctx.get("host") == ipinfo.host); test(ctx.get("compress") == "false"); test(parseInt(ctx.get("port")) > 0); out.writeLine("ok"); out.write("testing connection information... "); conn = await base.ice_getConnection(); conn.setBufferSize(1024, 2048); const info = conn.getInfo(); ipinfo = getTCPConnectionInfo(info); test(!info.incoming); test(info.adapterName.length === 0); if(conn.type() != "ws" && conn.type() != "wss") { test(ipinfo.localPort > 0); } test(ipinfo.remotePort == endpointPort); if(defaultHost == "127.0.0.1") { test(ipinfo.remoteAddress == defaultHost); if(conn.type() != "ws" && conn.type() != "wss") { test(ipinfo.localAddress == defaultHost); } } test(info.sndSize >= 2048); ctx = await testIntf.getConnectionInfoAsContext(); test(ctx.get("incoming") == "true"); test(ctx.get("adapterName") == "TestAdapter"); if(conn.type() != "ws" && conn.type() != "wss") { test(ctx.get("remoteAddress") == info.localAddress); test(ctx.get("localAddress") == info.remoteAddress); test(parseInt(ctx.get("remotePort")) === info.localPort); test(parseInt(ctx.get("localPort")) === info.remotePort); } if(conn.type() == "ws" || conn.type() == "wss") { test(ctx.get("ws.Upgrade").toLowerCase() == "websocket"); test(ctx.get("ws.Connection").indexOf("Upgrade") >= 0); test(ctx.get("ws.Sec-WebSocket-Protocol") == "ice.zeroc.com"); test(ctx.get("ws.Sec-WebSocket-Version") == "13"); test(ctx.get("ws.Sec-WebSocket-Key") !== null); } out.writeLine("ok"); await testIntf.shutdown(); }
async function allTests(communicator, out) { function test(value, ex) { if(!value) { let message = "test failed"; if(ex) { message += "\n" + ex.toString(); } throw new Error(message); } } async function testExceptions(obj) { try { await obj.requestFailedException(); test(false) } catch(ex) { test(ex instanceof Ice.ObjectNotExistException, ex); test(ex.id.equals(obj.ice_getIdentity())); test(ex.facet == obj.ice_getFacet()); test(ex.operation == "requestFailedException"); } try { await obj.unknownUserException(); test(false); } catch(ex) { test(ex instanceof Ice.UnknownUserException, ex); test(ex.unknown == "reason"); } try { await obj.unknownLocalException(); test(false); } catch(ex) { test(ex instanceof Ice.UnknownLocalException, ex); test(ex.unknown == "reason"); } try { await obj.unknownException(); test(false); } catch(ex) { test(ex instanceof Ice.UnknownException, ex); test(ex.unknown == "reason"); } try { await obj.userException(); test(false); } catch(ex) { test((ex instanceof Ice.OperationNotExistException) || (ex instanceof Ice.UnknownUserException && ex.unknown == "::Test::TestIntfUserException"), ex); } try { await obj.localException(); test(false); } catch(ex) { test(ex instanceof Ice.UnknownLocalException, ex); test(ex.unknown.indexOf("Ice::SocketException") >= 0 || ex.unknown.indexOf("Ice.SocketException") >= 0); } try { await obj.jsException(); test(false); } catch(ex) { test((ex instanceof Ice.OperationNotExistException) || (ex instanceof Ice.UnknownException || ex.unknown.indexOf("") >= 0), ex); } try { await obj.unknownExceptionWithServantException(); test(false); } catch(ex) { test(ex instanceof Ice.UnknownException, ex); test(ex.unknown == "reason"); } try { await obj.impossibleException(false); test(false); } catch(ex) { test(ex instanceof Ice.UnknownUserException, ex); } try { await obj.impossibleException(true); test(false); } catch(ex) { test(ex instanceof Ice.UnknownUserException, ex); } try { await obj.intfUserException(false); test(false); } catch(ex) { test(ex instanceof Test.TestImpossibleException, ex); } try { await obj.intfUserException(true); test(false); } catch(ex) { test(ex instanceof Test.TestImpossibleException, ex); } } out.write("testing stringToProxy... "); let ref = "asm:default -p 12010"; let base = communicator.stringToProxy(ref); test(base !== null); out.writeLine("ok"); out.write("testing checked cast... "); let obj = await Test.TestIntfPrx.checkedCast(base); test(obj != null); test(obj.equals(base)); out.writeLine("ok"); out.write("testing ice_ids... "); try { let o = communicator.stringToProxy("category/locate:default -p 12010"); await o.ice_ids(); test(false); } catch(ex) { test(ex instanceof Ice.UnknownUserException && ex.unknown == "::Test::TestIntfUserException", ex) } try { let o = communicator.stringToProxy("category/finished:default -p 12010"); await o.ice_ids(); test(false); } catch(ex) { test(ex instanceof Ice.UnknownUserException && ex.unknown == "::Test::TestIntfUserException", ex); } out.writeLine("ok"); out.write("testing servant locator... "); base = communicator.stringToProxy("category/locate:default -p 12010"); obj = await Test.TestIntfPrx.checkedCast(base); try { await Test.TestIntfPrx.checkedCast(communicator.stringToProxy("category/unknown:default -p 12010")); test(false); } catch(ex) { test(ex instanceof Ice.ObjectNotExistException, ex); } out.writeLine("ok"); out.write("testing default servant locator... "); base = communicator.stringToProxy("anothercat/locate:default -p 12010"); obj = await Test.TestIntfPrx.checkedCast(base); base = communicator.stringToProxy("locate:default -p 12010"); obj = await Test.TestIntfPrx.checkedCast(base); try { await Test.TestIntfPrx.checkedCast(communicator.stringToProxy("anothercat/unknown:default -p 12010")); test(false); } catch(ex) { test(ex instanceof Ice.ObjectNotExistException, ex); } try { await Test.TestIntfPrx.checkedCast(communicator.stringToProxy("unknown:default -p 12010")); test(false); } catch(ex) { test(ex instanceof Ice.ObjectNotExistException, ex); } out.writeLine("ok"); out.write("testing locate exceptions... "); base = communicator.stringToProxy("category/locate:default -p 12010"); obj = await Test.TestIntfPrx.checkedCast(base); await testExceptions(obj); out.writeLine("ok"); out.write("testing finished exceptions... "); base = communicator.stringToProxy("category/finished:default -p 12010"); obj = await Test.TestIntfPrx.checkedCast(base); await testExceptions(obj); try { // // Only call these for category/finished. // await obj.asyncResponse(); test(false); } catch(ex) { test(ex instanceof Test.TestImpossibleException, ex); // Called by finished(). } try { await obj.asyncException(); test(false); } catch(ex) { test(ex instanceof Test.TestImpossibleException, ex); // Called by finished(). } out.writeLine("ok"); out.write("testing servant locator removal... "); base = communicator.stringToProxy("test/activation:default -p 12010"); activation = await Test.TestActivationPrx.checkedCast(base); await activation.activateServantLocator(false); try { await obj.ice_ping(); test(false); } catch(ex) { test(ex instanceof Ice.ObjectNotExistException, ex); } out.writeLine("ok"); out.write("testing servant locator addition... "); await activation.activateServantLocator(true); await obj.ice_ping(); out.writeLine("ok"); await obj.shutdown(); }
async allTests() { const communicator = this.communicator(); const out = this.getWriter(); let sref = "test:" + this.getTestEndpoint(); let obj = communicator.stringToProxy(sref); test(obj !== null); const p = Test.TestIntfPrx.uncheckedCast(obj); sref = "testController:" + this.getTestEndpoint(1); obj = communicator.stringToProxy(sref); test(obj !== null); const testController = Test.TestIntfControllerPrx.uncheckedCast(obj); out.write("testing batch requests with proxy... "); { const count = await p.opBatchCount(); test(count === 0); const b1 = p.ice_batchOneway(); const bf = b1.opBatch(); test(bf.isCompleted()); test(!bf.isSent()); b1.opBatch(); await b1.ice_flushBatchRequests(); await p.waitForBatch(2); await b1.ice_flushBatchRequests(); } out.writeLine("ok"); out.write("testing batch requests with connection... "); { test(await p.opBatchCount() === 0); const b1 = p.ice_batchOneway(); await b1.opBatch(); const bf = b1.opBatch(); test(bf.isCompleted()); await b1.ice_flushBatchRequests(); test(await p.waitForBatch(2)); } if(await p.ice_getConnection() !== null) { test(await p.opBatchCount() == 0); const b1 = p.ice_batchOneway(); await b1.opBatch(); await b1.ice_getConnection().then(conn => conn.close(Ice.ConnectionClose.GracefullyWithWait)); await b1.ice_flushBatchRequests(); test(await p.waitForBatch(1)); } out.writeLine("ok"); out.write("testing batch requests with communicator... "); { // // Async task - 1 connection. // test(await p.opBatchCount() === 0); const b1 = Test.TestIntfPrx.uncheckedCast( await p.ice_getConnection().then(c => c.createProxy(p.ice_getIdentity()).ice_batchOneway())); await b1.opBatch(); await b1.opBatch(); await communicator.flushBatchRequests(); test(await p.waitForBatch(2)); } { // // Async task exception - 1 connection. // test(await p.opBatchCount() === 0); const b1 = Test.TestIntfPrx.uncheckedCast( await p.ice_getConnection().then(c => c.createProxy(p.ice_getIdentity()).ice_batchOneway())); await b1.opBatch(); await b1.ice_getConnection().then(c => c.close(Ice.ConnectionClose.GracefullyWithWait)); await communicator.flushBatchRequests(); test(await p.opBatchCount() == 0); } { // // Async task - 2 connections. // test(await p.opBatchCount() === 0); const b1 = Test.TestIntfPrx.uncheckedCast( await p.ice_getConnection().then(c => c.createProxy(p.ice_getIdentity()).ice_batchOneway())); const b2 = Test.TestIntfPrx.uncheckedCast( await p.ice_connectionId("2").ice_getConnection().then( c => c.createProxy(p.ice_getIdentity()).ice_batchOneway())); await b2.ice_getConnection(); // Ensure connection is established. await b1.opBatch(); await b1.opBatch(); await b2.opBatch(); await b2.opBatch(); await communicator.flushBatchRequests(); test(await p.waitForBatch(4)); } { // // AsyncResult exception - 2 connections - 1 failure. // // All connections should be flushed even if there are failures on some connections. // Exceptions should not be reported. // test(await p.opBatchCount() === 0); const b1 = Test.TestIntfPrx.uncheckedCast( await p.ice_getConnection().then(c => c.createProxy(p.ice_getIdentity()).ice_batchOneway())); const b2 = Test.TestIntfPrx.uncheckedCast( await p.ice_connectionId("2").ice_getConnection().then( c => c.createProxy(p.ice_getIdentity()).ice_batchOneway())); await b2.ice_getConnection(); // Ensure connection is established. await b1.opBatch(); await b2.opBatch(); await b1.ice_getConnection().then(c => c.close(Ice.ConnectionClose.GracefullyWithWait)); await communicator.flushBatchRequests(); test(await p.waitForBatch(1)); } { // // Async task exception - 2 connections - 2 failures. // // The sent callback should be invoked even if all connections fail. // test(await p.opBatchCount() == 0); const b1 = Test.TestIntfPrx.uncheckedCast( await p.ice_getConnection().then(c => c.createProxy(p.ice_getIdentity()).ice_batchOneway())); const b2 = Test.TestIntfPrx.uncheckedCast( await p.ice_connectionId("2").ice_getConnection().then( c => c.createProxy(p.ice_getIdentity()).ice_batchOneway())); await b2.ice_getConnection(); // Ensure connection is established. await b1.opBatch(); await b2.opBatch(); await b1.ice_getConnection().then(c => c.close(Ice.ConnectionClose.GracefullyWithWait)); await b2.ice_getConnection().then(c => c.close(Ice.ConnectionClose.GracefullyWithWait)); await communicator.flushBatchRequests(); test(await p.opBatchCount() === 0); } out.writeLine("ok"); out.write("testing AsyncResult operations... "); { await testController.holdAdapter(); let r1; let r2; try { r1 = p.op(); const seq = new Uint8Array(100000); while(true) { r2 = p.opWithPayload(seq); if(r2.sentSynchronously()) { await Ice.Promise.delay(0); } else { break; } } if(await p.ice_getConnection() !== null) { test(r1.sentSynchronously() && r1.isSent() && !r1.isCompleted() || !r1.sentSynchronously() && !r1.isCompleted()); test(!r2.sentSynchronously() && !r2.isCompleted()); test(!r1.isCompleted()); test(!r2.isCompleted()); } } finally { await testController.resumeAdapter(); } await r1; test(r1.isSent()); test(r1.isCompleted()); await r2; test(r2.isSent()); test(r2.isCompleted()); test(r1.operation == "op"); test(r2.operation == "opWithPayload"); let r = p.ice_ping(); test(r.operation === "ice_ping"); test(r.connection === null); // Expected test(r.communicator == communicator); test(r.proxy == p); // // Oneway // let p2 = p.ice_oneway(); r = p2.ice_ping(); test(r.operation === "ice_ping"); test(r.connection === null); // Expected test(r.communicator == communicator); test(r.proxy == p2); // // Batch request via proxy // p2 = p.ice_batchOneway(); p2.ice_ping(); r = p2.ice_flushBatchRequests(); test(r.operation === "ice_flushBatchRequests"); test(r.connection === null); // Expected test(r.communicator == communicator); test(r.proxy == p2); const con = p.ice_getCachedConnection(); p2 = p.ice_batchOneway(); p2.ice_ping(); r = con.flushBatchRequests(); test(r.operation === "flushBatchRequests"); test(r.connection == con); test(r.communicator == communicator); test(r.proxy === null); p2 = p.ice_batchOneway(); p2.ice_ping(); r = communicator.flushBatchRequests(); test(r.operation === "flushBatchRequests"); test(r.connection === null); test(r.communicator == communicator); test(r.proxy === null); } { await testController.holdAdapter(); const seq = new Uint8Array(new Array(100000)); let r; while(true) { r = p.opWithPayload(seq); if(r.sentSynchronously()) { await Ice.Promise.delay(0); } else { break; } } test(!r.isSent()); const r1 = p.ice_ping(); r1.then( () => test(false), ex => test(ex instanceof Ice.InvocationCanceledException)); const r2 = p.ice_id(); r2.then( () => test(false), ex => test(ex instanceof Ice.InvocationCanceledException)); r1.cancel(); r2.cancel(); await testController.resumeAdapter(); await p.ice_ping(); test(!r1.isSent() && r1.isCompleted()); test(!r2.isSent() && r2.isCompleted()); } { await testController.holdAdapter(); const r1 = p.op(); const r2 = p.ice_id(); await p.ice_oneway().ice_ping(); r1.cancel(); r1.then( () => test(false), ex => test(ex instanceof Ice.InvocationCanceledException)); r2.cancel(); r2.then( () => test(false), ex => test(ex instanceof Ice.InvocationCanceledException)); await testController.resumeAdapter(); } out.writeLine("ok"); await p.shutdown(); }
async allTests() { const out = this.getWriter(); const communicator = this.communicator(); out.write("testing stringToProxy... "); const ref = "test:" + this.getTestEndpoint(); const base = communicator.stringToProxy(ref); test(base !== null); out.writeLine("ok"); out.write("testing checked cast... "); const obj = await Test.TestIntfPrx.checkedCast(base); test(obj !== null); test(obj.equals(base)); out.writeLine("ok"); { out.write("creating/destroying/recreating object adapter... "); communicator.getProperties().setProperty("TransientTestAdapter.AdapterId", "dummy"); let adapter = await communicator.createObjectAdapter("TransientTestAdapter"); try { await communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", ""); test(false); } catch(ex) { test(ex instanceof Ice.AlreadyRegisteredException); } await adapter.destroy(); // // Use a different port than the first adapter to avoid an "address already in use" error. // adapter = await communicator.createObjectAdapterWithEndpoints("TransientTestAdapter", ""); await adapter.destroy(); out.writeLine("ok"); } out.write("creating/activating/deactivating object adapter in one operation... "); await obj.transient(); out.writeLine("ok"); out.write("testing connection closure... "); for(let i = 0; i < 10; ++i) { const initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().clone(); const comm = Ice.initialize(initData); comm.stringToProxy("test:" + this.getTestEndpoint()).ice_ping().catch(ex => {}); await comm.destroy(); } out.writeLine("ok"); out.write("testing object adapter published endpoints... "); { communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 30000"); const adapter = await communicator.createObjectAdapter("PAdapter"); test(adapter.getPublishedEndpoints().length === 1); const endpt = adapter.getPublishedEndpoints()[0]; test(endpt.toString() == "tcp -h localhost -p 12345 -t 30000"); const prx = communicator.stringToProxy("dummy:tcp -h localhost -p 12346 -t 20000:tcp -h localhost -p 12347 -t 10000"); adapter.setPublishedEndpoints(prx.ice_getEndpoints()); test(adapter.getPublishedEndpoints().length === 2); const id = new Ice.Identity(); id.name = "dummy"; test(Ice.ArrayUtil.equals(adapter.createProxy(id).ice_getEndpoints(), prx.ice_getEndpoints())); test(Ice.ArrayUtil.equals(adapter.getPublishedEndpoints(), prx.ice_getEndpoints())); await adapter.refreshPublishedEndpoints(); test(adapter.getPublishedEndpoints().length === 1); test(adapter.getPublishedEndpoints()[0].equals(endpt)); communicator.getProperties().setProperty("PAdapter.PublishedEndpoints", "tcp -h localhost -p 12345 -t 20000"); await adapter.refreshPublishedEndpoints(); test(adapter.getPublishedEndpoints().length === 1); test(adapter.getPublishedEndpoints()[0].toString() == "tcp -h localhost -p 12345 -t 20000"); await adapter.destroy(); test(adapter.getPublishedEndpoints().length === 0); } out.writeLine("ok"); test(obj.ice_getConnection() !== null); { out.write("testing object adapter with bi-dir connection... "); const adapter = await communicator.createObjectAdapter(""); (await obj.ice_getConnection()).setAdapter(adapter); (await obj.ice_getConnection()).setAdapter(null); await adapter.deactivate(); try { (await obj.ice_getConnection()).setAdapter(adapter); test(false); } catch(ex) { test(ex instanceof Ice.ObjectAdapterDeactivatedException); } out.writeLine("ok"); } out.write("testing object adapter with router... "); { const routerId = new Ice.Identity(); routerId.name = "router"; let router = Ice.RouterPrx.uncheckedCast(base.ice_identity(routerId).ice_connectionId("rc")); const adapter = await communicator.createObjectAdapterWithRouter("", router); test(adapter.getPublishedEndpoints().length == 1); test(adapter.getPublishedEndpoints()[0].toString() == "tcp -h localhost -p 23456 -t 30000"); await adapter.refreshPublishedEndpoints(); test(adapter.getPublishedEndpoints().length == 1); test(adapter.getPublishedEndpoints()[0].toString() == "tcp -h localhost -p 23457 -t 30000"); try { adapter.setPublishedEndpoints(router.ice_getEndpoints()); test(false); } catch(ex) { // Expected. test(ex instanceof Error); } await adapter.destroy(); try { routerId.name = "test"; router = Ice.RouterPrx.uncheckedCast(base.ice_identity(routerId)); await communicator.createObjectAdapterWithRouter("", router); test(false); } catch(ex) { // Expected: the "test" object doesn't implement Ice::Router! test(ex instanceof Ice.OperationNotExistException); } try { router = Ice.RouterPrx.uncheckedCast(communicator.stringToProxy("router:" + this.getTestEndpoint(1))); await communicator.createObjectAdapterWithRouter("", router); test(false); } catch(ex) { test(ex instanceof Ice.ConnectFailedException); } } out.writeLine("ok"); out.write("deactivating object adapter in the server... "); await obj.deactivate(); out.writeLine("ok"); out.write("testing adapter states... "); { const adpt = await communicator.createObjectAdapter(""); test(!adpt.isDeactivated()); await adpt.activate(); test(!adpt.isDeactivated()); let isHolding = false; let p1 = adpt.waitForHold().then(() => { isHolding = true; }); test(!isHolding); adpt.hold(); await adpt.waitForHold(); await p1; test(isHolding); isHolding = false; p1 = adpt.waitForHold().then(() => { isHolding = true; }); let isDeactivated = false; const p2 = adpt.waitForDeactivate().then(() => { isDeactivated = true; }); test(!isDeactivated); await adpt.deactivate(); await adpt.waitForDeactivate(); await Promise.all([p1, p2]); test(isDeactivated && isHolding); test(adpt.isDeactivated()); await adpt.destroy(); } out.writeLine("ok"); out.write("testing whether server is gone... "); try { await obj.ice_timeout(100).ice_ping(); // Use timeout to speed up testing on Windows throw new Error(); } catch(ex) { test(ex instanceof Ice.LocalException); out.writeLine("ok"); } }
function() { var test3 = Test.TestIntfPrx.uncheckedCast(test1); return Promise.all(test3.ice_getConnection(), test1.ice_getConnection()); }
function(o) { obj5 = o; test(obj !== null); return Test.TestIntfPrx.checkedCast(base6); }
function(prx) { prx = Test.TestIntfPrx.uncheckedCast(prx.ice_connectionCached(false)); test(!prx.ice_isConnectionCached()); return f2(prx); });
function(prx) { proxy = Test.TestIntfPrx.uncheckedCast(self._communicator.stringToProxy(prx.toString())); return proxy.ice_getConnection(); }
function allTests(communicator, out) { var promise = new Ice.Promise(); var test = function(b) { if(!b) { try { throw new Error("test failed"); } catch(err) { promise.fail(err); throw err; } } }; var getConnectionBatchProxy = function(proxy, connectionId) { if(!connectionId) { connectionId = ""; } var p = proxy; return p.ice_connectionId(connectionId).ice_getConnection().then( function(c) { p = p.constructor.uncheckedCast(c.createProxy(proxy.ice_getIdentity())).ice_batchOneway(); return p.ice_getConnection(); } ).then( function(c) { test(p.ice_getCachedConnection() === c); return p; } ); }; var result = null; var p = Test.TestIntfPrx.uncheckedCast(communicator.stringToProxy("test:default -p 12010")); var testController = Test.TestIntfControllerPrx.uncheckedCast(communicator.stringToProxy("testController:default -p 12011")); var r = null; var b1 = null; var b2 = null; Promise.try( function() { out.write("testing batch requests with proxy... "); return p.opBatchCount().then( function(count) { test(count === 0); b1 = p.ice_batchOneway(); test(b1.opBatch().completed()); test(b1.opBatch().completed()); return b1.ice_flushBatchRequests(); } ).then( function(r1) { test(r1.completed()); return p.waitForBatch(2); } ).then( function() { return b1.ice_flushBatchRequests(); } ).then( function(r2) { test(r2.completed()); } ).then( function() { out.writeLine("ok"); } ); } ).then( function() { out.write("testing batch requests with connection... "); return p.opBatchCount().then( function(count) { test(count === 0); return getConnectionBatchProxy(p).then( function(prx) { b1 = prx; var connection = b1.ice_getCachedConnection(); test(b1.opBatch().completed()); test(b1.opBatch().completed()); return connection.flushBatchRequests(); }); } ).then( function(r1) { test(r1.completed()); return p.waitForBatch(2); } ).then( function() { return b1.ice_getConnection().then(function(connection) { return connection.flushBatchRequests(); }); } ).then( function(r2) { test(r2.completed()); } ).then( function() { out.writeLine("ok"); } ); } ).then( function() { out.write("testing batch requests with communicator... "); return p.opBatchCount().then( function(count) { test(count === 0); test(b1.opBatch().completed()); test(b1.opBatch().completed()); return communicator.flushBatchRequests().then(function(r1) { test(r1.completed()); return p.waitForBatch(2).then( function() { return p.opBatchCount(); }); }); } ).then( function(batchCount) { // // AsyncResult exception - 1 connection. // test(batchCount === 0); b1.opBatch(); b1.ice_getCachedConnection().close(false); return communicator.flushBatchRequests().then(function(r) { test(r.completed()); return p.opBatchCount(); }); } ).then( function(batchCount) { // // AsyncResult exception - 2 connections // test(batchCount === 0); return getConnectionBatchProxy(p).then( function(prx) { b1 = prx; return getConnectionBatchProxy(p, "2"); } ).then( // Ensure connection is established. function(prx) { b2 = prx; b1.opBatch(); b1.opBatch(); b2.opBatch(); b2.opBatch(); return communicator.flushBatchRequests(); } ).then(function(r) { test(r.completed()); return p.waitForBatch(4).then( function() { return p.opBatchCount(); }); }); } ).then( function(batchCount) { // // AsyncResult exception - 2 connections - 1 failure. // // All connections should be flushed even if there are failures on some connections. // Exceptions should not be reported. // test(batchCount === 0); return getConnectionBatchProxy(p).then( function(prx) { b1 = prx; return getConnectionBatchProxy(p, "2"); } ).then( // Ensure connection is established. function(prx) { b2 = prx; b1.opBatch(); b2.opBatch(); b1.ice_getCachedConnection().close(false); return communicator.flushBatchRequests(); } ).then(function(r) { test(r.completed()); return p.waitForBatch(1).then( function() { return p.opBatchCount(); }); }); } ).then( function(batchCount) { // // AsyncResult exception - 2 connections - 2 failures. // // All connections should be flushed even if there are failures on some connections. // Exceptions should not be reported. // test(batchCount === 0); return getConnectionBatchProxy(p).then( function(prx) { b1 = prx; return getConnectionBatchProxy(p, "2"); } ).then( // Ensure connection is established. function(prx) { b2 = prx; b1.opBatch(); b2.opBatch(); b1.ice_getCachedConnection().close(false); b2.ice_getCachedConnection().close(false); return communicator.flushBatchRequests(); } ).then(function(r) { test(r.completed()); return p.opBatchCount(); }); } ).then( function(batchCount) { test(batchCount === 0); out.writeLine("ok"); } ); } ).then( function() { out.write("testing AsyncResult operations... "); var indirect = Test.TestIntfPrx.uncheckedCast(p.ice_adapterId("dummy")); return indirect.op().exception( function(ex, r) { try { r.throwLocalException(); } catch(ex) { test(ex instanceof Ice.NoEndpointException); } } ).then( function() { return testController.holdAdapter(); } ).then( function() { var r1 = p.op(); var r2 = null; var seq = Ice.Buffer.createNative(new Array(100000)); while((r2 = p.opWithPayload(seq)).sentSynchronously()); test(r1.sentSynchronously() && r1.isSent() && !r1.isCompleted() || !r1.sentSynchronously() && !r1.isCompleted()); test(!r2.sentSynchronously() && !r2.isCompleted()); testController.resumeAdapter(); test(r1.operation === "op"); test(r2.operation === "opWithPayload"); return r1.then( function() { test(r1.isSent()); test(r1.isCompleted()); return r2; } ).then( function() { test(r2.isSent()); test(r2.isCompleted()); } ); } ).then( function() { r = p.ice_ping(); test(r.operation === "ice_ping"); test(r.connection === null); // Expected test(r.communicator == communicator); test(r.proxy == p); // // Oneway // var p2 = p.ice_oneway(); r = p2.ice_ping(); test(r.operation === "ice_ping"); test(r.connection === null); // Expected test(r.communicator == communicator); test(r.proxy == p2); // // Batch request via proxy // p2 = p.ice_batchOneway(); p2.ice_ping(); r = p2.ice_flushBatchRequests(); test(r.operation === "ice_flushBatchRequests"); test(r.connection === null); // Expected test(r.communicator == communicator); test(r.proxy == p2); var con = p.ice_getCachedConnection(); p2 = p.ice_batchOneway(); p2.ice_ping(); r = con.flushBatchRequests(); test(r.operation === "flushBatchRequests"); test(r.connection == con); test(r.communicator == communicator); test(r.proxy === null); p2 = p.ice_batchOneway(); p2.ice_ping(); r = communicator.flushBatchRequests(); test(r.operation === "flushBatchRequests"); test(r.connection === null); test(r.communicator == communicator); test(r.proxy === null); } ).then( function() { return testController.holdAdapter(); } ).then( function() { var seq = Ice.Buffer.createNative(new Array(100024)); while((r = p.opWithPayload(seq)).sentSynchronously()); test(!r.isSent()); var r1 = p.ice_ping(); var r2 = p.ice_id(); r1.cancel(); r2.cancel(); try { r1.throwLocalException(); test(false); } catch(ex) { test(ex instanceof Ice.InvocationCanceledException); } try { r2.throwLocalException(); test(false); } catch(ex) { test(ex instanceof Ice.InvocationCanceledException); } return testController.resumeAdapter().then( function() { p.ice_ping().then( function() { test(!r1.isSent() && r1.isCompleted()); test(!r2.isSent() && r2.isCompleted()); }); }); } ).then( function() { return testController.holdAdapter(); } ).then( function() { var r1 = p.op(); var r2 = p.ice_id(); return p.ice_oneway().ice_ping().then( function() { r1.cancel(); r2.cancel(); try { r1.throwLocalException(); test(false); } catch(ex) { test(ex instanceof Ice.InvocationCanceledException); } try { r2.throwLocalException(); test(false); } catch(ex) { test(ex instanceof Ice.InvocationCanceledException); } testController.resumeAdapter(); }); } ).then( function() { out.writeLine("ok"); }); } ).then( function() { return p.shutdown(); }, function(ex) { console.log("unexpected exception:\n" + ex); test(false); } ).then( function() { promise.succeed(); } ); return promise; }