Esempio n. 1
0
        public void test_CreateTempQueue()
        {
            using (MQConnection con = connectToServer(address, null, null)) {
                String      queueName = String.Empty;
                QueueHandle qh        = new QueueHandle();

                // Try and create a temporary queue
                ErrorCode err = con.CreateTempQueue(out queueName, qh);
                Console.WriteLine("queueName:" + queueName);
                Assert.AreEqual(ErrorCode.EC_NOERROR, err, "Creating Queue");

                // Get permissions for that queue
                List <QueuePermissions> perms = new List <QueuePermissions>();
                con.QueueEnumeratePermissions(queueName, perms);
                for (int x = 0; x < perms.Count; ++x)
                {
                    QueuePermissions perm = perms[x];
                    Console.WriteLine(perm.EntityName + ":" + perm.Read + ":" + perm.Write + ":" + perm.Destroy + ":" + perm.ChangeSecurity);
                }
                Assert.IsTrue(perms.Count > 0);

                addAllUsers(con);

                // Try and write to that queue with another user.
                using (MQConnection con2 = connectToServer(simpleAddress, TEST_USERS[0], TEST_USERS[0])) {
                    QueueHandle qh2 = new QueueHandle();
                    ErrorCode   rc  = con2.OpenQueue(queueName, qh2);
                    Assert.IsTrue(rc == ErrorCode.EC_NOERROR, "Open Temp Queue rc:" + rc);
                    QueueMessage msg = new QueueMessage();
                    msg.Label = "Hello World";
                    Assert.IsTrue(ErrorCode.EC_NOERROR == con2.Enqueue(qh2, msg), "Enqueue to temp");
                    con2.CloseQueue(qh2);
                }
            }
        }
