Пример #1
0
        public void MsgQueueFileStore_Corrupt_MissingIndex()
        {
            MsgQueueFileStore store = null;
            int           count;
            QueuedMsgInfo msgInfo;
            QueuedMsg     msg;
            object        persistID;

            Guid[] ids;

            // Create a store with a bunch of messages, close it, and
            // then delete the index file.  Then open the store and
            // verify that it rebuilds the index.

            ClearFolders();

            try
            {
                store = new MsgQueueFileStore(root);
                store.Open();

                ids = new Guid[MessageCount];

                for (int i = 0; i < MessageCount; i++)
                {
                    msg          = new QueuedMsg();
                    msg.TargetEP = "logical://test/" + i.ToString();
                    msg.Body     = i;
                    msgInfo      = new QueuedMsgInfo(null, msg);

                    store.Add(msgInfo, msg);
                    ids[i] = msg.ID;
                }

                Assert.AreEqual(MessageCount, store.Count);
                count = 0;
                foreach (QueuedMsgInfo i in store)
                {
                    count++;
                }

                Assert.AreEqual(MessageCount, count);

                for (int i = 0; i < ids.Length; i++)
                {
                    Guid id = ids[i];

                    persistID = store.GetPersistID(id);
                    Assert.IsNotNull(persistID);

                    msgInfo = store.GetInfo(persistID);
                    Assert.IsNotNull(msgInfo);
                    Assert.AreEqual((MsgEP)("logical://test/" + i.ToString()), msgInfo.TargetEP);

                    msg = store.Get(persistID);
                    msg.DeserializedBody();
                    Assert.AreEqual(i, (int)msg.Body);
                }

                // Close the store, delete the index, then reopen the store and
                // verify that it rebuilt the index.

                store.Close();
                File.Delete(root + "\\messages.index");
                store.Open();
                Assert.AreEqual(MessageCount, store.Count);

                for (int i = 0; i < ids.Length; i++)
                {
                    Guid id = ids[i];

                    persistID = store.GetPersistID(id);
                    Assert.IsNotNull(persistID);

                    msgInfo = store.GetInfo(persistID);
                    Assert.IsNotNull(msgInfo);
                    Assert.AreEqual((MsgEP)("logical://test/" + i.ToString()), msgInfo.TargetEP);

                    msg = store.Get(persistID);
                    msg.DeserializedBody();
                    Assert.AreEqual(i, (int)msg.Body);
                }
            }
            finally
            {
                if (store != null)
                {
                    store.Close();
                }
            }
        }
Пример #2
0
        public void MsgQueueFileStore_Multiple()
        {
            MsgQueueFileStore store = null;
            int           count;
            QueuedMsgInfo msgInfo;
            QueuedMsg     msg;
            object        persistID;

            Guid[] ids;

            ClearFolders();

            try
            {
                store = new MsgQueueFileStore(root);
                store.Open();

                ids = new Guid[MessageCount];

                for (int i = 0; i < MessageCount; i++)
                {
                    msg          = new QueuedMsg();
                    msg.TargetEP = "logical://test/" + i.ToString();
                    msg.Body     = i;
                    msgInfo      = new QueuedMsgInfo(null, msg);

                    store.Add(msgInfo, msg);
                    ids[i] = msg.ID;
                }

                Assert.AreEqual(MessageCount, store.Count);
                count = 0;
                foreach (QueuedMsgInfo i in store)
                {
                    count++;
                }

                Assert.AreEqual(MessageCount, count);

                for (int i = 0; i < ids.Length; i++)
                {
                    Guid id = ids[i];

                    persistID = store.GetPersistID(id);
                    Assert.IsNotNull(persistID);

                    msgInfo = store.GetInfo(persistID);
                    Assert.IsNotNull(msgInfo);
                    Assert.AreEqual((MsgEP)("logical://test/" + i.ToString()), msgInfo.TargetEP);

                    msg = store.Get(persistID);
                    msg.DeserializedBody();
                    Assert.AreEqual(i, (int)msg.Body);
                }

                // Close and reopen the store, making sure that all of the
                // messages are still there.

                store.Close();
                store.Open();
                Assert.AreEqual(MessageCount, store.Count);

                for (int i = 0; i < ids.Length; i++)
                {
                    Guid id = ids[i];

                    persistID = store.GetPersistID(id);
                    Assert.IsNotNull(persistID);

                    msgInfo = store.GetInfo(persistID);
                    Assert.IsNotNull(msgInfo);
                    Assert.AreEqual((MsgEP)("logical://test/" + i.ToString()), msgInfo.TargetEP);

                    msg = store.Get(persistID);
                    msg.DeserializedBody();
                    Assert.AreEqual(i, (int)msg.Body);
                }

                // Remove all of the messges and verify that they're gone

                for (int i = 0; i < MessageCount; i++)
                {
                    persistID = store.GetPersistID(ids[i]);
                    Assert.IsNotNull(persistID);

                    store.Remove(persistID);
                    Assert.IsNull(store.GetPersistID(ids[i]));
                    Assert.IsNull(store.Get(persistID));
                    Assert.IsNull(store.GetInfo(persistID));
                }

                // Close and reopen the store and verify that there are no messages.

                store.Close();
                store.Open();

                Assert.AreEqual(0, store.Count);
            }
            finally
            {
                if (store != null)
                {
                    store.Close();
                }
            }
        }