public void TestGet()
        {
            var operation = new GetOperation<string>(Key, _vBucket);

            var buffer = operation.CreateBuffer();
            Assert.AreEqual(buffer.Count, 4);

            IConnection connection = null;
            try
            {
                connection = _connectionPool.Acquire();
                SocketError error;
                connection.Handle.Send(buffer, SocketFlags.None, out error);
                Assert.AreEqual(SocketError.Success, error);

                operation.Header = ReadHeader(connection);
                if (operation.Header.HasData())
                {
                    operation.Body = ReadBody(connection, operation.Header);
                    var operationResult = operation.GetResult();
                    Console.WriteLine(operationResult.Message);
                    Console.WriteLine(operationResult.Value);
                }
            }
            finally
            {
                _connectionPool.Release(connection);
            }
        }
        public void _When_Get_Is_Called_With_Invalid_Key_What_Happens()
        {
            const string keyThatDoesNotExist = "barfkey3";
            var operation = new GetOperation<string>(keyThatDoesNotExist, _vBucket);
            var buffer = operation.CreateBuffer();
            Assert.AreEqual(buffer.Count, 4);

            IConnection connection = null;
            try
            {
                connection = _connectionPool.Acquire();
                SocketError error;
                connection.Handle.Send(buffer, SocketFlags.None, out error);
                Assert.AreEqual(SocketError.Success, error);

                operation.Header = ReadHeader(connection);
                if (operation.Header.HasData())
                {
                    operation.Body = ReadBody(connection, operation.Header);
                    var result = operation.GetResult();
                    Console.WriteLine(result.Message);
                    Console.WriteLine(result.Value);
                }
            }
            finally
            {
                _connectionPool.Release(connection);
            }
        }
 public void TestSend()
 {
     _vBucket = _state.GetVBucket(Key);
     var operation = new GetOperation<string>(Key, _vBucket);
     var result = _ioStrategy.Execute(operation);
   
     Console.WriteLine(result.Value);
 }
 public async void TestSendAsync()
 {
     Console.WriteLine("Start thread: {0}", Thread.CurrentThread.ManagedThreadId);
     _vBucket = _state.GetVBucket(Key);
     var operation = new GetOperation<string>(Key, _vBucket);
     var result = await _ioStrategy.ExecuteAsync(operation);
     Assert.IsNotNullOrEmpty(result.Value);
     Console.WriteLine("Result for key '{0}' is '{1}'", operation.Key, result.Value);
 }
        public void Test_GetOperation()
        {
            var operation = new GetOperation<string>(Key, _vBucket);
            var operationResult = _ioStrategy.Execute(operation);

            Assert.IsTrue(operationResult.Success);
            Assert.AreEqual(operationResult.Status, ResponseStatus.Success);
            Assert.AreEqual(Value, operationResult.Value);
            Assert.IsEmpty(operationResult.Message);
            Console.WriteLine(operationResult.Value);
        }
        public void Test_GetOperation_Int32()
        {
            const string key = "MyInt32";
            const int value = 100;

            var operation = new GetOperation<int>(key, _vBucket);
            var operationResult = _ioStrategy.Execute(operation);

            Assert.IsTrue(operationResult.Success);
            Assert.AreEqual(operationResult.Status, ResponseStatus.Success);
            Assert.AreEqual(value, operationResult.Value);
            Assert.IsEmpty(operationResult.Message);
            Console.WriteLine(operationResult.Value);
        }
