protected async Task Grain_GuidKey_AWSStore_Read_Write()
        {
            Guid id = Guid.NewGuid();
            IAWSStorageTestGrain grain = this.fixture.GrainFactory.GetGrain <IAWSStorageTestGrain>(id);

            int val = await grain.GetValue();

            Assert.Equal(0, val);  // "Initial value"

            await grain.DoWrite(1);

            val = await grain.GetValue();

            Assert.Equal(1, val);  // "Value after Write-1"

            await grain.DoWrite(2);

            val = await grain.GetValue();

            Assert.Equal(2, val);  // "Value after Write-2"

            val = await grain.DoRead();

            Assert.Equal(2, val);  // "Value after Re-Read"
        }
        protected async Task Grain_AWSStore_Read()
        {
            Guid id = Guid.NewGuid();
            IAWSStorageTestGrain grain = this.fixture.GrainFactory.GetGrain <IAWSStorageTestGrain>(id);

            int val = await grain.GetValue();

            Assert.Equal(0, val);  // "Initial value"
        }
        protected async Task Grain_AWSStore_SiloRestart()
        {
            var initialServiceId    = this.HostedCluster.Options.ServiceId;
            var initialDeploymentId = this.HostedCluster.Options.ClusterId;
            var serviceId           = await this.HostedCluster.Client.GetGrain <IServiceIdGrain>(Guid.Empty).GetServiceId();

            output.WriteLine("ClusterId={0} ServiceId={1}", this.HostedCluster.Options.ClusterId, serviceId);

            Guid id = Guid.NewGuid();
            IAWSStorageTestGrain grain = this.fixture.GrainFactory.GetGrain <IAWSStorageTestGrain>(id);

            int val = await grain.GetValue();

            Assert.Equal(0, val);  // "Initial value"

            await grain.DoWrite(1);

            output.WriteLine("About to reset Silos");
            foreach (var silo in this.HostedCluster.GetActiveSilos().ToList())
            {
                await this.HostedCluster.RestartSiloAsync(silo);
            }
            await this.HostedCluster.StopClusterClientAsync();

            await this.HostedCluster.InitializeClientAsync();

            output.WriteLine("Silos restarted");

            serviceId = await this.HostedCluster.Client.GetGrain <IServiceIdGrain>(Guid.Empty).GetServiceId();

            output.WriteLine("ClusterId={0} ServiceId={1}", this.HostedCluster.Options.ClusterId, serviceId);
            Assert.Equal(initialServiceId, serviceId);                               // "ServiceId same after restart."
            Assert.Equal(initialDeploymentId, this.HostedCluster.Options.ClusterId); // "ClusterId same after restart."

            // Since the client was destroyed and restarted, the grain reference needs to be recreated.
            grain = this.fixture.GrainFactory.GetGrain <IAWSStorageTestGrain>(id);

            val = await grain.GetValue();

            Assert.Equal(1, val);  // "Value after Write-1"

            await grain.DoWrite(2);

            val = await grain.GetValue();

            Assert.Equal(2, val);  // "Value after Write-2"

            val = await grain.DoRead();

            Assert.Equal(2, val);  // "Value after Re-Read"
        }
        // ---------- Utility functions ----------

        protected void RunPerfTest(int n, string testName, TimeSpan target,
                                   Func <IEchoTaskGrain, Task> actionNoState,
                                   Func <IPersistenceTestGrain, Task> actionMemory,
                                   Func <IMemoryStorageTestGrain, Task> actionMemoryStore,
                                   Func <IAWSStorageTestGrain, Task> actionAWSTable)
        {
            IEchoTaskGrain[]          noStateGrains     = new IEchoTaskGrain[n];
            IPersistenceTestGrain[]   memoryGrains      = new IPersistenceTestGrain[n];
            IAWSStorageTestGrain[]    awsStoreGrains    = new IAWSStorageTestGrain[n];
            IMemoryStorageTestGrain[] memoryStoreGrains = new IMemoryStorageTestGrain[n];

            for (int i = 0; i < n; i++)
            {
                Guid id = Guid.NewGuid();
                noStateGrains[i]     = this.fixture.GrainFactory.GetGrain <IEchoTaskGrain>(id);
                memoryGrains[i]      = this.fixture.GrainFactory.GetGrain <IPersistenceTestGrain>(id);
                awsStoreGrains[i]    = this.fixture.GrainFactory.GetGrain <IAWSStorageTestGrain>(id);
                memoryStoreGrains[i] = this.fixture.GrainFactory.GetGrain <IMemoryStorageTestGrain>(id);
            }

            TimeSpan baseline, elapsed;

            elapsed = baseline = TestUtils.TimeRun(n, TimeSpan.Zero, testName + " (No state)",
                                                   () => RunIterations(testName, n, i => actionNoState(noStateGrains[i])));

            elapsed = TestUtils.TimeRun(n, baseline, testName + " (Local Memory Store)",
                                        () => RunIterations(testName, n, i => actionMemory(memoryGrains[i])));

            elapsed = TestUtils.TimeRun(n, baseline, testName + " (Dev Store Grain Store)",
                                        () => RunIterations(testName, n, i => actionMemoryStore(memoryStoreGrains[i])));

            elapsed = TestUtils.TimeRun(n, baseline, testName + " (AWS Table Store)",
                                        () => RunIterations(testName, n, i => actionAWSTable(awsStoreGrains[i])));

            if (elapsed > target.Multiply(timingFactor))
            {
                string msg = string.Format("{0}: Elapsed time {1} exceeds target time {2}", testName, elapsed, target);

                if (elapsed > target.Multiply(2.0 * timingFactor))
                {
                    Assert.True(false, msg);
                }
                else
                {
                    throw new SkipException(msg);
                }
            }
        }
        protected async Task Grain_AWSStore_Delete()
        {
            Guid id = Guid.NewGuid();
            IAWSStorageTestGrain grain = this.fixture.GrainFactory.GetGrain <IAWSStorageTestGrain>(id);

            await grain.DoWrite(1);

            await grain.DoDelete();

            int val = await grain.GetValue(); // Should this throw instead?

            Assert.Equal(0, val);             // "Value after Delete"

            await grain.DoWrite(2);

            val = await grain.GetValue();

            Assert.Equal(2, val);  // "Value after Delete + New Write"
        }
