Beispiel #1
0
        public void BenchmarkSetup()
        {
            var builder = new TestClusterBuilder(1);

            _host = builder.Build();
            _host.Deploy();
        }
Beispiel #2
0
        public Task InitializeAsync()
        {
            Cluster = _builder.Build();
            Cluster.Deploy();

            return(Task.CompletedTask);
        }
Beispiel #3
0
        public async Task TlsBasicEndToEnd()
        {
            TestCluster testCluster = default;

            try
            {
                var builder = new TestClusterBuilder()
                              .AddSiloBuilderConfigurator <TlsConfigurator>()
                              .AddClientBuilderConfigurator <TlsConfigurator>();

                var certificate = TestCertificateHelper.CreateSelfSignedCertificate(
                    CertificateSubjectName,
                    new[] { TestCertificateHelper.ClientAuthenticationOid, TestCertificateHelper.ServerAuthenticationOid });
                var encodedCertificate = TestCertificateHelper.ConvertToBase64(certificate);
                builder.Properties[CertificateConfigKey] = encodedCertificate;

                testCluster = builder.Build();
                await testCluster.DeployAsync();

                var client = testCluster.Client;

                var grain    = client.GetGrain <IPingGrain>("pingu");
                var expected = "secret chit chat";
                var actual   = await grain.Echo(expected);

                Assert.Equal(expected, actual);
            }
            finally
            {
                await testCluster?.StopAllSilosAsync();

                testCluster?.Dispose();
            }
        }
Beispiel #4
0
        protected BaseTestClusterFixture()
        {
            try
            {
                CheckPreconditionsOrThrow();
            }
            catch (Exception ex)
            {
                this.preconditionsException = ExceptionDispatchInfo.Capture(ex);
                return;
            }

            var builder = new TestClusterBuilder();

            TestDefaultConfiguration.ConfigureTestCluster(builder);
            builder.ConfigureLegacyConfiguration();
            ConfigureTestCluster(builder);

            var testCluster = builder.Build();

            if (testCluster?.Primary == null)
            {
                testCluster?.Deploy();
            }
            this.HostedCluster = testCluster;
            this.Logger        = this.Client?.ServiceProvider.GetRequiredService <ILoggerFactory>().CreateLogger("Application");
        }
