Fix Retransmitter creation to take effect of originalWaitInterval config
This commit is contained in:
parent
0ea60d85b3
commit
105a49749e
4
.gitignore
vendored
4
.gitignore
vendored
@ -7,3 +7,7 @@
|
|||||||
.project
|
.project
|
||||||
.settings/
|
.settings/
|
||||||
bin/
|
bin/
|
||||||
|
|
||||||
|
# Ignore IntelliJ IDEA files
|
||||||
|
.idea
|
||||||
|
*.iml
|
||||||
|
|||||||
@ -150,7 +150,7 @@ public class StunClientTransaction
|
|||||||
/**
|
/**
|
||||||
* A transaction request retransmitter
|
* A transaction request retransmitter
|
||||||
*/
|
*/
|
||||||
private final Retransmitter retransmitter = new Retransmitter();
|
private final Retransmitter retransmitter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a client transaction.
|
* Creates a client transaction.
|
||||||
@ -206,6 +206,8 @@ public class StunClientTransaction
|
|||||||
|
|
||||||
initTransactionConfiguration();
|
initTransactionConfiguration();
|
||||||
|
|
||||||
|
retransmitter = new Retransmitter(); // create it here to support 'originalWaitInterval' configuration
|
||||||
|
|
||||||
this.transactionID = transactionID;
|
this.transactionID = transactionID;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|||||||
@ -36,7 +36,8 @@ public class DatagramCollector
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// The 'receive' method synchronized the packet, hence the 'getData()' (also synchronized) will block
|
||||||
|
// on this anyway even after 'waitForPacket' and 'collectPacket' calls.
|
||||||
sock.receive(receivedPacket);
|
sock.receive(receivedPacket);
|
||||||
|
|
||||||
synchronized (this)
|
synchronized (this)
|
||||||
|
|||||||
@ -316,6 +316,63 @@ public class ShallowStackTest extends TestCase
|
|||||||
Arrays.equals(expectedReturn, actualReturn));
|
Arrays.equals(expectedReturn, actualReturn));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify StackProperties.FIRST_CTRAN_RETRANS_AFTER can indeed update StunClientTransaction.Retransmitter
|
||||||
|
*/
|
||||||
|
public void testRetransmissionOriginalWait()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
long originalWait = 200; // milliseconds
|
||||||
|
System.setProperty(StackProperties.FIRST_CTRAN_RETRANS_AFTER, String.valueOf(originalWait));
|
||||||
|
|
||||||
|
Request bindingRequest = MessageFactory.createBindingRequest();
|
||||||
|
|
||||||
|
dgramCollector.startListening(dummyServerSocket);
|
||||||
|
|
||||||
|
long firstTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
stunStack.sendRequest(bindingRequest,
|
||||||
|
dummyServerAddress,
|
||||||
|
localAddress,
|
||||||
|
new SimpleResponseCollector());
|
||||||
|
|
||||||
|
//wait for its arrival
|
||||||
|
dgramCollector.waitForPacket();
|
||||||
|
DatagramPacket receivedPacket = dgramCollector.collectPacket();
|
||||||
|
|
||||||
|
assertTrue("The stack did not properly send a Binding Request",
|
||||||
|
(receivedPacket.getLength() > 0));
|
||||||
|
|
||||||
|
Request receivedRequest =
|
||||||
|
(Request)Request.decode(receivedPacket.getData(),
|
||||||
|
(char)0,
|
||||||
|
(char)receivedPacket.getLength());
|
||||||
|
assertEquals("The received request did not match the "
|
||||||
|
+"one that was sent.",
|
||||||
|
bindingRequest, //expected
|
||||||
|
receivedRequest); // actual
|
||||||
|
|
||||||
|
// wait for the 1st retransmission with originalWait
|
||||||
|
dgramCollector.startListening(dummyServerSocket);
|
||||||
|
dgramCollector.waitForPacket();
|
||||||
|
receivedPacket = dgramCollector.collectPacket();
|
||||||
|
|
||||||
|
assertTrue("The stack did not retransmit a Binding Request",
|
||||||
|
(receivedPacket.getLength() > 0));
|
||||||
|
|
||||||
|
receivedRequest = (Request)Request.decode(
|
||||||
|
receivedPacket.getData(),
|
||||||
|
(char)0,
|
||||||
|
(char)receivedPacket.getLength());
|
||||||
|
assertEquals("The retransmitted request did not match the original.",
|
||||||
|
bindingRequest, //expected
|
||||||
|
receivedRequest); // actual
|
||||||
|
|
||||||
|
// verify the retransmission is longer than the originalWait
|
||||||
|
long secondTime = System.currentTimeMillis();
|
||||||
|
assertTrue((secondTime - firstTime) >= originalWait);
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------- listener implementations ---------
|
//--------------------------------------- listener implementations ---------
|
||||||
/**
|
/**
|
||||||
* A simple utility that allows us to asynchronously collect messages.
|
* A simple utility that allows us to asynchronously collect messages.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user