public async void ServiceLifetimeManagerIntegrationTest(string methodName, Type messageType)
        {
            var proxy = new ServiceConnectionProxy();

            var serviceConnectionManager = new ServiceConnectionManager <TestHub>();

            serviceConnectionManager.SetServiceConnection(proxy.ServiceConnectionContainer);

            var serviceLifetimeManager = new ServiceLifetimeManager <TestHub>(serviceConnectionManager,
                                                                              proxy.ClientConnectionManager, HubProtocolResolver, Logger, Marker, _globalHubOptions, _localHubOptions);

            var serverTask = proxy.WaitForServerConnectionAsync(1);

            _ = proxy.StartAsync();
            await proxy.WaitForServerConnectionsInited().OrTimeout();

            await serverTask.OrTimeout();

            var task = proxy.WaitForApplicationMessageAsync(messageType);

            var invokeTask = InvokeMethod(serviceLifetimeManager, methodName);

            if (typeof(IAckableMessage).IsAssignableFrom(messageType))
            {
                await proxy.WriteMessageAsync(new AckMessage(1, (int)AckStatus.Ok));
            }

            // Need to return in time, or it indicate a timeout when sending ack-able messages.
            await invokeTask.OrTimeout();

            var message = await task.OrTimeout();

            VerifyServiceMessage(methodName, message);
        }
Пример #2
0
        public async void ServiceLifetimeManagerIntegrationTest(string methodName, Type messageType)
        {
            var proxy = new ServiceConnectionProxy();

            var serviceConnectionManager = new ServiceConnectionManager <TestHub>();

            serviceConnectionManager.SetServiceConnection(proxy.ServiceConnectionContainer);

            var serviceLifetimeManager = new ServiceLifetimeManager <TestHub>(serviceConnectionManager,
                                                                              proxy.ClientConnectionManager, HubProtocolResolver, Logger, Marker);

            var serverTask = proxy.WaitForServerConnectionAsync(1);

            _ = proxy.StartAsync();
            await proxy.WaitForServerConnectionsInited().OrTimeout();

            await serverTask.OrTimeout();

            var task = proxy.WaitForApplicationMessageAsync(messageType);

            await InvokeMethod(serviceLifetimeManager, methodName);

            var message = await task.OrTimeout();

            VerifyServiceMessage(methodName, message);
        }
        public async void ServiceLifetimeManagerIgnoreBlazorHubProtocolTest(string functionName, Type type)
        {
            var protocolResolver = new DefaultHubProtocolResolver(new IHubProtocol[]
            {
                new JsonHubProtocol(),
                new MessagePackHubProtocol(),
                new CustomHubProtocol(),
            },
                                                                  NullLogger <DefaultHubProtocolResolver> .Instance);
            IOptions <HubOptions> globalHubOptions = Options.Create(new HubOptions()
            {
                SupportedProtocols = new List <string>()
                {
                    "json", "messagepack", MockProtocol, "json"
                }
            });
            IOptions <HubOptions <TestHub> > localHubOptions = Options.Create(new HubOptions <TestHub>()
            {
                SupportedProtocols = new List <string>()
                {
                    "json", "messagepack", MockProtocol
                }
            });
            var serviceConnectionManager = new TestServiceConnectionManager <TestHub>();
            var serviceLifetimeManager   = new ServiceLifetimeManager <TestHub>(serviceConnectionManager,
                                                                                new ClientConnectionManager(), protocolResolver, Logger, Marker, globalHubOptions, localHubOptions);

            await InvokeMethod(serviceLifetimeManager, functionName);

            Assert.Equal(1, serviceConnectionManager.GetCallCount(type));
            VerifyServiceMessage(functionName, serviceConnectionManager.ServiceMessage);
            Assert.Equal(2, (serviceConnectionManager.ServiceMessage as MulticastDataMessage).Payloads.Count);
        }
            public void Start(OperationContext context)
            {
                HasStarted = true;

                runAsync().Forget();

                async Task runAsync()
                {
                    int exitCode = await ServiceLifetimeManager.RunDeployedInterruptableServiceAsync(context, async token =>
                    {
                        try
                        {
                            IsRunningService = true;
                            using var reg    = token.Register(() =>
                            {
                                ExitSignal.SetResult(GracefulShutdownExitCode);
                            });
                            return(await ExitSignal.Task);
                        }
                        finally
                        {
                            IsRunningService = false;
                        }
                    },
                                                                                                     getEnvironmentVariable : name => StartInfo.EnvironmentVariables[name]);

                    Exit(exitCode);
                }
            }
