Esempio n. 1
0
        public void SetTwice()
        {
            var storageBuilder = new StoreRequestBuilder("set", "key", "value");

            Dispatch(storageBuilder.ToAsciiRequest());

            storageBuilder.Data("Updated");
            var response = Dispatch(storageBuilder.ToAsciiRequest());

            Assert.AreEqual("STORED\r\n", response.ToAsciiString());
        }
Esempio n. 2
0
        public void SetAndSetNewThenGet()
        {
            var storageBuilder = new StoreRequestBuilder("set", "key", "value");

            Dispatch(storageBuilder.ToAsciiRequest());
            storageBuilder.Data("new value");
            Dispatch(storageBuilder.ToAsciiRequest());
            var getBuilder = new GetRequestBuilder("get", "key");

            var response = Dispatch(getBuilder.ToAsciiRequest());

            Assert.AreEqual("VALUE key 0 9\r\nnew value\r\nEND\r\n", response.ToAsciiString());
        }
Esempio n. 3
0
        private static Task SendRequest(NetworkStream s)
        {
            var b       = new StoreRequestBuilder("set", "mykey", "MyData");
            var request = b.ToAsciiRequest();

            return(s.WriteAsync(request, 0, request.Length));
        }
Esempio n. 4
0
        public void ReplaceToEmpty()
        {
            var replaceBuilder = new StoreRequestBuilder("replace", "key", "value");

            var response = Dispatch(replaceBuilder.ToAsciiRequest());

            Assert.AreEqual("NOT_STORED\r\n", response.ToAsciiString());
        }
Esempio n. 5
0
        public void StoreOverCapacity()
        {
            var setBuilder = new StoreRequestBuilder("set", "key", "12345678901");

            var response = Dispatch(setBuilder.ToAsciiRequest());

            Assert.AreEqual("ERROR Over capacity\r\n", response.ToAsciiString());
        }
Esempio n. 6
0
        public void PrependToEmpty()
        {
            var prependBuilder = new StoreRequestBuilder("prepend", "key", "value");

            var response = Dispatch(prependBuilder.ToAsciiRequest());

            Assert.AreEqual("NOT_STORED\r\n", response.ToAsciiString());
        }
Esempio n. 7
0
        public void AddToEmpty()
        {
            var addBuilder = new StoreRequestBuilder("add", "key", "value");

            var response = Dispatch(addBuilder.ToAsciiRequest());

            Assert.AreEqual("STORED\r\n", response.ToAsciiString());
        }
Esempio n. 8
0
        public void Set()
        {
            var setBuilder = new StoreRequestBuilder("set", "key", "value");

            var response = Dispatch(setBuilder.ToAsciiRequest());

            Assert.AreEqual("STORED\r\n", response.ToAsciiString());
        }
Esempio n. 9
0
        public void Decr()
        {
            var storageBuilder = new StoreRequestBuilder("set", "key", "123");

            Dispatch(storageBuilder.ToAsciiRequest());
            var builder  = new MutateRequestBuilder("decr", "key", 1);
            var response = Dispatch(builder.ToAsciiRequest());

            Assert.AreEqual("122\r\n", response.ToAsciiString());
        }
Esempio n. 10
0
        public void PrependNoReply()
        {
            var prependBuilder = new StoreRequestBuilder("prepend", "key", "value");

            prependBuilder.NoReply();

            var response = Dispatch(prependBuilder.ToAsciiRequest());

            Assert.AreEqual("", response.ToAsciiString());
        }
Esempio n. 11
0
        public void AddNoReply()
        {
            var addBuilder = new StoreRequestBuilder("add", "key", "value");

            addBuilder.NoReply();

            var response = Dispatch(addBuilder.ToAsciiRequest());

            Assert.AreEqual("", response.ToAsciiString());
        }
Esempio n. 12
0
        public void ReplaceNoReply()
        {
            var replaceBuilder = new StoreRequestBuilder("replace", "key", "value");

            replaceBuilder.NoReply();

            var response = Dispatch(replaceBuilder.ToAsciiRequest());

            Assert.AreEqual("", response.ToAsciiString());
        }
Esempio n. 13
0
        public void GetValueOfAddToEmpty()
        {
            var addBuilder = new StoreRequestBuilder("add", "key", "value");

            Dispatch(addBuilder.ToAsciiRequest());

            var getBuilder = new GetRequestBuilder("get", "key");
            var response   = Dispatch(getBuilder.ToAsciiRequest());

            Assert.AreEqual("VALUE key 0 5\r\nvalue\r\nEND\r\n", response.ToAsciiString());
        }
