Beispiel #1
0
        public void CanRead()
        {
            SpaceProxy.AddRange(_testTupleType, new[] { _tuple10, _tuple20 });
            SpaceTuple result = null;

            // instant read
            SpaceProxy.Read(_tuple1Q, r => result = r);
            Assert.Equal(_tuple10, result);
            result = null;
            SpaceProxy.Read(_tuple1Q, r => result = r);
            Assert.Equal(_tuple10, result);

            result = SpaceProxy.TryTake(_tuple1Q);
            Assert.Equal(_tuple10, result);
            result = null;
            SpaceProxy.Read(_tuple1Q, r => result = r);
            Assert.Null(result);
            SpaceProxy.Add(_testTupleType, _tuple10);
            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.Equal(_tuple10, result);
            SpaceProxy.Add(_testTupleType, _tuple11);
            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.Equal(_tuple10, result);


            Assert.Equal(_tuple11, SpaceProxy.TryTake(new SpaceTupleQuery(1, 1)));
            Assert.Equal(_tuple10, SpaceProxy.TryTake(new SpaceTupleQuery(1, 0)));

            result = _tuple00;
            var cancel = SpaceProxy.Read(new SpaceTupleQuery(1, null), r => result = r);

            Assert.Equal(_tuple00, result);
            // cancel read
            cancel.Dispose();
            Assert.Null(result);

            SpaceProxy.Add(_testTupleType, _tuple10);
            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.Null(result);
        }
Beispiel #2
0
        public void CanTake()
        {
            SpaceProxy.AddRange(_testTupleType, new[] { _tuple10, _tuple20 });
            SpaceTuple result = null;

            // instant take
            SpaceProxy.Take(_tuple1Q, r => result = r);
            Assert.Equal(_tuple10, result);

            // wait take
            result = null;
            SpaceProxy.Take(_tuple1Q, r => result = r);
            Assert.Null(result);
            SpaceProxy.Add(_testTupleType, _tuple10);
            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.Equal(_tuple10, result);
            // wait take only once
            SpaceProxy.Add(_testTupleType, _tuple11);


            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.Equal(_tuple10, result);
            SpaceProxy.Take(_tuple1Q, r => result = r);
            Assert.Equal(_tuple11, result);

            result = _tuple00;
            var cancel = SpaceProxy.Take(_tuple1Q, r => result = r);

            Assert.Equal(_tuple00, result);
            // cancel take
            cancel.Dispose();
            Assert.Null(result);

            SpaceProxy.Add(_testTupleType, _tuple10);
            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.Null(result);

            // check that tuple was not taken
            Assert.Equal(_tuple10, SpaceProxy.TryRead(_tuple1Q));
        }
Beispiel #3
0
        private void CanAddInNestedTransactions(bool commitNested, bool commitTrans)
        {
            var cleanProxy = Space.CreateProxy();

            SpaceProxy.BeginTransaction();
            {
                SpaceTuple trans10Result = null;
                SpaceProxy.Read(_tuple1Q, x => trans10Result = x);

                SpaceTuple trans20Result = null;
                SpaceProxy.Read(_tuple2Q, x => trans20Result = x);
                SpaceProxy.BeginTransaction();
                {
                    SpaceProxy.Add(_testTupleType, _tuple10);
                    // space should not see it
                    Assert.Null(cleanProxy.TryRead(_tuple1Q));
                    // trans should not see it
                    Assert.Null(trans10Result);
                    // nested should see it
                    Assert.Equal(_tuple10, SpaceProxy.TryRead(_tuple1Q));

                    SpaceTuple nestedResult = null;
                    SpaceProxy.Read(_tuple2Q, x => nestedResult = x);
                    SpaceProxy.BeginTransaction();
                    {
                        // nested2 should see it
                        Assert.Equal(_tuple10, SpaceProxy.TryRead(_tuple1Q));

                        // add in nested 2
                        SpaceProxy.Add(_testTupleType, _tuple20);

                        // space should not see it
                        Assert.Null(cleanProxy.TryRead(_tuple2Q));
                        // trans should not see it
                        Assert.Null(trans20Result);
                        // nested should not see it
                        Assert.Null(nestedResult);
                        // nested2 should see it
                        Assert.Equal(_tuple20, SpaceProxy.TryRead(_tuple2Q));

                        SpaceProxy.CommitTransaction();
                    }
                    // space should not see it
                    Assert.Null(cleanProxy.TryRead(_tuple2Q));
                    // trans should not see it
                    Assert.Null(trans20Result);
                    // nested should see it
                    // ReSharper disable once ExpressionIsAlwaysNull
                    Assert.Equal(_tuple20, nestedResult);
                    if (commitNested)
                    {
                        SpaceProxy.CommitTransaction();
                    }
                    else
                    {
                        SpaceProxy.RollbackTransaction();
                    }
                }
                // space should not see both
                Assert.Null(cleanProxy.TryRead(_tuple1Q));
                Assert.Null(cleanProxy.TryRead(_tuple2Q));
                if (commitNested)
                {
                    // trans should see both
                    Assert.Equal(_tuple10, trans10Result);
                    Assert.Equal(_tuple20, trans20Result);
                }
                else
                {
                    // trans should not see both
                    Assert.Null(trans10Result);
                    Assert.Null(trans20Result);
                }

                if (commitTrans)
                {
                    SpaceProxy.CommitTransaction();
                }
                else
                {
                    SpaceProxy.RollbackTransaction();
                }

                if (commitTrans && commitNested)
                {
                    // now space should see both
                    Assert.Equal(_tuple10, cleanProxy.TryRead(_tuple1Q));
                    Assert.Equal(_tuple20, cleanProxy.TryRead(_tuple2Q));
                }
                else
                {
                    // space still should not see both
                    Assert.Null(cleanProxy.TryRead(_tuple1Q));
                    Assert.Null(cleanProxy.TryRead(_tuple2Q));
                }
            }
        }