/protocols/jain-mgcp/stack/src/test/java/org/mobicents/protocols/mgcp/stack/test/MessageFlowHarness.java

http://mobicents.googlecode.com/ · Java · 108 lines · 57 code · 27 blank · 24 comment · 4 complexity · 066160cf635fb6e9938f91caf3644a0d 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.mgcp.stack.test;
  23. import java.net.InetAddress;
  24. import org.apache.log4j.Logger;
  25. import org.mobicents.protocols.mgcp.stack.JainMgcpStackImpl;
  26. import org.mobicents.protocols.mgcp.stack.JainMgcpStackProviderImpl;
  27. public abstract class MessageFlowHarness extends TestHarness {
  28. private static Logger logger = Logger.getLogger("mgcp.test");
  29. protected static long TRANSACTION_TIMES_OUT_FOR = 31000;
  30. protected static long STACKS_START_FOR = 1000;
  31. protected static long STACKS_SHUT_DOWN_FOR = 500;
  32. // timeout values depend on pc
  33. protected static long MESSAGES_ARRIVE_FOR = 3000;
  34. protected static long RETRANSMISSION_TRANSACTION_TIMES_OUT_FOR = 5000;
  35. protected InetAddress caIPAddress = null;
  36. protected InetAddress mgIPAddress = null;
  37. protected JainMgcpStackImpl caStack = null;
  38. protected JainMgcpStackImpl mgStack = null;
  39. protected JainMgcpStackProviderImpl caProvider = null;
  40. protected JainMgcpStackProviderImpl mgProvider = null;
  41. public MessageFlowHarness(String name) {
  42. super(name);
  43. }
  44. public void setUp() throws java.lang.Exception {
  45. caIPAddress = InetAddress.getByName(LOCAL_ADDRESS);
  46. mgIPAddress = InetAddress.getByName(LOCAL_ADDRESS);
  47. caStack = new JainMgcpStackImpl(caIPAddress, CA_PORT);
  48. mgStack = new JainMgcpStackImpl(mgIPAddress, MGW_PORT);
  49. caProvider = (JainMgcpStackProviderImpl) caStack.createProvider();
  50. mgProvider = (JainMgcpStackProviderImpl) mgStack.createProvider();
  51. }
  52. public void tearDown() throws java.lang.Exception {
  53. System.out.println("CLOSE THE STACK");
  54. if (caStack != null) {
  55. caStack.close();
  56. caStack = null;
  57. }
  58. if (mgStack != null) {
  59. mgStack.close();
  60. mgStack = null;
  61. }
  62. // Wait for stack threads to release resources (e.g. port)
  63. sleep(STACKS_SHUT_DOWN_FOR);
  64. }
  65. protected static void waitForTimeout() {
  66. sleep(TRANSACTION_TIMES_OUT_FOR);
  67. }
  68. protected static void waitForRetransmissionTimeout() {
  69. sleep(RETRANSMISSION_TRANSACTION_TIMES_OUT_FOR);
  70. }
  71. public static void waitForMessage() {
  72. sleep(MESSAGES_ARRIVE_FOR);
  73. }
  74. protected static void sleep(long sleepFor) {
  75. try {
  76. Thread.sleep(sleepFor);
  77. } catch (InterruptedException ex) {
  78. // Ignore
  79. }
  80. }
  81. }