public void SupportsList() { var manager = new EventStoreManager(); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var userA = new User { Name = "A", Age = 1 }; var userB = new User { Name = "B", Age = 2 }; var userEvent = new UserEventList { Id = 10, List = new List <User> { userA, userB, userA } }; appender.Store(null, new object[] { userEvent }); manager = new EventStoreManager(); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); var readUserEvent = (UserEventList)eventObserver.Events[0][0]; Assert.Equal(readUserEvent, userEvent); }
public void CanStoreNullable() { var testEvent = new EventWithNullable { EventId = 1, NullableInt = 42, ListWithNullables = new List <int?> { 4, new int?() }, DictionaryWithNullables = new Dictionary <int?, bool?> { { 1, true }, { 2, new bool?() } } }; var manager = new EventStoreManager(); var appender = manager.AppendToStore(new MemoryEventFileStorage()); appender.Store(null, new object[] { testEvent }); var eventObserver = new StoringEventObserver(); appender.ReadFromStartToEnd(eventObserver); Assert.Equal(new object[] { null }, eventObserver.Metadata); var ev = eventObserver.Events[0][0] as EventWithNullable; Assert.Equal(42, ev.NullableInt.Value); Assert.False(ev.NullableEmpty.HasValue); Assert.Equal(2, ev.ListWithNullables.Count); Assert.Equal(4, ev.ListWithNullables[0].Value); Assert.False(ev.ListWithNullables[1].HasValue); Assert.Equal(2, ev.DictionaryWithNullables.Count); Assert.True(ev.DictionaryWithNullables[1]); Assert.False(ev.DictionaryWithNullables[2].HasValue); }
public void UpgradeToLessObjectProperties() { var manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(UserEvent), "UserEvent")); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var user = new User { Name = "A", Age = 1 }; var userEvent = new UserEvent { Id = 10, User1 = user, User2 = user }; appender.Store(null, new object[] { userEvent, new User { Name = "B" } }); manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(UserEventLess), "UserEvent")); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); var readUserEvent = (UserEventLess)eventObserver.Events[0][0]; Assert.Equal("A", readUserEvent.User2.Name); Assert.Equal(10, readUserEvent.Id); Assert.Equal("B", ((User)eventObserver.Events[0][1]).Name); }
public void SupportsDictionary() { var manager = new EventStoreManager(); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var userA = new User { Name = "A", Age = 1 }; var userB = new User { Name = "B", Age = 2 }; var userEvent = new UserEventDictionary { Id = 10, Dict = new Dictionary <string, User> { { "A", userA }, { "B", userB } } }; appender.Store(null, new object[] { userEvent }); manager = new EventStoreManager(); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); var readUserEvent = (UserEventDictionary)eventObserver.Events[0][0]; Assert.Equal(readUserEvent, userEvent); }
public void SurvivesListVsIList() { var manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(SomethingWithoutList), "Some")); var file = new MemoryEventFileStorage(); var file2 = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var ev = new SomethingWithList(); appender.Store(null, new object[] { ev }); var ev2 = new SomethingWithNestedIList { B = new Dictionary <ulong, IList <string> > { { 1, new List <string> { "a1" } } } }; appender.Store(null, new object[] { ev2 }); var appender2 = manager.AppendToStore(file); appender2.Store(null, new object[] { ev2 }); manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(SomethingWithList), "Some")); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); reader = manager.OpenReadOnlyStore(file2); reader.ReadFromStartToEnd(eventObserver); }
public void SkipListOnUpgrade() { var manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(UserEventList), "UserEvent")); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var userA = new User { Name = "A", Age = 1 }; var userB = new User { Name = "B", Age = 2 }; var userEvent = new UserEventList { Id = 10, List = new List <User> { userA, userB, userA } }; appender.Store(null, new object[] { userEvent }); manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(UserEvent), "UserEvent")); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); var readUserEvent = (UserEvent)eventObserver.Events[0][0]; Assert.Equal(10, readUserEvent.Id); Assert.Null(readUserEvent.User1); }
public void CustomEventIsReadFromSecondSplit() { var manager = new EventStoreManager(); manager.CompressionStrategy = new NoCompressionStrategy(); manager.SetNewTypeNameMapper(new SimplePersonTypeMapper()); var appender = manager.AppendToStore(new MemoryEventFileStorage(4096, 4096)); var first = appender.CurrentFileStorage; var user = new User { Name = "A", Age = 1 }; while (appender.CurrentFileStorage == first) { appender.Store(null, new object[] { user }); } var second = appender.CurrentFileStorage; manager = new EventStoreManager(); manager.CompressionStrategy = new NoCompressionStrategy(); manager.SetNewTypeNameMapper(new SimplePersonTypeMapper()); var reader = manager.OpenReadOnlyStore(second); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); Assert.Equal(new object[] { null }, eventObserver.Metadata); Assert.Equal(new[] { new object[] { user } }, eventObserver.Events); }
public void WhenReadOnlyStoreIsCreatedFromNewEventStoreManagerThenItShouldNotLeakMemory() { var storage = new MemoryEventFileStorage(); var manager = new EventStoreManager(); var appender = manager.AppendToStore(storage); var metadata = new User { Name = "A", Age = 1 }; var events = new object[] { new User { Name = "B", Age = 2 }, new User { Name = "C", Age = 3 } }; appender.Store(metadata, events); appender.FinalizeStore(); manager = new EventStoreManager(); var eventObserver = new StoringEventObserver(); long baselineMemory = 0; for (int i = 0; i <= 10000; i++) { var reader = manager.OpenReadOnlyStore(storage); reader.ReadToEnd(eventObserver); Assert.Single(eventObserver.Events); eventObserver.Events.Clear(); eventObserver.Metadata.Clear(); if (i == 10) { GC.Collect(2); GC.WaitForPendingFinalizers(); GC.Collect(2); baselineMemory = GC.GetTotalMemory(false); } } GC.Collect(2); GC.WaitForPendingFinalizers(); GC.Collect(2); Assert.InRange(GC.GetTotalMemory(false), 0, baselineMemory * 3F); }
public void MoreComplexRepeatedAppendingAndReading() { var manager = new EventStoreManager(); for (var i = 490; i < 520; i += 2) { var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); appender.Store(null, new object[] { new byte[i] }); var eventObserver = new StoringEventObserver(); appender.ReadFromStartToEnd(eventObserver); appender.Store(null, new object[] { new byte[i] }); appender.ReadFromStartToEnd(eventObserver); } }
public void CanWriteEventWithIndexer() { var manager = new EventStoreManager(); var appender = manager.AppendToStore(new MemoryEventFileStorage()); appender.Store(null, new object[] { new SimpleWithIndexer { EvenName = "e", OddName = "o" } }); var eventObserver = new StoringEventObserver(); appender.ReadFromStartToEnd(eventObserver); Assert.Equal(new object[] { null }, eventObserver.Metadata); var ev = eventObserver.Events[0][0] as SimpleWithIndexer; Assert.Equal("o", ev[11]); }
public void CanWriteSimpleEvent() { var manager = new EventStoreManager(); var appender = manager.AppendToStore(new MemoryEventFileStorage()); appender.Store(null, new object[] { 1 }); var eventObserver = new StoringEventObserver(); appender.ReadFromStartToEnd(eventObserver); Assert.Equal(new object[] { null }, eventObserver.Metadata); Assert.Equal(new[] { new object[] { 1 } }, eventObserver.Events); Assert.True(appender.IsKnownAsAppendable()); Assert.False(appender.IsKnownAsCorrupted()); Assert.False(appender.IsKnownAsFinished()); Assert.Equal(10ul, appender.KnownAppendablePosition()); }
public void SupportPureArray() { var manager = new EventStoreManager(); var appender = manager.AppendToStore(new MemoryEventFileStorage()); appender.Store(null, new object[] { new PureArray { A = new[] { "A", "B" }, B = new[] { 42, 7 } } }); var eventObserver = new StoringEventObserver(); appender.ReadFromStartToEnd(eventObserver); Assert.Equal(new object[] { null }, eventObserver.Metadata); var ev = eventObserver.Events[0][0] as PureArray; Assert.Equal(ev.A, new[] { "A", "B" }); Assert.Equal(ev.B, new[] { 42, 7 }); }
public void SupportStrangeVisibilities() { var manager = new EventStoreManager(); var appender = manager.AppendToStore(new MemoryEventFileStorage()); appender.Store(null, new object[] { new StrangeVisibilities { A = "a", C = "c", D = "d" } }); var eventObserver = new StoringEventObserver(); appender.ReadFromStartToEnd(eventObserver); Assert.Equal(new object[] { null }, eventObserver.Metadata); var ev = eventObserver.Events[0][0] as StrangeVisibilities; Assert.Equal("a", ev.A); Assert.Null(ev.B); Assert.Equal("c", ev.C); }
public void CompressionShortensData() { var manager = new EventStoreManager(); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var compressibleData = new byte[20000]; appender.Store(null, new object[] { compressibleData }); Assert.True(2000 > appender.KnownAppendablePosition()); manager = new EventStoreManager(); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); Assert.Equal(new object[] { null }, eventObserver.Metadata); Assert.Equal(new[] { new object[] { compressibleData } }, eventObserver.Events); }
public void Read() { var manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(ClassWithChangedUINTtoULONG), "BTDBTest.EventStoreTest+Credit")); using (var file = new StreamEventFileStorage(new MemoryStream(Convert.FromBase64String(base64EventFile)))) { var appender = manager.AppendToStore(file); var observer = new StoringEventObserver(); appender.ReadFromStartToEnd(observer); Assert.Equal(observer.Events.Count, 1); Assert.Equal(observer.Events[0].Length, 1); var e = observer.Events[0][0] as Ev1; Assert.Equal(e.Credit.A, 1u); Assert.Equal(e.Credit.B, 2u); } }
public void SupportsDataOverMaxBlockSize() { var manager = new EventStoreManager(); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var randomData = new byte[20000]; new Random().NextBytes(randomData); appender.Store(null, new object[] { randomData }); Assert.True(10000 < appender.KnownAppendablePosition()); manager = new EventStoreManager(); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); Assert.Equal(new object[] { null }, eventObserver.Metadata); Assert.Equal(new[] { new object[] { randomData } }, eventObserver.Events); }
public void SkipsIIndirect() { var manager = new EventStoreManager(); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var ev = new EventWithIIndirect { Name = "A", Ind1 = new DBIndirect <User>(), Ind2 = new List <IIndirect <User> >() }; appender.Store(null, new object[] { ev }); manager = new EventStoreManager(); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); }
public void NestedObjectsTest() { var manager = new EventStoreManager(); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var userEvent = new UserEvent { Id = 10, User1 = new User { Name = "A", Age = 1 } }; appender.Store(null, new object[] { userEvent }); manager = new EventStoreManager(); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); Assert.Equal(new object[] { null }, eventObserver.Metadata); Assert.Equal(new[] { new object[] { userEvent } }, eventObserver.Events); }
public void SupportSets() { var manager = new EventStoreManager(); var appender = manager.AppendToStore(new MemoryEventFileStorage()); appender.Store(null, new object[] { new SomeSets { A = new HashSet <string> { "A", "B" }, B = new HashSet <int> { 42, 7 } } }); var eventObserver = new StoringEventObserver(); appender.ReadFromStartToEnd(eventObserver); var ev = eventObserver.Events[0][0] as SomeSets; Assert.Equal(new[] { "A", "B" }, ev !.A.OrderBy(a => a)); Assert.Equal(new[] { 7, 42 }, ev.B.OrderBy(b => b)); }
public void CanWriteSimpleEventAndReadItIndependently() { var manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new SimplePersonTypeMapper()); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var user = new User { Name = "A", Age = 1 }; appender.Store(null, new object[] { user }); manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new SimplePersonTypeMapper()); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); Assert.Equal(new object[] { null }, eventObserver.Metadata); Assert.Equal(new[] { new object[] { user } }, eventObserver.Events); }
public void MixedIListAndList() { var manager = new EventStoreManager(); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var e1 = new SpecificDictIList { Dict = new Dictionary <ulong, IList <ulong> >() }; var e2 = new SpecificList { Ulongs = new List <ulong>() }; appender.Store(null, new object[] { e2 }); appender.Store(null, new object[] { e1 }); manager = new EventStoreManager(); appender = manager.AppendToStore(file); var eventObserver = new StoringEventObserver(); appender.ReadFromStartToEnd(eventObserver); appender.Store(null, new object[] { e1 }); }
public void SupportsDictionaryInDictionary() { var manager = new EventStoreManager(); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var dictInDictEvent = new EventDictionaryInDictionary { DictInDict = new Dictionary <string, IDictionary <string, string> > { { "level-A", new Dictionary <string, string> { { "level-B", "level-C" } } } } }; appender.Store(null, new object[] { dictInDictEvent }); manager = new EventStoreManager(); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); }
public void SameReferenceTest() { var manager = new EventStoreManager(); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var user = new User { Name = "A", Age = 1 }; var userEvent = new UserEvent { Id = 10, User1 = user, User2 = user }; appender.Store(null, new object[] { userEvent }); manager = new EventStoreManager(); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); var readUserEvent = (UserEvent)eventObserver.Events[0][0]; Assert.Same(readUserEvent.User1, readUserEvent.User2); }
public void UpgradeToDifferentEnumProperties() { var manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(ApplicationInfo), "ApplicationInfo")); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var applicationInfo = new ApplicationInfo { Type = ApplicationsType.First }; appender.Store(null, new object[] { applicationInfo }); manager = new EventStoreManager(); manager.SetNewTypeNameMapper(new OverloadableTypeMapper(typeof(ApplicationInfoPropertyEnumTypeChanged), "ApplicationInfo")); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); var readApplicationInfo = (ApplicationInfoPropertyEnumTypeChanged)eventObserver.Events[0][0]; Assert.Equal(readApplicationInfo.Type, ApplicationsRenamedType.First); }
public void CanWriteMultipleEventsWithMetadata() { var manager = new EventStoreManager(); var appender = manager.AppendToStore(new MemoryEventFileStorage()); var metadata = new User { Name = "A", Age = 1 }; var events = new object[] { new User { Name = "B", Age = 2 }, new User { Name = "C", Age = 3 } }; appender.Store(metadata, events); var eventObserver = new StoringEventObserver(); appender.ReadFromStartToEnd(eventObserver); Assert.Equal(new object[] { metadata }, eventObserver.Metadata); Assert.Equal(new[] { events }, eventObserver.Events); }
public void DeserializeErrorInfoWorks() { var manager = new EventStoreManager(); var file = new MemoryEventFileStorage(); var appender = manager.AppendToStore(file); var obj = new ErrorInfo(); obj.PropertyErrors = new Dictionary <string, IList <ErrorInfo> >(); var items = obj.PropertyErrors; items["a"] = new List <ErrorInfo> { new ErrorInfo() }; appender.Store(null, new object[] { obj }); manager = new EventStoreManager(); var reader = manager.OpenReadOnlyStore(file); var eventObserver = new StoringEventObserver(); reader.ReadFromStartToEnd(eventObserver); var readUserEvent = (ErrorInfo)eventObserver.Events[0][0]; Assert.Equal(1, readUserEvent.PropertyErrors.Count); }