Revert "Restore HazelcastHealthIndicatorTests"

This reverts commit 5a51b5853e.
This commit is contained in:
Phillip Webb 2020-12-05 07:47:50 -08:00
parent 5a51b5853e
commit 55ae5be84b

View File

@ -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");
assertThat(health.getStatus()).isEqualTo(Status.UP); given(this.hazelcast.executeTransaction(any())).willAnswer((invocation) -> {
assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name", TransactionalTask<?> task = invocation.getArgument(0);
"actuator-hazelcast"); return task.execute(null);
assertThat(health.getDetails().get("uuid")).asString().isNotEmpty(); });
} Health health = new HazelcastHealthIndicator(this.hazelcast).health();
finally { assertThat(health.getStatus()).isEqualTo(Status.UP);
hazelcast.shutdown(); assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name", "hz0-instance")
} .containsEntry("uuid", "7581bb2f-879f-413f-b574-0071d7519eb0");
} }
@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);
} }