Skip to content

Commit 28309be

Browse files
committed
Fix the hazelcast sample
1 parent e66f115 commit 28309be

File tree

7 files changed

+22
-12
lines changed

7 files changed

+22
-12
lines changed

spring-boot-admin-samples/spring-boot-admin-sample-hazelcast/src/main/java/de/codecentric/boot/admin/SpringBootAdminApplication.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
3030
import com.hazelcast.config.Config;
3131
import com.hazelcast.config.EvictionPolicy;
32-
import com.hazelcast.config.ListConfig;
32+
import com.hazelcast.config.InMemoryFormat;
3333
import com.hazelcast.config.MapConfig;
3434

3535
// tag::application-hazelcast[]
@@ -39,12 +39,10 @@
3939
public class SpringBootAdminApplication {
4040
@Bean
4141
public Config hazelcastConfig() {
42-
return new Config().setProperty("hazelcast.jmx", "true")
43-
.addMapConfig(new MapConfig("spring-boot-admin-application-eventstore").setBackupCount(1)
44-
.setEvictionPolicy(
45-
EvictionPolicy.NONE))
46-
.addListConfig(
47-
new ListConfig("spring-boot-admin-event-eventstore").setBackupCount(1).setMaxSize(1000));
42+
MapConfig mapConfig = new MapConfig("spring-boot-admin-event-store").setInMemoryFormat(InMemoryFormat.OBJECT)
43+
.setBackupCount(1)
44+
.setEvictionPolicy(EvictionPolicy.NONE);
45+
return new Config().setProperty("hazelcast.jmx", "true").addMapConfig(mapConfig);
4846
}
4947

5048
@Profile("insecure")

spring-boot-admin-samples/spring-boot-admin-sample-war/src/main/java/de/codecentric/boot/admin/SpringBootAdminApplication.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import de.codecentric.boot.admin.server.config.AdminServerProperties;
2020
import de.codecentric.boot.admin.server.config.EnableAdminServer;
2121

22+
import org.springframework.boot.SpringApplication;
2223
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2324
import org.springframework.boot.builder.SpringApplicationBuilder;
2425
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@@ -76,4 +77,8 @@ protected void configure(HttpSecurity http) throws Exception {
7677
}
7778
}
7879

80+
public static void main(String[] args) {
81+
SpringApplication.run(SpringBootAdminApplication.class, args);
82+
}
83+
7984
}

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/domain/entities/Instance.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ Instance apply(InstanceEvent event) {
168168
private Instance apply(InstanceEvent event, boolean isNewEvent) {
169169
Assert.notNull(event, "'event' must not be null");
170170
Assert.isTrue(this.id.equals(event.getInstance()), "'event' must refer the same instance");
171-
Assert.isTrue(this.nextVersion() == event.getVersion(), "expected event version doesn't match");
171+
Assert.isTrue(this.nextVersion() == event.getVersion(),
172+
() -> "Event " + event.getVersion() + " doesn't match exptected version " + this.nextVersion());
172173

173174
List<InstanceEvent> unsavedEvents = appendToEvents(event, isNewEvent);
174175

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/domain/entities/SnapshottingInstanceRepository.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ public Flux<Instance> findByName(String name) {
6464
}
6565

6666
public void start() {
67-
this.subscription = Flux.from(getEventStore()).doOnNext(this::updateSnapshot).retryWhen(retryOnAny).subscribe();
67+
this.subscription = getEventStore().findAll()
68+
.concatWith(getEventStore())
69+
.doOnNext(this::updateSnapshot)
70+
.retryWhen(retryOnAny)
71+
.subscribe();
6872
}
6973

7074
public void stop() {

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/server/eventstore/ConcurrentMapEventStore.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ protected boolean doAppend(List<InstanceEvent> events) {
102102
}
103103

104104
if (eventLog.replace(id, oldEvents, newEvents)) {
105-
log.debug("Events saved {}", events);
105+
log.debug("Events appended to log {}", events);
106106
return true;
107107
}
108+
109+
log.debug("Unsuccessful attempot append the events {} ", events);
108110
return false;
109111
}
110112

spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/server/config/AdminServerNotifierConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import static org.assertj.core.api.Assertions.assertThat;
5151

5252
public class AdminServerNotifierConfigurationTest {
53-
private static final InstanceEvent APP_DOWN = new InstanceStatusChangedEvent(InstanceId.of("id-2"), 1L,
53+
private static final InstanceEvent APP_DOWN = new InstanceStatusChangedEvent(InstanceId.of("id-2"), 0L,
5454
StatusInfo.ofDown());
5555

5656
private AnnotationConfigApplicationContext context;

spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/server/domain/entities/InstanceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void should_throw_when_applied_wrong_event() {
135135
IllegalArgumentException.class).hasMessage("'event' must refer the same instance");
136136

137137
assertThatThrownBy(() -> instance.apply(new InstanceDeregisteredEvent(InstanceId.of("id"), 1L))).isInstanceOf(
138-
IllegalArgumentException.class).hasMessage("expected event version doesn't match");
138+
IllegalArgumentException.class).hasMessage("Event 1 doesn't match exptected version 0");
139139
}
140140

141141
}

0 commit comments

Comments
 (0)