Example #1
0
        public void Exposes_ClusterClient()
        {
            // arrange
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new Dictionary <string, string>
            {
                { "Orleans:Ports:Silo:Start", "11111" },
                { "Orleans:Ports:Silo:End", "11111" },
                { "Orleans:Ports:Gateway:Start", "22222" },
                { "Orleans:Ports:Gateway:End", "22222" },
                { "Orleans:ClusterId", "SomeClusterId" },
                { "Orleans:ServiceId", "SomeServiceId" },
                { "Orleans:Providers:Clustering:Provider", "Localhost" }
            })
                         .Build();

            // act
            var service = new SiloHostedService(
                config,
                Mock.Of <ILoggerProvider>(_ => _.CreateLogger(It.IsAny <string>()) == Mock.Of <ILogger>()),
                Mock.Of <INetworkPortFinder>(_ =>
                                             _.GetAvailablePortFrom(11111, 11111) == 11111 &&
                                             _.GetAvailablePortFrom(22222, 22222) == 22222),
                Mock.Of <IHostingEnvironment>());

            // assert
            Assert.NotNull(service.ClusterClient);
        }
Example #2
0
        public void Has_Endpoints()
        {
            // arrange
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new Dictionary <string, string>
            {
                { "Orleans:Ports:Silo:Start", "11111" },
                { "Orleans:Ports:Silo:End", "11111" },
                { "Orleans:Ports:Gateway:Start", "22222" },
                { "Orleans:Ports:Gateway:End", "22222" },
                { "Orleans:ClusterId", "SomeClusterId" },
                { "Orleans:ServiceId", "SomeServiceId" },
                { "Orleans:Providers:Clustering:Provider", "Localhost" }
            })
                         .Build();

            // act
            var service = new SiloHostedService(
                config,
                Mock.Of <ILoggerProvider>(_ => _.CreateLogger(It.IsAny <string>()) == Mock.Of <ILogger>()),
                Mock.Of <INetworkPortFinder>(_ =>
                                             _.GetAvailablePortFrom(11111, 11111) == 11111 &&
                                             _.GetAvailablePortFrom(22222, 22222) == 22222),
                Mock.Of <IHostingEnvironment>());

            // white box
            var host = service.GetType().GetField("_host", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(service) as ISiloHost;

            // assert the endpoints are there
            var actual = host.Services.GetService <IOptions <EndpointOptions> >();

            Assert.NotNull(actual);
            Assert.Equal(11111, actual.Value.SiloPort);
            Assert.Equal(22222, actual.Value.GatewayPort);
        }
Example #3
0
        public void Has_SimpleMessageStreamProvider()
        {
            // arrange
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new Dictionary <string, string>
            {
                { "Orleans:Ports:Silo:Start", "11111" },
                { "Orleans:Ports:Silo:End", "11111" },
                { "Orleans:Ports:Gateway:Start", "22222" },
                { "Orleans:Ports:Gateway:End", "22222" },
                { "Orleans:ClusterId", "SomeClusterId" },
                { "Orleans:ServiceId", "SomeServiceId" },
                { "Orleans:Providers:Clustering:Provider", "Localhost" }
            })
                         .Build();

            // act
            var service = new SiloHostedService(
                config,
                Mock.Of <ILoggerProvider>(_ => _.CreateLogger(It.IsAny <string>()) == Mock.Of <ILogger>()),
                Mock.Of <INetworkPortFinder>(_ =>
                                             _.GetAvailablePortFrom(11111, 11111) == 11111 &&
                                             _.GetAvailablePortFrom(22222, 22222) == 22222),
                Mock.Of <IHostingEnvironment>());

            // white box
            var host = service.GetType().GetField("_host", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(service) as ISiloHost;

            // assert the stream provider is there
            var actual = host.Services.GetServices <IKeyedService <string, IStreamProvider> >().SingleOrDefault(_ => _.Key == "SMS");

            Assert.NotNull(actual);
            Assert.IsType <SimpleMessageStreamProvider>(actual.GetService(host.Services));
        }
Example #4
0
        public void Has_SiloHost()
        {
            // arrange
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new Dictionary <string, string>
            {
                { "Orleans:Ports:Silo:Start", "11111" },
                { "Orleans:Ports:Silo:End", "11111" },
                { "Orleans:ClusterId", "SomeClusterId" },
                { "Orleans:ServiceId", "SomeServiceId" },
                { "Orleans:Providers:Clustering:Provider", "Localhost" }
            })
                         .Build();

            // act
            var service = new SiloHostedService(
                config,
                Mock.Of <ILoggerProvider>(_ => _.CreateLogger(It.IsAny <string>()) == Mock.Of <ILogger>()),
                Mock.Of <INetworkPortFinder>(_ => _.GetAvailablePortFrom(It.IsAny <int>(), It.IsAny <int>()) == 11111),
                Mock.Of <IHostingEnvironment>());

            // assert - white box
            var host = service.GetType().GetField("_host", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(service) as ISiloHost;

            Assert.NotNull(host);
        }
