PageRenderTime 31ms CodeModel.GetById 20ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 23package org.mobicents.protocols.ss7.isup.impl.stack.timers;
 24
 25import java.util.ArrayList;
 26import java.util.List;
 27
 28import org.mobicents.protocols.ss7.isup.ISUPEvent;
 29import org.mobicents.protocols.ss7.isup.ISUPTimeoutEvent;
 30import org.mobicents.protocols.ss7.isup.message.ISUPMessage;
 31import org.testng.annotations.AfterClass;
 32import org.testng.annotations.AfterTest;
 33import org.testng.annotations.BeforeClass;
 34import org.testng.annotations.BeforeTest;
 35import org.testng.annotations.Test;
 36/**
 37 * @author baranowb
 38 * 
 39 */
 40public abstract class SingleTimers extends EventTestHarness {
 41
 42	protected int tid;
 43	protected long timeout;
 44
 45	protected ISUPMessage request; // message exchanged within
 46	protected ISUPMessage answer;
 47
 48	@BeforeClass
 49	public void setUp() throws Exception {
 50
 51		super.setUp();
 52		this.tid = getT_ID();
 53		this.timeout = getT();
 54		this.request = getRequest();
 55		this.answer = getAnswer();
 56	}
 57
 58	@AfterClass
 59	public void tearDown() throws Exception {
 60		super.provider.removeListener(this);
 61		super.tearDown();
 62	}
 63
 64	protected abstract long getT();
 65
 66	// IDS
 67	protected abstract int getT_ID();
 68
 69	protected ISUPMessage getAfterTRequest()
 70	{
 71		return this.provider.getMessageFactory().createREL(getRequest().getCircuitIdentificationCode().getCIC());
 72	}
 73	//@Test(groups = { "functional.timer","timer.timeout.timeout"})
 74	public void testWithTimeout() throws Exception
 75	{
 76		// add expected events on remote and local end
 77		List<EventReceived> expectedRemoteEventsReceived = new ArrayList<EventReceived>();
 78		List<EventReceived> expectedLocalEvents = new ArrayList<EventReceived>();
 79		
 80		long startTStamp = System.currentTimeMillis();
 81		super.provider.sendMessage(this.request);
 82		MessageEventReceived eventReceived = new MessageEventReceived(startTStamp, new ISUPEvent(super.provider, this.request));
 83		expectedRemoteEventsReceived.add(eventReceived);
 84		ISUPMessage afterTimeoutMessage = getAfterTRequest();
 85		if(afterTimeoutMessage!=null)
 86		{
 87			eventReceived = new MessageEventReceived(startTStamp+getT(), new ISUPEvent(super.provider,afterTimeoutMessage));
 88			expectedRemoteEventsReceived.add(eventReceived);
 89		}
 90		ISUPTimeoutEvent timeoutEvent = new ISUPTimeoutEvent(super.provider, this.request, tid);
 91		TimeoutEventReceived ter = new TimeoutEventReceived(startTStamp + timeout, timeoutEvent);
 92		expectedLocalEvents.add(ter);
 93		doWait(timeout+1000);
 94		
 95		// stop stack
 96		stack.stop();
 97
 98		// now make compare
 99		super.compareEvents(expectedLocalEvents, expectedRemoteEventsReceived);
100	}
101	//@Test(groups = { "functional.timer","timer.timeout.wotimeout"})
102	public void testWithoutTimeout() throws Exception
103	{
104		// add expected events on remote and local end
105		List<EventReceived> expectedRemoteEventsReceived = new ArrayList<EventReceived>();
106		List<EventReceived> expectedLocalEvents = new ArrayList<EventReceived>();
107
108		long startTStamp = System.currentTimeMillis();
109		this.provider.sendMessage(this.request);
110		MessageEventReceived eventReceived = new MessageEventReceived(startTStamp, new ISUPEvent(super.provider, this.request));
111		expectedRemoteEventsReceived.add(eventReceived);
112
113		doWait(timeout/2); //500 should be good even here.
114		long tstamp = System.currentTimeMillis();
115		doAnswer();
116		ISUPEvent event = new ISUPEvent(super.provider, this.answer);
117		eventReceived = new MessageEventReceived(tstamp, event);
118		expectedLocalEvents.add(eventReceived);
119		doWait(timeout); //wait more
120		
121		stack.stop();
122		// now make compare
123		super.compareEvents(expectedLocalEvents, expectedRemoteEventsReceived);
124	}
125	
126}