Esempio n. 2
0
        public void test_OpenQueue_Enqueue_Retrieve_CloseQueue()
        {
            MQConnection con = null;

            try {
                con = connectToServer(address, null, null);

                addAllGroups(con);
                addAllUsers(con);
                addAllQueues(con);

                QueueHandle handle = new QueueHandle();
                ErrorCode   ec     = con.OpenQueue(TEST_QUEUE[0], handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to open queue: " + TEST_QUEUE[0]);

                sendMessages(con, handle, 5, 0);

                for (int x = 0; x < 5; x++)
                {
                    QueueMessage msg = new QueueMessage();
                    ec = con.Retrieve(handle, true, 0, msg);
                    Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to retrieve message: " + x);

                    StreamReader r = new StreamReader(msg.Stream);
                    string       s = r.ReadLine();

                    Assert.IsTrue(int.Parse(s) == x, "Incorrect message retrieved: " + x);
                }

                ec = con.CloseQueue(handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to Close queue");
            } finally {
                if (con != null)
                {
                    con.Close();
                }
            }
        }
Esempio n. 3
0
        public void test_EnqueueWithRelay()
        {
            MQConnection con = null;

            try {
                con = connectToServer(address, null, null);
                QueueMessage msg = new QueueMessage();
                StreamWriter sw  = new StreamWriter(msg.Stream);
                sw.WriteLine(SPECIAL_MESSAGE);
                sw.Close();

                addAllQueues(con);
                ErrorCode ec = con.EnqueueWithRelay(new Uri(addressString + "/" + TEST_QUEUE[1]), msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unble to EnqueueWithRelay:" + ec);

                Thread.Sleep(100);

                QueueHandle handle = new QueueHandle();
                ec = con.OpenQueue(TEST_QUEUE[1], handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unble to OpenQueue:" + ec);

                msg = new QueueMessage();
                ec  = con.Retrieve(handle, true, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unble to Retrieve:" + ec);
                string txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals(SPECIAL_MESSAGE), "Incorrect Message: " + txt);

                ec = con.CloseQueue(handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unble to CloseQueue:" + ec);
            } finally {
                if (con != null)
                {
                    con.Close();
                }
            }
        }
Esempio n. 4
0
 /**
  * <summary>
  * Closes the connection to the queue.  After a call to close the MessageQueue
  * is no longer valid and should not be used.
  * </summary>
  *
  * <returns>The result code from a call to <c>MQConnection.CloseQueue()</c></returns>
  *
  * <seealso cref="MQConnection.CloseQueue(QueueHandle)">MQConnection.CloseQueue(QueueHandle) for details on errors</seealso>
  */
 public ErrorCode Close()
 {
     return(con.CloseQueue(que));
 }
Esempio n. 5
0
        public void test_Transactions()
        {
            MQConnection con = null;

            try {
                con = connectToServer(address, null, null);

                addAllGroups(con);
                addAllUsers(con);
                addAllQueues(con);

                QueueHandle handle = new QueueHandle();
                ErrorCode   ec     = con.OpenQueue(TEST_QUEUE[0], handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to open queue: " + TEST_QUEUE[0]);

                sendMessages(con, handle, 10, 0);

                ec = con.BeginTransaction();
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to BeginTransaction:" + ec);
                CursorHandle cur = new CursorHandle();

                ec = con.OpenCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to OpenCursor:" + ec);

                ec = con.AdvanceCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to AdvanceCursor:" + ec);
                ec = con.AdvanceCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to AdvanceCursor:" + ec);

                QueueMessage msg = new QueueMessage();
                ec = con.RetrieveCursor(handle, true, cur, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                string txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("2"), "Incorrect Message: " + txt + " should be 2");

                msg = new QueueMessage();
                ec  = con.RetrieveCursor(handle, true, cur, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("3"), "Incorrect Message: " + txt + " should be 3");

                msg = new QueueMessage();
                ec  = con.Retrieve(handle, true, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("0"), "Incorrect Message: " + txt + " should be 0");

                int[] ids = { 1, 4, 5, 6, 7, 8, 9 };
                for (int x = 0; x < ids.Length; x++)
                {
                    msg = new QueueMessage();
                    ec  = con.Retrieve(handle, true, 0, msg);
                    Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                    txt = (new StreamReader(msg.Stream)).ReadLine();
                    Console.WriteLine("txt: " + txt);
                    Assert.IsTrue(int.Parse(txt) == ids[x], "Incorrect Message: " + txt + " should be " + ids[x]);
                }

                ec = con.RollbackTransaction();
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RollbackTransaction:" + ec);

                for (int x = 0; x < 8; x++)
                {
                    msg = new QueueMessage();
                    ec  = con.Retrieve(handle, true, 0, msg);
                    Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                    txt = (new StreamReader(msg.Stream)).ReadLine();
                    Assert.IsTrue(int.Parse(txt) == x, "Incorrect Message: " + txt + " should be " + x);
                }

                ec = con.CommitTransaction();
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to CommitTransaction:" + ec);

                for (int x = 0; x < 2; x++)
                {
                    msg = new QueueMessage();
                    ec  = con.Retrieve(handle, true, 0, msg);
                    Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                    txt = (new StreamReader(msg.Stream)).ReadLine();
                    Assert.IsTrue(int.Parse(txt) == x + 8, "Incorrect Message: " + txt + " should be " + (x + 8));
                }

                ec = con.RollbackTransaction();
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RollbackTransaction:" + ec);

                ec = con.EndTransaction();
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RollbackTransaction:" + ec);

                for (int x = 0; x < 2; x++)
                {
                    msg = new QueueMessage();
                    ec  = con.Retrieve(handle, true, 0, msg);
                    Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor:" + ec);
                    txt = (new StreamReader(msg.Stream)).ReadLine();
                    Assert.IsTrue(int.Parse(txt) == x + 8, "Incorrect Message: " + txt + " should be " + (x + 8));
                }

                msg = new QueueMessage();
                ec  = con.Retrieve(handle, true, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOMOREMESSAGES, "Able to RetrieveCursor:" + ec);

                ec = con.CloseQueue(handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unble to CloseQueue:" + ec);
            } finally {
                if (con != null)
                {
                    con.Close();
                }
            }
        }
Esempio n. 6
0
        public void test_PeekID_PeekFront_OpenCursor_PeekCursor_SeekID_RetrieveCursor_AdvanceCursor_TestCurosr_CloseCursor_RetrieveID()
        {
            MQConnection con = null;

            try {
                con = connectToServer(address, null, null);

                addAllGroups(con);
                addAllUsers(con);
                addAllQueues(con);

                QueueHandle handle = new QueueHandle();
                ErrorCode   ec     = con.OpenQueue(TEST_QUEUE[0], handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to open queue: " + TEST_QUEUE[0]);

                sendMessages(con, handle, 5, 0);
                QueueMessage msg = new QueueMessage();
                StreamWriter sw  = new StreamWriter(msg.Stream);
                sw.WriteLine(SPECIAL_MESSAGE);
                sw.Close();

                byte[] b    = { 0, 0, 0, 0, 0, 0, 0, 0 };
                UUID   uuid = new UUID(new Guid(123456789, 4321, 1234, b));
                msg.ReciptID = uuid;
                //msg.ReciptID = ((UUID)uuid.Clone());

                ec = con.Enqueue(handle, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to write special message");

                sendMessages(con, handle, 5, 5);

                msg = new QueueMessage();
                ec  = con.PeekID(handle, true, uuid, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to PeekID:" + ec);

                string txt = (new StreamReader(msg.Stream)).ReadLine();
                Console.WriteLine("txt:\t\t\t" + txt);
                Console.WriteLine("uuid:\t\t\t" + (Guid)uuid);
                Console.WriteLine("msg.ReceiptID:\t" + (Guid)msg.ReciptID);
                Console.WriteLine("txt.Equals(SPECIAL_MESSAGE): " + txt.Equals(SPECIAL_MESSAGE));
                Console.WriteLine("uuid.Equals(msg.ReceiptID)): " + uuid.Equals(msg.ReciptID));
                Assert.IsTrue(txt.Equals(SPECIAL_MESSAGE) && uuid.Equals(msg.ReciptID), "Incorrect PeekID Message: " + (Guid)msg.ReciptID);

                msg = new QueueMessage();
                ec  = con.PeekFront(handle, true, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to PeekFront");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("0"), "Incorrect PeekFront Message: body=" + txt);

                CursorHandle cur = new CursorHandle();

                ec = con.OpenCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to OpenCursor");

                ec = con.SeekID(handle, uuid, 0, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to SeekID");
                msg = new QueueMessage();
                ec  = con.PeekCursor(handle, true, cur, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to PeekCursor");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals(SPECIAL_MESSAGE) && uuid.Equals(msg.ReciptID), "Incorrect PeekCursor Message: " + msg.ReciptID);

                ec = con.AdvanceCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to AdvanceCursor");
                msg = new QueueMessage();
                ec  = con.PeekCursor(handle, true, cur, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to PeekCursor (after advance)");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("5"), "Incorrect PeekCursor (after advance) Message: " + msg.ReciptID);

                msg = new QueueMessage();
                ec  = con.RetrieveCursor(handle, true, cur, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveCursor");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals("5"), "Incorrect PeekCursor (after RetrieveCursor) Message: " + msg.ReciptID);

                ec = con.TestCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to test Cursor, ec: " + ec);

                ec = con.CloseCursor(handle, cur);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to CloseCursor, ec: " + ec);


                msg = new QueueMessage();
                ec  = con.RetrieveID(handle, true, uuid, 0, msg);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to RetrieveID");
                txt = (new StreamReader(msg.Stream)).ReadLine();
                Assert.IsTrue(txt.Equals(SPECIAL_MESSAGE) && uuid.Equals(msg.ReciptID), "Incorrect RetrieveID Message: " + msg.ReciptID);

                int[] bodies = { 0, 1, 2, 3, 4, 6, 7, 8, 9 }; // 5 was retrieved above.
                for (int x = 0; x < bodies.Length; x++)
                {
                    msg = new QueueMessage();
                    ec  = con.Retrieve(handle, true, 0, msg);
                    Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to retrieve message: " + x);
                    txt = (new StreamReader(msg.Stream)).ReadLine();
                    Console.WriteLine("txt: " + txt);
                    Assert.IsTrue(int.Parse(txt) == bodies[x], "Incorrect message: " + txt);
                }


                ec = con.CloseQueue(handle);
                Assert.IsTrue(ec == ErrorCode.EC_NOERROR, "Unable to Close queue");
            } finally {
                if (con != null)
                {
                    con.Close();
                }
            }
        }