Exemple #1
0
        public void GetNotFound()
        {
            var getBuilder = new GetRequestBuilder("get", "key");
            var response   = Dispatch(getBuilder.ToAsciiRequest());

            Assert.AreEqual("END\r\n", response.ToAsciiString());
        }
Exemple #2
0
        public void SetThenGet()
        {
            var storageBuilder = new StoreRequestBuilder("set", "key", "value");

            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());
        }
Exemple #3
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());
        }
Exemple #4
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());
        }
Exemple #5
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());
        }
Exemple #6
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());
        }
Exemple #7
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);
        }
Exemple #8
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());
        }
Exemple #9
0
        public void DeleteExistingGetNotFound()
        {
            var storageBuilder = new StoreRequestBuilder("set", "key", "value");

            Dispatch(storageBuilder.ToAsciiRequest());

            var delBuilder = new DeleteRequestBuilder("key");

            Dispatch(delBuilder.ToAsciiRequest());

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

            Assert.AreEqual("END\r\n", response.ToAsciiString());
        }
Exemple #10
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());
        }
Exemple #11
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());
        }
Exemple #12
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());
        }
Exemple #13
0
        public void CasNoPrevious()
        {
            var   casBuilder = new CasRequestBuilder("key", "value");
            ulong lastCas    = 123;

            casBuilder.WithCasUnique(lastCas);

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

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

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

            Assert.AreEqual("VALUE key 0 5 123\r\nvalue\r\nEND\r\n", getResponse.ToAsciiString());
        }
Exemple #14
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());
        }
Exemple #15
0
        public void CasUpdatePreviousModifiedValue()
        {
            var casBuilder1 = new CasRequestBuilder("key", "value1");

            casBuilder1.WithCasUnique(789);
            Dispatch(casBuilder1.ToAsciiRequest());

            var casBuilder2 = new CasRequestBuilder("key", "value2");

            casBuilder2.WithCasUnique(567);

            Dispatch(casBuilder2.ToAsciiRequest());

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

            Assert.AreEqual("VALUE key 0 6 789\r\nvalue1\r\nEND\r\n", getResponse.ToAsciiString());
        }
Exemple #16
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());
        }
Exemple #17
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());
        }