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(); } } }