public void ShouldCommandNotFound() { var command = $"blablabla"; var result = ConsoleService.CommandExecute(command); result.Should().Be(NOT_FOUND_MSG_ERRO); }
public void ShouldReturnCorrectRangeValues() { ConsoleService.ClearDatabase(); // 1) "one" 2) "two" 3) "three" 4) "four" var command = $"zadd {PREFIX_KEY} 1 \"one\" 2 \"two\" 3 \"three\" 4 \"four\""; var result = ConsoleService.CommandExecute(command); result.Should().Be("4"); // 1) "one" 2) "two" var commandRange = $"zrange {PREFIX_KEY} 0 1"; var resultRange = ConsoleService.CommandExecute(commandRange); resultRange.Should().Be("1) \"one\"\r\n2) \"two\"\r\n"); // 1) "one" 2) "two" 3) "three" 4) "four" commandRange = $"zrange {PREFIX_KEY} 0 -1"; resultRange = ConsoleService.CommandExecute(commandRange); resultRange.Should().Be("1) \"one\"\r\n2) \"two\"\r\n3) \"three\"\r\n4) \"four\"\r\n"); // 1) "three" 2) "four" commandRange = $"zrange {PREFIX_KEY} -2 -1"; resultRange = ConsoleService.CommandExecute(commandRange); resultRange.Should().Be("1) \"three\"\r\n2) \"four\"\r\n"); }
public void ShouldReturnInvalidCommandWhenIndexNotTypeInt() { var command = $"zrange test a b"; var result = ConsoleService.CommandExecute(command); result.Should().Be(INVALID_COMMAND); }
public void ShouldReturnZeroWhenKeyNotFound() { var command = $"zcard blablabla"; var result = ConsoleService.CommandExecute(command); result.Should().Be("0"); }
public void ShouldIgnoreKeyNotFound() { ConsoleService.ClearDatabase(); for (int i = 0; i < 5; i++) { var commandSet = $"set {PREFIX_KEY}{i} {i}"; var resultSet = ConsoleService.CommandExecute(commandSet); resultSet.Should().Be("OK"); } // Shows that the value exists var commandGet = $"get {PREFIX_KEY}1"; var resultGet = ConsoleService.CommandExecute(commandGet); resultGet.Should().Be("1"); var commandDel = $"del {PREFIX_KEY}1 {PREFIX_KEY}2 {PREFIX_KEY}3 {PREFIX_KEY}10"; var resultDel = ConsoleService.CommandExecute(commandDel); resultDel.Should().Be("3"); // Shows that the value no longer exists commandGet = $"get {PREFIX_KEY}1"; resultGet = ConsoleService.CommandExecute(commandGet); resultGet.Should().Be("nil"); }
public void ShouldReturnInvalidCommand() { var command = $"incr"; var result = ConsoleService.CommandExecute(command); result.Should().Be(INVALID_COMMAND); }
public void ShouldAddOrUpdateCorrectsValues() { // 1) "one" 2) "two" var command = $"zadd {PREFIX_KEY} 1 \"one\" 2 \"two\""; var result = ConsoleService.CommandExecute(command); result.Should().Be("2"); var testResult = Zrange(PREFIX_KEY); testResult.Should().Be("1) \"one\"\r\n2) \"two\"\r\n"); // 1) "one" 2) "two" 3) "four" command = $"zadd {PREFIX_KEY} 3 \"two\" 4 \"four\""; result = ConsoleService.CommandExecute(command); result.Should().Be("1"); testResult = Zrange(PREFIX_KEY); testResult.Should().Be("1) \"one\"\r\n2) \"two\"\r\n3) \"four\"\r\n"); // 1) "one" 2) "two" 3) "four" command = $"zadd {PREFIX_KEY} 2 \"two\""; result = ConsoleService.CommandExecute(command); result.Should().Be("0"); testResult = Zrange(PREFIX_KEY); testResult.Should().Be("1) \"one\"\r\n2) \"two\"\r\n3) \"four\"\r\n"); }
public void ShouldReturnNilWhenKeyNotFound() { var command = $"zrank test test"; var result = ConsoleService.CommandExecute(command); result.Should().Be("nil"); }
public void ShouldEnsureSafeThreadWithCommandIncr() { ConsoleService.ClearDatabase(); var workers = CreateThreadsWithCommandIncr(500); Task.WaitAll(workers); var command = $"get {PREFIX_KEY}_incr"; var result = ConsoleService.CommandExecute(command); }
public void ShouldReturnCorrectValueByKey() { for (int i = 0; i < 5; i++) { var command = $"get {PREFIX_KEY}{i}"; var result = ConsoleService.CommandExecute(command); result.Should().Be(i.ToString()); } }
public void ShouldReturnNilWhenKeyNotFound() { var command = $"get {PREFIX_KEY}0"; var result = ConsoleService.CommandExecute(command); result.Should().Be("0"); command = $"get {PREFIX_KEY}AAAAA"; result = ConsoleService.CommandExecute(command); result.Should().Be("nil"); }
public void ShouldCreateKeyAndAddRecords() { var commandSet = $"set {PREFIX_KEY} 1"; var resultSet = ConsoleService.CommandExecute(commandSet); resultSet.Should().Be("OK"); var command = $"zadd {PREFIX_KEY} 3 \"two\" 4 \"four\""; var result = ConsoleService.CommandExecute(command); result.Should().Be(TYPE_IS_NOT_SORTED_SET); }
public void ShouldReturnInvalidCommandWhenCommandIncorrect() { var command = $"get"; var result = ConsoleService.CommandExecute(command); result.Should().Be(INVALID_COMMAND); command = $"get test 1 1"; result = ConsoleService.CommandExecute(command); result.Should().Be(INVALID_COMMAND); }
public void ShouldIncrTheValueOfNewKey() { var commandIncr = $"incr {PREFIX_KEY}_new"; var resultIncr = ConsoleService.CommandExecute(commandIncr); resultIncr.Should().Be("1"); var commandGet = $"get {PREFIX_KEY}_new"; var resultGet = ConsoleService.CommandExecute(commandGet); resultGet.Should().Be("1"); }
public void ShouldSetExpirationDateForKey() { var command = $"set {PREFIX_KEY}_Exp 1 1"; var result = ConsoleService.CommandExecute(command); result.Should().Be("OK"); Thread.Sleep(1000); command = $"get {PREFIX_KEY}_EXP"; result = ConsoleService.CommandExecute(command); result.Should().Be("nil"); }
public void ShouldReturnCorrectIndex() { ConsoleService.ClearDatabase(); var commandAdd = $"zadd {PREFIX_KEY} 1 \"one\""; var resultAdd = ConsoleService.CommandExecute(commandAdd); resultAdd.Should().Be("1"); var command = $"zrank {PREFIX_KEY} \"one\""; var result = ConsoleService.CommandExecute(command); result.Should().Be("0"); }
public void ShouldIgnoreExpirationValueForKeyLessThanOne() { var command = $"set {PREFIX_KEY}_Exp 1 0"; var result = ConsoleService.CommandExecute(command); result.Should().Be("OK"); Thread.Sleep(1000); command = $"get {PREFIX_KEY}_EXP"; result = ConsoleService.CommandExecute(command); result.Should().Be("1"); }
private Task[] CreateThreadsWithCommandSet(int maxThreadCount) { var workers = new Task[maxThreadCount]; for (int i = 0; i < maxThreadCount; i++) { var command = $"set {PREFIX_KEY} {i}"; var name = "Thread " + (i + 1); workers[i] = Task.Factory.StartNew(() => ConsoleService.CommandExecute(command));//new Thread(() => ConsoleService.CommandExecute(command)) { Name = name }; } return(workers); }
public void ShouldReturnNilWhenKeyExpired() { var command = $"get {PREFIX_KEY}0"; var result = ConsoleService.CommandExecute(command); result.Should().Be("0"); Thread.Sleep(1000); command = $"get {PREFIX_KEY}30"; result = ConsoleService.CommandExecute(command); result.Should().Be("nil"); }
public void ShouldReturnCountOfMembersOfKey() { ConsoleService.ClearDatabase(); var commandAdd = $"zadd {PREFIX_KEY} 1 \"one\" 2 \"two\""; var resultAdd = ConsoleService.CommandExecute(commandAdd); resultAdd.Should().Be("2"); var command = $"zcard {PREFIX_KEY}"; var result = ConsoleService.CommandExecute(command); result.Should().Be("2"); }
public void ShouldReturnNilWhenMemberNotFound() { ConsoleService.ClearDatabase(); var commandAdd = $"zadd {PREFIX_KEY} 1 \"one\""; var resultAdd = ConsoleService.CommandExecute(commandAdd); resultAdd.Should().Be("1"); var command = $"zrank {PREFIX_KEY} test"; var result = ConsoleService.CommandExecute(command); result.Should().Be("nil"); }
protected void SetupBase(LoadOptionsEnum loadOptionsEnum) { ConsoleService = new ConsoleService(); switch (loadOptionsEnum) { case LoadOptionsEnum.LoadDatabase: //Ok for (int i = 0; i < 25; i++) { ConsoleService.CommandExecute($"set key{i} {i}"); ConsoleService.CommandExecute($"set keyEx{i} Ex{i}"); } //Expiradas for (int i = 25; i < 50; i++) { ConsoleService.CommandExecute($"set key{i} {i} 1"); ConsoleService.CommandExecute($"set keyEx{i} Ex{i} 1"); } break; case LoadOptionsEnum.LoadOnlyKeysOk: //Ok for (int i = 0; i < 25; i++) { ConsoleService.CommandExecute($"set key{i} {i}"); ConsoleService.CommandExecute($"set keyEx{i} Ex{i}"); } break; case LoadOptionsEnum.LoadOnlyKeysExpired: //Expiradas for (int i = 25; i < 50; i++) { ConsoleService.CommandExecute($"set key{i} {i} 1"); ConsoleService.CommandExecute($"set keyEx{i} Ex{i} 1"); } break; default: break; } }
public void ShouldUpdateValueKey() { var commandGet = $"get {PREFIX_KEY}0"; var result = ConsoleService.CommandExecute(commandGet); result.Should().Be("0"); var commandSet = $"set {PREFIX_KEY}0 1"; var result2 = ConsoleService.CommandExecute(commandSet); result2.Should().Be("OK"); commandGet = $"get {PREFIX_KEY}0"; result = ConsoleService.CommandExecute(commandGet); result.Should().Be("1"); }
public void ShouldReturnExceptionOfType() { var commandSet = $"set {PREFIX_KEY}_letter A"; var resultSet = ConsoleService.CommandExecute(commandSet); resultSet.Should().Be("OK"); var commandGet = $"get {PREFIX_KEY}_letter"; var resultGet = ConsoleService.CommandExecute(commandGet); resultGet.Should().Be("A"); var commandIncr = $"incr {PREFIX_KEY}_letter"; var resultIncr = ConsoleService.CommandExecute(commandIncr); resultIncr.Should().Be(VALUE_OF_RECORD_NOT_INTEGER); }
public void ShouldRemoveKeys() { // Mounts the values for (int i = 0; i < 5; i++) { var commandSet = $"set {PREFIX_KEY}{i} {i}"; var resultSet = ConsoleService.CommandExecute(commandSet); resultSet.Should().Be("OK"); } // Shows that the values exist for (int i = 0; i < 5; i++) { var commandGet = $"get {PREFIX_KEY}{i}"; var resultGet = ConsoleService.CommandExecute(commandGet); resultGet.Should().Be(i.ToString()); } // Delete the values var commandDel = "del"; var builder = new StringBuilder(); builder.Append(commandDel); for (int i = 0; i < 5; i++) { builder.Append($" {PREFIX_KEY}{i}"); } commandDel = builder.ToString(); var resultDel = ConsoleService.CommandExecute(commandDel); resultDel.Should().Be("5"); // Shows that the values no longer exist for (int i = 0; i < 5; i++) { var commandGet = $"get {PREFIX_KEY}{i}"; var resultGet = ConsoleService.CommandExecute(commandGet); resultGet.Should().Be("nil"); } }
static void Main(string[] args) { var consoleService = new ConsoleService(); while (true) { Console.Write("smallredis> "); var command = Console.ReadLine(); if (command.Trim().ToLower() == "exit") { break; } var commandReturn = consoleService.CommandExecute(command); Console.WriteLine(commandReturn); } }
public void ShouldReturnEmptyWhenStartGreaterThanStopOrCount() { ConsoleService.ClearDatabase(); // 1) "one" 2) "two" 3) "three" 4) "four" var command = $"zadd {PREFIX_KEY} 1 \"one\" 2 \"two\" 3 \"three\" 4 \"four\""; var result = ConsoleService.CommandExecute(command); result.Should().Be("4"); // 1) "one" 2) "two" 3) "three" 4) "four" var commandRange = $"zrange {PREFIX_KEY} 8 0"; var resultRange = ConsoleService.CommandExecute(commandRange); resultRange.Should().Be(""); // 1) "one" 2) "two" 3) "three" 4) "four" commandRange = $"zrange {PREFIX_KEY} 8 9"; resultRange = ConsoleService.CommandExecute(commandRange); resultRange.Should().Be(""); }
public void ShouldReturnLengthDb() { // Count var command = $"dbsize"; var result = ConsoleService.CommandExecute(command); result.Should().Be(COUNT_DB_OK.ToString()); // Add Expired var commandSet = $"set exp 1 1"; var resultSet = ConsoleService.CommandExecute(commandSet); resultSet.Should().Be("OK"); //Expect to expire Thread.Sleep(1000); // Count command = $"dbsize"; result = ConsoleService.CommandExecute(command); result.Should().Be(COUNT_DB_OK.ToString()); }
private string Zrange(string key) { return(ConsoleService.CommandExecute($"zrange {key} 0 -1")); }