public void Test_DecrementOperation()
        {
            const string key = "Test_DecrementOperation";

            //delete key if exists
            var delete = new Delete(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result = IOService.Execute(delete);
            Console.WriteLine("Deleting key {0}: {1}", key, result.Success);

            //increment the key
            var operation = new Increment(key, 1, 1, 0, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result1 = IOService.Execute(operation);
            Assert.IsTrue(result1.Success);
            Assert.AreEqual(result1.Value, 1);

            //key should be 1
            var get = new Get<string>(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result3 = IOService.Execute(get);
            Assert.AreEqual(result1.Value.ToString(CultureInfo.InvariantCulture), result3.Value);

            //decrement the key
            var decrement = new Decrement(key, 1, 1, 0, GetVBucket(), Transcoder, OperationLifespanTimeout);
            var result2 = IOService.Execute(decrement);
            Assert.IsTrue(result2.Success);
            Assert.AreEqual(result2.Value, 0);

            //key should be 0
            get = new Get<string>(key, GetVBucket(), Transcoder, OperationLifespanTimeout);
            result3 = IOService.Execute(get);
            Assert.AreEqual(0.ToString(CultureInfo.InvariantCulture), result3.Value);
        }
Esempio n. 2
0
        public string Visit(Decrement node)
        {
            var st = $"// Start {node.GetType()} \n";

            if (currentFunction != null && globalFunctions[currentFunction].localVariables[node.AnchorToken.Lexeme].isParameter)
            {
                st += "\t\tldarg " + node.AnchorToken.Lexeme + "\n";
            }
            else
            {
                st += "\t\tldloc " + node.AnchorToken.Lexeme + "\n";
            }
            st += VisitChildren(node);
            st += "\t\tldc.i4.1\n";
            st += "\t\tsub.ovf\n";
            if (currentFunction != null && globalFunctions[currentFunction].localVariables[node.AnchorToken.Lexeme].isParameter)
            {
                st += "\t\tstarg " + node.AnchorToken.Lexeme + "\n";
            }
            else
            {
                st += "\t\tstloc " + node.AnchorToken.Lexeme + "\n";
            }
            st += $"// End {node.GetType()} \n";
            return(st);
        }
        public async Task DecrementAsync_With_Delta_ExecutesCorrectOperation()
        {
            // Arrange

            Decrement operation = null;

            var mockRequestExecuter = new Mock <IRequestExecuter>();

            mockRequestExecuter
            .Setup(m => m.SendWithRetryAsync(It.IsAny <Decrement>(), null, null))
            .Callback((IOperation <ulong> op, TaskCompletionSource <IOperationResult <ulong> > tcs, CancellationTokenSource ccs) => operation = (Decrement)op)
            .ReturnsAsync((IOperationResult <ulong>)null);

            // Act

            using (var bucket = new CouchbaseBucket(mockRequestExecuter.Object, _converter, _transcoder))
            {
                bucket.Name = "bucket";

                await bucket.DecrementAsync("key", 2);
            }

            // Assert

            Assert.NotNull(operation);
            Assert.AreEqual(2, operation.Delta);
            Assert.AreEqual(1, operation.Initial);
            Assert.AreEqual("bucket", operation.BucketName);
            Assert.AreEqual(0, operation.Expires);
            Assert.AreEqual(2, operation.Timeout);
        }
Esempio n. 4
0
        public void IncDecIntTest()
        {
            Increment inc = new Increment();
            Decrement dec = new Decrement();

            Assert.AreEqual(_zeroInt, dec.Execute(inc.Execute(_zeroInt)));
        }
Esempio n. 5
0
        public void Test_DecrementOperation()
        {
            const string key = "Test_DecrementOperation";

            //delete key if exists
            var delete = new Delete(key, GetVBucket(), Converter, Transcoder);
            var result = IOStrategy.Execute(delete);

            Console.WriteLine("Deleting key {0}: {1}", key, result.Success);

            //increment the key
            var operation = new Increment(key, 1, 1, 0, GetVBucket(), Converter, Transcoder);
            var result1   = IOStrategy.Execute(operation);

            Assert.IsTrue(result1.Success);
            Assert.AreEqual(result1.Value, 1);

            //key should be 1
            var get     = new Get <string>(key, GetVBucket(), Converter, Transcoder);
            var result3 = IOStrategy.Execute(get);

            Assert.AreEqual(result1.Value.ToString(CultureInfo.InvariantCulture), result3.Value);

            //decrement the key
            var decrement = new Decrement(key, 1, 1, 0, GetVBucket(), Converter, Transcoder);
            var result2   = IOStrategy.Execute(decrement);

            Assert.IsTrue(result2.Success);
            Assert.AreEqual(result2.Value, 0);

            //key should be 0
            get     = new Get <string>(key, GetVBucket(), Converter, Transcoder);
            result3 = IOStrategy.Execute(get);
            Assert.AreEqual(0.ToString(CultureInfo.InvariantCulture), result3.Value);
        }
Esempio n. 6
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            HomePageParams param = (HomePageParams)e.Parameter;

            this._param = param;

            Increment.rx_Tap()
            .Select(x => new MainAction(action: MainAction.Action.Increment))
            .Bind(to: this._param.Dependency._reactor.action)
            .DisposeBag(bag: this.disposeBag);

            Decrement.rx_Tap()
            .Select(x => new MainAction(action: MainAction.Action.Decrement))
            .Bind(to: this._param.Dependency._reactor.action)
            .DisposeBag(bag: this.disposeBag);

            InputText.rx_TextChanged()
            .Select(x => MainAction.Dispatcher(MainAction.Action.didMessage, x))
            .Bind(to: this._param.Dependency._reactor.action)
            .DisposeBag(bag: this.disposeBag);

            this._param.Dependency._reactor.state
            .Select(state => state.Counter.ToString())
            .Bind(to: Indicator.rx_Text())
            .DisposeBag(bag: this.disposeBag);


            this._param.Dependency._reactor.state
            .Select(state => state.Message)
            .Bind(to: MessageIndicator.rx_Text())
            .DisposeBag(bag: this.disposeBag);
        }
        public void Decrement_With_Delta_ExecutesCorrectOperation()
        {
            // Arrange

            Decrement operation = null;

            var mockRequestExecuter = new Mock <IRequestExecuter>();

            mockRequestExecuter
            .Setup(m => m.SendWithRetry(It.IsAny <Decrement>()))
            .Callback((IOperation <ulong> op) => operation = (Decrement)op);

            // Act

            using (var bucket = new CouchbaseBucket(mockRequestExecuter.Object, _converter, _transcoder))
            {
                bucket.Name = "bucket";

                bucket.Decrement("key", 2);
            }

            // Assert

            Assert.NotNull(operation);
            Assert.AreEqual(2, operation.Delta);
            Assert.AreEqual(1, operation.Initial);
            Assert.AreEqual("bucket", operation.BucketName);
            Assert.AreEqual(0, operation.Expires);
            Assert.AreEqual(2, operation.Timeout);
        }
Esempio n. 8
0
        public async Task <ICounterResult> DecrementAsync(string id, DecrementOptions?options = null)
        {
            //sanity check for deferred bootstrapping errors
            _bucket.ThrowIfBootStrapFailed();

            //Get the collection ID
            await PopulateCidAsync().ConfigureAwait(false);

            options ??= DecrementOptions.Default;
            using var rootSpan = RootSpan(OuterRequestSpans.ServiceSpan.Kv.Decrement);
            using var op       = new Decrement(_bucket.Name, id)
                  {
                      Cid             = Cid,
                      CName           = Name,
                      SName           = ScopeName,
                      Delta           = options.DeltaValue,
                      Initial         = options.InitialValue,
                      DurabilityLevel = options.DurabilityLevel,
                      Span            = rootSpan,
                      Expires         = options.ExpiryValue.ToTtl()
                  };
            _operationConfigurator.Configure(op, options);

            using var cts = CreateRetryTimeoutCancellationTokenSource(options, op, out var tokenPair);
            await _bucket.RetryAsync(op, tokenPair).ConfigureAwait(false);

            return(new CounterResult(op.GetValue(), op.Cas, null, op.MutationToken));
        }
Esempio n. 9
0
        protected override BaseExpression Visit(Decrement dec)
        {
            BaseExpression HandleExpression(BaseExpression right)
            {
                switch (right)
                {
                case Variable v:
                    return(new Decrement(v.Name));

                case ConstantNumber n:
                    return(new ConstantNumber(new Subtract(n, new ConstantNumber(1)).StaticEvaluate().Number));

                case ConstantString s:
                    if (s.Value.Length > 0)
                    {
                        return(new ConstantString(s.Value.Substring(0, s.Value.Length - 1)));
                    }
                    else
                    {
                        return(new ErrorExpression());
                    }

                case Bracketed b:
                    return(HandleExpression(b.Parameter));

                default:
                    return(dec);
                }
            }

            var r = Visit(new Variable(dec.Name));

            return(HandleExpression(r));
        }
Esempio n. 10
0
        [NotNull] protected virtual BaseExpression Visit([NotNull] Decrement dec)
        {
            var v = Visit(new Variable(dec.Name));
            var r = (Variable)v;

            return(new Decrement(r.Name));
        }
Esempio n. 11
0
 //check
 public string Visit(Decrement node)
 {
     return
         (putS(Indentar() + "ldloc '" + node.AnchorToken.Lexeme + "'") +
          putS(Indentar() + "ldc.i4.1") +
          putS(Indentar() + "sub") +
          putS(Indentar() + "stloc '" + node.AnchorToken.Lexeme + "'"));
 }
Esempio n. 12
0
        }        //100%

        public string Visit(Decrement node)
        {
            return
                (Line(Indent() + "ldloc '" + node.AnchorToken.Lexeme + "'") +
                 Line(Indent() + "ldc.i4.1") +
                 Line(Indent() + "sub") +
                 Line(Indent() + "stloc '" + node.AnchorToken.Lexeme + "'"));
        }        //100%
Esempio n. 13
0
        public void DecrementIntTest()
        {
            Decrement op = new Decrement();

            Assert.AreEqual(_zeroInt, op.Execute(_oneInt));
            Assert.AreEqual(_minusOneInt, op.Execute(_zeroInt));

            Assert.AreEqual(_zeroInt, op.Execute(op.Execute(_twoInt)));
        }
        public void When_Cloned_Expires_Is_Copied()
        {
            var op = new Decrement("key", 1, 1, 10, null, new DefaultTranscoder(), 1000);

            Assert.AreEqual(10, op.Expires);
            var cloned = op.Clone() as Decrement;

            Assert.AreEqual(10, cloned.Expires);
        }
Esempio n. 15
0
        public Node Decrement()
        {
            var n1 = new Decrement()
            {
                AnchorToken = Expect(TokenType.DECR)
            };

            return(n1);
        }
        public void Visit(Decrement node)
        {
            var lexeme = node.AnchorToken.Value;

            if (!Variables.Contains(lexeme, Scope) && !Variables.Contains(lexeme))
            {
                throw new SemanticError("Variable '" + lexeme + "' not declared!", node.AnchorToken);
            }
        }
Esempio n. 17
0
        public void UnaryDecrementTest()
        {
            Decrement op = new Decrement();

            Assert.AreEqual(zeroInt, new UnaryStatement(op, oneIntn).Evaluate(varTable));
            Assert.AreEqual(minusOneInt, new UnaryStatement(op, zeroIntn).Evaluate(varTable));

            Assert.AreEqual(zeroInt, new UnaryStatement(op, new TemporaryVariable(ref varTable, new UnaryStatement(op, twoIntn).Evaluate(varTable))).Evaluate(varTable));
        }
Esempio n. 18
0
        public string Visit(Decrement node)
        {
            var id     = node.AnchorToken.Value;
            var result = loadVariable(id);

            result += "\t\tldc.i4 1\n";
            result += "\t\tsub.ovf\n";
            result += "\t\t" + getVariableType(id) + "\n";
            return(result);
        }
        /// <summary>
        /// Decrements the value of a key by the delta. If the key doesn't exist, it will be created
        /// and seeded with the defaut initial value 1.
        /// </summary>
        /// <param name="key">The key to us for the counter.</param>
        /// <param name="delta">The number to increment the key by.</param>
        /// <param name="initial">The initial value to use. If the key doesn't exist, this value will returned.</param>
        /// <param name="expiration">The time-to-live (ttl) for the counter in seconds.</param>
        /// <returns>If the key doesn't exist, the server will respond with the initial value. If not the decremented value will be returned.</returns>
        public IOperationResult <ulong> Decrement(string key, ulong delta, ulong initial, uint expiration)
        {
            var keyMapper = _configInfo.GetKeyMapper(Name);
            var bucket    = keyMapper.MapKey(key);
            var server    = bucket.LocatePrimary();

            var operation       = new Decrement(key, initial, delta, expiration, null, _converter, _serializer);
            var operationResult = server.Send(operation);

            return(operationResult);
        }
        public Node StmtDecr(Token id)
        {
            var decrement = new Decrement()
            {
                AnchorToken = id
            };

            Expect(TokenCategory.DECREMENT);
            Expect(TokenCategory.SEMICOLON);
            return(decrement);
        }
Esempio n. 21
0
            protected override BaseExpression Visit(Decrement dec)
            {
                var t = _types.TypeOf(dec.Name);

                if (t != Execution.Type.Number)
                {
                    return(base.Visit(dec));
                }
                else
                {
                    return(new Subtract(new Variable(dec.Name), new ConstantNumber((Number)1)));
                }
            }
Esempio n. 22
0
        public void Visit(Decrement node)
        {
            var variableName = node.AnchorToken.Lexeme;

            if (!Functions.getLocalFT(currentFunc).Contains(variableName) &&
                !GlobalSymbols.Contains(variableName))
            {
                throw new SemanticError(
                          "Unknown Variable: " + variableName,
                          node.AnchorToken);
            }
            return;
        }
 public void Test_Clone()
 {
     var operation = new Decrement("key", 1, 1, 0, GetVBucket(), Transcoder, OperationLifespanTimeout)
     {
         Cas = 1123
     };
     var cloned = operation.Clone();
     Assert.AreEqual(operation.CreationTime, cloned.CreationTime);
     Assert.AreEqual(operation.Cas, cloned.Cas);
     Assert.AreEqual(operation.VBucket.Index, cloned.VBucket.Index);
     Assert.AreEqual(operation.Key, cloned.Key);
     Assert.AreEqual(operation.Opaque, cloned.Opaque);
 }
Esempio n. 24
0
        public void Test_Clone()
        {
            var operation = new Decrement("key", 1, 1, 0, GetVBucket(), Converter, Transcoder)
            {
                Cas = 1123
            };
            var cloned = operation.Clone();

            Assert.AreEqual(operation.CreationTime, cloned.CreationTime);
            Assert.AreEqual(operation.Cas, cloned.Cas);
            Assert.AreEqual(operation.VBucket.Index, cloned.VBucket.Index);
            Assert.AreEqual(operation.Key, cloned.Key);
            Assert.AreEqual(operation.Opaque, cloned.Opaque);
        }
        /// <summary>
        /// Decrements the value of a key by the delta. If the key doesn't exist, it will be created
        /// and seeded with the defaut initial value 1.
        /// </summary>
        /// <param name="key">The key to us for the counter.</param>
        /// <param name="delta">The number to increment the key by.</param>
        /// <param name="initial">The initial value to use. If the key doesn't exist, this value will returned.</param>
        /// <param name="expiration">The time-to-live (ttl) for the counter in seconds.</param>
        /// <returns>If the key doesn't exist, the server will respond with the initial value. If not the decremented value will be returned.</returns>
        public IOperationResult <ulong> Decrement(string key, ulong delta, ulong initial, uint expiration)
        {
            IVBucket vBucket;
            var      server = GetServer(key, out vBucket);

            var operation       = new Decrement(key, initial, delta, expiration, vBucket, _converter, _serializer);
            var operationResult = server.Send(operation);

            if (CheckForConfigUpdates(operationResult))
            {
                Log.Info(m => m("Requires retry {0}", key));
            }
            return(operationResult);
        }
        public async Task <ICounterResult> DecrementAsync(string id, DecrementOptions options)
        {
            using (var op = new Decrement
            {
                Cid = Cid,
                Key = id,
                Delta = options.Delta,
                Initial = options.Initial,
                DurabilityLevel = options.DurabilityLevel
            })
            {
                await ExecuteOp(op, options.Token, options.Timeout);

                return(new CounterResult(op.GetValue(), op.Cas, null, op.MutationToken));
            }
        }
Esempio n. 27
0
        private void PerformDecrementAction()
        {
            if (Decrement == null || Decrement.Trim().Equals(""))
            {
                return;
            }

            var GameLogic = getGameLogic();

            if (GameLogic == null)
            {
                return;
            }

            GameLogic.DecrementCounter(Decrement);
        }
        public async Task <ICounterResult> DecrementAsync(string id, DecrementOptions options = null)
        {
            options = options ?? new DecrementOptions();
            using (var op = new Decrement
            {
                Cid = Cid,
                Key = id,
                Delta = options.Delta,
                Initial = options.Initial,
                DurabilityLevel = options.DurabilityLevel,
                Transcoder = _transcoder
            })
            {
                await _bucket.SendAsync(op, options.Token, options.Timeout);

                return(new CounterResult(op.GetValue(), op.Cas, null, op.MutationToken));
            }
        }
        public async Task <ICounterResult> DecrementAsync(string id, DecrementOptions?options = null)
        {
            //sanity check for deferred bootstrapping errors
            _bucket.ThrowIfBootStrapFailed();

            options ??= new DecrementOptions();
            using var op = new Decrement(_bucket.Name, id)
                  {
                      Cid             = Cid,
                      Delta           = options.DeltaValue,
                      Initial         = options.InitialValue,
                      DurabilityLevel = options.DurabilityLevel,
                      Transcoder      = _transcoder
                  };
            await _bucket.SendAsync(op, options.TokenValue, options.TimeoutValue).ConfigureAwait(false);

            return(new CounterResult(op.GetValue(), op.Cas, null, op.MutationToken));
        }
Esempio n. 30
0
 public virtual TResult Visit(BaseExpression expression)
 {
     return(expression switch {
         Phi a => Visit(a),
         Increment a => Visit(a),
         Decrement a => Visit(a),
         ErrorExpression a => Visit(a),
         Bracketed a => Visit(a),
         Abs a => Visit(a),
         Sqrt a => Visit(a),
         Sine a => Visit(a),
         Cosine a => Visit(a),
         Tangent a => Visit(a),
         ArcSine a => Visit(a),
         ArcCos a => Visit(a),
         ArcTan a => Visit(a),
         PostIncrement a => Visit(a),
         PreIncrement a => Visit(a),
         PostDecrement a => Visit(a),
         PreDecrement a => Visit(a),
         Add a => Visit(a),
         Subtract a => Visit(a),
         Multiply a => Visit(a),
         Divide a => Visit(a),
         Modulo a => Visit(a),
         Negate a => Visit(a),
         Exponent a => Visit(a),
         Or a => Visit(a),
         And a => Visit(a),
         Not a => Visit(a),
         Factorial a => Visit(a),
         Variable a => Visit(a),
         ConstantNumber a => Visit(a),
         ConstantString a => Visit(a),
         EqualTo a => Visit(a),
         NotEqualTo a => Visit(a),
         GreaterThan a => Visit(a),
         GreaterThanEqualTo a => Visit(a),
         LessThan a => Visit(a),
         LessThanEqualTo a => Visit(a),
         _ => VisitUnknown(expression)
     });
Esempio n. 31
0
 public override IOperation Clone()
 {
     var cloned = new Decrement
     {
         Key = Key,
         Content = Content,
         Transcoder = Transcoder,
         VBucketId = VBucketId,
         Opaque = Opaque,
         Initial = Initial,
         Delta = Delta,
         Attempts = Attempts,
         Cas = Cas,
         CreationTime = CreationTime,
         MutationToken = MutationToken,
         LastConfigRevisionTried = LastConfigRevisionTried,
         BucketName = BucketName,
         ErrorCode = ErrorCode,
         Expires = Expires
     };
     return cloned;
 }
 public CounterViewModel()
 {
     title.Value  = "last value: ---";
     Title        = title.ToReadOnlyReactiveProperty();
     CounterValue = counter
                    .ObserveProperty(x => x.Value)
                    .Select(x => x.ToString())
                    .ToReadOnlyReactiveProperty();
     Increment.Subscribe(_ => counter.Increment());
     Decrement.Subscribe(_ => counter.Decrement());
     Reset.Subscribe(async _ =>
     {
         // Async Sample
         var count = await Task.Run(() =>
         {
             Task.Delay(1500).Wait();
             return(CounterValue.Value);
         });
         title.Value = $"last value: {count}";
         counter.Reset();
     });
 }
Esempio n. 33
0
    private void Init()
    {
        _glSerialisable = new GameLogicSerialisable();

        Counter = 0;

        _default   = new Default( );
        _increment = new Increment( );
        _decrement = new Decrement( );
    }
Esempio n. 34
0
 public virtual void VisitDecrement(Decrement n)
 {
 }