//ORIGINAL LINE: @Test public void testFuture() throws ThreadInterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testFuture() { RequestBody req = new RequestBody(2, "hello world future"); for (int i = 0; i < invokeTimes; i++) { try { RpcResponseFuture future = client.invokeWithFuture(addr, req, 3000); string res = (string)future.get(); Assert.Equal(RequestBody.DEFAULT_SERVER_RETURN_STR, res); } catch (RemotingException e) { string errMsg = "RemotingException caught in future!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } catch (ThreadInterruptedException e) { string errMsg = "ThreadInterruptedException caught in future!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } } Assert.True(serverConnectProcessor.Connected); Assert.Equal(1, serverConnectProcessor.ConnectTimes); Assert.Equal(invokeTimes, serverUserProcessor.InvokeTimes); }
//ORIGINAL LINE: @Test public void testInvokeContextCustomSerializer_FUTURE() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testInvokeContextCustomSerializer_FUTURE() { NormalRequestBodyCustomSerializer_InvokeContext s1 = new NormalRequestBodyCustomSerializer_InvokeContext(); NormalStringCustomSerializer_InvokeContext s2 = new NormalStringCustomSerializer_InvokeContext(); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: CustomSerializerManager.registerCustomSerializer(typeof(RequestBody), s1); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: CustomSerializerManager.registerCustomSerializer(typeof(string), s2); RequestBody body = new RequestBody(1, "hello world!"); InvokeContext invokeContext = new InvokeContext(); invokeContext.putIfAbsent(NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE_KEY, NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE1_value); RpcResponseFuture future = client.invokeWithFuture(addr, body, invokeContext, 1000); string ret = (string)future.get(1000); Assert.Equal(RequestBody.DEFAULT_SERVER_RETURN_STR + "RANDOM", ret); Assert.True(s1.Serialized); Assert.True(s1.Deserialized); invokeContext.clear(); invokeContext.putIfAbsent(NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE_KEY, NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE2_value); future = client.invokeWithFuture(addr, body, invokeContext, 1000); ret = (string)future.get(1000); Assert.Equal(NormalStringCustomSerializer_InvokeContext.UNIVERSAL_RESP, ret); Assert.True(s1.Serialized); Assert.True(s1.Deserialized); }
//ORIGINAL LINE: @Test public void testFuture() public virtual void testFuture() { RequestBody b4 = new RequestBody(4, "hello world future"); for (int i = 0; i < 3; i++) { try { java.lang.System.setProperty(Configs.SERIALIZER, i.ToString()); RpcResponseFuture future = client.invokeWithFuture(addr, b4, 1000); object obj = future.get(1500); Assert.Equal(RequestBody.DEFAULT_SERVER_RETURN_STR, obj); logger.LogWarning("Result received in future:" + obj); } catch (CodecException e) { string errMsg = "Codec System.Exception caught in callback!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } catch (RemotingException e) { string errMsg = "Remoting System.Exception caught in callback!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } catch (ThreadInterruptedException e) { string errMsg = "Interrupted System.Exception caught in callback!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } } }
//ORIGINAL LINE: @Test public void testFutureException1() public virtual void testFutureException1() { server.registerUserProcessor(new AsyncExceptionUserProcessor()); RequestBody b1 = new RequestBody(1, "Hello world!"); try { RpcResponseFuture future = client.invokeWithFuture(addr, b1, 1000); future.get(1500); string errMsg = "Should throw InvokeServerException!"; logger.LogError(errMsg); Assert.Null(errMsg); } catch (InvokeServerException) { Assert.True(true); } catch (RemotingException) { string errMsg = "RemotingException in testFutureException "; logger.LogError(errMsg); Assert.Null(errMsg); } catch (ThreadInterruptedException) { string errMsg = "ThreadInterruptedException in testFutureException "; logger.LogError(errMsg); Assert.Null(errMsg); } }
//ORIGINAL LINE: @Test public void testFutureWithShorterOrJustTheSameTime() public virtual void testFutureWithShorterOrJustTheSameTime() { RequestBody b4 = new RequestBody(4, "Hello world!"); object obj = null; try { RpcResponseFuture future = client.invokeWithFuture(addr, b4, timeout); obj = future.get(timeout - 50); Assert.Null("Should not reach here!"); } catch (InvokeTimeoutException) { Assert.Null(obj); } catch (RemotingException e) { logger.LogError("Should not catch any exception here", e); Assert.Null("Should not reach here!"); } catch (ThreadInterruptedException e) { logger.LogError("ThreadInterruptedException in sync", e); Assert.Null("Should not reach here!"); } }
//ORIGINAL LINE: @Test public void testFutureWaitShort() public virtual void testFutureWaitShort() { server.registerUserProcessor(new SimpleServerUserProcessor(100)); RequestBody req = new RequestBody(4, "hello world future"); object res = null; try { RpcResponseFuture future = client.invokeWithFuture(addr, req, 1000); res = future.get(10); Assert.Null("Should not reach here!"); } catch (InvokeTimeoutException) { Assert.Null(res); } catch (RemotingException e) { string errMsg = "RemotingException caught in testFutureWaitShort!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } catch (ThreadInterruptedException e) { string errMsg = "ThreadInterruptedException caught in testFutureWaitShort!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } }
//ORIGINAL LINE: @Test public void testFuture() public virtual void testFuture() { RequestBody b4 = new RequestBody(4, "Hello world!"); object obj = null; try { RpcResponseFuture future = client.invokeWithFuture(addr, b4, 1000); obj = future.get(1500); Assert.Null("Should not reach here!"); } catch (InvokeServerBusyException) { Assert.Null(obj); } catch (RemotingException e) { logger.LogError("Other RemotingException but InvokeServerBusyException occurred in future", e); Assert.Null("Should not reach here!"); } catch (ThreadInterruptedException e) { logger.LogError("ThreadInterruptedException in future", e); Assert.Null("Should not reach here!"); } }
public virtual void testFuture() { client.getConnection(addr, 1000); RequestBody req = new RequestBody(1, RequestBody.DEFAULT_SERVER_STR); for (int i = 0; i < invokeTimes; i++) { try { // only when client invoked, the remote address can be get by UserProcessor // otherwise, please use ConnectionEventProcessor string remoteAddr = serverUserProcessor.RemoteAddr; Assert.Null(remoteAddr); remoteAddr = serverConnectProcessor.RemoteAddr; Assert.NotNull(remoteAddr); RpcResponseFuture future = server.RpcServer.invokeWithFuture(remoteAddr, req, 1000); string clientres = (string)future.get(1000); Assert.Equal(clientres, RequestBody.DEFAULT_CLIENT_RETURN_STR); } catch (RemotingException e) { string errMsg = "RemotingException caught in future!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } } Assert.True(serverConnectProcessor.Connected); Assert.Equal(1, serverConnectProcessor.ConnectTimes); Assert.Equal(0, serverUserProcessor.InvokeTimes); Assert.Equal(invokeTimes, clientUserProcessor.InvokeTimes); }
//ORIGINAL LINE: @Test public void testFuturePreHandle() public virtual void testFuturePreHandle() { RequestBody b1 = new RequestBody(1, "hello world sync"); for (int i = 0; i < invokeTimes; i++) { try { RpcResponseFuture future = client.invokeWithFuture(addr, b1, 3000); object ret = future.get(); logger.LogWarning("Result received in sync: " + ret); Assert.Equal("test", ret); } catch (RemotingException e) { string errMsg = "RemotingException caught in testFuturePreHandle!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } catch (ThreadInterruptedException e) { string errMsg = "ThreadInterruptedException caught in testFuturePreHandle!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } } }
//ORIGINAL LINE: @Test public void testFuture() throws ThreadInterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testFuture() { RequestBody req = new RequestBody(2, "hello world future"); for (int i = 0; i < invokeTimes; i++) { Exception res = null; try { RpcResponseFuture future = client.invokeWithFuture(addr, req, 3000); res = (Exception)future.get(); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: Assert.Equal(typeof(ArgumentException), res.GetType()); } catch (RemotingException e) { string errMsg = "RemotingException caught in future!"; logger.LogError(errMsg, e); Assert.Null("Should not reach here!"); } catch (ThreadInterruptedException e) { string errMsg = "ThreadInterruptedException caught in future!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } } Assert.True(serverConnectProcessor.Connected); Assert.Equal(1, serverConnectProcessor.ConnectTimes); Assert.Equal(invokeTimes, serverUserProcessor.InvokeTimes); }
//ORIGINAL LINE: @Test public void testFuture() throws ThreadInterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testFuture() { NormalRequestBodyCustomSerializer s1 = new NormalRequestBodyCustomSerializer(); NormalStringCustomSerializer s2 = new NormalStringCustomSerializer(); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: CustomSerializerManager.registerCustomSerializer(typeof(RequestBody), s1); //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: CustomSerializerManager.registerCustomSerializer(typeof(string), s2); RequestBody req = new RequestBody(2, "hello world future"); for (int i = 0; i < invokeTimes; i++) { try { byte testCodec = (byte)i; InvokeContext invokeContext = new InvokeContext(); invokeContext.put(InvokeContext.BOLT_CUSTOM_SERIALIZER, testCodec); RpcResponseFuture future = client.invokeWithFuture(addr, req, invokeContext, 3000); string res = (string)future.get(); Assert.Equal(RequestBody.DEFAULT_SERVER_RETURN_STR + "RANDOM", res); Assert.Equal(testCodec, s1.ContentSerializer); Assert.Equal(testCodec, s2.ContentSerializer); } catch (RemotingException e) { string errMsg = "RemotingException caught in future!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } catch (ThreadInterruptedException e) { string errMsg = "ThreadInterruptedException caught in future!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } } Assert.True(serverConnectProcessor.Connected); Assert.Equal(1, serverConnectProcessor.ConnectTimes); Assert.Equal(invokeTimes, serverUserProcessor.InvokeTimes); }
/// <summary> /// do invoke /// </summary> /// <param name="type"> </param> /// <param name="url"> /// @return </param> /// <exception cref="RemotingException"> </exception> /// <exception cref="ThreadInterruptedException"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private Object doInvoke(com.alipay.remoting.rpc.common.RequestBody.InvokeType type, String url) throws com.alipay.remoting.exception.RemotingException, ThreadInterruptedException private object doInvoke(RequestBody.InvokeType type, string url) { RequestBody b1 = new RequestBody(1, "hello world"); object obj = null; if (type.Equals(RequestBody.InvokeType.ONEWAY)) { client.oneway(url, b1); } else if (type.Equals(RequestBody.InvokeType.SYNC)) { obj = client.invokeSync(url, b1, 3000); } else if (type.Equals(RequestBody.InvokeType.FUTURE)) { RpcResponseFuture future = client.invokeWithFuture(url, b1, 3000); obj = future.get(3000); } else if (type.Equals(RequestBody.InvokeType.CALLBACK)) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<String> rets = new java.util.ArrayList<String>(1); IList <string> rets = new List <string>(1); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountdownEvent latch = new java.util.concurrent.CountdownEvent(1); CountdownEvent latch = new CountdownEvent(1); client.invokeWithCallback(url, b1, new InvokeCallbackAnonymousInnerClass(this, rets, latch), 3000); try { latch.Wait(); } catch (ThreadInterruptedException e) { string errMsg = "ThreadInterruptedException caught in callback!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } if (rets.Count == 0) { Assert.Null("No result of callback! Maybe exception caught!"); } obj = rets[0]; } return(obj); }
//ORIGINAL LINE: @Test public void testFuture() throws ThreadInterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testFuture() { RequestBody req = new RequestBody(2, "hello world future"); for (int i = 0; i < invokeTimes; i++) { try { InvokeContext invokeContext = new InvokeContext(); invokeContext.put(TESTKEY, "TESTVALUE"); RpcResponseFuture future = client.invokeWithFuture(addr, req, invokeContext, 3000); string res = (string)future.get(); Assert.Equal(RequestBody.DEFAULT_SERVER_RETURN_STR, res); Assert.Equal(IPAddress.Loopback.MapToIPv6(), invokeContext.get(InvokeContext.CLIENT_LOCAL_IP)); Assert.Equal(IPAddress.Loopback.MapToIPv6(), invokeContext.get(InvokeContext.CLIENT_REMOTE_IP)); Assert.NotNull(invokeContext.get(InvokeContext.CLIENT_LOCAL_PORT)); Assert.NotNull(invokeContext.get(InvokeContext.CLIENT_REMOTE_PORT)); Assert.NotNull(invokeContext.get(InvokeContext.CLIENT_CONN_CREATETIME)); logger.LogWarning("CLIENT_CONN_CREATETIME:" + invokeContext.get(InvokeContext.CLIENT_CONN_CREATETIME)); Assert.Equal("TESTVALUE", invokeContext.get(TESTKEY)); TraceLogUtil.printConnectionTraceLog(logger, "0af4232214701387943901253", invokeContext); } catch (RemotingException e) { string errMsg = "RemotingException caught in future!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } catch (ThreadInterruptedException e) { string errMsg = "ThreadInterruptedException caught in future!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } } Assert.True(serverConnectProcessor.Connected); Assert.Equal(1, serverConnectProcessor.ConnectTimes); Assert.Equal(invokeTimes, serverUserProcessor.InvokeTimes); }
private void future(RpcClient client, RpcServer server, int timeout) { RequestBody b1 = new RequestBody(1, RequestBody.DEFAULT_FUTURE_STR); object obj = null; try { RpcResponseFuture future = null; if (null == server) { future = client.invokeWithFuture(addr, b1, timeout); } else { Connection conn = client.getConnection(addr, timeout); Assert.NotNull(serverConnectProcessor.Connection); Connection serverConn = serverConnectProcessor.Connection; future = server.invokeWithFuture(serverConn, b1, timeout); } obj = future.get(timeout); Assert.Null("Should not reach here!"); } catch (InvokeTimeoutException) { Assert.Null(obj); } catch (RemotingException e) { logger.LogError("Other RemotingException but RpcServerTimeoutException occurred in sync", e); Assert.Null("Should not reach here!"); } catch (ThreadInterruptedException e) { logger.LogError("ThreadInterruptedException in sync", e); Assert.Null("Should not reach here!"); } }