Beispiel #1
0
 public void SubsequentInvocations()
 {
     GrpcEnvironment.Initialize();
     GrpcEnvironment.Initialize();
     GrpcEnvironment.Shutdown();
     GrpcEnvironment.Shutdown();
 }
Beispiel #2
0
        private void Run()
        {
            GrpcEnvironment.Initialize();

            string addr = string.Format("{0}:{1}", options.serverHost, options.serverPort);

            Credentials credentials = null;

            if (options.useTls)
            {
                credentials = TestCredentials.CreateTestClientCredentials(options.useTestCa);
            }

            ChannelArgs channelArgs = null;

            if (!string.IsNullOrEmpty(options.serverHostOverride))
            {
                channelArgs = ChannelArgs.CreateBuilder()
                              .AddString(ChannelArgs.SslTargetNameOverrideKey, options.serverHostOverride).Build();
            }

            using (Channel channel = new Channel(addr, credentials, channelArgs))
            {
                TestServiceGrpc.ITestServiceClient client = new TestServiceGrpc.TestServiceClientStub(channel);
                RunTestCase(options.testCase, client);
            }

            GrpcEnvironment.Shutdown();
        }
Beispiel #3
0
        internal void RemoveFromTracker(
            [DefaultValue((uint)7089), Description("GRPC port")] uint grpcPort)
        {
            Initialize();

            // We need to initialize this here because there's no codepath otherwise.
            GrpcEnvironment.Initialize();

            var context     = new Context(_logger);
            var retryPolicy = RetryPolicyFactory.GetLinearPolicy(ex => ex is ClientCanRetryException, (int)_retryCount, TimeSpan.FromSeconds(_retryIntervalSeconds));

            _logger.Debug("Begin repair handling...");

            // This action is synchronous to make sure the calling application doesn't exit before the method returns.
            using (var rpcClient = new GrpcRepairClient(grpcPort))
            {
                var removeFromTrackerResult = retryPolicy.ExecuteAsync(() => rpcClient.RemoveFromTrackerAsync(context), _cancellationToken).Result;
                if (!removeFromTrackerResult.Succeeded)
                {
                    throw new CacheException(removeFromTrackerResult.ErrorMessage);
                }
                else
                {
                    _logger.Debug($"Repair handling succeeded. Removed {removeFromTrackerResult.Data} hashes from the content tracker.");
                }

                var shutdownResult = rpcClient.ShutdownAsync(context).Result;
                if (!shutdownResult.Succeeded)
                {
                    throw new CacheException(shutdownResult.ErrorMessage);
                }
            }
        }
Beispiel #4
0
        private void Run()
        {
            GrpcEnvironment.Initialize();

            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.AddListeningPort(host, port, TestCredentials.CreateTestServerCredentials());
            }
            else
            {
                server.AddListeningPort(host, options.port.Value);
            }
            Console.WriteLine("Running server on " + string.Format("{0}:{1}", host, port));
            server.Start();

            server.ShutdownTask.Wait();

            GrpcEnvironment.Shutdown();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            GrpcEnvironment.Initialize();

            using (Channel channel = new Channel("127.0.0.1:50052"))
            {
                var client = new RouteGuideClient(RouteGuide.NewStub(channel));

                // Looking for a valid feature
                client.GetFeature(409146138, -746188906);

                // Feature missing.
                client.GetFeature(0, 0);

                // Looking for features between 40, -75 and 42, -73.
                client.ListFeatures(400000000, -750000000, 420000000, -730000000).Wait();

                // Record a few randomly selected points from the features file.
                client.RecordRoute(RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile), 10).Wait();

                // Send and receive some notes.
                client.RouteChat().Wait();
            }

            GrpcEnvironment.Shutdown();
        }
Beispiel #6
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.AddListeningPort(addr, TestCredentials.CreateTestServerCredentials());
            }
            else
            {
                server.AddListeningPort(addr);
            }
            Console.WriteLine("Running server on " + addr);
            server.Start();

            server.ShutdownTask.Wait();

            GrpcEnvironment.Shutdown();
        }
 public CacheServerDistributedContentTests(
     LocalRedisFixture redis,
     ITestOutputHelper output)
     : base(redis, output)
 {
     UseGrpcServer = true;
     GrpcEnvironment.Initialize(TestGlobal.Logger, new BuildXL.Cache.ContentStore.Grpc.GrpcEnvironmentOptions()
     {
         LoggingVerbosity = BuildXL.Cache.ContentStore.Grpc.GrpcEnvironmentOptions.GrpcVerbosity.Info
     });
 }
Beispiel #8
0
        static void Main(string[] args)
        {
            GrpcEnvironment.Initialize();
            GrainClient.Initialize("DevTestClientConfiguration.xml");

            ProcessManager manager = new ProcessManager();

            manager.SubscribeNotification();

            Console.ReadLine();
            GrpcEnvironment.Shutdown();
        }
