Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw ClientNotActiveException instead of generic HazelcastException #13524

Merged
merged 1 commit into from Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,6 +18,7 @@

import com.hazelcast.client.AuthenticationException;
import com.hazelcast.client.ClientExtension;
import com.hazelcast.client.HazelcastClientNotActiveException;
import com.hazelcast.client.HazelcastClientOfflineException;
import com.hazelcast.client.config.ClientNetworkConfig;
import com.hazelcast.client.connection.AddressProvider;
Expand Down Expand Up @@ -322,6 +323,9 @@ private Connection getConnection(Address target, boolean asOwner, boolean acquir
}

private void checkAllowed(Address target, boolean asOwner, boolean acquiresResources) throws IOException {
if (!alive) {
throw new HazelcastClientNotActiveException("ConnectionManager is not active!");
}
if (asOwner) {
connectionStrategy.beforeConnectToCluster(target);
//opening an owner connection is always allowed
Expand Down Expand Up @@ -376,9 +380,6 @@ private AuthenticationFuture triggerConnect(Address target, boolean asOwner) {
if (!asOwner) {
connectionStrategy.beforeOpenConnection(target);
}
if (!alive) {
throw new HazelcastException("ConnectionManager is not active!");
}

AuthenticationFuture future = new AuthenticationFuture();
AuthenticationFuture oldFuture = connectionsInProgress.putIfAbsent(target, future);
Expand Down Expand Up @@ -459,9 +460,6 @@ private void bindSocketToPort(Socket socket) throws IOException {
}

protected ClientConnection createSocketConnection(final Address remoteAddress) throws IOException {
if (!alive) {
throw new HazelcastException("ConnectionManager is not active!");
}
SocketChannel socketChannel = null;
try {
socketChannel = SocketChannel.open();
Expand Down
Expand Up @@ -152,7 +152,7 @@ public void testRequestShouldFailOnShutdown() {
}

@Test(expected = HazelcastClientNotActiveException.class)
public void testExceptionAfterClientShutdown() throws Exception {
public void testExceptionAfterClientShutdown() {
hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
Expand All @@ -165,6 +165,18 @@ public void testExceptionAfterClientShutdown() throws Exception {
test.get("key");
}

@Test(expected = HazelcastClientNotActiveException.class)
public void testExceptionAfterClientShutdown_fromClientConnectionManager() {
hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);

IMap<Object, Object> test = client.getMap("test");
test.put("key", "value");
client.shutdown();
test.size();
}

@Test
public void testShutdownClient_whenThereIsNoCluster() {
ClientConfig clientConfig = new ClientConfig();
Expand Down