Skip to content

Commit

Permalink
configure timeout from outside
Browse files Browse the repository at this point in the history
  • Loading branch information
Loki-Afro committed Feb 12, 2024
1 parent fc4e1b5 commit ba30a93
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/main/java/de/svs/NamespaceActivationWaiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ public class NamespaceActivationWaiter {
@ConfigProperty(name = "baseDomain")
String baseDomain;

@ConfigProperty(name = "waiter.tries", defaultValue = "60")
int tries;

@ConfigProperty(name = "waiter.delayInSeconds", defaultValue = "2")
int delayInSeconds;

Multi<OutboundSseEvent> waitForNamespaceToBecomeAvailable(String namespace) {
Multi<OutboundSseEvent> waitForNamespaceToBecomeAvailable(String namespace, int maxWaitTimeInSeconds) {
int delayInSeconds = 2;
int maxTries = maxWaitTimeInSeconds / delayInSeconds;
AtomicBoolean finalMessageReceived = new AtomicBoolean();

return Multi.createBy()
Expand All @@ -43,6 +42,6 @@ Multi<OutboundSseEvent> waitForNamespaceToBecomeAvailable(String namespace) {
.data(String.class, objectMapper.writeValueAsString(statusDto))
.build()))
.select()
.first(tries);
.first(maxTries);
}
}
6 changes: 3 additions & 3 deletions src/main/java/de/svs/NamespaceController.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public RestMulti<OutboundSseEvent> createIfNotExistsAndWait(NamespaceDto dto) {
ne.name = namespace;
ne.activatedUntil = getActivatedUntil();
ne.persist();
return RestMulti.fromMultiData(namespaceActivationWaiter.waitForNamespaceToBecomeAvailable(namespace))
return RestMulti.fromMultiData(namespaceActivationWaiter.waitForNamespaceToBecomeAvailable(namespace, dto.getMaxWaitTimeInSeconds()))
.status(201)
.build();
}
Expand All @@ -120,7 +120,7 @@ public RestMulti<OutboundSseEvent> extendAndWait(NamespaceDto dto) {
Namespace ns = namespaceEntity.get();
ns.activatedUntil = (ns.activatedUntil.isAfter(newActivatedUntil) ? ns.activatedUntil : newActivatedUntil);
ns.update();
return RestMulti.fromMultiData(namespaceActivationWaiter.waitForNamespaceToBecomeAvailable(namespace))
return RestMulti.fromMultiData(namespaceActivationWaiter.waitForNamespaceToBecomeAvailable(namespace, dto.getMaxWaitTimeInSeconds()))
.status(200)
.build();
} else {
Expand Down Expand Up @@ -151,7 +151,7 @@ public NamespaceDto createNamespaceEntry(NamespaceDto dto) {
@GET()
@RestStreamElementType(MediaType.TEXT_PLAIN)
public Multi<OutboundSseEvent> status(@QueryParam("namespace") String namespace) {
return namespaceActivationWaiter.waitForNamespaceToBecomeAvailable(namespace);
return namespaceActivationWaiter.waitForNamespaceToBecomeAvailable(namespace, 60);
}


Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/svs/NamespaceDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class NamespaceDto {

private String name;
private Instant activatedUntil;
private int maxWaitTimeInSeconds = 60;

}
3 changes: 2 additions & 1 deletion src/test/java/de/svs/NamespaceControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.within;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when;

@QuarkusTest
Expand All @@ -33,7 +34,7 @@ class NamespaceControllerTest {
public static void setup() {
NamespaceActivationWaiter mock = Mockito.mock(NamespaceActivationWaiter.class);
String namespace = any(String.class);
when(mock.waitForNamespaceToBecomeAvailable(namespace)).thenReturn(Multi.createFrom().empty());
when(mock.waitForNamespaceToBecomeAvailable(namespace, anyInt())).thenReturn(Multi.createFrom().empty());
QuarkusMock.installMockForType(mock, NamespaceActivationWaiter.class);
}

Expand Down

0 comments on commit ba30a93

Please sign in to comment.