public async Task Insert_And_Get_WorksCorrectly() { const int port = 9999; const string key = "key"; byte[] data = Encoding.UTF8.GetBytes("lorem ipsum"); DateTime expiry = DateTime.MaxValue; byte[] received; 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); received = await client.GetAsync(key); } } Assert.Equal(data, received); }
protected override async Task RunInternalAsync(IKronosClient client, byte[] package) { string key = Guid.NewGuid().ToString(); await client.InsertAsync(key, package, DateTime.UtcNow.AddSeconds(2)); byte[] data = await client.GetAsync(key); Debug.Assert(data.SequenceEqual(package)); }
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)); byte[] received = await client.GetAsync(key); // Assert Assert.Equal(data, received); }
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); }
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})"); }