Skip to content

Commit

Permalink
address reviewed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chathuranga-jayanath-99 committed Dec 10, 2024
1 parent 213b9ec commit e79f395
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public EndpointDefinition createDefinition(OMElement elem) {
if (timeoutDurationValue.getKeyValue() != null) {
Long.parseLong(timeoutDurationValue.getKeyValue());
}
definition.setTimeoutDuration(valueFactory.createTextValue(duration));
definition.setTimeoutDuration(timeoutDurationValue);
} catch (NumberFormatException e) {
handleException("Endpoint timeout duration expected as a " +
"number but was not a number");
Expand Down Expand Up @@ -242,7 +242,7 @@ public EndpointDefinition createDefinition(OMElement elem) {
if (retryDelayValue.getKeyValue() != null) {
Integer.parseInt(retryDelayValue.getKeyValue());
}
definition.setRetryDurationOnTimeout(valueFactory.createTextValue(retryDelay));
definition.setRetryDurationOnTimeout(retryDelayValue);
} catch (NumberFormatException e) {
handleException("The retry delay for timeouts should be specified " +
"as a valid number : " + retryDelay.getText(), e);
Expand Down Expand Up @@ -289,7 +289,7 @@ public EndpointDefinition createDefinition(OMElement elem) {
}
}
}
definition.setSuspendErrorCodes(valueFactory.createTextValue(suspendCodes));
definition.setSuspendErrorCodes(suspendErrorCodesValue);
}

OMElement initialDuration = suspendOnFailure.getFirstChildWithName(new QName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,41 @@ public void testSetDynamicTimeoutAction() throws XMLStreamException, AxisFault {

HTTPEndpointFactory httpEndpointFactory = new HTTPEndpointFactory();
OMElement omElement = AXIOMUtil.stringToOM(
"<http method=\"get\" statistics=\"enable\" trace=\"enable\" uri-template=\"http://localhost:3000/banks\" xmlns=\"http://ws.apache.org/ns/synapse\"><enableAddressing separateListener=\"true\" version=\"final\"/><timeout><duration>12</duration><responseAction>{$ctx:timeoutAction}</responseAction></timeout></http>");
"<http method=\"get\" statistics=\"enable\" trace=\"enable\" " +
"uri-template=\"http://localhost:3000/banks\" xmlns=\"http://ws.apache.org/ns/synapse\">" +
"<enableAddressing separateListener=\"true\" version=\"final\"/>" +
"<timeout>" +
"<duration>12</duration>" +
"<responseAction>{$ctx:timeoutAction}</responseAction>" +
"</timeout>" +
"</http>");
EndpointDefinition ep = httpEndpointFactory.createEndpointDefinition(omElement);
HTTPEndpoint httpEndpoint = new HTTPEndpoint();
httpEndpoint.setDefinition(ep);
MessageContext messageContext = createMessageContext();
messageContext.setProperty("timeoutAction", "discard");
Assert.assertEquals(httpEndpoint.getDefinition().getResolvedTimeoutAction(messageContext), SynapseConstants.DISCARD);
Assert.assertEquals(
httpEndpoint.getDefinition().getResolvedTimeoutAction(messageContext), SynapseConstants.DISCARD);
}

@Test
public void testSetSuspendOnFailureInitialDuration() throws XMLStreamException, AxisFault {

HTTPEndpointFactory httpEndpointFactory = new HTTPEndpointFactory();
OMElement omElement = AXIOMUtil.stringToOM(
"<http method=\"get\" uri-template=\"http://localhost:3000/banks\" xmlns=\"http://ws.apache.org/ns/synapse\"><timeout><duration>10</duration></timeout><suspendOnFailure><initialDuration>1000</initialDuration><progressionFactor>1</progressionFactor></suspendOnFailure><markForSuspension><retriesBeforeSuspension>0</retriesBeforeSuspension></markForSuspension></http>");
"<http method=\"get\" uri-template=\"http://localhost:3000/banks\" " +
"xmlns=\"http://ws.apache.org/ns/synapse\">" +
"<timeout>" +
"<duration>10</duration>" +
"</timeout>" +
"<suspendOnFailure>" +
"<initialDuration>1000</initialDuration>" +
"<progressionFactor>1</progressionFactor>" +
"</suspendOnFailure>" +
"<markForSuspension>" +
"<retriesBeforeSuspension>0</retriesBeforeSuspension>" +
"</markForSuspension>" +
"</http>");
EndpointDefinition ep1 = httpEndpointFactory.createEndpointDefinition(omElement);
Assert.assertEquals(ep1.getRetriesOnTimeoutBeforeSuspend(), "0");
Assert.assertEquals(ep1.getInitialSuspendDuration(), "1000");
Expand All @@ -187,28 +207,37 @@ public void testDefaultErrorHandlingValues() throws XMLStreamException, AxisFaul

