-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): close client if service is unavailable (#123)
* close the client if it lost the connection to the Hazelcast server and reached the connection timeout
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
connector-java/src/test/java/io/zeebe/hazelcast/ZeebeHazelcastClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.zeebe.hazelcast; | ||
|
||
import com.hazelcast.client.HazelcastClient; | ||
import com.hazelcast.client.config.ClientConfig; | ||
import com.hazelcast.config.Config; | ||
import com.hazelcast.core.Hazelcast; | ||
import com.hazelcast.core.HazelcastInstance; | ||
import io.zeebe.hazelcast.connect.java.ZeebeHazelcast; | ||
import io.zeebe.hazelcast.exporter.ExporterConfiguration; | ||
import org.awaitility.Awaitility; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.time.Duration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ZeebeHazelcastClientTest { | ||
|
||
private static final ExporterConfiguration CONFIGURATION = new ExporterConfiguration(); | ||
private static final Duration CONNECTION_TIMEOUT = Duration.ofSeconds(5); | ||
|
||
private ZeebeHazelcast zeebeHazelcast; | ||
|
||
private HazelcastInstance hzInstance; | ||
private HazelcastInstance hzClient; | ||
|
||
@Before | ||
public void init() { | ||
final Config config = new Config(); | ||
config.getNetworkConfig().setPort(5702); | ||
hzInstance = Hazelcast.newHazelcastInstance(config); | ||
|
||
final ClientConfig clientConfig = new ClientConfig(); | ||
|
||
final var connectionRetryConfig = | ||
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig(); | ||
connectionRetryConfig.setClusterConnectTimeoutMillis(CONNECTION_TIMEOUT.toMillis()); | ||
|
||
clientConfig.getNetworkConfig().addAddress("127.0.0.1:5702"); | ||
hzClient = HazelcastClient.newHazelcastClient(clientConfig); | ||
} | ||
|
||
@After | ||
public void cleanUp() throws Exception { | ||
zeebeHazelcast.close(); | ||
hzClient.shutdown(); | ||
hzInstance.shutdown(); | ||
} | ||
|
||
@Test | ||
public void shouldCloseIfHazelcastIsUnavailable() { | ||
// given | ||
zeebeHazelcast = ZeebeHazelcast.newBuilder(hzClient).build(); | ||
|
||
// when | ||
hzInstance.shutdown(); | ||
|
||
// then | ||
Awaitility.await() | ||
.atMost(CONNECTION_TIMEOUT.multipliedBy(2)) | ||
.untilAsserted(() -> assertThat(zeebeHazelcast.isClosed()).isTrue()); | ||
} | ||
} |