Example #1
0
        public void LoggingStateWriter_Errors()
        {
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                using var w      = new MyWriter { Throw = true };
                using var writer = new LoggingStateWriter(w, sw);

                Assert.ThrowsException <NotImplementedException>(() => _ = writer.GetItemWriter("bar", "foo"));
                Assert.ThrowsException <NotImplementedException>(() => writer.DeleteItem("bar", "foo"));
                Assert.ThrowsException <NotImplementedException>(() => writer.Rollback());
                Assert.ThrowsException <NotImplementedException>(() => writer.CommitAsync().GetAwaiter().GetResult());
                Assert.ThrowsException <NotImplementedException>(() => writer.Dispose());

                w.Throw = false;
            }

            var log = sb.ToString();

            foreach (var entry in new[]
            {
                "GetItemWriter(bar, foo)/Start",
                "GetItemWriter(bar, foo)/Error",
                "GetItemWriter(bar, foo)/Stop",

                "DeleteItem(bar, foo)/Start",
                "DeleteItem(bar, foo)/Error",
                "DeleteItem(bar, foo)/Stop",

                "Rollback()/Start",
                "Rollback()/Error",
                "Rollback()/Stop",

                "CommitAsync()/Start",
                "CommitAsync()/Error",
                "CommitAsync()/Stop",

                "Dispose()/Start",
                "Dispose()/Error",
                "Dispose()/Stop",
            })
            {
                Assert.IsTrue(log.Contains(entry), "Not found: '" + entry + "'");
            }
        }
Example #2
0
        public void LoggingStateWriter_Basics()
        {
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                using var w      = new MyWriter();
                using var writer = new LoggingStateWriter(w, sw);

                Assert.AreEqual(CheckpointKind.Full, writer.CheckpointKind);

                var s = writer.GetItemWriter("bar", "foo");
                Assert.IsNotNull(s);

                writer.DeleteItem("bar", "foo");

                writer.Rollback();

                writer.CommitAsync().Wait();
            }

            var log = sb.ToString();

            foreach (var entry in new[]
            {
                "GetItemWriter(bar, foo)/Start",
                "GetItemWriter(bar, foo)/Stop",

                "DeleteItem(bar, foo)/Start",
                "DeleteItem(bar, foo)/Stop",

                "Rollback()/Start",
                "Rollback()/Stop",

                "CommitAsync()/Start",
                "CommitAsync()/Stop",

                "Dispose()/Start",
                "Dispose()/Stop",
            })
            {
                Assert.IsTrue(log.Contains(entry), "Not found: '" + entry + "'");
            }
        }
Example #3
0
            public StateWriterOperation[] SaveSpace(bool differential)
            {
                //
                // NB: Full checkpoints only make sense to be applied to an empty store.
                //

                if (!differential)
                {
                    Store.Data.Clear();
                }

                using var writer = new StateWriter(Store, differential ? CheckpointKind.Differential : CheckpointKind.Full);
                using var logger = new LoggingStateWriter(writer, TextWriter.Null);

                Space.Save(logger);

                logger.CommitAsync().GetAwaiter().GetResult();

                Space.OnSaved();

                return(writer.GetLog());
            }