public void SiloStreamConfiguratorSetsUpCreatableRedisAdapterFactory() { // Create the service collection var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(Mock.Of <ILogger>()); // Mock out the silo builder var mockSiloHostBuilder = new Mock <ISiloHostBuilder>() { DefaultValue = DefaultValue.Mock }; mockSiloHostBuilder .Setup(x => x.ConfigureServices(It.IsAny <Action <HostBuilderContext, IServiceCollection> >())) .Callback((Action <HostBuilderContext, IServiceCollection> action) => action?.Invoke(null, serviceCollection)) .Returns(mockSiloHostBuilder.Object); // Create the actual stream configurator var siloStreamConfigurator = new SiloRedisStreamConfigurator(MockStreamProviderName, x => mockSiloHostBuilder.Object.ConfigureServices(x), x => mockSiloHostBuilder.Object.ConfigureApplicationParts(x)); // Override some required dependencies so mocks work serviceCollection.AddSingleton(Mock.Of <ISerializationManager>()); siloStreamConfigurator.ConfigureRedis(options => { options.ConnectionString = ValidRedisConnectionString; }); var serviceProvider = (IServiceProvider)serviceCollection.BuildServiceProvider(); var redisAdapterFactory = RedisQueueAdapterFactory.Create(serviceProvider, MockStreamProviderName); }
/// <summary> /// Configure silo to use redis queue persistent streams. /// </summary> public static ISiloHostBuilder AddRedisStreams(this ISiloHostBuilder builder, string name, Action <SiloRedisStreamConfigurator> configure) { var configurator = new SiloRedisStreamConfigurator(name, builder); configure?.Invoke(configurator); return(builder); }
/// <summary> /// Configure silo to use redis queue persistent streams. /// </summary> public static ISiloHostBuilder AddRedisStreams(this ISiloHostBuilder builder, string name, Action <SiloRedisStreamConfigurator> configure) { var configurator = new SiloRedisStreamConfigurator( name, x => builder.ConfigureServices(x), x => builder.ConfigureApplicationParts(x)); configure?.Invoke(configurator); return(builder); }
public void SiloStreamConfiguratorThrowsOnNullRedisOptionsConnectionString() { // Create the service collection var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(Mock.Of <ILogger>()); // Mock the silo host builder var mockSiloHostBuilder = new Mock <ISiloHostBuilder>() { DefaultValue = DefaultValue.Mock }; mockSiloHostBuilder .Setup(x => x.ConfigureServices(It.IsAny <Action <HostBuilderContext, IServiceCollection> >())) .Callback((Action <HostBuilderContext, IServiceCollection> action) => action?.Invoke(null, serviceCollection)) .Returns(mockSiloHostBuilder.Object); // Create the stream configurator var siloStreamConfigurator = new SiloRedisStreamConfigurator(MockStreamProviderName, x => mockSiloHostBuilder.Object.ConfigureServices(x), x => mockSiloHostBuilder.Object.ConfigureApplicationParts(x)); // Override the normal multiplexer dependency factory serviceCollection.AddSingleton(new Mock <IConnectionMultiplexer>() { DefaultValue = DefaultValue.Mock }.Object); // Setup redis siloStreamConfigurator.ConfigureRedis(options => { options.ConnectionString = null; }); // Build the service provider var serviceProvider = (IServiceProvider)serviceCollection.BuildServiceProvider(); // Mimic the validation call ISiloHostBuilder makes var validator = serviceProvider.GetServices <IConfigurationValidator>().First(v => v.GetType() == typeof(RedisStreamOptionsValidator)); var exception = Assert.Throws <OrleansConfigurationException>(() => validator.ValidateConfiguration()); Assert.Equal($"RedisStreamOptions on stream provider {MockStreamProviderName} is invalid. ConnectionString is invalid", exception.Message); }
public void SiloStreamConfiguratorAddsConnectionMultiplexer() { // Create the service collection var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(Mock.Of <ILogger>()); // Mock the silo host builder var mockSiloHostBuilder = new Mock <ISiloHostBuilder>() { DefaultValue = DefaultValue.Mock }; mockSiloHostBuilder .Setup(x => x.ConfigureServices(It.IsAny <Action <HostBuilderContext, IServiceCollection> >())) .Callback((Action <HostBuilderContext, IServiceCollection> action) => action?.Invoke(null, serviceCollection)) .Returns(mockSiloHostBuilder.Object); // Create the stream configurator var siloStreamConfigurator = new SiloRedisStreamConfigurator(MockStreamProviderName, x => mockSiloHostBuilder.Object.ConfigureServices(x), x => mockSiloHostBuilder.Object.ConfigureApplicationParts(x)); // Override the normal multiplexer dependency factory serviceCollection.AddSingleton(new Mock <IConnectionMultiplexer>() { DefaultValue = DefaultValue.Mock }.Object); // Setup redis siloStreamConfigurator.ConfigureRedis(options => { options.ConnectionString = ValidRedisConnectionString; }); // Build the service provider var serviceProvider = (IServiceProvider)serviceCollection.BuildServiceProvider(); serviceProvider.AssertRegistered <IConnectionMultiplexer>(); }