Reset ApplicationEventMulticaster/MessageSource/LifecycleProcessor on close
Closes gh-21988 Closes gh-31397
This commit is contained in:
@@ -165,11 +165,27 @@ class AnnotationDrivenEventListenerTests {
|
||||
assertThat(events).as("Wrong number of initial context events").hasSize(1);
|
||||
assertThat(events.get(0).getClass()).isEqualTo(ContextRefreshedEvent.class);
|
||||
|
||||
this.context.start();
|
||||
List<Object> eventsAfterStart = this.eventCollector.getEvents(listener);
|
||||
assertThat(eventsAfterStart).as("Wrong number of context events on start").hasSize(2);
|
||||
assertThat(eventsAfterStart.get(1).getClass()).isEqualTo(ContextStartedEvent.class);
|
||||
this.eventCollector.assertTotalEventsCount(2);
|
||||
|
||||
this.context.stop();
|
||||
List<Object> eventsAfterStop = this.eventCollector.getEvents(listener);
|
||||
assertThat(eventsAfterStop).as("Wrong number of context events on shutdown").hasSize(2);
|
||||
assertThat(eventsAfterStop.get(1).getClass()).isEqualTo(ContextStoppedEvent.class);
|
||||
this.eventCollector.assertTotalEventsCount(2);
|
||||
assertThat(eventsAfterStop).as("Wrong number of context events on stop").hasSize(3);
|
||||
assertThat(eventsAfterStop.get(2).getClass()).isEqualTo(ContextStoppedEvent.class);
|
||||
this.eventCollector.assertTotalEventsCount(3);
|
||||
|
||||
this.context.close();
|
||||
List<Object> eventsAfterClose = this.eventCollector.getEvents(listener);
|
||||
assertThat(eventsAfterClose).as("Wrong number of context events on close").hasSize(4);
|
||||
assertThat(eventsAfterClose.get(3).getClass()).isEqualTo(ContextClosedEvent.class);
|
||||
this.eventCollector.assertTotalEventsCount(4);
|
||||
|
||||
// Further events are supposed to be ignored after context close
|
||||
this.context.publishEvent(new ContextClosedEvent(this.context));
|
||||
this.eventCollector.assertTotalEventsCount(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
@@ -210,6 +211,8 @@ class ResourceBundleMessageSourceTests {
|
||||
ac.refresh();
|
||||
assertThat(ac.getMessage("code1", null, "default", Locale.ENGLISH)).isEqualTo("default");
|
||||
assertThat(ac.getMessage("code1", new Object[]{"value"}, "default {0}", Locale.ENGLISH)).isEqualTo("default value");
|
||||
ac.close();
|
||||
assertThatIllegalStateException().isThrownBy(() -> ac.getMessage("code1", null, "default", Locale.ENGLISH));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -222,6 +225,8 @@ class ResourceBundleMessageSourceTests {
|
||||
ac.refresh();
|
||||
assertThat(ac.getMessage("code1", null, "default", Locale.ENGLISH)).isEqualTo("default");
|
||||
assertThat(ac.getMessage("code1", new Object[]{"value"}, "default {0}", Locale.ENGLISH)).isEqualTo("default value");
|
||||
ac.close();
|
||||
assertThatIllegalStateException().isThrownBy(() -> ac.getMessage("code1", null, "default", Locale.ENGLISH));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -234,6 +239,8 @@ class ResourceBundleMessageSourceTests {
|
||||
ac.refresh();
|
||||
assertThat(ac.getMessage("code1", null, "default", Locale.ENGLISH)).isEqualTo("default");
|
||||
assertThat(ac.getMessage("code1", new Object[]{"value"}, "default {0}", Locale.ENGLISH)).isEqualTo("default value");
|
||||
ac.close();
|
||||
assertThatIllegalStateException().isThrownBy(() -> ac.getMessage("code1", null, "default", Locale.ENGLISH));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -246,6 +253,8 @@ class ResourceBundleMessageSourceTests {
|
||||
ac.refresh();
|
||||
assertThat(ac.getMessage("code1", null, "default", Locale.ENGLISH)).isEqualTo("default");
|
||||
assertThat(ac.getMessage("code1", new Object[]{"value"}, "default {0}", Locale.ENGLISH)).isEqualTo("default value");
|
||||
ac.close();
|
||||
assertThatIllegalStateException().isThrownBy(() -> ac.getMessage("code1", null, "default", Locale.ENGLISH));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user