Example #1
0
        //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);
                InvokeContext  invokeContext = new InvokeContext();
                try
                {
                    client.invokeWithCallback(addr, req, invokeContext, new InvokeCallbackAnonymousInnerClass(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.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));

                TraceLogUtil.printConnectionTraceLog(logger, "0af4232214701387943901253", invokeContext);
            }

            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()
        {
            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);
        }