//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); }
/// <seealso cref= RpcRemoting#preProcessInvokeContext(InvokeContext, RemotingCommand, Connection) </seealso> protected internal override void preProcessInvokeContext(InvokeContext invokeContext, RemotingCommand cmd, Connection connection) { if (null != invokeContext) { invokeContext.putIfAbsent(InvokeContext.CLIENT_LOCAL_IP, ((IPEndPoint)connection.Channel.LocalAddress).Address); invokeContext.putIfAbsent(InvokeContext.CLIENT_LOCAL_PORT, ((IPEndPoint)connection.Channel.LocalAddress).Port); invokeContext.putIfAbsent(InvokeContext.CLIENT_REMOTE_IP, ((IPEndPoint)connection.Channel.RemoteAddress).Address); invokeContext.putIfAbsent(InvokeContext.CLIENT_REMOTE_PORT, ((IPEndPoint)connection.Channel.RemoteAddress).Port); invokeContext.putIfAbsent(InvokeContext.BOLT_INVOKE_REQUEST_ID, cmd.Id); } }
//ORIGINAL LINE: @Test public void testOneway() throws ThreadInterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testOneway() { RequestBody req = new RequestBody(2, "hello world oneway"); for (int i = 0; i < invokeTimes; i++) { try { if (i % 2 == 0) { client.oneway(addr, req); } else { InvokeContext invokeContext = new InvokeContext(); invokeContext.putIfAbsent(InvokeContext.BOLT_CRC_SWITCH, false); client.oneway(addr, req, invokeContext); } Thread.Sleep(100); } catch (RemotingException e) { string errMsg = "RemotingException caught in oneway!"; 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 testCallback() throws ThreadInterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testCallback() { RequestBody req = new RequestBody(1, "hello world 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); for (int i = 0; i < invokeTimes; i++) { //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); try { if (i % 2 == 0) { client.invokeWithCallback(addr, req, new InvokeCallBackImpl(this, rets, latch), 1000); } else { InvokeContext invokeContext = new InvokeContext(); invokeContext.putIfAbsent(InvokeContext.BOLT_CRC_SWITCH, false); client.invokeWithCallback(addr, req, invokeContext, new InvokeCallBackImpl(this, rets, latch), 1000); } } catch (RemotingException e) { if (!latch.IsSet) { latch.Signal(); } string errMsg = "RemotingException caught in callback!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } 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! Maybe exception caught!"); } Assert.Equal(RequestBody.DEFAULT_SERVER_RETURN_STR, rets[0]); rets.Clear(); } Assert.True(serverConnectProcessor.Connected); Assert.Equal(1, serverConnectProcessor.ConnectTimes); Assert.Equal(invokeTimes, serverUserProcessor.InvokeTimes); }
//ORIGINAL LINE: @Test public void testInvokeContextCustomSerializer_CALLBACK() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testInvokeContextCustomSerializer_CALLBACK() { 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); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<Object> rets = new java.util.ArrayList<Object>(); IList <object> rets = new List <object>(); //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(addr, body, invokeContext, new InvokeCallbackAnonymousInnerClass(this, rets, latch), 1000); latch.Wait(); string ret = (string)rets[0]; 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); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountdownEvent latch1 = new java.util.concurrent.CountdownEvent(1); CountdownEvent latch1 = new CountdownEvent(1); client.invokeWithCallback(addr, body, invokeContext, new InvokeCallbackAnonymousInnerClass2(this, rets, latch1), 1000); latch1.Wait(); ret = (string)rets[0]; Assert.Equal(NormalStringCustomSerializer_InvokeContext.UNIVERSAL_RESP, ret); Assert.True(s1.Serialized); Assert.True(s1.Deserialized); }
/// <summary> /// Get connection and set init invokeContext if invokeContext not {@code null} /// </summary> /// <param name="url"> target url </param> /// <param name="invokeContext"> invoke context to set </param> /// <returns> connection </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected Connection getConnectionAndInitInvokeContext(Url url, InvokeContext invokeContext) throws exception.RemotingException, ThreadInterruptedException protected internal virtual Connection getConnectionAndInitInvokeContext(Url url, InvokeContext invokeContext) { long start = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds(); Connection conn; try { conn = connectionManager.getAndCreateIfAbsent(url); } finally { if (null != invokeContext) { invokeContext.putIfAbsent(InvokeContext.CLIENT_CONN_CREATETIME, new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds() - start); } } return(conn); }
//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 = null; if (i % 2 == 0) { future = client.invokeWithFuture(addr, req, 3000); } else { InvokeContext invokeContext = new InvokeContext(); invokeContext.putIfAbsent(InvokeContext.BOLT_CRC_SWITCH, false); future = client.invokeWithFuture(addr, req, invokeContext, 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 testSync() throws ThreadInterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testSync() { RequestBody req = new RequestBody(1, "hello world sync"); for (int i = 0; i < invokeTimes; i++) { try { string res = null; if (i % 2 == 0) { res = (string)client.invokeSync(addr, req, 3000); } else { InvokeContext invokeContext = new InvokeContext(); invokeContext.putIfAbsent(InvokeContext.BOLT_CRC_SWITCH, false); res = (string)client.invokeSync(addr, req, invokeContext, 3000); } logger.LogWarning("Result received in sync: " + res); Assert.Equal(RequestBody.DEFAULT_SERVER_RETURN_STR, res); } catch (RemotingException e) { string errMsg = "RemotingException caught in sync!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } catch (ThreadInterruptedException e) { string errMsg = "ThreadInterruptedException caught in sync!"; logger.LogError(errMsg, e); Assert.Null(errMsg); } } Assert.True(serverConnectProcessor.Connected); Assert.Equal(1, serverConnectProcessor.ConnectTimes); Assert.Equal(invokeTimes, serverUserProcessor.InvokeTimes); }