PageRenderTime 28ms CodeModel.GetById 17ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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