Exemplo n.º 1
0
 public void Init()
 {
     server = new Server();
     server.AddServiceDefinition(ServiceDefinition);
     int port = server.AddPort(Host, Server.PickUnusedPort, ServerCredentials.Insecure);
     server.Start();
     channel = new Channel(Host, port, Credentials.Insecure);
 }
Exemplo n.º 2
0
        public void Init()
        {
            server = new Server();
            server.AddServiceDefinition(ServiceDefinition);
            int port = server.AddPort(Host, Server.PickUnusedPort, ServerCredentials.Insecure);
            server.Start();
            channel = new Channel(Host, port, Credentials.Insecure);

            stringFromServerHandlerTcs = new TaskCompletionSource<string>();
        }
Exemplo n.º 3
0
        public void StartAndShutdownServer()
        {
            GrpcEnvironment.Initialize();

            Server server = new Server();
            server.AddPort("localhost:0");
            server.Start();
            server.ShutdownAsync().Wait();

            GrpcEnvironment.Shutdown();
        }
Exemplo n.º 4
0
        public void Init()
        {
            serviceImpl = new HealthServiceImpl();

            server = new Server();
            server.AddServiceDefinition(Grpc.Health.V1Alpha.Health.BindService(serviceImpl));
            int port = server.AddPort(Host, Server.PickUnusedPort, ServerCredentials.Insecure);
            server.Start();
            channel = new Channel(Host, port, Credentials.Insecure);

            client = Grpc.Health.V1Alpha.Health.NewClient(channel);
        }
Exemplo n.º 5
0
        public void Init()
        {
            server = new Server();
            server.AddServiceDefinition(TestService.BindService(new TestServiceImpl()));
            int port = server.AddPort(host, Server.PickUnusedPort, TestCredentials.CreateTestServerCredentials());
            server.Start();

            var options = new List<ChannelOption>
            {
                new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
            };
            channel = new Channel(host, port, TestCredentials.CreateTestClientCredentials(true), options);
            client = TestService.NewClient(channel);
        }
Exemplo n.º 6
0
        public void Init()
        {
            server = new Server();
            server.AddServiceDefinition(Math.BindService(new MathServiceImpl()));
            int port = server.AddPort(host, Server.PickUnusedPort, ServerCredentials.Insecure);
            server.Start();
            channel = new Channel(host, port, Credentials.Insecure);
            client = Math.NewClient(channel);

            // TODO(jtattermusch): get rid of the custom header here once we have dedicated tests
            // for header support.
            client.HeaderInterceptor = (metadata) =>
            {
                metadata.Add(new Metadata.Entry("customHeader", "abcdef"));
            };
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            string host = "0.0.0.0";

            Server server = new Server();
            server.AddServiceDefinition(Math.BindService(new MathServiceImpl()));
            int port = server.AddPort(host, 23456, ServerCredentials.Insecure);
            server.Start();

            Console.WriteLine("MathServer listening on port " + port);

            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
            GrpcEnvironment.Shutdown();
        }
Exemplo n.º 8
0
        public void UnaryCall()
        {
            Server server = new Server();
            server.AddServiceDefinition(
                ServerServiceDefinition.CreateBuilder("someService")
                    .AddMethod(unaryEchoStringMethod, HandleUnaryEchoString).Build());

            int port = server.AddPort(host + ":0");
            server.Start();

            using (Channel channel = new Channel(host + ":" + port))
            {
                var call = new Call<string, string>(unaryEchoStringMethod, channel);

                Assert.AreEqual("ABC", Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken)));

                Assert.AreEqual("abcdef", Calls.BlockingUnaryCall(call, "abcdef", default(CancellationToken)));
            }

            server.ShutdownAsync().Wait();
        }