Beispiel #9
0
        public void StartAndShutdownServer()
        {
            GrpcEnvironment.Initialize();

            Server server = new Server();

            server.AddListeningPort("localhost:0");
            server.Start();
            server.ShutdownAsync().Wait();

            GrpcEnvironment.Shutdown();
        }
Beispiel #10
0
        public void Init()
        {
            GrpcEnvironment.Initialize();

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

            server.Start();
            channel = new Channel(host + ":" + port);
            client  = TestServiceGrpc.NewStub(channel);
        }
Beispiel #11
0
        public void InitializeAfterShutdown()
        {
            GrpcEnvironment.Initialize();
            var tp1 = GrpcEnvironment.ThreadPool;

            GrpcEnvironment.Shutdown();

            GrpcEnvironment.Initialize();
            var tp2 = GrpcEnvironment.ThreadPool;

            GrpcEnvironment.Shutdown();

            Assert.IsFalse(Object.ReferenceEquals(tp1, tp2));
        }
Beispiel #12
0
        private void Run()
        {
            GrpcEnvironment.Initialize();

            string addr = string.Format("{0}:{1}", options.serverHost, options.serverPort);

            using (Channel channel = new Channel(addr))
            {
                TestServiceGrpc.ITestServiceClient client = new TestServiceGrpc.TestServiceClientStub(channel);

                RunTestCase(options.testCase, client);
            }

            GrpcEnvironment.Shutdown();
        }
Beispiel #13
0
        public SessionManager(Guid id, int port)
        {
            gameId         = id;
            gameRunning    = 0;
            rpcPort        = port;
            controller     = new SessionController(this);
            currentSession = new SessionImpl(gameId, Constants.SessionDuration);
            launchEvent    = new ManualResetEvent(false);

            GrpcEnvironment.Initialize();
            rpcServer = new Server();
            rpcServer.AddServiceDefinition(Controller.BindService(controller));
            rpcServer.AddListeningPort("localhost", rpcPort);
            rpcServer.Start();
        }
Beispiel #14
0
        public void Init()
        {
            GrpcEnvironment.Initialize();

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

            server.Start();

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

            channel = new Channel(host + ":" + port, TestCredentials.CreateTestClientCredentials(true), channelArgs);
            client  = TestServiceGrpc.NewStub(channel);
        }
Beispiel #15
0
        public static void Main(string[] args)
        {
            GrpcEnvironment.Initialize();

            using (Channel channel = new Channel("127.0.0.1:50051"))
            {
                var    client = Greeter.NewStub(channel);
                String user   = "******";

                var reply = client.SayHello(new HelloRequest.Builder {
                    Name = user
                }.Build());
                Console.WriteLine("Greeting: " + reply.Message);
            }

            GrpcEnvironment.Shutdown();
        }
Beispiel #16
0
        private void Run()
        {
            GrpcEnvironment.Initialize();

            var server = new Server();

            server.AddServiceDefinition(TestServiceGrpc.BindService(new TestServiceImpl()));

            string addr = "0.0.0.0:" + options.port;

            server.AddPort(addr);
            Console.WriteLine("Running server on " + addr);
            server.Start();

            server.ShutdownTask.Wait();

            GrpcEnvironment.Shutdown();
        }
Beispiel #17
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ServiceClientContentStore"/> class.
        /// </summary>
        public ServiceClientContentStore(
            ILogger logger,
            IAbsFileSystem fileSystem,
            ServiceClientContentStoreConfiguration configuration)
        {
            Contract.Requires(logger != null);
            Contract.Requires(fileSystem != null);
            Contract.Requires(configuration != null);

            Logger        = logger;
            FileSystem    = fileSystem;
            Configuration = configuration;

            // We need to be able to initialize the gRPC environment on the client side. This MUST happen before our
            // first gRPC connection is created, due to the possibility that we may set options that can only be set at
            // that point in time. Hence, we do so here, which is the main entrypoint for most of our clients.
            GrpcEnvironment.Initialize(Logger, Configuration.GrpcEnvironmentOptions, overwriteSafeOptions: true);
        }
