public async Task Grain_GuidKey_AzureStore_Read_Write() { Guid id = Guid.NewGuid(); IAzureStorageTestGrain grain = GrainClient.GrainFactory.GetGrain <IAzureStorageTestGrain>(id); int val = await grain.GetValue(); Assert.AreEqual(0, val, "Initial value"); await grain.DoWrite(1); val = await grain.GetValue(); Assert.AreEqual(1, val, "Value after Write-1"); await grain.DoWrite(2); val = await grain.GetValue(); Assert.AreEqual(2, val, "Value after Write-2"); val = await grain.DoRead(); Assert.AreEqual(2, val, "Value after Re-Read"); }
protected async Task Grain_GuidKey_AzureStore_Read_Write() { Guid id = Guid.NewGuid(); IAzureStorageTestGrain grain = this.GrainFactory.GetGrain <IAzureStorageTestGrain>(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_AzureStore_Read() { Guid id = Guid.NewGuid(); IAzureStorageTestGrain grain = this.GrainFactory.GetGrain <IAzureStorageTestGrain>(id); int val = await grain.GetValue(); Assert.Equal(0, val); // "Initial value" }
public async Task Grain_AzureStore_Read() { Guid id = Guid.NewGuid(); IAzureStorageTestGrain grain = GrainClient.GrainFactory.GetGrain <IAzureStorageTestGrain>(id); int val = await grain.GetValue(); Assert.AreEqual(0, val, "Initial value"); }
// ---------- Utility functions ---------- protected void RunPerfTest(int n, string testName, TimeSpan target, Func <IEchoTaskGrain, Task> actionNoState, Func <IPersistenceTestGrain, Task> actionMemory, Func <IMemoryStorageTestGrain, Task> actionMemoryStore, Func <IAzureStorageTestGrain, Task> actionAzureTable) { IEchoTaskGrain[] noStateGrains = new IEchoTaskGrain[n]; IPersistenceTestGrain[] memoryGrains = new IPersistenceTestGrain[n]; IAzureStorageTestGrain[] azureStoreGrains = new IAzureStorageTestGrain[n]; IMemoryStorageTestGrain[] memoryStoreGrains = new IMemoryStorageTestGrain[n]; for (int i = 0; i < n; i++) { Guid id = Guid.NewGuid(); noStateGrains[i] = this.GrainFactory.GetGrain <IEchoTaskGrain>(id); memoryGrains[i] = this.GrainFactory.GetGrain <IPersistenceTestGrain>(id); azureStoreGrains[i] = this.GrainFactory.GetGrain <IAzureStorageTestGrain>(id); memoryStoreGrains[i] = this.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 + " (Azure Table Store)", () => RunIterations(testName, n, i => actionAzureTable(azureStoreGrains[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_AzureStore_Delete() { Guid id = Guid.NewGuid(); IAzureStorageTestGrain grain = this.GrainFactory.GetGrain <IAzureStorageTestGrain>(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" }
public async Task Grain_AzureStore_Delete() { Guid id = Guid.NewGuid(); IAzureStorageTestGrain grain = GrainClient.GrainFactory.GetGrain <IAzureStorageTestGrain>(id); await grain.DoWrite(1); await grain.DoDelete(); int val = await grain.GetValue(); // Should this throw instead? Assert.AreEqual(0, val, "Value after Delete"); await grain.DoWrite(2); val = await grain.GetValue(); Assert.AreEqual(2, val, "Value after Delete + New Write"); }
protected async Task Grain_AzureStore_SiloRestart() { var initialServiceId = this.HostedCluster.ServiceId; output.WriteLine("ClusterId={0} ServiceId={1}", this.HostedCluster.ClusterId, this.HostedCluster.ServiceId); Guid id = Guid.NewGuid(); IAzureStorageTestGrain grain = this.GrainFactory.GetGrain <IAzureStorageTestGrain>(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"); var serviceId = await this.GrainFactory.GetGrain <IServiceIdGrain>(Guid.Empty).GetServiceId(); output.WriteLine("ClusterId={0} ServiceId={1}", this.HostedCluster.ClusterId, serviceId); Assert.Equal(initialServiceId, serviceId); // "ServiceId 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" }
protected async Task Grain_AzureStore_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(); IAzureStorageTestGrain grain = GrainClient.GrainFactory.GetGrain <IAzureStorageTestGrain>(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" }
public async Task Grain_AzureStore_SiloRestart() { var initialDeploymentId = DeploymentId; Console.WriteLine("DeploymentId={0} ServiceId={1}", DeploymentId, Globals.ServiceId); Guid id = Guid.NewGuid(); IAzureStorageTestGrain grain = GrainClient.GrainFactory.GetGrain <IAzureStorageTestGrain>(id); int val = await grain.GetValue(); Assert.AreEqual(0, val, "Initial value"); await grain.DoWrite(1); Console.WriteLine("About to reset Silos"); RestartDefaultSilos(true); Console.WriteLine("Silos restarted"); Console.WriteLine("DeploymentId={0} ServiceId={1}", DeploymentId, Globals.ServiceId); Assert.AreEqual(initialServiceId, Globals.ServiceId, "ServiceId same after restart."); Assert.AreNotEqual(initialDeploymentId, DeploymentId, "DeploymentId different after restart."); val = await grain.GetValue(); Assert.AreEqual(1, val, "Value after Write-1"); await grain.DoWrite(2); val = await grain.GetValue(); Assert.AreEqual(2, val, "Value after Write-2"); val = await grain.DoRead(); Assert.AreEqual(2, val, "Value after Re-Read"); }
// ---------- Utility functions ---------- private void RunPerfTest(int n, string testName, TimeSpan target, Func<IEchoTaskGrain, Task> actionNoState, Func<IPersistenceTestGrain, Task> actionMemory, Func<IMemoryStorageTestGrain, Task> actionMemoryStore, Func<IAzureStorageTestGrain, Task> actionAzureTable) { IEchoTaskGrain[] noStateGrains = new IEchoTaskGrain[n]; IPersistenceTestGrain[] memoryGrains = new IPersistenceTestGrain[n]; IAzureStorageTestGrain[] azureStoreGrains = new IAzureStorageTestGrain[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); azureStoreGrains[i] = GrainClient.GrainFactory.GetGrain<IAzureStorageTestGrain>(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 + " (Azure Table Store)", () => RunIterations(testName, n, i => actionAzureTable(azureStoreGrains[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.Fail(msg); } else { Assert.Inconclusive(msg); } } }