HTTPEndpointFactory httpEndpointFactory = new HTTPEndpointFactory();
OMElement omElement = AXIOMUtil.stringToOM(
"<http method=\"get\" uri-template=\"http://localhost:3000/banks\" xmlns=\"http://ws.apache.org/ns/synapse\">\n" +
" </http>");
"<http method=\"get\" uri-template=\"http://localhost:3000/banks\" " +
"xmlns=\"http://ws.apache.org/ns/synapse\"></http>");
EndpointDefinition ep = httpEndpointFactory.createEndpointDefinition(omElement);
HTTPEndpoint httpEndpoint = new HTTPEndpoint();
httpEndpoint.setDefinition(ep);
MessageContext messageContext = createMessageContext();
Assert.assertEquals("Default timeout action should be 100", 100, httpEndpoint.getDefinition().getResolvedTimeoutAction(messageContext));
Assert.assertEquals("Default initial suspend duration should be -1", -1, httpEndpoint.getDefinition().getResolvedInitialSuspendDuration(messageContext));
Assert.assertEquals("Default maximum suspend duration should be 0", Long.MAX_VALUE, httpEndpoint.getDefinition().getResolvedSuspendMaximumDuration(messageContext));
Assert.assertEquals("Default suspend progression factor should be 1", 1f, httpEndpoint.getDefinition().getResolvedSuspendProgressionFactor(messageContext), 0.0f);
Assert.assertEquals("Default suspend error codes should be empty", new ArrayList<>(), httpEndpoint.getDefinition().getResolvedSuspendErrorCodes(messageContext));
Assert.assertEquals("Default timeout error codes should be empty", new ArrayList<>(), httpEndpoint.getDefinition().getResolvedTimeoutErrorCodes(messageContext));
Assert.assertEquals("Default retries on timeout before suspend should be 0", 0, httpEndpoint.getDefinition().getResolvedRetriesOnTimeoutBeforeSuspend(messageContext));
Assert.assertEquals("Default retry duration on timeout should be 0", 0, httpEndpoint.getDefinition().getResolvedRetryDurationOnTimeout(messageContext));
Assert.assertEquals("Default timeout action should be 100", 100,
httpEndpoint.getDefinition().getResolvedTimeoutAction(messageContext));
Assert.assertEquals("Default initial suspend duration should be -1", -1,
httpEndpoint.getDefinition().getResolvedInitialSuspendDuration(messageContext));
Assert.assertEquals("Default maximum suspend duration should be 0", Long.MAX_VALUE,
httpEndpoint.getDefinition().getResolvedSuspendMaximumDuration(messageContext));
Assert.assertEquals("Default suspend progression factor should be 1", 1f,
httpEndpoint.getDefinition().getResolvedSuspendProgressionFactor(messageContext), 0.0f);
Assert.assertEquals("Default suspend error codes should be empty", new ArrayList<>(),
httpEndpoint.getDefinition().getResolvedSuspendErrorCodes(messageContext));
Assert.assertEquals("Default timeout error codes should be empty", new ArrayList<>(),
httpEndpoint.getDefinition().getResolvedTimeoutErrorCodes(messageContext));
Assert.assertEquals("Default retries on timeout before suspend should be 0", 0,
httpEndpoint.getDefinition().getResolvedRetriesOnTimeoutBeforeSuspend(messageContext));
Assert.assertEquals("Default retry duration on timeout should be 0", 0,
httpEndpoint.getDefinition().getResolvedRetryDurationOnTimeout(messageContext));
}

@Test
public void testSetSuspendErrorCodes() throws XMLStreamException, AxisFault {

HTTPEndpointFactory httpEndpointFactory = new HTTPEndpointFactory();
OMElement omElement = AXIOMUtil.stringToOM(
"<http method=\"get\" uri-template=\"http://localhost:3000/banks\" xmlns=\"http://ws.apache.org/ns/synapse\">\n" +
"<http method=\"get\" uri-template=\"http://localhost:3000/banks\" " +
"xmlns=\"http://ws.apache.org/ns/synapse\">\n" +
" <suspendOnFailure>\n" +
" <errorCodes>{$ctx:suspendErrorCodes}</errorCodes>\n" +
" <initialDuration>-1</initialDuration>\n" +
Expand All @@ -227,7 +256,8 @@ public void testSetSuspendErrorCodes() throws XMLStreamException, AxisFault {
List<Integer> actualSuspendErrorCodes = new ArrayList<>();
actualSuspendErrorCodes.add(101503);
actualSuspendErrorCodes.add(101504);
List<Integer> expectedSuspendErrorCodes = httpEndpoint.getDefinition().getResolvedSuspendErrorCodes(messageContext);
List<Integer> expectedSuspendErrorCodes =
httpEndpoint.getDefinition().getResolvedSuspendErrorCodes(messageContext);
Assert.assertTrue(expectedSuspendErrorCodes.equals(actualSuspendErrorCodes));
}

Expand All @@ -236,7 +266,8 @@ public void testSetTimeoutErrorCodes() throws XMLStreamException, AxisFault {

HTTPEndpointFactory httpEndpointFactory = new HTTPEndpointFactory();
OMElement omElement = AXIOMUtil.stringToOM(
"<http method=\"get\" uri-template=\"http://localhost:3000/banks\" xmlns=\"http://ws.apache.org/ns/synapse\">\n" +
"<http method=\"get\" uri-template=\"http://localhost:3000/banks\" " +
"xmlns=\"http://ws.apache.org/ns/synapse\">\n" +
" <markForSuspension>\n" +
" <errorCodes>{$ctx:timeoutErrorCodes}</errorCodes>\n" +
" <retriesBeforeSuspension>10</retriesBeforeSuspension>\n" +
Expand All @@ -251,7 +282,8 @@ public void testSetTimeoutErrorCodes() throws XMLStreamException, AxisFault {
List<Integer> actualTimeoutErrorCodes = new ArrayList<>();
actualTimeoutErrorCodes.add(101503);
actualTimeoutErrorCodes.add(101504);
List<Integer> expectedTimeoutErrorCodes = httpEndpoint.getDefinition().getResolvedTimeoutErrorCodes(messageContext);
List<Integer> expectedTimeoutErrorCodes =
httpEndpoint.getDefinition().getResolvedTimeoutErrorCodes(messageContext);
Assert.assertTrue(expectedTimeoutErrorCodes.equals(actualTimeoutErrorCodes));
}

Expand Down

0 comments on commit e79f395

Please sign in to comment.