public async Task PersistenceProvider_Azure_ChangeWriteFormat(int?stringLength, bool useJsonForFirstWrite, bool useJsonForSecondWrite) { var testName = string.Format("{0}({1}={2},{3}={4},{5}={6})", nameof(PersistenceProvider_Azure_ChangeWriteFormat), nameof(stringLength), stringLength == null ? "default" : stringLength.ToString(), "json1stW", useJsonForFirstWrite, "json2ndW", useJsonForSecondWrite); var grainState = TestStoreGrainState.NewRandomState(stringLength); EnsureEnvironmentSupportsState(grainState); var grainId = LegacyGrainId.NewId(); var store = await InitAzureTableGrainStorage(useJsonForFirstWrite); await Test_PersistenceProvider_WriteRead(testName, store, grainState, grainId); grainState = TestStoreGrainState.NewRandomState(stringLength); grainState.ETag = "*"; store = await InitAzureTableGrainStorage(useJsonForSecondWrite); await Test_PersistenceProvider_WriteRead(testName, store, grainState, grainId); }
public void Store_WriteRead() { string name = Guid.NewGuid().ToString();//TestContext.TestName; ILocalDataStore store = new HierarchicalKeyStore(2); GrainReference reference = fixture.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()); var state = TestStoreGrainState.NewRandomState(); Stopwatch sw = new Stopwatch(); sw.Start(); var keys = GetKeys(name, reference); var stateProperties = AsDictionary(state.State); store.WriteRow(keys, stateProperties, state.ETag); TimeSpan writeTime = sw.Elapsed; sw.Restart(); var data = store.ReadRow(keys); TimeSpan readTime = sw.Elapsed; output.WriteLine("{0} - Write time = {1} Read time = {2}", store.GetType().FullName, writeTime, readTime); Assert.Equal(state.State.A, data["A"]); // "A" Assert.Equal(state.State.B, data["B"]); // "B" Assert.Equal(state.State.C, data["C"]); // "C" }
public async Task PersistenceProvider_Memory_FixedLatency_WriteRead() { const string testName = nameof(PersistenceProvider_Memory_FixedLatency_WriteRead); TimeSpan expectedLatency = TimeSpan.FromMilliseconds(200); MemoryGrainStorageWithLatency store = new MemoryGrainStorageWithLatency(testName, new MemoryStorageWithLatencyOptions() { Latency = expectedLatency, MockCallsOnly = true }, NullLoggerFactory.Instance, this.providerRuntime.ServiceProvider.GetService <IGrainFactory>()); GrainReference reference = this.fixture.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()); var state = TestStoreGrainState.NewRandomState(); Stopwatch sw = new Stopwatch(); sw.Start(); await store.WriteStateAsync(testName, reference, state); TimeSpan writeTime = sw.Elapsed; this.output.WriteLine("{0} - Write time = {1}", store.GetType().FullName, writeTime); Assert.True(writeTime >= expectedLatency, $"Write: Expected minimum latency = {expectedLatency} Actual = {writeTime}"); sw.Restart(); var storedState = new GrainState <TestStoreGrainState>(); await store.ReadStateAsync(testName, reference, storedState); TimeSpan readTime = sw.Elapsed; this.output.WriteLine("{0} - Read time = {1}", store.GetType().FullName, readTime); Assert.True(readTime >= expectedLatency, $"Read: Expected minimum latency = {expectedLatency} Actual = {readTime}"); }
public void GrainState_Store_WriteRead() { string name = Guid.NewGuid().ToString();//TestContext.TestName; ILocalDataStore store = new HierarchicalKeyStore(2); GrainReference reference = this.fixture.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()); var grainState = TestStoreGrainState.NewRandomState(); var state = grainState.State; Stopwatch sw = new Stopwatch(); sw.Start(); IList <Tuple <string, string> > keys = new[] { Tuple.Create("GrainType", name), Tuple.Create("GrainId", reference.GrainId.ToString()) }.ToList(); store.WriteRow(keys, AsDictionary(state), grainState.ETag); TimeSpan writeTime = sw.Elapsed; sw.Restart(); var data = store.ReadRow(keys); TimeSpan readTime = sw.Elapsed; output.WriteLine("{0} - Write time = {1} Read time = {2}", store.GetType().FullName, writeTime, readTime); Assert.Equal(state.A, data["A"]); // "A" Assert.Equal(state.B, data["B"]); // "B" Assert.Equal(state.C, data["C"]); // "C" }
private ReminderEntry NewReminderEntry() { Guid guid = Guid.NewGuid(); return(new ReminderEntry { GrainRef = this.fixture.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()), ReminderName = string.Format("TestReminder.{0}", guid), Period = TimeSpan.FromSeconds(5), StartAt = DateTime.UtcNow }); }
public void Serialize_GrainReference() { GrainId grainId = LegacyGrainId.NewId(); GrainReference input = (GrainReference)environment.InternalGrainFactory.GetGrain(grainId); object deserialized = OrleansSerializationLoop(environment.Serializer, environment.DeepCopier, input); var grainRef = Assert.IsAssignableFrom <GrainReference>(deserialized); //GrainReference copied as wrong type Assert.Equal(grainId, grainRef.GrainId); //GrainId different after copy Assert.Equal(input, grainRef); //Wrong contents after round-trip of input }
private void RunTest(int numItems) { InvokeMethodRequest request = new InvokeMethodRequest(0, 2, 0, null); Message resp = this.messageFactory.CreateMessage(request, InvokeMethodOptions.None); resp.Id = new CorrelationId(); resp.SendingSilo = SiloAddress.New(new IPEndPoint(IPAddress.Loopback, 200), 0); resp.TargetSilo = SiloAddress.New(new IPEndPoint(IPAddress.Loopback, 300), 0); resp.SendingGrain = LegacyGrainId.NewId(); resp.TargetGrain = LegacyGrainId.NewId(); resp.IsAlwaysInterleave = true; Assert.True(resp.IsUsingInterfaceVersions); List <object> requestBody = new List <object>(); for (int k = 0; k < numItems; k++) { requestBody.Add(k + ": test line"); } resp.BodyObject = requestBody; string s = resp.ToString(); output.WriteLine(s); var resp1 = RoundTripMessage(resp); //byte[] serialized = resp.FormatForSending(); //Message resp1 = new Message(serialized, serialized.Length); Assert.Equal(resp.Category, resp1.Category); //Category is incorrect" Assert.Equal(resp.Direction, resp1.Direction); //Direction is incorrect Assert.Equal(resp.Id, resp1.Id); //Correlation ID is incorrect Assert.Equal(resp.IsAlwaysInterleave, resp1.IsAlwaysInterleave); //Foo Boolean is incorrect Assert.Equal(resp.CacheInvalidationHeader, resp1.CacheInvalidationHeader); //Bar string is incorrect Assert.True(resp.TargetSilo.Equals(resp1.TargetSilo)); Assert.True(resp.TargetGrain.Equals(resp1.TargetGrain)); Assert.True(resp.SendingGrain.Equals(resp1.SendingGrain)); Assert.True(resp.SendingSilo.Equals(resp1.SendingSilo)); //SendingSilo is incorrect Assert.True(resp1.IsUsingInterfaceVersions); List <object> responseList = Assert.IsAssignableFrom <List <object> >(resp1.BodyObject); Assert.Equal <int>(numItems, responseList.Count); //Body list has wrong number of entries for (int k = 0; k < numItems; k++) { Assert.IsAssignableFrom <string>(responseList[k]); //Body list item " + k + " has wrong type Assert.Equal((string)(requestBody[k]), (string)(responseList[k])); //Body list item " + k + " is incorrect } }
public void Store_Delete() { string name = Guid.NewGuid().ToString();//TestContext.TestName; ILocalDataStore store = new HierarchicalKeyStore(2); GrainReference reference = this.fixture.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()); var data = TestStoreGrainState.NewRandomState(); output.WriteLine("Using store = {0}", store.GetType().FullName); Stopwatch sw = new Stopwatch(); var keys = GetKeys(name, reference); sw.Restart(); string eTag = store.WriteRow(keys, AsDictionary(data.State), null); output.WriteLine("Write returned Etag={0} after {1} {2}", eTag, sw.Elapsed, StorageProviderUtils.PrintOneWrite(keys, data, eTag)); sw.Restart(); var storedData = store.ReadRow(keys); output.WriteLine("Read returned {0} after {1}", StorageProviderUtils.PrintOneWrite(keys, storedData, eTag), sw.Elapsed); Assert.NotNull(data); // Should get some data from Read sw.Restart(); bool ok = store.DeleteRow(keys, eTag); Assert.True(ok, $"Row deleted OK after {sw.Elapsed}. Etag={eTag} Keys={StorageProviderUtils.PrintKeys(keys)}"); sw.Restart(); storedData = store.ReadRow(keys); // Try to re-read after delete output.WriteLine("Re-Read took {0} and returned {1}", sw.Elapsed, StorageProviderUtils.PrintData(storedData)); Assert.NotNull(data); // Should not get null data from Re-Read Assert.True(storedData.Count == 0, $"Should get no data from Re-Read but got: {StorageProviderUtils.PrintData(storedData)}"); sw.Restart(); const string oldEtag = null; eTag = store.WriteRow(keys, storedData, oldEtag); output.WriteLine("Write for Keys={0} Etag={1} Data={2} returned New Etag={3} after {4}", StorageProviderUtils.PrintKeys(keys), oldEtag, StorageProviderUtils.PrintData(storedData), eTag, sw.Elapsed); sw.Restart(); ok = store.DeleteRow(keys, eTag); Assert.True(ok, $"Row deleted OK after {sw.Elapsed}. Etag={eTag} Keys={StorageProviderUtils.PrintKeys(keys)}"); }
public void Serialize_ActivationAddress() { GrainId grain = LegacyGrainId.NewId(); var addr = ActivationAddress.GetAddress(null, grain, default); object deserialized = OrleansSerializationLoop(environment.Serializer, environment.DeepCopier, addr, false); Assert.IsAssignableFrom <ActivationAddress>(deserialized); Assert.True(((ActivationAddress)deserialized).Activation.IsDefault); //Activation no longer null after copy Assert.Null(((ActivationAddress)deserialized).Silo); //Silo no longer null after copy Assert.Equal(grain, ((ActivationAddress)deserialized).Grain); //Grain different after copy deserialized = OrleansSerializationLoop(environment.Serializer, environment.DeepCopier, addr); Assert.IsAssignableFrom <ActivationAddress>(deserialized); //ActivationAddress full serialization loop as wrong type Assert.True(((ActivationAddress)deserialized).Activation.IsDefault); //Activation no longer null after full serialization loop Assert.Null(((ActivationAddress)deserialized).Silo); //Silo no longer null after full serialization loop Assert.Equal(grain, ((ActivationAddress)deserialized).Grain); //Grain different after copy }
private async Task TestTableInsertRate(IReminderTable reminderTable, double numOfInserts) { DateTime startedAt = DateTime.UtcNow; try { List <Task <bool> > promises = new List <Task <bool> >(); for (int i = 0; i < numOfInserts; i++) { //"177BF46E-D06D-44C0-943B-C12F26DF5373" string s = string.Format("177BF46E-D06D-44C0-943B-C12F26D{0:d5}", i); var e = new ReminderEntry { //GrainId = LegacyGrainId.GetGrainId(new Guid(s)), GrainRef = this.fixture.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()), ReminderName = "MY_REMINDER_" + i, Period = TimeSpan.FromSeconds(5), StartAt = DateTime.UtcNow }; int capture = i; Task <bool> promise = Task.Run(async() => { await reminderTable.UpsertRow(e); this.output.WriteLine("Done " + capture); return(true); }); promises.Add(promise); this.log.Info("Started " + capture); } this.log.Info("Started all, now waiting..."); await Task.WhenAll(promises).WithTimeout(TimeSpan.FromSeconds(500)); } catch (Exception exc) { this.log.Info("Exception caught {0}", exc); } TimeSpan dur = DateTime.UtcNow - startedAt; this.log.Info("Inserted {0} rows in {1}, i.e., {2:f2} upserts/sec", numOfInserts, dur, (numOfInserts / dur.TotalSeconds)); }
public async Task PersistenceProvider_DynamoDB_ChangeReadFormat(int?stringLength, bool useJsonForWrite, bool useJsonForRead) { var testName = string.Format("{0}({1} = {2}, {3} = {4}, {5} = {6})", nameof(PersistenceProvider_DynamoDB_ChangeReadFormat), nameof(stringLength), stringLength == null ? "default" : stringLength.ToString(), nameof(useJsonForWrite), useJsonForWrite, nameof(useJsonForRead), useJsonForRead); var grainState = TestStoreGrainState.NewRandomState(stringLength); EnsureEnvironmentSupportsState(grainState); var grainId = LegacyGrainId.NewId(); var store = await InitDynamoDBGrainStorage(useJsonForWrite); grainState = await Test_PersistenceProvider_WriteRead(testName, store, grainState, grainId); store = await InitDynamoDBGrainStorage(useJsonForRead); await Test_PersistenceProvider_Read(testName, store, grainState, grainId); }
private async Task <GrainState <TestStoreGrainState> > Test_PersistenceProvider_WriteClearRead(string grainTypeName, IGrainStorage store, GrainState <TestStoreGrainState> grainState = null, GrainId grainId = default) { GrainReference reference = (GrainReference)this.fixture.InternalGrainFactory.GetGrain(grainId.IsDefault ? (GrainId)LegacyGrainId.NewId() : grainId); if (grainState == null) { grainState = TestStoreGrainState.NewRandomState(); } Stopwatch sw = new Stopwatch(); sw.Start(); await store.WriteStateAsync(grainTypeName, reference, grainState); TimeSpan writeTime = sw.Elapsed; sw.Restart(); await store.ClearStateAsync(grainTypeName, reference, grainState); var storedGrainState = new GrainState <TestStoreGrainState> { State = new TestStoreGrainState() }; await store.ReadStateAsync(grainTypeName, reference, storedGrainState); TimeSpan readTime = sw.Elapsed; this.output.WriteLine("{0} - Write time = {1} Read time = {2}", store.GetType().FullName, writeTime, readTime); Assert.NotNull(storedGrainState.State); Assert.Equal(default(string), storedGrainState.State.A); Assert.Equal(default(int), storedGrainState.State.B); Assert.Equal(default(long), storedGrainState.State.C); return(storedGrainState); }
private async Task Test_PersistenceProvider_Read(string grainTypeName, IGrainStorage store, GrainState <TestStoreGrainState> grainState = null, GrainId grainId = default) { var reference = (GrainReference)this.fixture.InternalGrainFactory.GetGrain(grainId.IsDefault ? (GrainId)LegacyGrainId.NewId() : grainId); if (grainState == null) { grainState = new GrainState <TestStoreGrainState>(new TestStoreGrainState()); } var storedGrainState = new GrainState <TestStoreGrainState>(new TestStoreGrainState()); Stopwatch sw = new Stopwatch(); sw.Start(); await store.ReadStateAsync(grainTypeName, reference, storedGrainState); TimeSpan readTime = sw.Elapsed; this.output.WriteLine("{0} - Read time = {1}", store.GetType().FullName, readTime); var storedState = storedGrainState.State; Assert.Equal(grainState.State.A, storedState.A); Assert.Equal(grainState.State.B, storedState.B); Assert.Equal(grainState.State.C, storedState.C); }
public void Serialize_ArrayOfArrays() { var source1 = new[] { new[] { 1, 3, 5 }, new[] { 10, 20, 30 }, new[] { 17, 13, 11, 7, 5, 3, 2 } }; object deserialized = OrleansSerializationLoop(environment.Serializer, environment.DeepCopier, source1); ValidateArrayOfArrays(source1, deserialized, "int"); var source2 = new[] { new[] { "hello", "goodbye", "yes", "no", "", "I don't know" }, new[] { "yes" } }; deserialized = OrleansSerializationLoop(environment.Serializer, environment.DeepCopier, source2); ValidateArrayOfArrays(source2, deserialized, "string"); var source3 = new HashSet <string> [3][]; source3[0] = new HashSet <string> [2]; source3[1] = new HashSet <string> [3]; source3[2] = new HashSet <string> [1]; source3[0][0] = new HashSet <string>(); source3[0][1] = new HashSet <string>(); source3[1][0] = new HashSet <string>(); source3[1][1] = null; source3[1][2] = new HashSet <string>(); source3[2][0] = new HashSet <string>(); source3[0][0].Add("this"); source3[0][0].Add("that"); source3[1][0].Add("the other"); source3[1][2].Add("and another"); source3[2][0].Add("but not yet another"); deserialized = OrleansSerializationLoop(environment.Serializer, environment.DeepCopier, source3); var result = Assert.IsAssignableFrom <HashSet <string>[][]>(deserialized); //Array of arrays of hash sets type is wrong on deserialization Assert.Equal(3, result.Length); //Outer array size wrong on array of array of sets Assert.Equal(2, result[0][0].Count); //Inner set size wrong on array of array of sets, element 0,0 Assert.Empty(result[0][1]); //Inner set size wrong on array of array of sets, element 0,1 Assert.Single(result[1][0]); //Inner set size wrong on array of array of sets, element 1,0 Assert.Null(result[1][1]); //Inner set not null on array of array of sets, element 1, 1 Assert.Single(result[1][2]); //Inner set size wrong on array of array of sets, element 1,2 Assert.Single(result[2][0]); //Inner set size wrong on array of array of sets, element 2,0 var source4 = new GrainReference[3][]; source4[0] = new GrainReference[2]; source4[1] = new GrainReference[3]; source4[2] = new GrainReference[1]; source4[0][0] = (GrainReference)environment.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()); source4[0][1] = (GrainReference)environment.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()); source4[1][0] = (GrainReference)environment.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()); source4[1][1] = (GrainReference)environment.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()); source4[1][2] = (GrainReference)environment.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()); source4[2][0] = (GrainReference)environment.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()); deserialized = OrleansSerializationLoop(environment.Serializer, environment.DeepCopier, source4); ValidateArrayOfArrays(source4, deserialized, "grain reference"); var source5 = new GrainReference[32][]; for (int i = 0; i < source5.Length; i++) { source5[i] = new GrainReference[64]; for (int j = 0; j < source5[i].Length; j++) { source5[i][j] = (GrainReference)environment.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()); } } deserialized = OrleansSerializationLoop(environment.Serializer, environment.DeepCopier, source5); ValidateArrayOfArrays(source5, deserialized, "grain reference (large)"); }