Skip to content

Commit

Permalink
Move retryOnFailed test to Utils class
Browse files Browse the repository at this point in the history
  • Loading branch information
kagkarlsson committed Oct 25, 2023
1 parent 7aaab59 commit b4ebb3d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.kagkarlsson.scheduler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Utils {
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);

public static void sleep(int millis) {
try {
Expand All @@ -9,4 +13,17 @@ public static void sleep(int millis) {
throw new RuntimeException(e);
}
}

public static void retryOnFailed(int retryTimes, Runnable r) {
try {
r.run();
} catch (RuntimeException e) {
if (retryTimes == 0) {
throw e;
} else {
LOG.info("Retrying test after failure.");
retryOnFailed(retryTimes - 1, r);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.kagkarlsson.scheduler.DbUtils;
import com.github.kagkarlsson.scheduler.SchedulerBuilder;
import com.github.kagkarlsson.scheduler.StopSchedulerExtension;
import com.github.kagkarlsson.scheduler.Utils;
import com.github.kagkarlsson.scheduler.jdbc.MssqlJdbcCustomization;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
Expand Down Expand Up @@ -64,7 +65,7 @@ static void initSchema() {
public void test_concurrency_optimistic_locking() throws InterruptedException {
// Observed failed heartbeats due to deadlock.
// FIXLATER: add retry of update heartbeats
retryOnFailed(
Utils.retryOnFailed(
1,
() -> {
DEBUG_LOG.info("Starting test_concurrency_optimistic_locking");
Expand All @@ -78,19 +79,6 @@ public void test_concurrency_optimistic_locking() throws InterruptedException {
});
}

static void retryOnFailed(int retryTimes, Runnable r) {
try {
r.run();
} catch (RuntimeException e) {
if (retryTimes == 0) {
throw e;
} else {
DEBUG_LOG.info("Retrying test after failure.");
retryOnFailed(retryTimes - 1, r);
}
}
}

@Test // select-for-update does not really work for sql server, there are too many deadlocks..
@Disabled
public void test_concurrency_select_for_update_generic() throws InterruptedException {
Expand Down

0 comments on commit b4ebb3d

Please sign in to comment.