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); }
private async Task SendToWarnup(IKronosClient client, int size, int times) { byte[] package = PrepareData(size); for (int i = 0; i < times; i++) { string key = Guid.NewGuid().ToString(); await client.InsertAsync(key, package, DateTime.UtcNow.AddDays(1)); } }
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]; TimeSpan expiryTime = TimeSpan.FromSeconds(1); DateTime now = DateTime.UtcNow; // Act bool added = await client.InsertAsync(key, data, now + expiryTime); await Task.Delay(expiryTime); bool addedAgain = await client.InsertAsync(key, data, now + TimeSpan.FromDays(1)); // Assert Assert.True(added, "Object was not added"); Assert.True(addedAgain, "Object is not added even if previous was expired"); }
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 ProcessAsync(IKronosClient client) { // Arrange string key = Guid.NewGuid().ToString(); byte[] data = new byte[1024]; // Act bool added = await client.InsertAsync(key, data, DateTime.UtcNow.AddDays(5)); bool contains = await client.ContainsAsync(key); // Assert Assert.True(added, "Object is not added"); Assert.True(contains, "Object is not added, contains returns false"); }
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); await Task.Delay(Settings.CleanupTimeMs); bool contains = await client.ContainsAsync(key); // Assert Assert.False(contains, "Object exists after cleanup"); }
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)); await client.DeleteAsync(key); bool contains = await client.ContainsAsync(key); // Assert Assert.False(contains); }
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)); await client.ClearAsync(); int count = await client.CountAsync(); // Assert Assert.Equal(count, 0); }
private static async Task SendFileFilesAsync() { const string directory = @"path"; string configPath = "KronosConfig.json"; IKronosClient client = KronosClientFactory.CreateClient(configPath); foreach (string file in Directory.EnumerateFiles(directory, "*.*", SearchOption.AllDirectories)) { var time = Stopwatch.StartNew(); var data = File.ReadAllBytes(file); string name = Path.GetFileName(file); Console.WriteLine($"Sending {name}"); await client.InsertAsync(name, data, DateTime.Now.AddMinutes(10)); time.Stop(); Console.WriteLine($"Sending finished. Time: {time.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})"); }