Exemplo n.º 9
0
        public void Init()
        {
            var rootCert = File.ReadAllText(TestCredentials.ClientCertAuthorityPath);
            var keyCertPair = new KeyCertificatePair(
                File.ReadAllText(TestCredentials.ServerCertChainPath),
                File.ReadAllText(TestCredentials.ServerPrivateKeyPath));

            var serverCredentials = new SslServerCredentials(new[] { keyCertPair }, rootCert);
            var clientCredentials = new SslCredentials(rootCert, keyCertPair);

            server = new Server();
            server.AddServiceDefinition(TestService.BindService(new TestServiceImpl()));
            int port = server.AddPort(host, Server.PickUnusedPort, serverCredentials);
            server.Start();

            var options = new List<ChannelOption>
            {
                new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
            };

            channel = new Channel(host, port, clientCredentials, options);
            client = TestService.NewClient(channel);
        }
Exemplo n.º 10
0
        public void Init()
        {
            GrpcEnvironment.Initialize();

            server = new Server();
            server.AddServiceDefinition(MathGrpc.BindService(new MathServiceImpl()));
            int port = server.AddPort(host + ":0");
            server.Start();
            channel = new Channel(host + ":" + port);
            client = MathGrpc.NewStub(channel);
        }
Exemplo n.º 11
0
        private void Run()
        {
            var server = new Server();
            server.AddServiceDefinition(TestService.BindService(new TestServiceImpl()));

            string host = "0.0.0.0";
            int port = options.port.Value;
            if (options.useTls)
            {
                server.AddPort(host, port, TestCredentials.CreateTestServerCredentials());
            }
            else
            {
                server.AddPort(host, options.port.Value, ServerCredentials.Insecure);
            }
            Console.WriteLine("Running server on " + string.Format("{0}:{1}", host, port));
            server.Start();

            server.ShutdownTask.Wait();

            GrpcEnvironment.Shutdown();
        }
Exemplo n.º 12
0
        public void Init()
        {
            GrpcEnvironment.Initialize();

            server = new Server();
            server.AddServiceDefinition(TestServiceGrpc.BindService(new TestServiceImpl()));
            int port = server.AddPort(host + ":0", TestCredentials.CreateTestServerCredentials());
            server.Start();

            var channelArgs = ChannelArgs.NewBuilder()
                .AddString(ChannelArgs.SslTargetNameOverrideKey, TestCredentials.DefaultHostOverride).Build();

            channel = new Channel(host + ":" + port, TestCredentials.CreateTestClientCredentials(true), channelArgs);
            client = TestServiceGrpc.NewStub(channel);
        }
Exemplo n.º 13
0
        public void UnaryCallPerformance()
        {
            Server server = new Server();
            server.AddServiceDefinition(
                ServerServiceDefinition.CreateBuilder("someService")
                .AddMethod(unaryEchoStringMethod, HandleUnaryEchoString).Build());

            int port = server.AddPort(host + ":0");
            server.Start();

            using (Channel channel = new Channel(host + ":" + port))
            {
                var call = new Call<string, string>(unaryEchoStringMethod, channel);
                BenchmarkUtil.RunBenchmark(100, 1000,
                                           () => { Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken)); });
            }

            server.ShutdownAsync().Wait();
        }
Exemplo n.º 14
0
        public void UnknownMethodHandler()
        {
            Server server = new Server();
            server.AddServiceDefinition(
                ServerServiceDefinition.CreateBuilder("someService").Build());

            int port = server.AddPort(host + ":0");
            server.Start();

            using (Channel channel = new Channel(host + ":" + port))
            {
                var call = new Call<string, string>(unaryEchoStringMethod, channel);

                try {
                    Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken));
                    Assert.Fail();
                } catch(RpcException e) {
                    Assert.AreEqual(StatusCode.Unimplemented, e.Status.StatusCode);
                }
            }

            server.ShutdownAsync().Wait();
        }
Exemplo n.º 15
0
        private void Run()
        {
            GrpcEnvironment.Initialize();

            var server = new Server();
            server.AddServiceDefinition(TestServiceGrpc.BindService(new TestServiceImpl()));

            string addr = "0.0.0.0:" + options.port;
            if (options.useTls)
            {
                server.AddPort(addr, TestCredentials.CreateTestServerCredentials());
            }
            else
            {
                server.AddPort(addr);
            }
            Console.WriteLine("Running server on " + addr);
            server.Start();

            server.ShutdownTask.Wait();

            GrpcEnvironment.Shutdown();
        }