Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class WindupRulesLinksTest {

private static final Logger LOG = LoggerFactory.getLogger(WindupRulesLinksTest.class);
private static final String RUN_TEST_MATCHING = "runTestsMatching";
private static final String RETRY_ATTEMPTS = "retryAttempts";
private static final int RETRY_ATTEMPTS_NUM = Integer.parseInt(System.getProperty(RETRY_ATTEMPTS, "3"));
private static final List<Integer> ACCEPTED_RESPONSE_CODE = Arrays.asList(
HttpURLConnection.HTTP_OK,
HttpURLConnection.HTTP_MOVED_PERM,
Expand Down Expand Up @@ -152,8 +154,20 @@ private boolean isValidLink(final String link)
final HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
// property name from https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html
urlConn.setConnectTimeout(Integer.getInteger("sun.net.client.defaultConnectTimeout", 5000));
urlConn.connect();
CACHE_ANALYZED_LINKS.put(link, urlConn.getResponseCode());
int attempt = 0;
while (true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend not to use this infinite loops. Even you are not specifying the delay between calls, so this is an over-kill.
You can use Awaitily to do this kind of checks where you have a max time or max retries to consider a process Success, and also you can define the delay between attempts.
We already use that in xavier-integration/EndToEndTests : https://github.com/project-xavier/xavier-integration/blob/9b01b4c1a932c16976b38f476a41a0d2bb799bcd/src/test/java/org/jboss/xavier/integrations/EndToEndTest.java#L596

{
try {
urlConn.connect();
CACHE_ANALYZED_LINKS.put(link, urlConn.getResponseCode());
break;
} catch (IOException e) {
LOG.warn(String.format("Attempt [%s/%s]: '%s' exception connecting to %s", ++attempt, RETRY_ATTEMPTS_NUM, e.getMessage(), link));
if (attempt == RETRY_ATTEMPTS_NUM) throw e;
} finally {
urlConn.disconnect();
}
}
}
final boolean validLink = ACCEPTED_RESPONSE_CODE.contains(CACHE_ANALYZED_LINKS.get(link));
if (validLink) LOG.debug(String.format("Response code %d for %s [%dms]", CACHE_ANALYZED_LINKS.get(link), link, System.currentTimeMillis() - starTime));
Expand Down