public void PersistRestore() { const string StoreName = "TestStore"; var message = new MyMessage(); // clean up this.QueueStorage.DeleteQueue(this.QueueName); foreach (var skey in this.QueueStorage.ListPersisted(StoreName)) { this.QueueStorage.DeletePersisted(StoreName, skey); } // put this.QueueStorage.Put(this.QueueName, message); // get var retrieved = this.QueueStorage.Get<MyMessage>(this.QueueName, 1).First(); Assert.AreEqual(message.MyGuid, retrieved.MyGuid, "#A01"); // persist this.QueueStorage.Persist(retrieved, StoreName, "manual test"); // abandon should fail (since not invisible anymore) Assert.IsFalse(this.QueueStorage.Abandon(retrieved), "#A02"); // list persisted message var key = this.QueueStorage.ListPersisted(StoreName).Single(); // get persisted message var persisted = this.QueueStorage.GetPersisted(StoreName, key); Assert.IsTrue(persisted.HasValue, "#A03"); Assert.IsTrue(persisted.Value.DataXml.HasValue, "#A04"); var xml = persisted.Value.DataXml.Value; var property = xml.Elements().Single(x => x.Name.LocalName == "MyGuid"); Assert.AreEqual(message.MyGuid, new Guid(property.Value), "#A05"); // restore persisted message this.QueueStorage.RestorePersisted(StoreName, key); // list no longer contains key Assert.IsFalse(this.QueueStorage.ListPersisted(StoreName).Any(), "#A06"); // get var retrieved2 = this.QueueStorage.Get<MyMessage>(this.QueueName, 1).First(); Assert.AreEqual(message.MyGuid, retrieved2.MyGuid, "#A07"); // delete Assert.IsTrue(this.QueueStorage.Delete(retrieved2), "#A08"); }
public void PutGetAbandonDelete() { var message = new MyMessage(); this.QueueStorage.DeleteQueue(this.QueueName); // deleting queue on purpose // (it's slow but necessary to really validate the retry policy) // put this.QueueStorage.Put(this.QueueName, message); // get var retrieved = this.QueueStorage.Get<MyMessage>(this.QueueName, 1).First(); Assert.AreEqual(message.MyGuid, retrieved.MyGuid, "#A01"); // abandon var abandoned = this.QueueStorage.Abandon(retrieved); Assert.IsTrue(abandoned, "#A02"); // abandon II should fail (since not invisible) var abandoned2 = this.QueueStorage.Abandon(retrieved); Assert.IsFalse(abandoned2, "#A03"); // get again var retrieved2 = this.QueueStorage.Get<MyMessage>(this.QueueName, 1).First(); Assert.AreEqual(message.MyGuid, retrieved2.MyGuid, "#A04"); // delete var deleted = this.QueueStorage.Delete(retrieved2); Assert.IsTrue(deleted, "#A05"); // get now should fail var retrieved3 = this.QueueStorage.Get<MyMessage>(this.QueueName, 1).FirstOrDefault(); Assert.IsNull(retrieved3, "#A06"); // abandon does not put it to the queue again var abandoned3 = this.QueueStorage.Abandon(retrieved2); Assert.IsFalse(abandoned3, "#A07"); // get now should still fail var retrieved4 = this.QueueStorage.Get<MyMessage>(this.QueueName, 1).FirstOrDefault(); Assert.IsNull(retrieved4, "#A07"); }
public void PutGetDelete() { var message = new MyMessage(); this.QueueStorage.DeleteQueue(this.QueueName); // deleting queue on purpose // (it's slow but necessary to really validate the retry policy) this.QueueStorage.Put(this.QueueName, message); var retrieved = this.QueueStorage.Get<MyMessage>(this.QueueName, 1).First(); Assert.AreEqual(message.MyGuid, retrieved.MyGuid, "#A01"); this.QueueStorage.Delete(retrieved); }
public void PutGetDeleteOverflowing() { // 20k chosen so that it doesn't fit into the queue. var message = new MyMessage { MyBuffer = new byte[80000] }; // fill buffer with random content _rand.NextBytes(message.MyBuffer); QueueStorage.Clear(QueueName); QueueStorage.Put(QueueName, message); var retrieved = QueueStorage.Get<MyMessage>(QueueName, 1).First(); Assert.AreEqual(message.MyGuid, retrieved.MyGuid, "#A01"); CollectionAssert.AreEquivalent(message.MyBuffer, retrieved.MyBuffer, "#A02"); for (int i = 0; i < message.MyBuffer.Length; i++) { Assert.AreEqual(message.MyBuffer[i], retrieved.MyBuffer[i], "#A02-" + i); } QueueStorage.Delete(retrieved); }