Can attempt message send without subscribers

- Change state assert not to throw if we're in state
  where message would never get consumed. Now
  just returning false.
- Fixes #1002
This commit is contained in:
Janne Valkealahti
2024-02-15 09:26:03 +00:00
parent a13109dd38
commit 27c2717d3b
2 changed files with 16 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,6 @@ import org.springframework.shell.component.view.control.View;
import org.springframework.shell.component.view.control.ViewEvent;
import org.springframework.shell.component.view.event.processor.AnimationEventLoopProcessor;
import org.springframework.shell.component.view.event.processor.TaskEventLoopProcessor;
import org.springframework.util.Assert;
/**
* Default implementation of an {@link EventLoop}.
@@ -202,8 +201,11 @@ public class DefaultEventLoop implements EventLoop {
// }
private boolean doSend(Message<?> message, long timeout) {
Assert.state(this.active && this.many.currentSubscriberCount() > 0,
() -> "The [" + this + "] doesn't have subscribers to accept messages");
if (!this.active || this.many.currentSubscriberCount() == 0) {
return false;
}
// Assert.state(this.active && this.many.currentSubscriberCount() > 0,
// () -> "The [" + this + "] doesn't have subscribers to accept messages");
long remainingTime = 0;
if (timeout > 0) {
remainingTime = timeout;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2023 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -120,6 +120,15 @@ class DefaultEventLoopTests {
verifier1.verify(Duration.ofSeconds(1));
}
@Test
void dispatchNoSubscribersDoesNotError() {
initDefault();
Message<String> message = MessageBuilder.withPayload("TEST").build();
loop.dispatch(message);
}
@Test
void subsribtionCompletesWhenLoopDestroyed() {
initDefault();