private async Task MergeGrainResolverTestsImpl <T>(Type defaultPlacementStrategy, bool restartClient, Func <IGrain, Task> func, params Type[] blackListedTypes)
            where T : IGrainWithIntegerKey
        {
            SetupAndDeployCluster(defaultPlacementStrategy, blackListedTypes);

            var delayTimeout = RefreshInterval.Add(RefreshInterval);

            // Should fail
            var exception = Assert.Throws <ArgumentException>(() => this.cluster.GrainFactory.GetGrain <T>(0));

            Assert.Contains("Cannot find an implementation class for grain interface", exception.Message);

            // Start a new silo with TestGrain
            await cluster.StartAdditionalSiloAsync();

            await Task.Delay(delayTimeout);

            if (restartClient)
            {
                // Disconnect/Reconnect the client
                await cluster.Client.Close();

                cluster.Client.Dispose();
                cluster.InitializeClient();
            }
            else
            {
                await Task.Delay(ClientRefreshDelay.Multiply(3));
            }

            for (var i = 0; i < 5; i++)
            {
                // Success
                var g = this.cluster.GrainFactory.GetGrain <T>(i);
                await func(g);
            }

            // Stop the latest silos
            await cluster.StopSecondarySilosAsync();

            await Task.Delay(delayTimeout);

            if (restartClient)
            {
                // Disconnect/Reconnect the client
                await cluster.Client.Close();

                cluster.Client.Dispose();
                cluster.InitializeClient();
            }
            else
            {
                await Task.Delay(ClientRefreshDelay.Multiply(3));
            }

            // Should fail
            exception = Assert.Throws <ArgumentException>(() => this.cluster.GrainFactory.GetGrain <T>(0));
            Assert.Contains("Cannot find an implementation class for grain interface", exception.Message);
        }
        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 #3
0
        private async Task MergeGrainResolverTestsImpl(string defaultPlacementStrategy, params Type[] blackListedTypes)
        {
            SetupAndDeployCluster(defaultPlacementStrategy, blackListedTypes);

            var delayTimeout = refreshInterval.Add(refreshInterval);

            // Should fail
            var exception = Assert.Throws <ArgumentException>(() => this.cluster.GrainFactory.GetGrain <ITestGrain>(0));

            Assert.Contains("Cannot find an implementation class for grain interface", exception.Message);

            // Start a new silo with TestGrain
            cluster.StartAdditionalSilo();
            await Task.Delay(delayTimeout);

            // Disconnect/Reconnect the client
            await cluster.Client.Close();

            cluster.Client.Dispose();
            cluster.InitializeClient();

            for (var i = 0; i < 5; i++)
            {
                // Success
                var g = this.cluster.GrainFactory.GetGrain <ITestGrain>(i);
                await g.SetLabel("Hello world");
            }

            // Stop the latest silos
            cluster.StopSecondarySilos();
            await Task.Delay(delayTimeout);

            var grain            = this.cluster.GrainFactory.GetGrain <ITestGrain>(0);
            var orleansException = await Assert.ThrowsAsync <OrleansException>(() => grain.SetLabel("Hello world"));

            Assert.Contains("Cannot find an implementation class for grain interface", orleansException.Message);

            // Disconnect/Reconnect the client
            await cluster.Client.Close();

            cluster.Client.Dispose();
            cluster.InitializeClient();

            // Should fail
            exception = Assert.Throws <ArgumentException>(() => this.cluster.GrainFactory.GetGrain <ITestGrain>(0));
            Assert.Contains("Cannot find an implementation class for grain interface", exception.Message);
        }
Beispiel #4
0
        public async Task StreamProducerOnDroppedClientTest(string streamProviderName, string streamNamespace)
        {
            const int eventsProduced = 10;
            Guid      streamGuid     = Guid.NewGuid();

            await ProduceEventsFromClient(streamProviderName, streamGuid, streamNamespace, eventsProduced);

            // Hard kill client
            testHost.KillClient();

            // make sure dead client has had time to drop
            await Task.Delay(testHost.ClusterConfiguration.Globals.ClientDropTimeout + TimeSpan.FromSeconds(5));

            // initialize new client
            testHost.InitializeClient();

            // run test again.
            await ProduceEventsFromClient(streamProviderName, streamGuid, streamNamespace, eventsProduced);
        }
