/protocols/ss7/isup/isup-impl/src/test/java/org/mobicents/protocols/ss7/isup/impl/stack/timers/SingleTimers.java

http://mobicents.googlecode.com/ · Java · 126 lines · 75 code · 18 blank · 33 comment · 1 complexity · bb4c6d797464e420c203c10051132554 MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.ss7.isup.impl.stack.timers;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. import org.mobicents.protocols.ss7.isup.ISUPEvent;
  26. import org.mobicents.protocols.ss7.isup.ISUPTimeoutEvent;
  27. import org.mobicents.protocols.ss7.isup.message.ISUPMessage;
  28. import org.testng.annotations.AfterClass;
  29. import org.testng.annotations.AfterTest;
  30. import org.testng.annotations.BeforeClass;
  31. import org.testng.annotations.BeforeTest;
  32. import org.testng.annotations.Test;
  33. /**
  34. * @author baranowb
  35. *
  36. */
  37. public abstract class SingleTimers extends EventTestHarness {
  38. protected int tid;
  39. protected long timeout;
  40. protected ISUPMessage request; // message exchanged within
  41. protected ISUPMessage answer;
  42. @BeforeClass
  43. public void setUp() throws Exception {
  44. super.setUp();
  45. this.tid = getT_ID();
  46. this.timeout = getT();
  47. this.request = getRequest();
  48. this.answer = getAnswer();
  49. }
  50. @AfterClass
  51. public void tearDown() throws Exception {
  52. super.provider.removeListener(this);
  53. super.tearDown();
  54. }
  55. protected abstract long getT();
  56. // IDS
  57. protected abstract int getT_ID();
  58. protected ISUPMessage getAfterTRequest()
  59. {
  60. return this.provider.getMessageFactory().createREL(getRequest().getCircuitIdentificationCode().getCIC());
  61. }
  62. //@Test(groups = { "functional.timer","timer.timeout.timeout"})
  63. public void testWithTimeout() throws Exception
  64. {
  65. // add expected events on remote and local end
  66. List<EventReceived> expectedRemoteEventsReceived = new ArrayList<EventReceived>();
  67. List<EventReceived> expectedLocalEvents = new ArrayList<EventReceived>();
  68. long startTStamp = System.currentTimeMillis();
  69. super.provider.sendMessage(this.request);
  70. MessageEventReceived eventReceived = new MessageEventReceived(startTStamp, new ISUPEvent(super.provider, this.request));
  71. expectedRemoteEventsReceived.add(eventReceived);
  72. ISUPMessage afterTimeoutMessage = getAfterTRequest();
  73. if(afterTimeoutMessage!=null)
  74. {
  75. eventReceived = new MessageEventReceived(startTStamp+getT(), new ISUPEvent(super.provider,afterTimeoutMessage));
  76. expectedRemoteEventsReceived.add(eventReceived);
  77. }
  78. ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(super.provider, this.request, tid);
  79. TimeoutEventReceived ter = new TimeoutEventReceived(startTStamp + timeout, timeoutEvent);
  80. expectedLocalEvents.add(ter);
  81. doWait(timeout+1000);
  82. // stop stack
  83. stack.stop();
  84. // now make compare
  85. super.compareEvents(expectedLocalEvents, expectedRemoteEventsReceived);
  86. }
  87. //@Test(groups = { "functional.timer","timer.timeout.wotimeout"})
  88. public void testWithoutTimeout() throws Exception
  89. {
  90. // add expected events on remote and local end
  91. List<EventReceived> expectedRemoteEventsReceived = new ArrayList<EventReceived>();
  92. List<EventReceived> expectedLocalEvents = new ArrayList<EventReceived>();
  93. long startTStamp = System.currentTimeMillis();
  94. this.provider.sendMessage(this.request);
  95. MessageEventReceived eventReceived = new MessageEventReceived(startTStamp, new ISUPEvent(super.provider, this.request));
  96. expectedRemoteEventsReceived.add(eventReceived);
  97. doWait(timeout/2); //500 should be good even here.
  98. long tstamp = System.currentTimeMillis();
  99. doAnswer();
  100. ISUPEvent event = new ISUPEvent(super.provider, this.answer);
  101. eventReceived = new MessageEventReceived(tstamp, event);
  102. expectedLocalEvents.add(eventReceived);
  103. doWait(timeout); //wait more
  104. stack.stop();
  105. // now make compare
  106. super.compareEvents(expectedLocalEvents, expectedRemoteEventsReceived);
  107. }
  108. }