public void TryAddTest()
        {
            TryAddTestFunctions functions = new();

            using var session = fht.For(functions).NewSession <TryAddTestFunctions>();

            Status status;
            var    key    = 1;
            var    value1 = new RMWValue {
                value = 1
            };
            var value2 = new RMWValue {
                value = 2
            };

            functions.noNeedInitialUpdater = true;
            status = session.RMW(ref key, ref value1); // needInitialUpdater false + NOTFOUND
            Assert.IsFalse(status.Found, status.ToString());
            Assert.IsFalse(value1.flag);               // InitialUpdater is not called
            functions.noNeedInitialUpdater = false;

            status = session.RMW(ref key, ref value1); // InitialUpdater + NotFound
            Assert.IsFalse(status.Found, status.ToString());
            Assert.IsTrue(value1.flag);                // InitialUpdater is called

            status = session.RMW(ref key, ref value2); // InPlaceUpdater + Found
            Assert.IsTrue(status.Record.InPlaceUpdated, status.ToString());

            fht.Log.Flush(true);
            status = session.RMW(ref key, ref value2); // NeedCopyUpdate returns false, so RMW returns simply Found
            Assert.IsTrue(status.Found, status.ToString());

            fht.Log.FlushAndEvict(true);
            status = session.RMW(ref key, ref value2, new(StatusCode.Found), 0); // PENDING + NeedCopyUpdate + Found
            Assert.IsTrue(status.IsPending, status.ToString());
            session.CompletePendingWithOutputs(out var outputs, true);

            var output = new RMWValue();

            (status, output) = GetSinglePendingResult(outputs);
            Assert.IsTrue(status.Found, status.ToString()); // NeedCopyUpdate returns false, so RMW returns simply Found

            // Test stored value. Should be value1
            status = session.Read(ref key, ref value1, ref output, new(StatusCode.Found), 0);
            Assert.IsTrue(status.IsPending, status.ToString());
            session.CompletePending(true);

            status = session.Delete(ref key);
            Assert.IsTrue(!status.Found && status.Record.Created, status.ToString());
            session.CompletePending(true);
            fht.Log.FlushAndEvict(true);
            status = session.RMW(ref key, ref value2, new(StatusCode.NotFound | StatusCode.CreatedRecord), 0); // PENDING + InitialUpdater + NOTFOUND
            Assert.IsTrue(status.IsPending, status.ToString());
            session.CompletePending(true);
        }
Example #2
0
        public void TryAddTest()
        {
            using var session = fht.For(new TryAddTestFunctions()).NewSession <TryAddTestFunctions>();

            Status status;
            var    key    = 1;
            var    value1 = new RMWValue {
                value = 1
            };
            var value2 = new RMWValue {
                value = 2
            };

            status = session.RMW(ref key, ref value1); // InitialUpdater + NOTFOUND
            Assert.IsTrue(status == Status.NOTFOUND);
            Assert.IsTrue(value1.flag);                // InitialUpdater is called

            status = session.RMW(ref key, ref value2); // InPlaceUpdater + OK
            Assert.IsTrue(status == Status.OK);

            fht.Log.Flush(true);
            status = session.RMW(ref key, ref value2); // NeedCopyUpdate + OK
            Assert.IsTrue(status == Status.OK);

            fht.Log.FlushAndEvict(true);
            status = session.RMW(ref key, ref value2, Status.OK, 0); // PENDING + NeedCopyUpdate + OK
            Assert.IsTrue(status == Status.PENDING);
            session.CompletePending(true);

            // Test stored value. Should be value1
            var output = new RMWValue();

            status = session.Read(ref key, ref value1, ref output, Status.OK, 0);
            Assert.IsTrue(status == Status.PENDING);
            session.CompletePending(true);

            status = session.Delete(ref key);
            Assert.IsTrue(status == Status.OK);
            session.CompletePending(true);
            fht.Log.FlushAndEvict(true);
            status = session.RMW(ref key, ref value2, Status.NOTFOUND, 0); // PENDING + InitialUpdater + NOTFOUND
            Assert.IsTrue(status == Status.PENDING);
            session.CompletePending(true);
        }