Beispiel #18
0
        public static void Main(string[] args)
        {
            GrpcEnvironment.Initialize();

            Server server = new Server();

            server.AddServiceDefinition(Greeter.BindService(new GreeterImpl()));
            int port = server.AddListeningPort("localhost", 50051);

            server.Start();

            Console.WriteLine("Greeter server listening on port " + port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
            GrpcEnvironment.Shutdown();
        }
Beispiel #19
0
        public static void Main(string[] args)
        {
            GrpcEnvironment.Initialize();

            using (Channel channel = new Channel("127.0.0.1:23456"))
            {
                MathGrpc.IMathServiceClient stub = new MathGrpc.MathServiceClientStub(channel);
                MathExamples.DivExample(stub);

                MathExamples.FibExample(stub);

                MathExamples.SumExample(stub);

                MathExamples.DivManyExample(stub);
            }

            GrpcEnvironment.Shutdown();
        }
Beispiel #20
0
        public void Init()
        {
            GrpcEnvironment.Initialize();

            server = new Server();
            server.AddServiceDefinition(TestService.BindService(new TestServiceImpl()));
            int port = server.AddListeningPort(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.NewStub(channel);
        }
Beispiel #21
0
        public StartupShutdownBase Create()
        {
            var cacheConfig = _arguments.Configuration;

            if (TryCreateLauncherIfSpecified(cacheConfig, out var launcher))
            {
                return(launcher);
            }

            cacheConfig.LocalCasSettings = cacheConfig.LocalCasSettings.FilterUnsupportedNamedCaches(_arguments.HostInfo.Capabilities, _logger);

            var distributedSettings = cacheConfig.DistributedContentSettings;
            var isLocal             = distributedSettings == null || !distributedSettings.IsDistributedContentEnabled;

            var serviceConfiguration = CreateServiceConfiguration(
                _logger,
                _fileSystem,
                cacheConfig.LocalCasSettings,
                distributedSettings,
                new AbsolutePath(_arguments.DataRootPath),
                isDistributed: !isLocal);
            var localServerConfiguration = CreateLocalServerConfiguration(cacheConfig.LocalCasSettings.ServiceSettings, serviceConfiguration, distributedSettings);

            // Initialization of the GrpcEnvironment is nasty business: we have a wrapper class around the internal
            // state. The internal state has a flag inside that marks whether it's been initialized or not. If we do
            // any Grpc activity, the internal state will be initialized, and all further attempts to change things
            // will throw. Since we may need to initialize a Grpc client before we do a Grpc server, this means we
            // need to call this early, even if it doesn't have anything to do with what's going on here.
            GrpcEnvironment.Initialize(_logger, localServerConfiguration.GrpcEnvironmentOptions, overwriteSafeOptions: true);

            if (isLocal)
            {
                // In practice, we don't really pass in a null distributedSettings. Hence, we'll enable the metadata
                // store whenever its set to true. This can only happen in the Application verb, because the Service
                // verb doesn't change the defaults.
                return(CreateLocalServer(localServerConfiguration, distributedSettings));
            }
            else
            {
                return(CreateDistributedServer(localServerConfiguration, distributedSettings));
            }
        }
        public void Init()
        {
            GrpcEnvironment.Initialize();

            server = new Server();
            server.AddServiceDefinition(Math.BindService(new MathServiceImpl()));
            int port = server.AddListeningPort(host, Server.PickUnusedPort);

            server.Start();
            channel = new Channel(host, port);

            // TODO(jtattermusch): get rid of the custom header here once we have dedicated tests
            // for header support.
            var stubConfig = new StubConfiguration((headerBuilder) =>
            {
                headerBuilder.Add(new Metadata.MetadataEntry("customHeader", "abcdef"));
            });

            client = Math.NewStub(channel, stubConfig);
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            var features = RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile);

            GrpcEnvironment.Initialize();

            Server server = new Server();

            server.AddServiceDefinition(RouteGuide.BindService(new RouteGuideImpl(features)));
            int port = server.AddListeningPort("localhost", 50052);

            server.Start();

            Console.WriteLine("RouteGuide server listening on port " + port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
            GrpcEnvironment.Shutdown();
        }
Beispiel #24
0
        public static void Main(string[] args)
        {
            string host = "0.0.0.0";

            GrpcEnvironment.Initialize();

            Server server = new Server();

            server.AddServiceDefinition(MathGrpc.BindService(new MathServiceImpl()));
            int port = server.AddListeningPort(host + ":23456");

            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();
        }
Beispiel #25
0
        private void Run()
        {
            GrpcEnvironment.Initialize();

            Credentials credentials = null;

            if (options.useTls)
            {
                credentials = TestCredentials.CreateTestClientCredentials(options.useTestCa);
            }

            List <ChannelOption> channelOptions = null;

            if (!string.IsNullOrEmpty(options.serverHostOverride))
            {
                channelOptions = new List <ChannelOption>
                {
                    new ChannelOption(ChannelOptions.SslTargetNameOverride, options.serverHostOverride)
                };
            }

            using (Channel channel = new Channel(options.serverHost, options.serverPort.Value, credentials, channelOptions))
            {
                var stubConfig = StubConfiguration.Default;
                if (options.testCase == "service_account_creds" || options.testCase == "compute_engine_creds")
                {
                    var credential = GoogleCredential.GetApplicationDefault();
                    if (credential.IsCreateScopedRequired)
                    {
                        credential = credential.CreateScoped(new[] { AuthScope });
                    }
                    stubConfig = new StubConfiguration(OAuth2InterceptorFactory.Create(credential));
                }

                TestService.ITestServiceClient client = new TestService.TestServiceClient(channel, stubConfig);
                RunTestCase(options.testCase, client);
            }

            GrpcEnvironment.Shutdown();
        }
Beispiel #26
0
        public static void Main(string[] args)
        {
            GrpcEnvironment.Initialize();

            using (Channel channel = new Channel("127.0.0.1", 23456))
            {
                Math.IMathClient stub = new Math.MathClient(channel);
                MathExamples.DivExample(stub);

                MathExamples.DivAsyncExample(stub).Wait();

                MathExamples.FibExample(stub).Wait();

                MathExamples.SumExample(stub).Wait();

                MathExamples.DivManyExample(stub).Wait();

                MathExamples.DependendRequestsExample(stub).Wait();
            }

            GrpcEnvironment.Shutdown();
        }
Beispiel #27
0
 public void Init()
 {
     GrpcEnvironment.Initialize();
 }
 public GrpcRepairClientTests()
     : base(() => new PassThroughFileSystem(TestGlobal.Logger), TestGlobal.Logger)
 {
     GrpcEnvironment.Initialize();
 }
Beispiel #29
0
        /// <summary>
        /// Creates a cache server.
        /// </summary>
        /// <remarks>
        /// Currently it can be one of the following:
        /// * Launcher that will download configured bits and start them.
        /// * Out-of-proc launcher that will start the current bits in a separate process.
        /// * In-proc distributed cache service.
        /// * In-proc local cache service.
        /// </remarks>
        public async Task <StartupShutdownBase> CreateAsync(OperationContext operationContext)
        {
            var cacheConfig = _arguments.Configuration;

            if (IsLauncherEnabled(cacheConfig))
            {
                _tracer.Debug(operationContext, $"Creating a launcher.");
                return(await CreateLauncherAsync(cacheConfig));
            }

            var distributedSettings = cacheConfig.DistributedContentSettings;

            if (IsOutOfProcCacheEnabled(cacheConfig))
            {
                _tracer.Debug(operationContext, $"Creating an out-of-proc cache service.");
                var outOfProcCache = await CacheServiceWrapper.CreateAsync(_arguments);

                if (outOfProcCache.Succeeded)
                {
                    return(outOfProcCache.Value);
                }

                // Tracing and falling back to the in-proc cache
                _tracer.Error(operationContext, $"Failed to create out of proc cache: {outOfProcCache}. Using in-proc cache instead.");
            }

            _tracer.Debug(operationContext, "Creating an in-proc cache service.");
            cacheConfig.LocalCasSettings = cacheConfig.LocalCasSettings.FilterUnsupportedNamedCaches(_arguments.HostInfo.Capabilities, _logger);

            var isLocal = distributedSettings == null || !distributedSettings.IsDistributedContentEnabled;

            if (distributedSettings is not null)
            {
                LogManager.Update(distributedSettings.LogManager);
            }

            var serviceConfiguration = CreateServiceConfiguration(
                _logger,
                _fileSystem,
                cacheConfig.LocalCasSettings,
                distributedSettings,
                new AbsolutePath(_arguments.DataRootPath),
                isDistributed: !isLocal);
            var localServerConfiguration = CreateLocalServerConfiguration(cacheConfig.LocalCasSettings.ServiceSettings, serviceConfiguration, distributedSettings);

            // Initialization of the GrpcEnvironment is nasty business: we have a wrapper class around the internal
            // state. The internal state has a flag inside that marks whether it's been initialized or not. If we do
            // any Grpc activity, the internal state will be initialized, and all further attempts to change things
            // will throw. Since we may need to initialize a Grpc client before we do a Grpc server, this means we
            // need to call this early, even if it doesn't have anything to do with what's going on here.
            GrpcEnvironment.Initialize(_logger, localServerConfiguration.GrpcEnvironmentOptions, overwriteSafeOptions: true);

            if (isLocal)
            {
                // In practice, we don't really pass in a null distributedSettings. Hence, we'll enable the metadata
                // store whenever its set to true. This can only happen in the Application verb, because the Service
                // verb doesn't change the defaults.
                return(CreateLocalServer(localServerConfiguration, distributedSettings));
            }
            else
            {
                return(CreateDistributedServer(localServerConfiguration, distributedSettings));
            }
        }
Beispiel #30
0
 public void InitializeAndShutdownGrpcEnvironment()
 {
     GrpcEnvironment.Initialize();
     Assert.IsNotNull(GrpcEnvironment.ThreadPool.CompletionQueue);
     GrpcEnvironment.Shutdown();
 }