public void StatefulOperator_Versioning_NotSupportedByDefault() { var o = Observer.Create <int>(_ => { }, _ => Assert.Fail(), () => Assert.Fail()); var state = new MockOperatorStateContainer(); var writerFactory = state.CreateWriter(); var readerFactory = state.CreateReader(); var mo = new MyOperator(o) { State = 42 }; mo.Start(); var writer = writerFactory.Create(mo); Assert.ThrowsException <NotSupportedException>(() => mo.SaveState(writer, new Version(2, 0, 0, 0))); var mor = new MyOperator(o); var reader = readerFactory.Create(mor); Assert.ThrowsException <NotSupportedException>(() => mor.LoadState(reader, new Version(2, 0, 0, 0))); }
public void StatefulOperator_State() { var o = Observer.Create <int>(_ => { }, _ => Assert.Fail(), () => Assert.Fail()); var state = new MockOperatorStateContainer(); var writerFactory = state.CreateWriter(); var readerFactory = state.CreateReader(); var mo = new MyOperator(o) { State = 42 }; mo.Start(); Assert.IsTrue(mo.Started); Assert.IsTrue(mo.StateChanged); Assert.ThrowsException <ArgumentNullException>(() => mo.SaveState(null, mo.Version)); var writer = writerFactory.Create(mo); mo.SaveState(writer, mo.Version); Assert.IsTrue(mo.StateChanged); mo.OnStateSaved(); Assert.IsFalse(mo.StateChanged); var mor = new MyOperator(o); var reader = readerFactory.Create(mor); Assert.ThrowsException <ArgumentNullException>(() => mor.LoadState(null, mor.Version)); mor.LoadState(reader, mor.Version); mor.Start(); Assert.IsTrue(mor.Started); Assert.AreEqual(42, mor.State); mo.State = 43; Assert.IsTrue(mo.StateChanged); writer = writerFactory.Create(mo); mo.SaveState(writer, mo.Version); mo.OnStateSaved(); Assert.IsFalse(mo.StateChanged); var moq = new MyOperator(o); reader = readerFactory.Create(moq); moq.LoadState(reader, moq.Version); moq.Start(); Assert.IsTrue(moq.Started); Assert.AreEqual(43, moq.State); mo.Dispose(); Assert.IsTrue(mo.Disposed); writer = writerFactory.Create(mo); mo.SaveState(writer, mo.Version); mo.OnStateSaved(); var mop = new MyOperator(o); reader = readerFactory.Create(mop); mop.LoadState(reader, mop.Version); mop.Start(); Assert.IsTrue(mop.Disposed); Assert.IsFalse(mop.Started); }