public void FromDbEntryPerformance() { var count = 10000; var options = new DynamoDBProviderOptions("proto_actor_events", "proto_actor_snapshots"); var provider = new DynamoDBProvider(_client, options); var dynamoDBContext = new DynamoDBContext(_client); var fromDocumentMI = typeof(DynamoDBContext).GetMethods().First(m => m.Name == "FromDocument" && m.GetParameters().Count() == 1); var toDocumentMI = typeof(DynamoDBContext).GetMethods().First(m => m.Name == "ToDocument" && m.GetParameters().Count() == 1); var obj = SomeObj.GetMe(); var doc = dynamoDBContext.ToDocument(obj); var stopwatch = new Stopwatch(); stopwatch.Start(); for (var i = 0; i < count; i++) { // Simulate what provider does var dataType = Type.GetType(typeof(SomeObj).AssemblyQualifiedName); var data = dynamoDBContext.FromDocumentDynamic(doc, dataType); } stopwatch.Stop(); // Console.WriteLine(String.Format("FromDbEntryPerformance: Total: {0}, Per item: {1}", stopwatch.Elapsed.TotalMilliseconds, stopwatch.Elapsed.TotalMilliseconds / count)); Assert.True(stopwatch.Elapsed.TotalMilliseconds / count < 0.05); }
public async Task PersistSnapshotShouldGoThru() { var options = new DynamoDBProviderOptions("proto_actor_events", "proto_actor_snapshots"); var provider = new DynamoDBProvider(_client, options); var actorName = GetRandomActorName(); await provider.PersistSnapshotAsync(actorName, 1, new SomeSnapshot { Something = "asdf", Something2 = 1 }); }
public async Task DeleteSnapshotsShouldRemoveSnapshots() { var options = new DynamoDBProviderOptions("proto_actor_events", "proto_actor_snapshots"); var provider = new DynamoDBProvider(_client, options); var actorName = GetRandomActorName(); await provider.PersistSnapshotAsync(actorName, 1, new SomeSnapshot { Something = "asdf2", Something2 = 2 }); await provider.PersistSnapshotAsync(actorName, 2, new SomeSnapshot { Something = "asdf3", Something2 = 3 }); var retreived = new List <object>(); var res = await provider.GetSnapshotAsync(actorName); Assert.Equal(2, res.Index); Assert.NotNull(res.Snapshot); await provider.DeleteSnapshotsAsync(actorName, 1); res = await provider.GetSnapshotAsync(actorName); Assert.Equal(2, res.Index); Assert.NotNull(res.Snapshot); await provider.DeleteSnapshotsAsync(actorName, 2); res = await provider.GetSnapshotAsync(actorName); Assert.Equal(0, res.Index); Assert.Null(res.Snapshot); }
public async Task DeleteEventsShouldRemoveEvents() { var options = new DynamoDBProviderOptions("proto_actor_events", "proto_actor_snapshots"); var provider = new DynamoDBProvider(_client, options); var actorName = GetRandomActorName(); await provider.PersistEventAsync(actorName, 1, new SomeEvent { Something = "asdf2", Something2 = 2 }); await provider.PersistEventAsync(actorName, 2, new SomeEvent { Something = "asdf3", Something2 = 3 }); var retreived = new List <object>(); await provider.GetEventsAsync(actorName, 1, 2, @event => { retreived.Add(@event); }); Assert.Equal(2, retreived.Count); await provider.DeleteEventsAsync(actorName, 1); retreived.Clear(); await provider.GetEventsAsync(actorName, 1, 2, @event => { retreived.Add(@event); }); Assert.Equal(1, retreived.Count); }
public async Task GetEventsShouldReturnJustEventsInRange() { var options = new DynamoDBProviderOptions("proto_actor_events", "proto_actor_snapshots"); var provider = new DynamoDBProvider(_client, options); var actorName = GetRandomActorName(); await provider.PersistEventAsync(actorName, 1, new SomeEvent { Something = "asdf2", Something2 = 2 }); await provider.PersistEventAsync(actorName, 2, new SomeEvent { Something = "asdf3", Something2 = 3 }); await provider.PersistEventAsync(actorName, 3, new SomeEvent { Something = "asdf4", Something2 = 4 }); await provider.PersistEventAsync(actorName, 4, new SomeEvent { Something = "asdf5", Something2 = 5 }); var retreived = new List <object>(); await provider.GetEventsAsync(actorName, 2, 3, @event => { retreived.Add(@event); }); Assert.Equal(2, retreived.Count); var first = retreived.First() as SomeEvent; Assert.NotNull(first); Assert.Equal("asdf3", first.Something); var second = retreived.Skip(1).First() as SomeEvent; Assert.NotNull(second); Assert.Equal("asdf4", second.Something); }
public async Task GetEventsShouldReturnPersistetEventsInOrder() { var options = new DynamoDBProviderOptions("proto_actor_events", "proto_actor_snapshots"); var provider = new DynamoDBProvider(_client, options); var actorName = GetRandomActorName(); var Date1 = DateTime.Now; var Date2 = DateTime.Now; await provider.PersistEventAsync(actorName, 1, new SomeEvent { Something = "asdf2", Something2 = 2, Date1 = Date1, Date2 = Date2 }); await provider.PersistEventAsync(actorName, 2, new SomeEvent { Something = "asdf3", Something2 = 3 }); var retreived = new List <object>(); await provider.GetEventsAsync(actorName, 1, 2, @event => { retreived.Add(@event); }); Assert.Equal(2, retreived.Count); var obj1 = retreived.First(); Assert.IsType <SomeEvent>(obj1); var event1 = obj1 as SomeEvent; Assert.Equal("asdf2", event1.Something); Assert.Equal(2, event1.Something2); Assert.Equal(Date1.Truncate(TimeSpan.FromMilliseconds(1)), event1.Date1); Assert.Equal(Date2.Truncate(TimeSpan.FromMilliseconds(1)), event1.Date2); }
public async Task GetSnapshotShouldReturnNullIfNoSnapshot() { var options = new DynamoDBProviderOptions("proto_actor_events", "proto_actor_snapshots"); var provider = new DynamoDBProvider(_client, options); var actorName = GetRandomActorName(); var res = await provider.GetSnapshotAsync(actorName); Assert.Equal(0, res.Index); Assert.Null(res.Snapshot); }
public async Task GetSnapshotShouldReturnLastSnapshot() { var options = new DynamoDBProviderOptions("proto_actor_events", "proto_actor_snapshots"); var provider = new DynamoDBProvider(_client, options); var actorName = GetRandomActorName(); await provider.PersistSnapshotAsync(actorName, 1, new SomeSnapshot { Something = "asdf2", Something2 = 2 }); await provider.PersistSnapshotAsync(actorName, 2, new SomeSnapshot { Something = "asdf3", Something2 = 3 }); var res = await provider.GetSnapshotAsync(actorName); Assert.Equal(2, res.Index); var snapshot = res.Snapshot as SomeSnapshot; Assert.NotNull(snapshot); Assert.Equal("asdf3", snapshot.Something); Assert.Equal(3, snapshot.Something2); }