Revert "Restore HazelcastHealthIndicatorTests"

This reverts commit 5a51b5853e.
pull/24789/head
Phillip Webb 4 years ago
parent 5a51b5853e
commit 55ae5be84b

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,16 +16,14 @@
package org.springframework.boot.actuate.hazelcast; package org.springframework.boot.actuate.hazelcast;
import java.io.IOException; import com.hazelcast.core.Endpoint;
import com.hazelcast.core.HazelcastException; import com.hazelcast.core.HazelcastException;
import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.transaction.TransactionalTask;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status; import org.springframework.boot.actuate.health.Status;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastInstanceFactory;
import org.springframework.core.io.ClassPathResource;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -40,27 +38,28 @@ import static org.mockito.Mockito.mock;
*/ */
class HazelcastHealthIndicatorTests { class HazelcastHealthIndicatorTests {
private final HazelcastInstance hazelcast = mock(HazelcastInstance.class);
@Test @Test
void hazelcastUp() throws IOException { void hazelcastUp() {
HazelcastInstance hazelcast = new HazelcastInstanceFactory(new ClassPathResource("hazelcast.xml")) Endpoint endpoint = mock(Endpoint.class);
.getHazelcastInstance(); given(this.hazelcast.getName()).willReturn("hz0-instance");
try { given(this.hazelcast.getLocalEndpoint()).willReturn(endpoint);
Health health = new HazelcastHealthIndicator(hazelcast).health(); given(endpoint.getUuid()).willReturn("7581bb2f-879f-413f-b574-0071d7519eb0");
given(this.hazelcast.executeTransaction(any())).willAnswer((invocation) -> {
TransactionalTask<?> task = invocation.getArgument(0);
return task.execute(null);
});
Health health = new HazelcastHealthIndicator(this.hazelcast).health();
assertThat(health.getStatus()).isEqualTo(Status.UP); assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name", assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name", "hz0-instance")
"actuator-hazelcast"); .containsEntry("uuid", "7581bb2f-879f-413f-b574-0071d7519eb0");
assertThat(health.getDetails().get("uuid")).asString().isNotEmpty();
}
finally {
hazelcast.shutdown();
}
} }
@Test @Test
void hazelcastDown() { void hazelcastDown() {
HazelcastInstance hazelcast = mock(HazelcastInstance.class); given(this.hazelcast.executeTransaction(any())).willReturn(new HazelcastException());
given(hazelcast.executeTransaction(any())).willThrow(new HazelcastException()); Health health = new HazelcastHealthIndicator(this.hazelcast).health();
Health health = new HazelcastHealthIndicator(hazelcast).health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN); assertThat(health.getStatus()).isEqualTo(Status.DOWN);
} }

Loading…
Cancel
Save