Esempio n. 14
0
        public void FlushDelayResponse()
        {
            var storageBuilder = new StoreRequestBuilder("set", "key", "value");

            Dispatch(storageBuilder.ToAsciiRequest());

            var flushRequest = Encoding.ASCII.GetBytes("flush_all 123\r\n");
            var response     = Dispatch(flushRequest);

            Assert.AreEqual("OK\r\n", response.ToAsciiString());
        }
Esempio n. 15
0
        public void DeleteExisting()
        {
            var storageBuilder = new StoreRequestBuilder("set", "key", "value");

            Dispatch(storageBuilder.ToAsciiRequest());

            var delBuilder = new DeleteRequestBuilder("key");
            var response   = Dispatch(delBuilder.ToAsciiRequest());

            Assert.AreEqual("DELETED\r\n", response.ToAsciiString());
        }
Esempio n. 16
0
        public void AddToExisting()
        {
            var setBuilder = new StoreRequestBuilder("set", "key", "value");

            var response2 = Dispatch(setBuilder.ToAsciiRequest()).ToAsciiString();

            var addBuilder = new StoreRequestBuilder("add", "key", "value");

            var response = Dispatch(addBuilder.ToAsciiRequest());

            Assert.AreEqual("NOT_STORED\r\n", response.ToAsciiString());
        }
Esempio n. 17
0
        public void FlagsSetAndGet()
        {
            var storageBuilder = new StoreRequestBuilder("set", "key", "value");

            storageBuilder.WithFlags(1234567890);
            Dispatch(storageBuilder.ToAsciiRequest());

            var getBuilder = new GetRequestBuilder("get", "key");
            var response   = Dispatch(getBuilder.ToAsciiRequest());

            Assert.AreEqual("VALUE key 1234567890 5\r\nvalue\r\nEND\r\n", response.ToAsciiString());
        }
Esempio n. 18
0
        public void SetExpiryThenGet()
        {
            var storageBuilder = new StoreRequestBuilder("set", "key", "value");

            storageBuilder.WithExpiry(100);

            Dispatch(storageBuilder.ToAsciiRequest());

            var getBuilder = new GetRequestBuilder("get", "key");
            var response   = Dispatch(getBuilder.ToAsciiRequest());

            Assert.AreEqual("VALUE key 0 5\r\nvalue\r\nEND\r\n", response.ToAsciiString());
        }
Esempio n. 19
0
        public void TouchOk()
        {
            var storageBuilder = new StoreRequestBuilder("set", "key", "value");

            storageBuilder.WithExpiry(100);
            Dispatch(storageBuilder.ToAsciiRequest());

            var touchBuilder = new TouchRequestBuilder("key");

            touchBuilder.WithExpiry(1);
            var response = Dispatch(touchBuilder.ToAsciiRequest());

            Assert.AreEqual("OK\r\n", response.ToAsciiString());
        }
Esempio n. 20
0
        public void GetValueOfAppendToExisting()
        {
            var setBuilder = new StoreRequestBuilder("set", "key", "first");

            Dispatch(setBuilder.ToAsciiRequest());

            var appendBuilder = new StoreRequestBuilder("append", "key", " second");

            Dispatch(appendBuilder.ToAsciiRequest());

            var getBuilder = new GetRequestBuilder("get", "key");
            var response   = Dispatch(getBuilder.ToAsciiRequest());

            Assert.AreEqual("VALUE key 0 12\r\nfirst second\r\nEND\r\n", response.ToAsciiString());
        }
Esempio n. 21
0
        public void SetExpiryThenGetGone()
        {
            var storageBuilder = new StoreRequestBuilder("set", "key", "value");

            storageBuilder.WithExpiry(1);

            Dispatch(storageBuilder.ToAsciiRequest());

            _testScheduler.AdvanceBy(TimeSpan.FromSeconds(2).Ticks);

            var getBuilder = new GetRequestBuilder("get", "key");
            var response   = Dispatch(getBuilder.ToAsciiRequest());

            Assert.AreEqual("END\r\n", response.ToAsciiString());
        }
Esempio n. 22
0
        public void StoreEvictOverCapacity()
        {
            var setBuilder1 = new StoreRequestBuilder("set", "key1", "1234567890");
            var setBuilder2 = new StoreRequestBuilder("set", "key2", "1234567890");

            Dispatch(setBuilder1.ToAsciiRequest());
            var response = Dispatch(setBuilder2.ToAsciiRequest());

            Assert.AreEqual("STORED\r\n", response.ToAsciiString());

            var getBuilder = new GetRequestBuilder("get", "key1");
            var response2  = Dispatch(getBuilder.ToAsciiRequest());

            Assert.AreEqual("END\r\n", response2.ToAsciiString());
        }
Esempio n. 23
0
        private static async void SimpleBenchmark(SyncClient client, string key = "key", int iterations = 100000)
        {
            for (int i = 0; i < iterations; ++i)
            {
                var b        = new StoreRequestBuilder("set", key, string.Format("Data{0}", i));
                var request  = b.ToAsciiRequest();
                var resposne = await client.SendAsync(request);

                Interlocked.Increment(ref _count);
            }

            var get       = new GetRequestBuilder("get", key);
            var request2  = get.ToAsciiRequest();
            var resposne2 = client.Send(request2);
        }
Esempio n. 24
0
        public void FlushClearsCache()
        {
            var storageBuilder = new StoreRequestBuilder("set", "key", "value");

            Dispatch(storageBuilder.ToAsciiRequest());

            var flushRequest = Encoding.ASCII.GetBytes("flush_all\r\n");

            Dispatch(flushRequest);

            var getBuilder = new GetRequestBuilder("get", "key");
            var response   = Dispatch(getBuilder.ToAsciiRequest());

            Assert.AreEqual("END\r\n", response.ToAsciiString());
        }
Esempio n. 25
0
        public void SetThenGetMultiple()
        {
            var storageBuilder1 = new StoreRequestBuilder("set", "key1", "111111");

            Dispatch(storageBuilder1.ToAsciiRequest());

            var storageBuilder2 = new StoreRequestBuilder("set", "key2", "222");

            Dispatch(storageBuilder2.ToAsciiRequest());

            var getBuilder = new GetRequestBuilder("get", "key1", "key2");
            var response   = Dispatch(getBuilder.ToAsciiRequest());

            Assert.AreEqual("VALUE key1 0 6\r\n111111\r\nVALUE key2 0 3\r\n222\r\nEND\r\n", response.ToAsciiString());
        }
Esempio n. 26
0
        public void GetValueOfReplaceToExisting()
        {
            var setBuilder = new StoreRequestBuilder("set", "key", "first");

            Dispatch(setBuilder.ToAsciiRequest());

            var replaceBuilder = new StoreRequestBuilder("replace", "key", "second");

            Dispatch(replaceBuilder.ToAsciiRequest());

            var getBuilder = new GetRequestBuilder("get", "key");
            var response   = Dispatch(getBuilder.ToAsciiRequest());

            Assert.AreEqual("VALUE key 0 6\r\nsecond\r\nEND\r\n", response.ToAsciiString());
        }
Esempio n. 27
0
        public void FlushWithDelayNoEffect()
        {
            var storageBuilder = new StoreRequestBuilder("set", "key", "value");

            Dispatch(storageBuilder.ToAsciiRequest());

            var flushRequest = Encoding.ASCII.GetBytes("flush_all 100\r\n");

            Dispatch(flushRequest);

            _testScheduler.AdvanceBy(TimeSpan.FromSeconds(90).Ticks);

            var getBuilder = new GetRequestBuilder("get", "key");
            var response   = Dispatch(getBuilder.ToAsciiRequest());

            Assert.AreEqual("VALUE key 0 5\r\nvalue\r\nEND\r\n", response.ToAsciiString());
        }
Esempio n. 28
0
        public void AbsoluteLongExpiry()
        {
            var unixEpoc = new DateTime(1970, 1, 1);

            _testScheduler.AdvanceBy((unixEpoc - _testScheduler.Now).Ticks); // Advance to the start of unix time
            TimeSpan span     = (new DateTime(1970, 6, 1) - unixEpoc);
            var      unixTime = (int)span.TotalSeconds;

            var storageBuilder = new StoreRequestBuilder("set", "key", "value");

            storageBuilder.WithExpiry(unixTime);

            Dispatch(storageBuilder.ToAsciiRequest());

            _testScheduler.AdvanceBy(TimeSpan.FromDays(200).Ticks);

            var getBuilder = new GetRequestBuilder("get", "key");
            var response   = Dispatch(getBuilder.ToAsciiRequest());

            Assert.AreEqual("END\r\n", response.ToAsciiString());
        }
Esempio n. 29
0
        public void StoreCasInCapacity()
        {
            var setBuilder = new StoreRequestBuilder("set", "s", "12345");

            Dispatch(setBuilder.ToAsciiRequest());

            var builder = new CasRequestBuilder("key", "12345");

            builder.WithCasUnique(123);
            Dispatch(builder.ToAsciiRequest());

            var getBuilder = new GetRequestBuilder("get", "key");

            Dispatch(getBuilder.ToAsciiRequest());

            var builder2 = new CasRequestBuilder("key", "123456");

            builder2.WithCasUnique(123);
            var response2 = Dispatch(builder2.ToAsciiRequest());

            Assert.AreEqual("STORED\r\n", response2.ToAsciiString());
        }