Exemplo n.º 7
0
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec codec = new Codec();
            Serializer s = new DefaultSerializer();

            // byte[] key = s.serialize("11");

            byte[] key = s.serialize("key10");
            //byte[] key= UTF8Encoding.UTF8.GetBytes("key10");

            GetOperation target = new GetOperation(codec, key, null, 0, null);
            Transport transport = trans;
            string expected = "hexachlorocyclohexane 777";
            byte[] actual;
            actual = target.executeOperation(transport);
            string res = (string)(s.deserialize(actual));

            Assert.AreEqual(expected, res);
        }
        /// <summary>
        /// Gets the Node configuration from "config get cluster" if it's new or "get AmazonElastiCache:cluster" if it's older than
        /// 1.4.14
        /// </summary>
        /// <returns>A string in the format "hostname1|ip1|port1 hostname2|ip2|port2 ..."</returns>
        internal string GetNodeConfig()
        {
            var    tries       = this.tries;
            var    nodeVersion = this.GetNodeVersion();
            var    older       = new Version("1.4.14");
            var    waiting     = true;
            string message     = "";

            string[] items = null;

            IGetOperation command = nodeVersion.CompareTo(older) < 0 ?
                                    command                     = new GetOperation("AmazonElastiCache:cluster") :
                                                        command = new ConfigGetOperation("cluster");

            while (waiting && tries > 0)
            {
                tries--;
                try
                {
                    lock (nodesLock)
                    {
                        // This avoids timing out from requesting the config from the endpoint
                        foreach (var node in this.nodes.ToArray())
                        {
                            try
                            {
                                var result = node.Execute(command);

                                if (result.Success)
                                {
                                    var configCommand = command as IConfigOperation;
                                    items   = Encoding.UTF8.GetString(configCommand.ConfigResult.Data.Array, configCommand.ConfigResult.Data.Offset, configCommand.ConfigResult.Data.Count).Split('\n');
                                    waiting = false;
                                    break;
                                }
                                else
                                {
                                    message = result.Message;
                                }
                            }
                            catch (Exception ex)
                            {
                                message = ex.Message;
                            }
                        }
                    }

                    if (waiting)
                    {
                        System.Threading.Thread.Sleep(this.delay);
                    }
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    System.Threading.Thread.Sleep(this.delay);
                }
            }

            if (waiting)
            {
                throw new TimeoutException(String.Format("Could not get config of version " + this.NodeVersion.ToString() + ". Tries: {0} Delay: {1}. " + message, this.tries, this.delay));
            }

            lock (clusterLock)
            {
                if (this.ClusterVersion < Convert.ToInt32(items[0]))
                {
                    this.ClusterVersion = Convert.ToInt32(items[0]);
                }
            }
            return(items[1]);
        }
Exemplo n.º 9
0
        private string PerformSCMOperation(FileSystemInfo destination, GetOperation getOperation)
        {
            Console.WriteLine("In Download performing a {0}", getOperation);

            if (!destination.Exists)
                ((DirectoryInfo)destination).Create();

            _tempFile = new FileInfo(Path.Combine(destination.FullName, "horn.boo"));

            FileHelper.CreateFileWithRandomData(_tempFile.FullName);

            if (getOperation == GetOperation.CheckOut)
                CheckOutWasCalled = true;
            else if (getOperation == GetOperation.Update)
                UpdateWasCalled = true;
            else if (getOperation == GetOperation.Export)
                ExportWasCalled = true;

            return long.MaxValue.ToString();
        }
Exemplo n.º 10
0
 public decimal Calculate(Tuple <char, decimal, decimal> input)
 {
     return(GetOperation(input.Item1.ConvertToEnum())(input.Item2, input.Item3));
 }
Exemplo n.º 11
0
        public static void RequestOperation_Contains_GetOperation(RequestOperation ro, GetOperation go)
        {
            // Arrange

            // Act
            Assert.Equal((int)ro, (int)go);

            // Assert
        }
Exemplo n.º 12
0
 public int Calculate(CalculationRequest request)
 {
     return(GetOperation(request.Operation)(request.X, request.Y));
 }
Exemplo n.º 13
0
 public void GetMany(GetOperation operation, byte[][] keys)
 {
     throw new NotImplementedException();
 }
 public async void TestSendAsync_100_PartDuex()
 {
     Console.WriteLine("Start thread: {0}", Thread.CurrentThread.ManagedThreadId);
     for (var i = 0; i < 100; i++)
     {
         await Task.Factory.StartNew(async () =>
         {
             Console.WriteLine("task thread: {0}", Thread.CurrentThread.ManagedThreadId);
             _vBucket = _state.GetVBucket(Key);
             var operation = new GetOperation<string>(Key, _vBucket);
             var result = await _ioStrategy.ExecuteAsync(operation);
             Assert.IsNotNullOrEmpty(result.Value);
             Console.WriteLine("Result for key '{0}' is '{1}'", operation.Key, result.Value);
         });
     }
 }