Example #5
0
        public void Has_ClusterMembershipOptions_And_ValidateInitialConnectivity_On_Development()
        {
            // arrange
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new Dictionary <string, string>
            {
                { "Orleans:Ports:Silo:Start", "11111" },
                { "Orleans:Ports:Silo:End", "11111" },
                { "Orleans:Ports:Gateway:Start", "22222" },
                { "Orleans:Ports:Gateway:End", "22222" },
                { "Orleans:ClusterId", "SomeClusterId" },
                { "Orleans:ServiceId", "SomeServiceId" },
                { "Orleans:Providers:Clustering:Provider", "Localhost" }
            })
                         .Build();

            // act
            var service = new SiloHostedService(
                config,
                Mock.Of <ILoggerProvider>(_ => _.CreateLogger(It.IsAny <string>()) == Mock.Of <ILogger>()),
                Mock.Of <INetworkPortFinder>(_ =>
                                             _.GetAvailablePortFrom(11111, 11111) == 11111 &&
                                             _.GetAvailablePortFrom(22222, 22222) == 22222),
                Mock.Of <IHostingEnvironment>(_ => _.EnvironmentName == EnvironmentName.Development));

            // white box
            var host = service.GetType().GetField("_host", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(service) as ISiloHost;

            // assert the cluster membership options are there
            var actual = host.Services.GetService <IOptions <ClusterMembershipOptions> >();

            Assert.NotNull(actual);
            Assert.False(actual.Value.ValidateInitialConnectivity);
        }
Example #6
0
        public void Has_AdoNetGrainStorageOptions_As_Default()
        {
            // arrange
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new Dictionary <string, string>
            {
                { "Orleans:Ports:Silo:Start", "11111" },
                { "Orleans:Ports:Silo:End", "11111" },
                { "Orleans:Ports:Gateway:Start", "22222" },
                { "Orleans:Ports:Gateway:End", "22222" },
                { "Orleans:ClusterId", "SomeClusterId" },
                { "Orleans:ServiceId", "SomeServiceId" },
                { "Orleans:Providers:Clustering:Provider", "Localhost" },
                { "Orleans:Providers:Storage:Default:Provider", "AdoNet" },
                { "Orleans:Providers:Storage:Default:AdoNet:ConnectionStringName", "SomeConnectionStringName" },
                { "Orleans:Providers:Storage:Default:AdoNet:Invariant", "SomeInvariant" },
                { "Orleans:Providers:Storage:Default:AdoNet:UseJsonFormat", "true" },
                { "Orleans:Providers:Storage:Default:AdoNet:TypeNameHandling", "None" },
                { "ConnectionStrings:SomeConnectionStringName", "SomeConnectionString" },
            })
                         .Build();

            // act
            var service = new SiloHostedService(
                config,
                Mock.Of <ILoggerProvider>(_ => _.CreateLogger(It.IsAny <string>()) == Mock.Of <ILogger>()),
                Mock.Of <INetworkPortFinder>(_ =>
                                             _.GetAvailablePortFrom(11111, 11111) == 11111 &&
                                             _.GetAvailablePortFrom(22222, 22222) == 22222),
                Mock.Of <IHostingEnvironment>());

            // white box
            var host = service.GetType().GetField("_host", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(service) as ISiloHost;

            // assert the grain storage options are there
            var actual = host.Services.GetService <IOptionsSnapshot <AdoNetGrainStorageOptions> >().Get(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME);

            Assert.Equal("SomeConnectionString", actual.ConnectionString);
            Assert.Equal("SomeInvariant", actual.Invariant);
            Assert.True(actual.UseJsonFormat);
            Assert.Equal(TypeNameHandling.None, actual.TypeNameHandling);
        }
Example #7
0
        public void Has_DirectClient()
        {
            // arrange
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new Dictionary <string, string>
            {
                { "Orleans:Ports:Silo:Start", "11111" },
                { "Orleans:Ports:Silo:End", "11111" },
                { "Orleans:Ports:Gateway:Start", "22222" },
                { "Orleans:Ports:Gateway:End", "22222" },
                { "Orleans:ClusterId", "SomeClusterId" },
                { "Orleans:ServiceId", "SomeServiceId" },
                { "Orleans:Providers:Clustering:Provider", "Localhost" }
            })
                         .Build();

            // act
            var service = new SiloHostedService(
                config,
                Mock.Of <ILoggerProvider>(_ => _.CreateLogger(It.IsAny <string>()) == Mock.Of <ILogger>()),
                Mock.Of <INetworkPortFinder>(_ =>
                                             _.GetAvailablePortFrom(11111, 11111) == 11111 &&
                                             _.GetAvailablePortFrom(22222, 22222) == 22222),
                Mock.Of <IHostingEnvironment>());

            // white box
            var host = service.GetType().GetField("_host", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(service) as ISiloHost;

            // assert the cluster client is there
            var client = host.Services.GetService <IClusterClient>();

            Assert.NotNull(client);

            // assert the grain factory is there
            var factory = host.Services.GetService <IGrainFactory>();

            Assert.NotNull(factory);
        }