Пример #1
0
        public void TestException()
        {
            using (ScopedServer server = new ScopedServer(new TBinaryProtocol.Factory(), new AsyncService()))
            {
                using (ThriftClientManager manager = new ThriftClientManager())
                {
                    using (var client = server.CreateScribeClient <IAsyncService>(manager, server, new TBinaryProtocol.Factory()))
                    {
                        SimpleStruct structObj = CreateSimpleStructWithData();
                        try
                        {
                            var task = client.ExceptionMethod();
                            task.GetAwaiter().GetResult();
                            Assert.True(false);
                        }
                        catch (ThriftyApplicationException e)
                        {
                            Assert.NotNull(e);
                            Assert.Contains(AsyncService.ExceptionMessage, e.Message);
                        }
                    }

                    manager.CloseAsync(TimeSpan.FromSeconds(3));
                }
            }
        }
Пример #2
0
 public void TestOneWay()
 {
     using (ScopedServer server = new ScopedServer(new TBinaryProtocol.Factory(), new AsyncService()))
     {
         using (ThriftClientManager manager = new ThriftClientManager())
         {
             using (var client = server.CreateScribeClient <IAsyncService>(manager, server, new TBinaryProtocol.Factory()))
             {
                 client.OneWayMethod().GetAwaiter().GetResult();
                 client.VerifyConnectionState();
             }
             manager.CloseAsync(TimeSpan.FromSeconds(3));
         }
     }
 }
Пример #3
0
        public void TestOneWayException()
        {
            using (ScopedServer server = new ScopedServer(new TBinaryProtocol.Factory(), new OneWayService()))
            {
                using (ThriftClientManager manager = new ThriftClientManager())
                {
                    using (var client = server.CreateScribeClient <IOneWayService>(manager, server, new TBinaryProtocol.Factory()))
                    {
                        //client.OneWayThrow();
                        client.VerifyConnectionState();
                    }

                    manager.CloseAsync(TimeSpan.FromSeconds(3));
                }
            }
        }
Пример #4
0
        public void TestServerException()
        {
            using (ScopedServer server = new ScopedServer(new TBinaryProtocol.Factory(), new ExceptionService()))
            {
                using (ThriftClientManager manager = new ThriftClientManager())
                {
                    using (var client = server.CreateScribeClient <IExceptionService>(manager, server, new TBinaryProtocol.Factory()))
                    {
                        ThriftyException ex = Assert.Throws <ThriftyApplicationException>(() => client.ThrowArgumentException());
                        Assert.Contains(ExceptionService.ExceptionMessage, ex.Message);
                    }

                    manager.CloseAsync(TimeSpan.FromSeconds(3));
                }
            }
        }
Пример #5
0
        public void TestTwoWay()
        {
            using (ScopedServer server = new ScopedServer(new TBinaryProtocol.Factory(), new AsyncService()))
            {
                using (ThriftClientManager manager = new ThriftClientManager())
                {
                    using (var client = server.CreateScribeClient <IAsyncService>(manager, server, new TBinaryProtocol.Factory()))
                    {
                        SimpleStruct structObj = CreateSimpleStructWithData();
                        var          result    = client.TwoWayMethod(structObj).GetAwaiter().GetResult();

                        Assert.Equal(structObj, result);
                    }

                    manager.CloseAsync(TimeSpan.FromSeconds(3));
                }
            }
        }
Пример #6
0
        public void ByteTest(String content)
        {
            using (ScopedServer server = new ScopedServer(new TBinaryProtocol.Factory(), new MultipleParameterService()))
            {
                using (ThriftClientManager manager = new ThriftClientManager())
                {
                    using (var client = server.CreateScribeClient <IMultipleParameterService>(manager, server, new TBinaryProtocol.Factory()))
                    {
                        var test        = Encoding.UTF8.GetBytes(content);
                        var bytesString = client.BytesToString(test);

                        Assert.Equal(content, bytesString);
                    }

                    manager.CloseAsync(TimeSpan.FromSeconds(3));
                }
            }
        }
Пример #7
0
        public void TestCompactProtocolClient()
        {
            using (ScopedServer server = new ScopedServer(new TCompactProtocol.Factory(), new ScribeTest()))
            {
                using (ThriftClientManager manager = new ThriftClientManager())
                {
                    using (var client = server.CreateScribeClient <IScribe>(manager, server, new TCompactProtocol.Factory()))
                    {
                        var code = client.log(new List <LogEntry>
                        {
                            new LogEntry("testCategory1", "testMessage1"),
                            new LogEntry("testCategory2", "testMessage2")
                        });
                        Assert.Equal(ResultCode.TRY_LATER, code);
                    }

                    manager.CloseAsync(TimeSpan.FromSeconds(3));
                }
            }
        }
Пример #8
0
        public void ParametersTest(String args1,
                                   int args2,
                                   float args3,
                                   double args4,
                                   bool args5,
                                   byte args6,
                                   TestEnum args7,
                                   long args8,
                                   short args9,
                                   int?nargs2,
                                   float?nargs3,
                                   double?nargs4,
                                   bool?nargs5,
                                   byte?nargs6,
                                   TestEnum?nargs7,
                                   long?nargs8,
                                   short?nargs9)
        {
            using (ScopedServer server = new ScopedServer(new TBinaryProtocol.Factory(), new MultipleParameterService()))
            {
                using (ThriftClientManager manager = new ThriftClientManager())
                {
                    using (var client = server.CreateScribeClient <IMultipleParameterService>(manager, server, new TBinaryProtocol.Factory()))
                    {
                        Random   random = new Random();
                        DateTime date   = RandomDateTime(random);
                        DateTime?date2  = RandomDateTime(random);

                        String bytesString = Guid.NewGuid().ToString();
                        byte[] bytes       = Encoding.UTF8.GetBytes(bytesString);

                        string expected = $@"{args1}{args2}{args3}{args4}{args5}{args6}{args7}{args8}{args9}"
                                          + $@"{nargs2}{nargs3}{nargs4}{nargs5}{nargs6}{nargs7}{nargs8}{nargs9}{date}{date2}{bytesString}";

                        string result = client.MergeString(
                            args1,
                            args2,
                            args3,
                            args4,
                            args5,
                            args6,
                            args7,
                            args8,
                            args9,
                            nargs2,
                            nargs3,
                            nargs4,
                            nargs5,
                            nargs6,
                            nargs7,
                            nargs8,
                            nargs9,
                            date,
                            date2,
                            bytes);

                        Assert.Equal(expected, result);
                    }

                    manager.CloseAsync(TimeSpan.FromSeconds(3));
                }
            }
        }