Exemplo n.º 1
0
        public async Task ConnectIsRetryableTest()
        {
            var gwEndpoint = this.HostedCluster.Client.Configuration().Gateways.First();

            // Create a client with no gateway endpoint and then add a gateway endpoint when the client fails to connect.
            var gatewayProvider = new MockGatewayListProvider();
            var client          = new ClientBuilder()
                                  .Configure <ClusterOptions>(options =>
            {
                var existingClientOptions = this.HostedCluster.ServiceProvider.GetRequiredService <IOptions <ClusterOptions> >().Value;
                options.ClusterId         = existingClientOptions.ClusterId;
                options.ServiceId         = existingClientOptions.ServiceId;
            })
                                  .ConfigureServices(services => services.AddSingleton <IGatewayListProvider>(gatewayProvider))
                                  .Build();
            var exceptions = new List <Exception>();

            Task <bool> RetryFunc(Exception exception)
            {
                Assert.IsType <OrleansException>(exception);
                exceptions.Add(exception);
                gatewayProvider.Gateways = new List <Uri> {
                    gwEndpoint.ToGatewayUri()
                }.AsReadOnly();
                return(Task.FromResult(true));
            }

            await client.Connect(RetryFunc);

            Assert.Single(exceptions);
        }
Exemplo n.º 2
0
        public async Task ConnectIsRetryableTest()
        {
            var gateways = await this.HostedCluster.Client.ServiceProvider.GetRequiredService <IGatewayListProvider>().GetGateways();

            var gwEndpoint = gateways.First();

            // Create a client with no gateway endpoint and then add a gateway endpoint when the client fails to connect.
            var gatewayProvider = new MockGatewayListProvider();
            var exceptions      = new List <Exception>();

            Task <bool> RetryFunc(Exception exception, CancellationToken cancellationToken)
            {
                Assert.IsType <SiloUnavailableException>(exception);
                exceptions.Add(exception);
                gatewayProvider.Gateways = new List <Uri> {
                    gwEndpoint
                }.AsReadOnly();
                return(Task.FromResult(true));
            }

            using var host = new HostBuilder().UseOrleansClient(clientBuilder =>
            {
                clientBuilder
                .Configure <ClusterOptions>(options =>
                {
                    var existingClientOptions = this.HostedCluster.ServiceProvider
                                                .GetRequiredService <IOptions <ClusterOptions> >().Value;
                    options.ClusterId = existingClientOptions.ClusterId;
                    options.ServiceId = existingClientOptions.ServiceId;
                })
                .ConfigureServices(services => services.AddSingleton <IGatewayListProvider>(gatewayProvider))
                .UseConnectionRetryFilter(RetryFunc);
            })
                             .Build();

            var client = host.Services.GetRequiredService <IClusterClient>();

            await host.StartAsync();

            Assert.Single(exceptions);
            await host.StopAsync();
        }