Пример #1
0
        public async Task Insert_And_Count_WorksCorrectly()
        {
            const int    port = 9997;
            const string key  = "key";

            byte[]   data   = Encoding.UTF8.GetBytes("lorem ipsum");
            DateTime expiry = DateTime.MaxValue;

            int countFromClientApi;
            int countFromStorage;

            IExpiryProvider expiryProvider = new StorageExpiryProvider();

            using (IStorage storage = new InMemoryStorage(expiryProvider))
            {
                var processor        = new SocketProcessor();
                var requestProcessor = new RequestProcessor(storage);
                using (IListener server = new Listener(IPAddress.Any, port, processor, requestProcessor))
                {
                    server.Start();
                    IKronosClient client = KronosClientFactory.CreateClient(localHost, port);
                    await client.InsertAsync(key, data, expiry);

                    countFromClientApi = await client.CountAsync();

                    countFromStorage = storage.Count;
                }
            }

            Assert.Equal(countFromClientApi, 1);
            Assert.Equal(countFromClientApi, countFromStorage);
        }
Пример #2
0
        public async Task Contains_WorksCorrectly()
        {
            const int    port = 9995;
            const string key  = "key";

            bool            containsFromClientApi;
            bool            containsFromStorage;
            IExpiryProvider expiryProvider = new StorageExpiryProvider();

            using (IStorage storage = new InMemoryStorage(expiryProvider))
            {
                var processor        = new SocketProcessor();
                var requestProcessor = new RequestProcessor(storage);
                using (IListener server = new Listener(IPAddress.Any, port, processor, requestProcessor))
                {
                    server.Start();
                    IKronosClient client = KronosClientFactory.CreateClient(localHost, port);

                    containsFromClientApi = await client.ContainsAsync(key);

                    containsFromStorage = storage.Contains(key);
                }
            }

            Assert.False(containsFromClientApi);
            Assert.Equal(containsFromClientApi, containsFromStorage);
        }