Beispiel #6
0
        protected async Task Grain_AWSStore_SiloRestart()
        {
            var initialServiceId    = this.HostedCluster.ClusterConfiguration.Globals.ServiceId;
            var initialDeploymentId = this.HostedCluster.DeploymentId;

            output.WriteLine("DeploymentId={0} ServiceId={1}", this.HostedCluster.DeploymentId, this.HostedCluster.ClusterConfiguration.Globals.ServiceId);

            Guid id = Guid.NewGuid();
            IAWSStorageTestGrain grain = this.fixture.GrainFactory.GetGrain <IAWSStorageTestGrain>(id);

            int val = await grain.GetValue();

            Assert.Equal(0, val);  // "Initial value"

            await grain.DoWrite(1);

            output.WriteLine("About to reset Silos");
            foreach (var silo in this.HostedCluster.GetActiveSilos().ToList())
            {
                this.HostedCluster.RestartSilo(silo);
            }
            this.HostedCluster.InitializeClient();

            output.WriteLine("Silos restarted");

            output.WriteLine("DeploymentId={0} ServiceId={1}", this.HostedCluster.DeploymentId, this.HostedCluster.ClusterConfiguration.Globals.ServiceId);
            Assert.Equal(initialServiceId, this.HostedCluster.ClusterConfiguration.Globals.ServiceId); // "ServiceId same after restart."
            Assert.Equal(initialDeploymentId, this.HostedCluster.DeploymentId);                        // "DeploymentId same after restart."

            val = await grain.GetValue();

            Assert.Equal(1, val);  // "Value after Write-1"

            await grain.DoWrite(2);

            val = await grain.GetValue();

            Assert.Equal(2, val);  // "Value after Write-2"

            val = await grain.DoRead();

            Assert.Equal(2, val);  // "Value after Re-Read"
        }
