예제 #1
0
        private object handleRequest(BizContext bizCtx, RequestBodyC1 request)
        {
            long?waittime = (long?)bizCtx.InvokeContext.get(InvokeContext.BOLT_PROCESS_WAIT_TIME);

            Assert.NotNull(waittime);
            if (logger.IsEnabled(LogLevel.Information))
            {
                logger.LogInformation("Client User processor process wait time {}", waittime);
            }

            processTimes(request);
            if (!delaySwitch)
            {
                return(RequestBodyC1.DEFAULT_CLIENT_RETURN_STR);
            }
            try
            {
                Thread.Sleep(delayMs);
            }
            catch (ThreadInterruptedException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            return(RequestBodyC1.DEFAULT_CLIENT_RETURN_STR);
        }
예제 #2
0
        //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()
        {
            MultiInterestBaseRequestBody req  = new RequestBodyC1(2, "hello world future--c1");
            MultiInterestBaseRequestBody req2 = new RequestBodyC2(3, "hello world future--c2");

            for (int i = 0; i < invokeTimes; i++)
            {
                try
                {
                    RpcResponseFuture future = client.invokeWithFuture(addr, req, 3000);
                    string            res    = (string)future.get();
                    Assert.Equal(RequestBodyC1.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);
                }
            }
            for (int i = 0; i < invokeTimes; i++)
            {
                try
                {
                    RpcResponseFuture future = client.invokeWithFuture(addr, req2, 3000);
                    string            res    = (string)future.get();
                    Assert.Equal(RequestBodyC2.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.InvokeTimesC1);
            Assert.Equal(invokeTimes, serverUserProcessor.InvokeTimesC2);
        }
예제 #3
0
        //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()
        {
            MultiInterestBaseRequestBody req  = new RequestBodyC1(1, "hello world sync--c1");
            MultiInterestBaseRequestBody req2 = new RequestBodyC2(4, "hello world sync--c2");

            for (int i = 0; i < invokeTimes; i++)
            {
                try
                {
                    string res = (string)client.invokeSync(addr, req, 3000);
                    logger.LogWarning("Result received in sync: " + res);
                    Assert.Equal(RequestBodyC1.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);
                }
            }
            for (int i = 0; i < invokeTimes; i++)
            {
                try
                {
                    string res = (string)client.invokeSync(addr, req2, 3000);
                    logger.LogWarning("Result received in sync: " + res);
                    Assert.Equal(RequestBodyC2.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.InvokeTimesC1);
            Assert.Equal(invokeTimes, serverUserProcessor.InvokeTimesC2);
        }
예제 #4
0
 // ~~~ private methods
 private void processTimes(RequestBodyC1 req)
 {
     this.c1invokeTimes.incrementAndGet();
     if (req.Msg.Equals(RequestBodyC1.DEFAULT_ONEWAY_STR))
     {
         this.c1onewayTimes.incrementAndGet();
     }
     else if (req.Msg.Equals(RequestBodyC1.DEFAULT_SYNC_STR))
     {
         this.c1syncTimes.incrementAndGet();
     }
     else if (req.Msg.Equals(RequestBodyC1.DEFAULT_FUTURE_STR))
     {
         this.c1futureTimes.incrementAndGet();
     }
     else if (req.Msg.Equals(RequestBodyC1.DEFAULT_CALLBACK_STR))
     {
         this.c1callbackTimes.incrementAndGet();
     }
 }
예제 #5
0
        //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()
        {
            MultiInterestBaseRequestBody req  = new RequestBodyC1(2, "hello world oneway--c1");
            MultiInterestBaseRequestBody req2 = new RequestBodyC2(3, "hello world oneway--c2");

            for (int i = 0; i < invokeTimes; i++)
            {
                try
                {
                    client.oneway(addr, req);
                    Thread.Sleep(100);
                }
                catch (RemotingException e)
                {
                    string errMsg = "RemotingException caught in oneway!";
                    logger.LogError(errMsg, e);
                    Assert.Null(errMsg);
                }
            }
            for (int j = 0; j < invokeTimes; j++)
            {
                try
                {
                    client.oneway(addr, req2);
                    Thread.Sleep(100);
                }
                catch (RemotingException e)
                {
                    string errMsg = "RemotingException caught in oneway!";
                    logger.LogError(errMsg, e);
                    Assert.Null(errMsg);
                }
            }
            //System.out.println(serverUserProcessor.getInvokeTimesC1()+" "+serverUserProcessor.getInvokeTimesC2());

            Assert.True(serverConnectProcessor.Connected);
            Assert.Equal(1, serverConnectProcessor.ConnectTimes);
            Assert.Equal(invokeTimes, serverUserProcessor.InvokeTimesC1);
            Assert.Equal(invokeTimes, serverUserProcessor.InvokeTimesC2);
        }
예제 #6
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()
        {
            MultiInterestBaseRequestBody req  = new RequestBodyC1(1, "hello world callback--c1");
            MultiInterestBaseRequestBody req2 = new RequestBodyC2(1, "hello world callback--c2");
//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
                {
                    client.invokeWithCallback(addr, req, 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(RequestBodyC1.DEFAULT_SERVER_RETURN_STR, rets[0]);
                rets.Clear();
            }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<String> rets2 = new java.util.ArrayList<String>(1);
            IList <string> rets2 = 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
                {
                    client.invokeWithCallback(addr, req2, new InvokeCallbackAnonymousInnerClass2(this, rets2, 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 (rets2.Count == 0)
                {
                    Assert.Null("No result! Maybe exception caught!");
                }
                Assert.Equal(RequestBodyC2.DEFAULT_SERVER_RETURN_STR, rets2[0]);
                rets.Clear();
            }

            Assert.True(serverConnectProcessor.Connected);
            Assert.Equal(1, serverConnectProcessor.ConnectTimes);
            Assert.Equal(invokeTimes, serverUserProcessor.InvokeTimesC1);
            Assert.Equal(invokeTimes, serverUserProcessor.InvokeTimesC2);
        }