Skip to content

Commit

Permalink
Merge branch 'master' into issue-2073
Browse files Browse the repository at this point in the history
* master:
  Patch to remove blocking on S3AccessTool This refer to #2339
  Fixes for testsuite
  • Loading branch information
Maria Farooq committed Aug 8, 2017
2 parents fdde995 + 5fd4fe5 commit 0edeab0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,25 @@ public boolean uploadFile(final String fileToUpload) {
logger.info("File to upload to S3: " + fileUri.toString());
}

DateTime start = DateTime.now();
while (!FileUtils.waitFor(file, 30)){}
DateTime end = DateTime.now();
double waitDuration = (end.getMillis() - start.getMillis())/1000;
if (waitDuration > maxDelay || testing) {
if (logger.isInfoEnabled()) {
String msg = String.format("Finished waiting for recording file %s. Wait time %,.2f. Size of file in bytes %s", fileUri.toString(), waitDuration, file.length());
logger.info(msg);
}
}
if (file.exists()) {
//For statistics and logs
DateTime start, end;
double waitDuration;

// if (!file.exists()) {
// start = DateTime.now();
// while (!FileUtils.waitFor(file, 2)) {
// }
// end = DateTime.now();
// waitDuration = (end.getMillis() - start.getMillis()) / 1000;
// if (waitDuration > maxDelay || testing) {
// if (logger.isInfoEnabled()) {
// String msg = String.format("Finished waiting for recording file %s. Wait time %,.2f. Size of file in bytes %s", fileUri.toString(), waitDuration, file.length());
// logger.info(msg);
// }
// }
// }

if (fileExists(file)) {
start = DateTime.now();
if (testing) {
try {
Expand Down Expand Up @@ -167,7 +175,8 @@ public boolean uploadFile(final String fileToUpload) {
}
return true;
} else {
logger.error("Timeout waiting for the recording file: "+file.getAbsolutePath());
String msg = String.format("Recording file \"%s\" doesn't exists ",file.getPath());
logger.error(msg);
return false;
}
} catch (AmazonServiceException ase) {
Expand All @@ -188,6 +197,14 @@ public boolean uploadFile(final String fileToUpload) {
}
}

private boolean fileExists(final File file) {
if (file.exists()) {
return true;
} else {
return FileUtils.waitFor(file, 2);
}
}

public URI getS3Uri(final String fileToUpload) {
if (s3client == null) {
s3client = getS3client();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ public void testDialClientAliceWithTimeLimit() throws ParseException, Interrupte
assertTrue(bobCall.respondToDisconnect());
assertTrue(aliceCall.respondToDisconnect());

Thread.sleep(1000);
Thread.sleep(2000);

logger.info("About to check the Requests");
List<LoggedRequest> requests = findAll(getRequestedFor(urlPathMatching("/1111")));
Expand All @@ -681,7 +681,9 @@ public void testDialClientAliceWithTimeLimit() throws ParseException, Interrupte
}
JsonObject cdr = RestcommCallsTool.getInstance().getCall(deploymentUrl.toString(), adminAccountSid, adminAuthToken, callSid);
JsonObject jsonObj = cdr.getAsJsonObject();
assertEquals("completed", jsonObj.get("status").getAsString().toLowerCase());
String cdrStatus = jsonObj.get("status").getAsString().toLowerCase();
logger.info("CDR Status: "+ cdrStatus);
assertEquals("completed", cdrStatus);

JsonObject metrics = MonitoringServiceTool.getInstance().getMetrics(deploymentUrl.toString(),adminAccountSid, adminAuthToken);
assertNotNull(metrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
/**
* Test for Dial Action attribute. Reference: https://www.twilio.com/docs/api/twiml/dial#attributes-action The 'action'
* attribute takes a URL as an argument. When the dialed call ends, Restcomm will make a GET or POST request to this URL
*
*
* @author <a href="mailto:gvagenas@gmail.com">gvagenas</a>
*
*
*/
@RunWith(Arquillian.class)
public class DialActionAnswerDelayTest {
Expand All @@ -92,7 +92,7 @@ public class DialActionAnswerDelayTest {
private Deployer deployer;
@ArquillianResource
URL deploymentUrl;

//Dial Action URL: http://ACae6e420f425248d6a26948c17a9e2acf:77f8c12cc7b8f8423e5c38b035249166@127.0.0.1:8080/restcomm/2012-04-24/DialAction Method: POST
@Rule
public WireMockRule wireMockRule = new WireMockRule(8090); // No-args constructor defaults to port 8080
Expand Down Expand Up @@ -187,7 +187,7 @@ public void after() throws Exception {

@Test
public void testDialActionInvalidCall() throws ParseException, InterruptedException {

stubFor(post(urlPathMatching("/DialAction.*"))
.willReturn(aResponse()
.withStatus(200)));
Expand Down Expand Up @@ -219,7 +219,7 @@ public void testDialActionInvalidCall() throws ParseException, InterruptedExcept
assertTrue(requests.size() == 1);
String requestBody = requests.get(0).getBodyAsString();
String[] params = requestBody.split("&");
assertTrue(requestBody.contains("DialCallStatus=null"));
assertTrue(requestBody.contains("DialCallStatus=failed"));
assertTrue(requestBody.contains("To=%2B12223334455"));
assertTrue(requestBody.contains("From=bob"));
assertTrue(requestBody.contains("DialCallDuration=0"));
Expand All @@ -237,10 +237,10 @@ public void testDialActionInvalidCall() throws ParseException, InterruptedExcept
// JsonObject cdr = RestcommCallsTool.getInstance().getCall(deploymentUrl.toString(), adminAccountSid, adminAuthToken, dialCallSid);
// assertNotNull(cdr);
}

@Test //No regression test for https://github.com/Mobicents/RestComm/issues/505
public void testDialActionInvalidCallCheckCallStatusCompleted() throws ParseException, InterruptedException {

stubFor(post(urlPathMatching("/DialAction.*"))
.willReturn(aResponse()
.withStatus(200)));
Expand All @@ -261,23 +261,19 @@ public void testDialActionInvalidCallCheckCallStatusCompleted() throws ParseExce
assertTrue(bobCall.waitOutgoingCallResponse(5 * 1000));
assertEquals(Response.SERVER_INTERNAL_ERROR, bobCall.getLastReceivedResponse().getStatusCode());

try {
Thread.sleep(10 * 1000);
} catch (final InterruptedException exception) {
exception.printStackTrace();
}
Thread.sleep(10 * 1000);

logger.info("About to check the DialAction Requests");
List<LoggedRequest> requests = findAll(postRequestedFor(urlPathMatching("/DialAction.*")));
assertTrue(requests.size() == 1);
String requestBody = requests.get(0).getBodyAsString();
String[] params = requestBody.split("&");
//DialCallStatus should be null since there was no call made - since Alice is not registered
assertTrue(requestBody.contains("DialCallStatus=null"));
assertTrue(requestBody.contains("DialCallStatus=failed"));
assertTrue(requestBody.contains("To=%2B12223334455"));
assertTrue(requestBody.contains("From=bob"));
assertTrue(requestBody.contains("DialCallDuration=0"));
assertTrue(requestBody.contains("CallStatus=completed"));
assertTrue(requestBody.contains("CallStatus=wait-for-answer"));
Iterator iter = Arrays.asList(params).iterator();
String dialCallSid = null;
while (iter.hasNext()) {
Expand All @@ -299,7 +295,7 @@ public void testDialActionAliceAnswers() throws ParseException, InterruptedExcep
stubFor(post(urlPathMatching("/DialAction.*"))
.willReturn(aResponse()
.withStatus(200)));

// Phone2 register as alice
SipURI uri = aliceSipStack.getAddressFactory().createSipURI(null, "127.0.0.1:5080");
assertTrue(alicePhone.register(uri, "alice", "1234", aliceContact, 3600, 3600));
Expand Down Expand Up @@ -379,7 +375,7 @@ public void testDialActionAliceAnswersAliceHangup() throws ParseException, Inter
stubFor(post(urlPathMatching("/DialAction.*"))
.willReturn(aResponse()
.withStatus(200)));

// Phone2 register as alice
SipURI uri = aliceSipStack.getAddressFactory().createSipURI(null, "127.0.0.1:5080");
assertTrue(alicePhone.register(uri, "alice", "1234", aliceContact, 3600, 3600));
Expand Down Expand Up @@ -450,14 +446,14 @@ public void testDialActionAliceAnswersAliceHangup() throws ParseException, Inter
JsonObject cdr = RestcommCallsTool.getInstance().getCall(deploymentUrl.toString(), adminAccountSid, adminAuthToken, dialCallSid);
assertNotNull(cdr);
}

@Test
public void testDialActionAliceAnswersBobDisconnects() throws ParseException, InterruptedException {

stubFor(post(urlPathMatching("/DialAction.*"))
.willReturn(aResponse()
.withStatus(200)));

// Phone2 register as alice
SipURI uri = aliceSipStack.getAddressFactory().createSipURI(null, "127.0.0.1:5080");
assertTrue(alicePhone.register(uri, "alice", "1234", aliceContact, 3600, 3600));
Expand Down Expand Up @@ -528,14 +524,14 @@ public void testDialActionAliceAnswersBobDisconnects() throws ParseException, In
JsonObject cdr = RestcommCallsTool.getInstance().getCall(deploymentUrl.toString(), adminAccountSid, adminAuthToken, dialCallSid);
assertNotNull(cdr);
}

@Test
public void testDialActionAliceNOAnswer() throws ParseException, InterruptedException {

stubFor(post(urlPathMatching("/DialAction.*"))
.willReturn(aResponse()
.withStatus(200)));

// Phone2 register as alice
SipURI uri = aliceSipStack.getAddressFactory().createSipURI(null, "127.0.0.1:5080");
assertTrue(alicePhone.register(uri, "alice", "1234", aliceContact, 3600, 3600));
Expand Down Expand Up @@ -566,11 +562,11 @@ public void testDialActionAliceNOAnswer() throws ParseException, InterruptedExce

assertTrue(bobCall.waitOutgoingCallResponse(120 * 1000));
assertEquals(Response.REQUEST_TIMEOUT, bobCall.getLastReceivedResponse().getStatusCode());

Thread.sleep(3700);

Thread.sleep(10000);

logger.info("About to check the DialAction Requests");
List<LoggedRequest> requests = findAll(postRequestedFor(urlPathMatching("/DialAction.*")));
assertTrue(requests.size() == 1);
Expand Down Expand Up @@ -605,7 +601,7 @@ public void testDialActionAliceBusy() throws ParseException, InterruptedExceptio
stubFor(post(urlPathMatching("/DialAction.*"))
.willReturn(aResponse()
.withStatus(200)));

// Phone2 register as alice
SipURI uri = aliceSipStack.getAddressFactory().createSipURI(null, "127.0.0.1:5080");
assertTrue(alicePhone.register(uri, "alice", "1234", aliceContact, 3600, 3600));
Expand Down Expand Up @@ -640,7 +636,7 @@ public void testDialActionAliceBusy() throws ParseException, InterruptedExceptio
} catch (final InterruptedException exception) {
exception.printStackTrace();
}

logger.info("About to check the DialAction Requests");
List<LoggedRequest> requests = findAll(postRequestedFor(urlPathMatching("/DialAction.*")));
assertTrue(requests.size() == 1);
Expand All @@ -666,14 +662,14 @@ public void testDialActionAliceBusy() throws ParseException, InterruptedExceptio
JsonObject cdr = RestcommCallsTool.getInstance().getCall(deploymentUrl.toString(), adminAccountSid, adminAuthToken, dialCallSid);
assertNotNull(cdr);
}

@Test
public void testSipInviteCustomHeaders() throws ParseException, InterruptedException {

stubFor(post(urlPathMatching("/DialAction.*"))
.willReturn(aResponse()
.withStatus(200)));

// Phone2 register as alice
SipURI uri = aliceSipStack.getAddressFactory().createSipURI(null, "127.0.0.1:5080");
assertTrue(alicePhone.register(uri, "alice", "1234", aliceContact, 3600, 3600));
Expand Down Expand Up @@ -706,7 +702,7 @@ public void testSipInviteCustomHeaders() throws ParseException, InterruptedExcep

assertTrue(aliceCall.waitForIncomingCall(30 * 1000));
assertTrue(aliceCall.sendIncomingCallResponse(Response.RINGING, "Ringing-Alice", 3600));

// Add custom headers to the SIP INVITE
String receivedBody = new String(aliceCall.getLastReceivedRequest().getRawContent());
// public boolean sendIncomingCallResponse(int statusCode,
Expand Down

0 comments on commit 0edeab0

Please sign in to comment.