Beispiel #5
0
        public async Task StreamProducerOnDroppedClientTest(string streamProviderName, string streamNamespace)
        {
            const int eventsProduced = 10;
            Guid      streamGuid     = Guid.NewGuid();

            await ProduceEventsFromClient(streamProviderName, streamGuid, streamNamespace, eventsProduced);

            // Hard kill client
            await testHost.KillClientAsync();

            // make sure dead client has had time to drop
            await Task.Delay(Constants.DEFAULT_CLIENT_DROP_TIMEOUT + TimeSpan.FromSeconds(5));

            // initialize new client
            testHost.InitializeClient();

            // run test again.
            await ProduceEventsFromClient(streamProviderName, streamGuid, streamNamespace, eventsProduced);
        }
Beispiel #6
0
        public async Task StoresGrainStateWithReferencedGrainTest()
        {
            var grainId = Guid.NewGuid();
            var grain   = this.host.GrainFactory.GetGrain <ICouchBaseWithGrainReferenceStorageGrain>(grainId);

            // Request grain to reference another grain
            var referenceTag = $"Referenced by grain {grainId}";
            await grain.ReferenceOtherGrain(referenceTag);

            // Verify referenced grain values
            var retrievedReferenceTag = await grain.GetReferencedTag();

            Assert.Equal(referenceTag, retrievedReferenceTag);
            var retrievedReferencedAt = await grain.GetReferencedAt();

            Assert.NotEqual(default(DateTime), retrievedReferencedAt);

            // Write state
            await grain.Write();

            // Restart all test silos
            var silos = new[] { this.host.Primary }.Union(this.host.SecondarySilos).ToList();

            foreach (var siloHandle in silos)
            {
                this.host.RestartSilo(siloHandle);
            }

            // Re-initialize client
            host.KillClient();
            host.InitializeClient();

            // Revive persisted grain
            var grainPostRestart = this.host.GrainFactory.GetGrain <ICouchBaseWithGrainReferenceStorageGrain>(grainId);

            // Force read persisted state
            await grainPostRestart.Read();

            // Verify persisted state post restart
            var retrievedReferenceTagPostWrite = await grainPostRestart.GetReferencedTag();

            Assert.Equal(referenceTag, retrievedReferenceTagPostWrite);
            var retrievedReferencedAtPostWrite = await grainPostRestart.GetReferencedAt();

            Assert.Equal(retrievedReferencedAt, retrievedReferencedAtPostWrite);
        }
        public StreamTestClusterFixture()
        {
            GrainClient.Uninitialize();
            SerializationManager.InitializeForTesting();

            TestClusterOptions opts = new TestClusterOptions(2);

            opts.ClusterConfiguration.LoadFromFile("OrleansConfigurationForTesting.xml");
            opts.ClientConfiguration = ClientConfiguration.LoadFromFile("ClientConfigurationForTesting.xml");
            TestCluster cluster = new TestCluster(opts);

            if (cluster.Primary == null)
            {
                cluster.Deploy();
            }

            cluster.InitializeClient();
        }
Beispiel #8
0
        public ClusterFixture()
        {
            Console.WriteLine("Initializing Orleans TestCluster");

            var builder = new TestClusterBuilder(1);

            builder.Options.ServiceId = Guid.NewGuid().ToString();
            builder.Options.ClusterId = "TestCluster";
            builder.AddSiloBuilderConfigurator <SiloConfigurator>();
            builder.AddClientBuilderConfigurator <ClientConfigurator>();
            Cluster = builder.Build();

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

            var redisOptions = ConfigurationOptions.Parse("localhost:6379");
            var connection   = ConnectionMultiplexer.ConnectAsync(redisOptions).Result;

            Database = connection.GetDatabase();
            Console.WriteLine("Initialized Orleans TestCluster");
        }