Skip to content

Commit

Permalink
improve get shutdown timeout from props and use it for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-landiak committed Nov 22, 2024
1 parent 9526699 commit b4c5c4f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.paho.mqttv5.common.packet.MqttProperties;
import org.eclipse.paho.mqttv5.common.packet.UserProperty;
import org.jetbrains.annotations.NotNull;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.rules.ExternalResource;
import org.springframework.beans.BeansException;
Expand Down Expand Up @@ -80,6 +81,11 @@ public abstract class AbstractPubSubIntegrationTest {

protected final ObjectMapper mapper = new ObjectMapper();

@BeforeClass
public static void setup() throws Exception {
System.setProperty("tbmq.graceful.shutdown.timeout.sec", "1");
}

@Autowired
@Lazy
protected BCryptPasswordEncoder passwordEncoder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,19 @@ public static void shutdownAndAwaitTermination(ExecutorService service, long tim
}

public static long getTimeoutSeconds(long timeoutSeconds) {
String timeoutEnv = System.getenv("TBMQ_GRACEFUL_SHUTDOWN_TIMEOUT_SEC");
return timeoutSeconds > 0 ? timeoutSeconds : (timeoutEnv == null ? 5 : Long.parseLong(timeoutEnv));
if (timeoutSeconds > 0) {
return timeoutSeconds;
}
String timeoutValue = System.getenv("TBMQ_GRACEFUL_SHUTDOWN_TIMEOUT_SEC");
if (timeoutValue == null) {
timeoutValue = System.getProperty("tbmq.graceful.shutdown.timeout.sec");
}
final long defaultTimeout = 5L;
try {
return timeoutValue != null ? Long.parseLong(timeoutValue) : defaultTimeout;
} catch (NumberFormatException e) {
log.error("Invalid timeout value from system properties {}. Using default: 5 seconds", timeoutValue);
return defaultTimeout;
}
}
}

0 comments on commit b4c5c4f

Please sign in to comment.