Esempio n. 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);
        }
Esempio n. 2
0
        protected override async Task ProcessAsync(IKronosClient client)
        {
            // Act
            Exception ex = await Record.ExceptionAsync(() => client.CountAsync());

            Assert.IsType <KronosException>(ex);
        }
Esempio n. 3
0
        protected override async Task ProcessAsync(IKronosClient client)
        {
            // Arrange
            string key = Guid.NewGuid().ToString();

            byte[] data = new byte[1024];

            // Act
            await client.InsertAsync(key, data, DateTime.UtcNow.AddDays(5));

            int count = await client.CountAsync();

            // Assert
            Assert.Equal(count, 1);
        }
Esempio n. 4
0
        private static async Task StartAsync()
        {
            string configPath = "KronosConfig.json";

            IKronosClient client = KronosClientFactory.FromFile(configPath);

            var watch = Stopwatch.StartNew();

            byte[] package = new byte[1024 * 9];
            new Random().NextBytes(package);

            for (int i = 0; i < 10000; i++)
            {
                Debug.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                string   key        = Guid.NewGuid().ToString();
                DateTime expiryDate = DateTime.UtcNow.AddDays(1);

                Debug.WriteLine("ADD - testing");
                await client.InsertAsync(key, package, expiryDate);

                Debug.WriteLine($"ADD - done (size: {package.Length})");

                Debug.WriteLine("COUNT - testing");
                int count = await client.CountAsync();

                Debug.WriteLine($"COUNT - done (count: {count})");

                Debug.WriteLine("CONTAINS - testing");
                bool contains = await client.ContainsAsync(key);

                Debug.WriteLine($"CONTAINS - done (exists: {contains})");

                Debug.WriteLine("GET - testing");
                byte[] fromServer = await client.GetAsync(key);

                Debug.WriteLine($"GET - done (size: {fromServer.Length})");
                Debug.Assert(fromServer.Length == package.Length);

                Debug.WriteLine("DELETE - testing");
                await client.DeleteAsync(key);

                bool containsAfterDeletion = await client.ContainsAsync(key);

                Debug.WriteLine($"DELETE - done (exists after deletion: {containsAfterDeletion})");
            }
            watch.Stop();
            Console.WriteLine(watch.ElapsedMilliseconds);
        }
Esempio n. 5
0
        protected override async Task RunInternalAsync(IKronosClient client, byte[] package)
        {
            string   key        = Guid.NewGuid().ToString();
            DateTime expiryDate = DateTime.UtcNow.AddSeconds(5);

            Debug.WriteLine($"ADD - testing");
            await client.InsertAsync(key, package, expiryDate);

            Debug.WriteLine($" ADD - done (size: {package.Length})");

            Debug.WriteLine($" COUNT - testing");
            int count = await client.CountAsync();

            Debug.WriteLine($" COUNT - done (count: {count})");

            Debug.WriteLine($" CONTAINS - testing");
            bool contains = await client.ContainsAsync(key);

            Debug.WriteLine($"CONTAINS - done (exists: {contains})");

            Debug.WriteLine($" GET - testing");
            byte[] fromServer = await client.GetAsync(key);

            Debug.WriteLine($" GET - done (size: {fromServer.Length})");

            if (fromServer.Length != package.Length)
            {
                throw new Exception(
                          $"Received message is invalid! Size should be {package.Length}, but wit {fromServer.Length}");
            }

            Debug.WriteLine($" DELETE - testing");
            await client.DeleteAsync(key);

            bool containsAfterDeletion = await client.ContainsAsync(key);

            Debug.WriteLine($" DELETE - done (exists after deletion: {containsAfterDeletion})");
        }