Skip to content

Commit

Permalink
Merge pull request #13525 from sancar/fix/exceptionType/maint3.x
Browse files Browse the repository at this point in the history
Throw ClientNotActiveException instead of generic HazelcastException
  • Loading branch information
mustafa sancar koyunlu committed Sep 25, 2018
2 parents a794ca3 + f67b9a2 commit 9c02039
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Expand Up @@ -19,6 +19,7 @@
import com.hazelcast.client.AuthenticationException;
import com.hazelcast.client.ClientExtension;
import com.hazelcast.client.ClientTypes;
import com.hazelcast.client.HazelcastClientNotActiveException;
import com.hazelcast.client.HazelcastClientOfflineException;
import com.hazelcast.client.config.ClientNetworkConfig;
import com.hazelcast.client.config.SocketOptions;
Expand Down Expand Up @@ -377,6 +378,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) {
//opening an owner connection is always allowed
return;
Expand Down Expand Up @@ -435,9 +439,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 @@ -561,9 +562,6 @@ private void bindSocketToPort(Socket socket) throws IOException {
}

protected ClientConnection createSocketConnection(final Address address) throws IOException {
if (!alive) {
throw new HazelcastException("ConnectionManager is not active!");
}
SocketChannel socketChannel = null;
try {
socketChannel = SocketChannel.open();
Expand Down
Expand Up @@ -153,7 +153,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 @@ -166,6 +166,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

0 comments on commit 9c02039

Please sign in to comment.