Пример #5
0
        public async void ServiceLifetimeManagerGroupTest(string functionName, Type type)
        {
            var serviceConnectionManager = new TestServiceConnectionManager <TestHub>();
            var serviceLifetimeManager   = new ServiceLifetimeManager <TestHub>(serviceConnectionManager,
                                                                                new ClientConnectionManager(), HubProtocolResolver, Logger, Marker);

            await InvokeMethod(serviceLifetimeManager, functionName);

            Assert.Equal(1, serviceConnectionManager.GetPartitionedCallCount(type));
            VerifyServiceMessage(functionName, serviceConnectionManager.ServiceMessage);
        }
        public async void ServiceLifetimeManagerTest(string functionName, Type type)
        {
            var serviceConnectionManager = new TestServiceConnectionManager <TestHub>();
            var serviceLifetimeManager   = new ServiceLifetimeManager <TestHub>(serviceConnectionManager,
                                                                                new ClientConnectionManager(), HubProtocolResolver, Logger, Marker, _globalHubOptions, _localHubOptions);

            await InvokeMethod(serviceLifetimeManager, functionName);

            Assert.Equal(1, serviceConnectionManager.GetCallCount(type));
            VerifyServiceMessage(functionName, serviceConnectionManager.ServiceMessage);
            Assert.Equal(2, (serviceConnectionManager.ServiceMessage as MulticastDataMessage).Payloads.Count);
        }
Пример #7
0
        /// <summary>
        /// Run the cache service verb.
        ///
        /// NOTE: Currently, this is highly reliant on being launched by the launcher.
        /// TODO: Add command line args with HostParameters and ServiceLifetime args so that
        /// this can be used standalone.
        /// </summary>
        public static async Task RunCacheServiceAsync(
            OperationContext context,
            string configurationPath,
            Func <HostParameters, DistributedCacheServiceConfiguration, CancellationToken, IDistributedCacheServiceHost> createHost,
            HostParameters hostParameters    = null,
            bool requireServiceInterruptable = true)
        {
            try
            {
                hostParameters ??= HostParameters.FromEnvironment();

                using var cancellableContext = new CancellableOperationContext(context, default(CancellationToken));
                context = cancellableContext;

                var config = LoadAndWatchPreprocessedConfig <DistributedCacheServiceConfiguration, DistributedCacheServiceConfiguration>(
                    context,
                    configurationPath,
                    hostParameters,
                    out var configHash,
                    c => c);

                await ServiceLifetimeManager.RunDeployedInterruptableServiceAsync(context, async token =>
                {
                    var hostInfo = new HostInfo(hostParameters.Stamp, hostParameters.Ring, new List <string>());

                    var host = createHost(hostParameters, config, token);

                    await DistributedCacheServiceFacade.RunWithConfigurationAsync(
                        logger: context.TracingContext.Logger,
                        host: host,
                        hostInfo: hostInfo,
                        telemetryFieldsProvider: new HostTelemetryFieldsProvider(hostParameters)
                    {
                        ConfigurationId = configHash
                    },
                        config,
                        token: token);;

                    return(BoolResult.Success);
                },
                                                                                  requireServiceInterruptionEnabled : requireServiceInterruptable).ThrowIfFailure();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public async void ServiceLifetimeManagerGroupTest(string functionName, Type type)
        {
            var serviceConnectionManager = new TestServiceConnectionManager <TestHub>();
            var blazorDetector           = new DefaultBlazorDetector();
            var serviceLifetimeManager   = new ServiceLifetimeManager <TestHub>(
                serviceConnectionManager,
                new ClientConnectionManager(),
                HubProtocolResolver,
                Logger,
                Marker,
                _globalHubOptions,
                _localHubOptions,
                blazorDetector);

            await InvokeMethod(serviceLifetimeManager, functionName);

            Assert.Equal(1, serviceConnectionManager.GetCallCount(type));
            VerifyServiceMessage(functionName, serviceConnectionManager.ServiceMessage);
            Assert.False(blazorDetector.IsBlazor(nameof(TestHub)));
        }
Пример #9
0
        public static async Task <Result <CacheServiceWrapper> > CreateAsync(DistributedCacheServiceArguments configuration)
        {
            // Validating the cache configuration

            var wrapperConfiguration = tryCreateConfiguration(configuration);

            if (!wrapperConfiguration.Succeeded)
            {
                const string BaseError = "Can't start cache service as a separate process because";
                return(Result.FromErrorMessage <CacheServiceWrapper>($"{BaseError} {wrapperConfiguration.ErrorMessage}"));
            }

            // Obtaining the secrets and creating a wrapper.
            var serviceLifetimeManager = new ServiceLifetimeManager(wrapperConfiguration.Value.WorkingDirectory, wrapperConfiguration.Value.ServiceLifetimePollingInterval);
            var secretsRetriever       = new DistributedCacheSecretRetriever(configuration);

            var secrets = await secretsRetriever.TryRetrieveSecretsAsync();

            if (!secrets.Succeeded)
            {
                return(new Result <CacheServiceWrapper>(secrets));
            }

            return(Result.Success(new CacheServiceWrapper(wrapperConfiguration.Value, serviceLifetimeManager, secrets.Value)));
Пример #10
0
 public CacheServiceWrapper(CacheServiceWrapperConfiguration configuration, ServiceLifetimeManager serviceLifetimeManager, RetrievedSecrets secrets)
 {
     _configuration          = configuration;
     _serviceLifetimeManager = serviceLifetimeManager;
     _secrets = secrets;
 }
Пример #11
0
 public LauncherManagedProcess(ILauncherProcess process, string serviceId, ServiceLifetimeManager lifetimeManager)
 {
     _process         = process;
     _lifetimeManager = lifetimeManager;
     ServiceId        = serviceId;
 }