Beispiel #7
0
        protected async Task Grain_AWSStore_SiloRestart()
        {
            var initialServiceId    = this.HostedCluster.Globals.ServiceId;
            var initialDeploymentId = this.HostedCluster.DeploymentId;

            output.WriteLine("DeploymentId={0} ServiceId={1}", this.HostedCluster.DeploymentId, this.HostedCluster.Globals.ServiceId);

            Guid id = Guid.NewGuid();
            IAWSStorageTestGrain grain = GrainClient.GrainFactory.GetGrain <IAWSStorageTestGrain>(id);

            int val = await grain.GetValue();

            Assert.Equal(0, val);  // "Initial value"

            await grain.DoWrite(1);

            output.WriteLine("About to reset Silos");
            this.HostedCluster.RestartDefaultSilos(true);
            output.WriteLine("Silos restarted");

            output.WriteLine("DeploymentId={0} ServiceId={1}", this.HostedCluster.DeploymentId, this.HostedCluster.Globals.ServiceId);
            Assert.Equal(initialServiceId, this.HostedCluster.Globals.ServiceId);  // "ServiceId same after restart."
            Assert.NotEqual(initialDeploymentId, this.HostedCluster.DeploymentId); // "DeploymentId different after restart."

            val = await grain.GetValue();

            Assert.Equal(1, val);  // "Value after Write-1"

            await grain.DoWrite(2);

            val = await grain.GetValue();

            Assert.Equal(2, val);  // "Value after Write-2"

            val = await grain.DoRead();

            Assert.Equal(2, val);  // "Value after Re-Read"
        }
        // ---------- Utility functions ----------

        protected void RunPerfTest(int n, string testName, TimeSpan target,
            Func<IEchoTaskGrain, Task> actionNoState,
            Func<IPersistenceTestGrain, Task> actionMemory,
            Func<IMemoryStorageTestGrain, Task> actionMemoryStore,
            Func<IAWSStorageTestGrain, Task> actionAWSTable)
        {
            IEchoTaskGrain[] noStateGrains = new IEchoTaskGrain[n];
            IPersistenceTestGrain[] memoryGrains = new IPersistenceTestGrain[n];
            IAWSStorageTestGrain[] awsStoreGrains = new IAWSStorageTestGrain[n];
            IMemoryStorageTestGrain[] memoryStoreGrains = new IMemoryStorageTestGrain[n];

            for (int i = 0; i < n; i++)
            {
                Guid id = Guid.NewGuid();
                noStateGrains[i] = GrainClient.GrainFactory.GetGrain<IEchoTaskGrain>(id);
                memoryGrains[i] = GrainClient.GrainFactory.GetGrain<IPersistenceTestGrain>(id);
                awsStoreGrains[i] = GrainClient.GrainFactory.GetGrain<IAWSStorageTestGrain>(id);
                memoryStoreGrains[i] = GrainClient.GrainFactory.GetGrain<IMemoryStorageTestGrain>(id);
            }

            TimeSpan baseline, elapsed;

            elapsed = baseline = TestUtils.TimeRun(n, TimeSpan.Zero, testName + " (No state)",
                () => RunIterations(testName, n, i => actionNoState(noStateGrains[i])));

            elapsed = TestUtils.TimeRun(n, baseline, testName + " (Local Memory Store)",
                () => RunIterations(testName, n, i => actionMemory(memoryGrains[i])));

            elapsed = TestUtils.TimeRun(n, baseline, testName + " (Dev Store Grain Store)",
                () => RunIterations(testName, n, i => actionMemoryStore(memoryStoreGrains[i])));

            elapsed = TestUtils.TimeRun(n, baseline, testName + " (AWS Table Store)",
                () => RunIterations(testName, n, i => actionAWSTable(awsStoreGrains[i])));

            if (elapsed > target.Multiply(timingFactor))
            {
                string msg = string.Format("{0}: Elapsed time {1} exceeds target time {2}", testName, elapsed, target);

                if (elapsed > target.Multiply(2.0 * timingFactor))
                {
                    Assert.True(false, msg);
                }
                else
                {
                    throw new SkipException(msg);
                }
            }
        }