public void CouldOpenStateTable()
        {
            var path       = TestUtils.GetPath();
            var stateTable = new StreamLogStateStorage(path);

            stateTable.Dispose();
        }
        public void CouldAcquirePackerLock()
        {
            var path = TestUtils.GetPath();

            ProcessConfig.Init(path);
            var streamId = 42;

            StartupConfig.PackerTimeoutSeconds = 0.1;

            var stateTable = new StreamLogStateStorage(path);
            var state      = stateTable.GetState((StreamLogId)streamId);

            var pl  = state.AcquirePackerLock();
            var pl1 = state.AcquirePackerLock();

            Assert.IsTrue(pl > 0);
            Assert.IsTrue(pl1 == 0);

            var pl2 = state.AcquirePackerLock(pl);

            Assert.IsTrue(pl2 > pl);

            Thread.Sleep(200);

            var pl3 = state.AcquirePackerLock();
            var pl4 = state.AcquirePackerLock();

            Assert.IsTrue(pl3 > 0);
            Assert.IsTrue(pl4 == 0);

            stateTable.Dispose();
        }
        public void CouldOpenSharedState()
        {
            var path = TestUtils.GetPath();

            var stateTable = new StreamLogStateStorage(path);

            stateTable.SharedState.SetWalPosition(123);

            var position = stateTable.SharedState.GetWalPosition();

            Assert.AreEqual(123, position);

            stateTable.Dispose();
        }
        public void CouldCreateStreamStateView()
        {
            var path = TestUtils.GetPath();

            var stateTable = new StreamLogStateStorage(path);

            Console.WriteLine($"Used size before 1: {stateTable.UsedSize}");
            var view0 = stateTable.GetState((StreamLogId)1);

            Console.WriteLine($"Used size after 1: {stateTable.UsedSize}");

            var view1 = stateTable.GetState((StreamLogId)2);

            Console.WriteLine($"Used size after 2: {stateTable.UsedSize}");

            Console.WriteLine($"0 - 1 Pointer diff: {view1.StatePointer.ToInt64() - view0.StatePointer.ToInt64()}");

            var view1023 = stateTable.GetState((StreamLogId)1023);

            Console.WriteLine($"Used size after 1023: {stateTable.UsedSize}");

            Console.WriteLine($"1 - 1024 Pointer diff: {view1023.StatePointer.ToInt64() - view0.StatePointer.ToInt64()}");

            var view1024 = stateTable.GetState((StreamLogId)1024);

            Console.WriteLine($"Used size after 1024: {stateTable.UsedSize}");

            Console.WriteLine($"1 - 1024 Pointer diff: {view1024.StatePointer.ToInt64() - view0.StatePointer.ToInt64()}");

            var viewN1 = stateTable.GetState((StreamLogId)(-1));

            Console.WriteLine($"Used size after -1: {stateTable.UsedSize}");

            var viewN2 = stateTable.GetState((StreamLogId)(-2));

            Console.WriteLine($"Used size after -2: {stateTable.UsedSize}");

            Console.WriteLine($"-2 - -1 Pointer diff: {viewN2.StatePointer.ToInt64() - viewN1.StatePointer.ToInt64()}");

            stateTable.Dispose();
        }