transaction.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. module("Stomp Transaction");
  2. test("Send a message in a transaction and abort", function() {
  3. var body = Math.random();
  4. var body2 = Math.random();
  5. var client = Stomp.client(TEST.url);
  6. client.debug = TEST.debug;
  7. client.connect(TEST.login, TEST.password,
  8. function() {
  9. client.subscribe(TEST.destination, function(message)
  10. {
  11. start();
  12. // we should receive the 2nd message outside the transaction
  13. equals(message.body, body2);
  14. client.disconnect();
  15. });
  16. var tx = client.begin("txid_" + Math.random());
  17. client.send(TEST.destination, {transaction: tx.id}, body);
  18. tx.abort();
  19. client.send(TEST.destination, {}, body2);
  20. });
  21. stop(TEST.timeout);
  22. });
  23. test("Send a message in a transaction and commit", function() {
  24. var body = Math.random();
  25. var client = Stomp.client(TEST.url);
  26. client.debug = TEST.debug;
  27. client.connect(TEST.login, TEST.password,
  28. function() {
  29. client.subscribe(TEST.destination, function(message)
  30. {
  31. start();
  32. equals(message.body, body);
  33. client.disconnect();
  34. });
  35. var tx = client.begin();
  36. client.send(TEST.destination, {transaction: tx.id}, body);
  37. tx.commit();
  38. });
  39. stop(TEST.timeout);
  40. });
  41. test("Send a message outside a transaction and abort", function() {
  42. var body = Math.random();
  43. var client = Stomp.client(TEST.url);
  44. client.debug = TEST.debug;
  45. client.connect(TEST.login, TEST.password,
  46. function() {
  47. client.subscribe(TEST.destination, function(message)
  48. {
  49. start();
  50. // we should receive the message since it was sent outside the transaction
  51. equals(message.body, body);
  52. client.disconnect();
  53. });
  54. var tx = client.begin();
  55. client.send(TEST.destination, {}, body);
  56. tx.abort();
  57. });
  58. stop(TEST.timeout);
  59. });