Commit 8b7c58c0 by Johannes Edmeier

Assert instances synchronized events via hazelcast in tests

parent 76df8b0a
...@@ -26,7 +26,6 @@ import java.util.Map; ...@@ -26,7 +26,6 @@ import java.util.Map;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
...@@ -37,13 +36,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -37,13 +36,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@Configuration @Configuration
public class AdminServerWebConfiguration implements WebMvcConfigurer, ApplicationContextAware { public class AdminServerWebConfiguration implements WebMvcConfigurer, ApplicationContextAware {
private final ApplicationEventPublisher publisher;
private final AdminServerProperties adminServerProperties; private final AdminServerProperties adminServerProperties;
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
public AdminServerWebConfiguration(ApplicationEventPublisher publisher, public AdminServerWebConfiguration(AdminServerProperties adminServerProperties) {
AdminServerProperties adminServerProperties) {
this.publisher = publisher;
this.adminServerProperties = adminServerProperties; this.adminServerProperties = adminServerProperties;
} }
......
...@@ -16,14 +16,20 @@ ...@@ -16,14 +16,20 @@
package de.codecentric.boot.admin.server; package de.codecentric.boot.admin.server;
import de.codecentric.boot.admin.server.config.EnableAdminServer; import de.codecentric.boot.admin.server.config.EnableAdminServer;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import java.util.stream.Collectors;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.test.web.reactive.server.WebTestClient;
import com.hazelcast.config.Config; import com.hazelcast.config.Config;
import com.hazelcast.config.EvictionPolicy; import com.hazelcast.config.EvictionPolicy;
import com.hazelcast.config.InMemoryFormat; import com.hazelcast.config.InMemoryFormat;
...@@ -31,6 +37,7 @@ import com.hazelcast.config.MapConfig; ...@@ -31,6 +37,7 @@ import com.hazelcast.config.MapConfig;
import com.hazelcast.config.TcpIpConfig; import com.hazelcast.config.TcpIpConfig;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Integration test to verify the correct functionality of the REST API with Hazelcast * Integration test to verify the correct functionality of the REST API with Hazelcast
...@@ -40,6 +47,7 @@ import static java.util.Collections.singletonList; ...@@ -40,6 +47,7 @@ import static java.util.Collections.singletonList;
public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest { public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest {
private ServletWebServerApplicationContext instance1; private ServletWebServerApplicationContext instance1;
private ServletWebServerApplicationContext instance2; private ServletWebServerApplicationContext instance2;
private WebTestClient webClient2;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
...@@ -52,6 +60,38 @@ public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest ...@@ -52,6 +60,38 @@ public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest
"--management.security.enabled=false", "--info.test=foobar"); "--management.security.enabled=false", "--info.test=foobar");
super.setUp(instance1.getWebServer().getPort()); super.setUp(instance1.getWebServer().getPort());
this.webClient2 = createWebClient(instance2.getWebServer().getPort());
}
@Test
@Override
public void lifecycle() {
super.lifecycle();
Mono<String> events1 = getWebClient().get()
.uri("/api/applications/events")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.returnResult(String.class)
.getResponseBody()
.collect(Collectors.joining());
Mono<String> events2 = webClient2.get()
.uri("/api/applications/events")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.returnResult(String.class)
.getResponseBody()
.collect(Collectors.joining());
StepVerifier.create(events1.and(events2))
.assertNext(t -> assertThat(t.getT1()).isEqualTo(t.getT2()))
.verifyComplete();
} }
@After @After
...@@ -67,7 +107,6 @@ public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest ...@@ -67,7 +107,6 @@ public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest
@Bean @Bean
public Config hazelcastConfig() { public Config hazelcastConfig() {
Config config = new Config(); Config config = new Config();
config.addMapConfig(new MapConfig("spring-boot-admin-event-store").setInMemoryFormat(InMemoryFormat.OBJECT) config.addMapConfig(new MapConfig("spring-boot-admin-event-store").setInMemoryFormat(InMemoryFormat.OBJECT)
.setBackupCount(1) .setBackupCount(1)
.setEvictionPolicy(EvictionPolicy.NONE)); .setEvictionPolicy(EvictionPolicy.NONE));
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package de.codecentric.boot.admin.server.config; package de.codecentric.boot.admin.server.config;
import de.codecentric.boot.admin.server.discovery.ApplicationDiscoveryListener;
import de.codecentric.boot.admin.server.domain.entities.ApplicationRepository; import de.codecentric.boot.admin.server.domain.entities.ApplicationRepository;
import de.codecentric.boot.admin.server.domain.entities.EventSourcingApplicationRepository; import de.codecentric.boot.admin.server.domain.entities.EventSourcingApplicationRepository;
import de.codecentric.boot.admin.server.eventstore.ClientApplicationEventStore; import de.codecentric.boot.admin.server.eventstore.ClientApplicationEventStore;
...@@ -29,6 +30,7 @@ import org.junit.Test; ...@@ -29,6 +30,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration; import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration;
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration; import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
import org.springframework.cloud.commons.util.UtilAutoConfiguration; import org.springframework.cloud.commons.util.UtilAutoConfiguration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -52,7 +54,7 @@ public class AdminServerWebConfigurationTest { ...@@ -52,7 +54,7 @@ public class AdminServerWebConfigurationTest {
@Test @Test
public void jacksonMapperPresentFromDefault() { public void jacksonMapperPresentFromDefault() {
AdminServerWebConfiguration config = new AdminServerWebConfiguration(null, null); AdminServerWebConfiguration config = new AdminServerWebConfiguration(null);
List<HttpMessageConverter<?>> converters = new ArrayList<>(); List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter()); converters.add(new MappingJackson2HttpMessageConverter());
...@@ -65,7 +67,7 @@ public class AdminServerWebConfigurationTest { ...@@ -65,7 +67,7 @@ public class AdminServerWebConfigurationTest {
@Test @Test
public void jacksonMapperPresentNeedExtend() { public void jacksonMapperPresentNeedExtend() {
AdminServerWebConfiguration config = new AdminServerWebConfiguration(null, null); AdminServerWebConfiguration config = new AdminServerWebConfiguration(null);
List<HttpMessageConverter<?>> converters = new ArrayList<>(); List<HttpMessageConverter<?>> converters = new ArrayList<>();
config.extendMessageConverters(converters); config.extendMessageConverters(converters);
...@@ -89,14 +91,12 @@ public class AdminServerWebConfigurationTest { ...@@ -89,14 +91,12 @@ public class AdminServerWebConfigurationTest {
assertThat(context.getBean(ClientApplicationEventStore.class)).isInstanceOf(HazelcastEventStore.class); assertThat(context.getBean(ClientApplicationEventStore.class)).isInstanceOf(HazelcastEventStore.class);
} }
//TODO @Test
/*@Test
public void discoveryConfig() { public void discoveryConfig() {
load(NoopDiscoveryClientAutoConfiguration.class); load(SimpleDiscoveryClientAutoConfiguration.class);
assertThat(context.getBean(ApplicationRepository.class)) assertThat(context.getBean(ApplicationRepository.class)).isInstanceOf(EventSourcingApplicationRepository.class);
.isInstanceOf(EventSourcingApplicationRepository.class);
context.getBean(ApplicationDiscoveryListener.class); context.getBean(ApplicationDiscoveryListener.class);
}*/ }
@Configuration @Configuration
static class TestHazelcastConfig { static class TestHazelcastConfig {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment