public void Test_Timed_Execution()
        {
            var converter = new DefaultConverter();
            var transcoder = new DefaultTranscoder(converter);
            var vbucket = GetVBucket();
            int n = 1000; //set to a higher # if needed

            using (new OperationTimer())
            {
                var key = string.Format("key{0}", 111);

                for (var i = 0; i < n; i++)
                {
                    var set = new Set<int?>(key, 111, vbucket, transcoder, OperationLifespanTimeout);
                    var get = new Get<int?>(key, vbucket, transcoder, OperationLifespanTimeout);

                    var result = IOService.Execute(set);
                    Assert.IsTrue(result.Success);

                    var result1 = IOService.Execute(get);
                    Assert.IsTrue(result1.Success);
                    Assert.AreEqual(111, result1.Value);
                }
            }
        }
        public void Test_ToByte()
        {
            var converter = new DefaultConverter();
            var actual = converter.ToByte(_buffer, 0);
            const int expected = 128;

            Assert.AreEqual(expected, actual);
        }
        public void Test_ToInt32()
        {
            var converter = new DefaultConverter();
            var actual = converter.ToInt32(_buffer, 8);
            const uint expected = 5u;

            Assert.AreEqual(expected, actual);
        }
        public void Test_ToBoolean_UseNbo()
        {
            var converter = new DefaultConverter();
            bool theBool = true;
            var bytes = BitConverter.GetBytes(theBool).Reverse().ToArray();
            var actual = converter.ToBoolean(bytes, 0, true);
            const bool expected = true;

            Assert.AreEqual(expected, actual);
        }
        public void Test_ToBoolean()
        {
            var converter = new DefaultConverter();
            bool theBool = true;
            var bytes =  BitConverter.GetBytes(theBool);
            var actual = converter.ToBoolean(bytes, 0, false);
            const bool expected = true;

            Assert.AreEqual(expected, actual);
        }
        public void Test_ToDouble()
        {
            var converter = new DefaultConverter();
            double theDouble = 2.3d;

            var bytes = BitConverter.GetBytes(theDouble);
            var actual = converter.ToDouble(bytes, 0, false);
            const double expected = 2.3d;

            Assert.AreEqual(expected, actual);
        }
        public void Test_ToDouble_UseNbo()
        {
            var converter = new DefaultConverter();
            double theDouble = 2.3d;

            var bytes = BitConverter.GetBytes(theDouble).Reverse().ToArray();
            var actual = converter.ToDouble(bytes, 0, true);
            const double expected = 2.3d;

            Assert.AreEqual(expected, actual);
        }
 public void SetUp()
 {
     _address = string.Format("{0}:11207", ConfigurationManager.AppSettings["serverIp"]);
     var ipEndpoint = UriExtensions.GetEndPoint(_address);
     var factory = DefaultConnectionFactory.GetGeneric<SslConnection>();
     var converter = new DefaultConverter();
     _configuration = new PoolConfiguration(MaxSize, MinSize, WaitTimeout, RecieveTimeout, ShutdownTimeout, SendTimeout, ConnectTimeout, MaxConnectionAcquireCount)
     {
         UseSsl = true
     };
     _connectionPool = new ConnectionPool<SslConnection>(_configuration, ipEndpoint, factory, converter);
     _connectionPool.Initialize();
 }
        public void Test_ObserveSeqno_Parse_Packet()
        {
            var converter = new DefaultConverter();
            var packet = new byte []
            {
                0x81, //magic
                0x01, //opcode
                0x00, 0x00, //key length
                0x10, //extra length
                0x00, //data type
                0x00, 0x00, //status
                0x00, 0x00, 0x00, 0x10, //total body
                0x00, 0x00, 0x00, 0x01, //opaque
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//cas
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x39, //uuid
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2D //seqno
            };
            var extras = new byte[converter.ToByte(packet, HeaderIndexFor.ExtrasLength)];
            var uuid = converter.ToUInt64(packet, 24);
            var seqno = converter.ToInt64(packet, 32);

            Assert.AreEqual(12345, uuid);
            Assert.AreEqual(45, seqno);
        }
        public void Test_Timed_Execution_Parallel()
        {
            var options = new ParallelOptions { MaxDegreeOfParallelism = 4 };
            var converter = new DefaultConverter();
            var transcoder = new DefaultTranscoder(converter);
            var vbucket = GetVBucket();
            var n = 1000;//set to a higher # if needed

            using (new OperationTimer())
            {
                Parallel.For(0, n, options, i =>
                {
                    var key = string.Format("key{0}", i);
                    var set = new Set<int?>(key, i, vbucket, transcoder, OperationLifespanTimeout);
                    var result = IOService.Execute(set);
                    Assert.IsTrue(result.Success);

                    var get = new Get<int?>(key, vbucket, transcoder, OperationLifespanTimeout);
                    var result1 = IOService.Execute(get);
                    Assert.IsTrue(result1.Success);
                    Assert.AreEqual(i, result1.Value);
                });
            }
        }
        public void Test_Cas2()
        {
            var converter = new DefaultConverter();
             var bytes = new byte[]
             {
                 0x00,
		        0x00,
		        0xa9,
		        0x53,
		        0x5f,
		        0x3d,
		        0xa7,
		        0x0f
             };
             const ulong expected = 186175545255695;
            var actual = converter.ToUInt64(bytes, 0);
            Assert.AreEqual(expected, actual);
        }
 public void Test_Cas()
 {
     var converter = new DefaultConverter();
     var bytes = new byte[] {255, 255, 255, 255, 229, 93, 159, 223};
     const ulong expected = 18446744073262702559;
     var actual = converter.ToUInt64(bytes, 0);
     Assert.AreEqual(expected, actual);
 }
        public void Test_FromUInt64()
        {
            var converter = new DefaultConverter();
            var actual = new byte[15];
            converter.FromUInt64(5, actual, 3);
            var expected = new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00 };

            Assert.AreEqual(expected, actual);
        }
        public void Test_ToDateTime_UseNbo()
        {
            var converter = new DefaultConverter();
            var theDateTime = new DateTime(1972, 12, 7);

            var bytes = BitConverter.GetBytes(theDateTime.ToBinary()).Reverse().ToArray();
            var actual = converter.ToDateTime(bytes, 0, true);
            var expected = new DateTime(1972, 12, 7);

            Assert.AreEqual(expected, actual);
        }
        public void Test_FromString()
        {
#pragma warning disable 618
            var converter = new DefaultConverter();
#pragma warning restore 618
            var buffer = new byte[Encoding.UTF8.GetByteCount("Hello")];
            converter.FromString("Hello", buffer, 0);
            var expected = new byte[]{0x48, 0x65, 0x6c, 0x6c, 0x6f};

            Assert.AreEqual(expected, buffer);
        }
        public void Test_ToString()
        {
            const int offset = 24;
            const int length = 5;

            var converter = new DefaultConverter();
            var actual = converter.ToString(_buffer, offset, length);
            const string expected = "Hello";

            Assert.AreEqual(expected, actual);
        }
        public void When_ByteArray_Is_Stored_With_Legacy_Flags_It_Is_Decoded_As_A_ByteArray()
        {
            var legacyByteArray = new byte[]
            {
                129, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 8, 0,
                0, 0, 5, 19, 185, 8, 248, 3, 104, 208, 188, 0,
                0, 250, 82, 116, 101, 115, 116
            };

            var converter = new DefaultConverter();
            var format = new byte();

            var temp = converter.ToByte(legacyByteArray, 24);
            converter.SetBit(ref format, 0, converter.GetBit(temp, 0));
            converter.SetBit(ref format, 1, converter.GetBit(temp, 1));
            converter.SetBit(ref format, 2, converter.GetBit(temp, 2));
            converter.SetBit(ref format, 3, converter.GetBit(temp, 3));

            var compression = new byte();
            converter.SetBit(ref compression, 4, converter.GetBit(temp, 4));
            converter.SetBit(ref compression, 5, converter.GetBit(temp, 5));
            converter.SetBit(ref compression, 6, converter.GetBit(temp, 6));

            var flags = new Flags
            {
                DataFormat = (DataFormat)format,
                Compression = (Compression)compression,
                TypeCode = (TypeCode)(converter.ToUInt16(legacyByteArray, 26) & 0xff),
            };

            var transcoder = new DefaultTranscoder(new DefaultConverter());
            var result = transcoder.Decode<byte[]>(legacyByteArray, 28, 4, flags, OperationCode.Get);
            Assert.AreEqual("test", Encoding.UTF8.GetString(result));
        }
        public void Test_ToSingle()
        {
            var converter = new DefaultConverter();
            float theSingle = 2.3f;

            var bytes = BitConverter.GetBytes(theSingle);
            var actual = converter.ToSingle(bytes, 0, false);
            const float expected = 2.3f;

            Assert.AreEqual(expected, actual);
        }