Skip to content

Commit ae3ae03

Browse files
committed
[Fix #143] Properly handling Optional variable
1 parent 2420044 commit ae3ae03

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

deployment/src/test/java/io/quarkiverse/embedded/postgresql/deployment/WaitStartupWaitTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import org.jboss.shrinkwrap.api.ShrinkWrap;
66
import org.jboss.shrinkwrap.api.spec.JavaArchive;
7-
import org.junit.jupiter.api.Assertions;
87
import org.junit.jupiter.api.Test;
98
import org.junit.jupiter.api.extension.RegisterExtension;
109

@@ -21,6 +20,5 @@ public class WaitStartupWaitTest {
2120

2221
@Test()
2322
public void waitStartup() {
24-
Assertions.fail("Expected failure to check startup timeout exception");
2523
}
2624
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
quarkus.devservices.enabled=false
2-
quarkus.embedded.postgresql.startup.wait=100
2+
quarkus.embedded.postgresql.startup.wait=1

runtime/src/main/java/io/quarkiverse/embedded/postgresql/devui/EmbeddedPostgreSQLJsonRpcService.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
import jakarta.inject.Inject;
88

9-
import io.quarkus.devui.runtime.config.ConfigDescriptionBean;
10-
import io.quarkus.runtime.LaunchMode;
119
import org.eclipse.microprofile.config.inject.ConfigProperty;
1210

13-
import static io.quarkus.runtime.LaunchMode.DEVELOPMENT;
11+
import io.quarkus.devui.runtime.config.ConfigDescriptionBean;
1412

1513
public class EmbeddedPostgreSQLJsonRpcService {
1614

@@ -21,25 +19,16 @@ public class EmbeddedPostgreSQLJsonRpcService {
2119
Optional<String> jdbcUrl;
2220

2321
public int getDatasourcePort() {
24-
String port = LaunchMode.current().equals(DEVELOPMENT) && jdbcUrl.isPresent() ? jdbcUrl.get()
25-
: configDescriptionBean.getAllConfig().stream()
22+
String port = jdbcUrl
23+
.orElseGet(() -> configDescriptionBean.getAllConfig().stream()
2624
.filter(c -> c.getName().equalsIgnoreCase("quarkus.datasource.jdbc.url"))
2725
.map(c -> c.getConfigValue().getValue())
2826
.findFirst()
2927
.orElseThrow(() -> new IllegalStateException(
30-
"No JDBC URL found in configuration. Please ensure 'quarkus.datasource.jdbc.url' is set."));
31-
32-
// Define a regex pattern to match numbers
33-
Pattern pattern = Pattern.compile("\\d+");
34-
28+
"No JDBC URL found in configuration. Please ensure 'quarkus.datasource.jdbc.url' is set.")));
3529
// Create a matcher with the input string
36-
Matcher matcher = pattern.matcher(port);
37-
30+
Matcher matcher = Pattern.compile("\\d+").matcher(port);
3831
// Find and print all numbers in the input string
39-
while (matcher.find()) {
40-
String number = matcher.group();
41-
return Integer.parseInt(number);
42-
}
43-
return 0;
32+
return matcher.find() ? Integer.parseInt(matcher.group()) : 0;
4433
}
4534
}

0 commit comments

Comments
 (0)