Beispiel #5
0
        public ClusterFixture()
        {
            var builder = new TestClusterBuilder();

            this.Cluster = builder.Build();
            this.Cluster.Deploy();
        }
        public async Task Test1()
        {
            var valuesToAdd = new[] { 1, 2, 3, 4, 5, 6 };


            var anticipatedResult = new DistributedState()
            {
                val = valuesToAdd.Sum()
            };

            var builder = new TestClusterBuilder();

            builder.Options.ServiceId = Guid.NewGuid().ToString();
            var cluster = builder.Build();

            cluster.Deploy();

            var distributedType = cluster.GrainFactory
                                  .GetGrain <ITestDistributedType>(Guid.NewGuid());

            valuesToAdd.Map(v => new AddValue(v)).ToList().ForEach(async m => await distributedType.Handle(m));

            cluster.StopAllSilos();

            Result <DistributedState> result = await distributedType.Get();

            // Assert
            result.Should().NotBeNull();

            var _ = result switch
            {
                { IsSuccess : true } => result.IfSucc((resultOfHandleOp) =>
Beispiel #7
0
        public ClusterFixture()
        {
            // prepare to receive the fake services from individual silos
            GrainStorageGroups[TestClusterId]  = new ConcurrentBag <FakeGrainStorage>();
            TimerRegistryGroups[TestClusterId] = new ConcurrentBag <FakeTimerRegistry>();

            var builder = new TestClusterBuilder();

            // add the cluster id for this instance
            // this allows the silos to safely lookup shared data for this cluster deployment
            // without this we can only share data via static properties and that messes up parallel testing
            builder.ConfigureHostConfiguration(config =>
            {
                config.AddInMemoryCollection(new Dictionary <string, string>()
                {
                    { nameof(TestClusterId), TestClusterId }
                });
            });

            // a configurator allows the silos to configure themselves
            // at this time, configurators cannot take injected parameters
            // therefore we must other means of sharing objects as you can see above
            builder.AddSiloBuilderConfigurator <SiloBuilderConfigurator>();

            Cluster = builder.Build();
            Cluster.Deploy();
        }
        private async Task <SiloHandle> StartSilo(DirectoryInfo rootDir)
        {
            SiloHandle silo;

            if (this.siloIdx == 0)
            {
                // Setup configuration
                this.builder = new TestClusterBuilder(1)
                {
                    CreateSilo = AppDomainSiloHandle.Create
                };
                TestDefaultConfiguration.ConfigureTestCluster(this.builder);
                builder.Options.ApplicationBaseDirectory = rootDir.FullName;
                builder.AddSiloBuilderConfigurator <VersionGrainsSiloBuilderConfigurator>();
                builder.ConfigureLegacyConfiguration(legacy =>
                {
                    legacy.ClusterConfiguration.Globals.ExpectedClusterSize             = SiloCount;
                    legacy.ClusterConfiguration.Globals.AssumeHomogenousSilosForTesting = false;
                    legacy.ClusterConfiguration.Globals.TypeMapRefreshInterval          = refreshInterval;
                    legacy.ClusterConfiguration.Globals.DefaultVersionSelectorStrategy  = VersionSelectorStrategy;
                    legacy.ClusterConfiguration.Globals.DefaultCompatibilityStrategy    = CompatibilityStrategy;

                    legacy.ClientConfiguration.Gateways = legacy.ClientConfiguration.Gateways.Take(1).ToList(); // Only use primary gw

                    waitDelay = TestClusterLegacyUtils.GetLivenessStabilizationTime(legacy.ClusterConfiguration.Globals, false);
                });

                this.cluster = builder.Build();
                await this.cluster.DeployAsync();

                silo = this.cluster.Primary;
            }
            else
            {
                var configBuilder = new ConfigurationBuilder();
                foreach (var source in cluster.ConfigurationSources)
                {
                    configBuilder.Add(source);
                }
                var testClusterOptions = new TestClusterOptions();
                configBuilder.Build().Bind(testClusterOptions);

                // Override the root directory.
                var sources = new IConfigurationSource[]
                {
                    new MemoryConfigurationSource {
                        InitialData = new TestClusterOptions {
                            ApplicationBaseDirectory = rootDir.FullName
                        }.ToDictionary()
                    }
                };

                silo = TestCluster.StartOrleansSilo(cluster, siloIdx, testClusterOptions, sources);
            }

            this.deployedSilos.Add(silo);
            this.siloIdx++;

            return(silo);
        }
        public ClusterFixture()
        {
            _redis = new RedisInside.Redis();
            Console.WriteLine(_redis.Endpoint.ToString());

            Console.WriteLine("Initializing Orleans TestCluster");
            var builder = new TestClusterBuilder(1);

            builder.Options.ServiceId = "Service";
            builder.Options.ClusterId = "TestCluster";
            builder.AddSiloBuilderConfigurator <SiloConfigurator>();
            builder.AddClientBuilderConfigurator <ClientConfigurator>();

            //this is one of the only ways to be able to pass data (the redis connection string) to the silo(s) that TestCluster will startup
            builder.ConfigureHostConfiguration(config =>
            {
                config.AddInMemoryCollection(new Dictionary <string, string>()
                {
                    { nameof(RedisInside.Redis), _redis.Endpoint.ToString() }
                });
            });

            Cluster = builder.Build();

            Cluster.Deploy();
            Cluster.InitializeClient();
            Client = Cluster.Client;

            var redisOptions = ConfigurationOptions.Parse(_redis.Endpoint.ToString());
            var connection   = ConnectionMultiplexer.ConnectAsync(redisOptions).Result;

            Database = connection.GetDatabase();
            Console.WriteLine("Initialized Orleans TestCluster");
        }
Beispiel #10
0
        public async Task DoAccountingCorrectly()
        {
            NekaraClient client = RuntimeEnvironment.Client;

            client.InitSessionDir();
            var _t3 = RuntimeEnvironment.Client.Api;

            _t3.CreateTask();



            var _t1     = new TestClusterBuilder();
            var cluster = _t1.Build();

            cluster.Deploy();

            Guid acc1 = Guid.NewGuid();

            _ = Task.WhenAll(
                cluster.GrainFactory.GetGrain <IAccountGrain11>(acc1).Withdraw(200),
                cluster.GrainFactory.GetGrain <IAccountGrain11>(acc1).Deposit(100));

            uint fromBalance = await cluster.GrainFactory.GetGrain <IAccountGrain11>(acc1).GetBalance();

            cluster.StopAllSilos();

            Assert.Equal(900u, fromBalance);
        }
Beispiel #11
0
        public void Setup()
        {
            var builder = new TestClusterBuilder();

            builder.AddSiloBuilderConfigurator <TestSiloConfigurations>();
            this._cluster = builder.Build();
        }
Beispiel #12
0
        public ClusterFixture()
        {
            var builder = new TestClusterBuilder();

            builder.AddSiloBuilderConfigurator <TestSiloConfigurations>();
            this.Cluster = builder.Build();
            this.Cluster.Deploy();
            var memorySQLiteConnection = new SqliteConnection("Data Source=EFCoreInMemory;Mode=Memory;Cache=Shared");

            memorySQLiteConnection.Open();
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton(memorySQLiteConnection);
            serviceCollection.AddVertex();
            serviceCollection.AddLogging();
            serviceCollection.AddEntityFrameworkSqlite()
            .AddDbContext <TestDbContext>(
                options => { options.UseSqlite(memorySQLiteConnection); },
                ServiceLifetime.Transient);
            this.Provider = serviceCollection.BuildServiceProvider();
            using (var db = this.Provider.GetService <TestDbContext>())
            {
                db.Database.EnsureCreated();
                db.Database.Migrate();
            }
        }
        public ClusterFixture()
        {
            TestClusterBuilder builder = new TestClusterBuilder(1);

            builder.Options.ServiceId = "Service";
            builder.Options.ClusterId = "TestCluster";
            builder.AddSiloBuilderConfigurator <SiloConfigurator>();

            string redisHost             = Environment.GetEnvironmentVariable("REDIS_HOST") ?? "127.0.0.1";
            string redisPort             = Environment.GetEnvironmentVariable("REDIS_PORT") ?? "6379";
            string redisConnectionString = $"{redisHost}:{redisPort}, allowAdmin=true";

            builder.ConfigureHostConfiguration(config =>
            {
                config.AddInMemoryCollection(new Dictionary <string, string>()
                {
                    { "RedisConnectionString", redisConnectionString }
                });
            });

            Cluster = builder.Build();

            Cluster.Deploy();
            Cluster.InitializeClient();
            Client = Cluster.Client;

            ConfigurationOptions redisOptions = ConfigurationOptions.Parse(redisConnectionString);

            _redis   = ConnectionMultiplexer.ConnectAsync(redisOptions).Result;
            Database = _redis.GetDatabase();
        }
Beispiel #14
0
        public ClusterFixture()
        {
            var builder = new TestClusterBuilder();

            builder.AddSiloBuilderConfigurator <TestSiloConfigurations>();
            Cluster = builder.Build();
            Cluster.Deploy();
        }
Beispiel #15
0
        public TestClusterFixture()
        {
            var builder = new TestClusterBuilder();

            builder.AddClientBuilderConfigurator <TestClientBuilderConfigurator>();
            Cluster = builder.Build();
            Cluster.Deploy();
        }
Beispiel #16
0
        public void AzureBlobSetup()
        {
            var builder = new TestClusterBuilder();

            builder.AddSiloBuilderConfigurator <SiloAzureBlobStorageConfigurator>();
            this.host = builder.Build();
            this.host.Deploy();
        }
Beispiel #17
0
        public void OneTImeSetup()
        {
            var builder = new TestClusterBuilder();

            builder.AddSiloBuilderConfigurator <TestSiloConfigurations>();
            Cluster = builder.Build();
            Cluster.Deploy();
        }
Beispiel #18
0
        public TestCluster CreateTestCluster()
        {
            var builder = new TestClusterBuilder();

            builder.AddClientBuilderConfigurator <TestClientBuilderConfigurator>();
            builder.AddSiloBuilderConfigurator <TestSiloBuilderConfigurator>();
            return(builder.Build());
        }
        public CartGrainTest()
        {
            var builder = new TestClusterBuilder();

            builder.AddSiloBuilderConfigurator <ClusterConfigurator>();
            _cluster = builder.Build();
            _cluster.Deploy();
        }
Beispiel #20
0
    public TestClusterFixture()
    {
        var builder = new TestClusterBuilder();

        builder.AddSiloBuilderConfigurator <SiloMemoryStorageConfigurator>();
        this.Cluster = builder.Build();
        this.Cluster.Deploy();
    }
        public ClusterFixture()
        {
            var builder = new TestClusterBuilder();

            builder.Options.ServiceId = Guid.NewGuid().ToString();
            Cluster = builder.Build();
            Cluster.Deploy();
        }
Beispiel #22
0
        public ClusterFixture()
        {
            var builder = new TestClusterBuilder();

            builder.AddSiloBuilderConfigurator <MySiloBuilderConfigurator>();
            this.Cluster = builder.Build();
            this.Cluster.Deploy();
        }
        private void CreateAndDeployTestCluster()
        {
            var builder = new TestClusterBuilder(3);

            builder.AddSiloBuilderConfigurator <SiloConfigurator>();
            builder.AddClientBuilderConfigurator <ClientConfigurator>();
            this.hostedCluster = builder.Build();
            this.hostedCluster.Deploy();
        }
        public void MemorySetup()
        {
            var builder = new TestClusterBuilder(4);

            builder.AddSiloBuilderConfigurator <SiloMemoryStorageConfigurator>();
            builder.AddSiloBuilderConfigurator <SiloTransactionConfigurator>();
            this.host = builder.Build();
            this.host.Deploy();
        }
        public ClusterFixture()
        {
            var builder = new TestClusterBuilder(1);

            builder.AddSiloBuilderConfigurator <SiloConfigurations>();
            builder.AddClientBuilderConfigurator <ClientConfigurations>();

            Cluster = builder.Build();
        }
        public static TestCluster BuildTestCluster()
        {
            var builder = new TestClusterBuilder(3);

            builder.Options.ServiceId = Guid.NewGuid().ToString();
            builder.AddSiloBuilderConfigurator <SampleSiloBuilderConfigurator>();
            builder.AddClientBuilderConfigurator <SampleClientBuilderConfigurator>();
            return(builder.Build());
        }
        public void AzureThrottledSetup()
        {
            var builder = new TestClusterBuilder(4);

            builder.AddSiloBuilderConfigurator <SiloAzureStorageConfigurator>();
            builder.AddSiloBuilderConfigurator <SiloTransactionConfigurator>();
            builder.AddSiloBuilderConfigurator <SiloTransactionThrottlingConfigurator>();
            this.host = builder.Build();
            this.host.Deploy();
        }
Beispiel #28
0
        private void InitializeOrleans()
        {
            var builder = new TestClusterBuilder();

            SiloBuilder.LoggerProvider = new WpfLogProvider(ClusterLogViewer);
            builder.AddSiloBuilderConfigurator <SiloBuilder>();

            Cluster = builder.Build();
            Cluster.Deploy();
        }
        public async Task CanInitialize()
        {
            var builder = new TestClusterBuilder(2);

            builder.Options.ServiceId = Guid.NewGuid().ToString();
            builder.ConfigureHostConfiguration(TestDefaultConfiguration.ConfigureHostConfiguration);
            var testCluster = builder.Build();

            await testCluster.DeployAsync();
        }
Beispiel #30
0
        public OrleansFixture(/*ITestOutputHelper outputHelper*/)
        {
            var builder = new TestClusterBuilder();

            //TestSiloConfigurator.OutputHelper = outputHelper;
            builder.AddSiloBuilderConfigurator <TestSiloConfigurator>();

            Cluster = builder.Build();
            Cluster.Deploy();
        }