public void Adding_item_that_does_exists_on_cache_and_has_matching_timestamp_value_will_replace_value() { Cache["foo"] = new CachedItem { Buffer = new byte[] { 3, 4 }, Timestamp = 4 }; var stream = new MemoryStream(); stream.WriteByte(1); stream.WriteByte(2); stream.WriteByte(13); stream.WriteByte(10); stream.Position = 0; var command = new CasCommand(); command.SetContext(stream); command.Init("foo", "1", "0", "2", "4"); command.FinishedExecuting += () => wait.Set(); command.Execute(); wait.WaitOne(); var c = (CachedItem)Cache["foo"]; CollectionAssert.AreEqual(new byte[] { 1, 2 }, c.Buffer); Assert.IsTrue(4L != c.Timestamp); }
public void When_deleting_item_in_cache_with_time_will_block_cas_operations() { Cache["foo2"] = new CachedItem(); var stream = new MemoryStream(); var command = new DeleteCommand(); command.SetContext(stream); command.Init("foo2", "500"); command.FinishedExecuting += () => wait.Set(); command.Execute(); wait.WaitOne(); Assert.AreEqual("DELETED\r\n", ReadAll(stream)); wait.Reset(); var buffer = new byte[] { 1, 2, 3, 4 }; stream = GetStreamWithData(buffer); var casCommand = new CasCommand(); casCommand.SetContext(stream); casCommand.Init("foo2", "1", "6000", "4", "2"); casCommand.FinishedExecuting += () => wait.Set(); casCommand.Execute(); wait.WaitOne(); Assert.AreEqual("NOT_STORED\r\n", ReadAll(6, stream)); }
public void Will_parse_store_arguments_include_cas() { var command = new CasCommand(); command.SetContext(new MemoryStream()); command.Init("foo", "1", "0", "2", "523423"); Assert.AreEqual(523423, command.Timestamp); }
public void Specifying_too_many_arguments_will_send_error() { var stream = new MemoryStream(); var cmd = new CasCommand(); cmd.SetContext(stream); bool result = cmd.Init("b", "1", "2", "3", "noreply", "3", "3"); Assert.IsFalse(result); string actual = ReadAll(stream); Assert.AreEqual("CLIENT_ERROR Expected to get 'cas <key> <flags> <exptime> <bytes> <cas unqiue> [noreply]'\r\n", actual); }
public void Trying_to_call_invalid_noreply_will_result_in_error() { var stream = new MemoryStream(); var cmd = new CasCommand(); cmd.SetContext(stream); bool result = cmd.Init("b", "1", "2", "2", "1", "blah"); Assert.IsFalse(result); string actual = ReadAll(stream); Assert.AreEqual("CLIENT_ERROR Last argument was expected to be [noreply]\r\n", actual); }
public void Trying_to_call_empty_key_will_result_in_error() { var stream = new MemoryStream(); var cmd = new CasCommand(); cmd.SetContext(stream); bool result = cmd.Init("", "1", "2", "2", "?x"); Assert.IsFalse(result); string actual = ReadAll(stream); Assert.AreEqual("CLIENT_ERROR Key cannot be empty\r\n", actual); }
public void Specifying_invalid_cas_value_will_result_in_error() { var stream = new MemoryStream(); var cmd = new CasCommand(); cmd.SetContext(stream); bool result = cmd.Init("b", "1", "2", "2", "?x"); Assert.IsFalse(result); string actual = ReadAll(stream); Assert.AreEqual("CLIENT_ERROR cas value should be numeric\r\n", actual); }
public void Adding_item_that_does_not_exists_will_return_not_found() { var stream = new MemoryStream(); stream.WriteByte(1); stream.WriteByte(2); stream.WriteByte(13); stream.WriteByte(10); stream.Position = 0; var command = new CasCommand(); command.SetContext(stream); command.Init("foo", "1", "0", "2", "523423"); command.FinishedExecuting += () => wait.Set(); command.Execute(); wait.WaitOne(); Assert.AreEqual("NOT_FOUND\r\n", ReadAll(4, stream)); }
public void Adding_item_that_does_exists_on_cache_and_has_matching_timestamp_value_will_return_stored() { Cache["foo"] = new CachedItem { Timestamp = 4 }; var stream = new MemoryStream(); stream.WriteByte(1); stream.WriteByte(2); stream.WriteByte(13); stream.WriteByte(10); stream.Position = 0; var command = new CasCommand(); command.SetContext(stream); command.Init("foo", "1", "0", "2", "4"); command.FinishedExecuting += () => wait.Set(); command.Execute(); wait.WaitOne(); Assert.AreEqual("STORED\r\n", ReadAll(4, stream)); }