Repository: ignite
Updated Branches:
  refs/heads/ignite-2.5 c43049d4f -> b3f252666


IGNITE-8097: Java thin client: throw handshake exception eagerly on connect 
phase in case of failure. This closes #3822.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b3f25266
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b3f25266
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b3f25266

Branch: refs/heads/ignite-2.5
Commit: b3f252666785fddf41ef07846e034d55ae0dda71
Parents: c43049d
Author: Alexey Kukushkin <alexeykukush...@yahoo.com>
Authored: Mon Apr 16 11:47:19 2018 +0300
Committer: devozerov <voze...@gridgain.com>
Committed: Mon Apr 16 11:49:37 2018 +0300

----------------------------------------------------------------------
 .../internal/client/thin/ReliableChannel.java   |  2 ++
 .../apache/ignite/client/FunctionalTest.java    | 37 ++++++++++++++++----
 .../org/apache/ignite/client/SecurityTest.java  | 22 ++++++------
 3 files changed, 42 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b3f25266/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
index 392b8f8..dac4320 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ReliableChannel.java
@@ -81,6 +81,8 @@ final class ReliableChannel implements AutoCloseable {
 
         primary = addrs.get(new Random().nextInt(addrs.size())); // we already 
verified there is at least one address
 
+        ch = chFactory.apply(new 
ClientChannelConfiguration(clientCfg).setAddress(primary)).get();
+
         for (InetSocketAddress a : addrs)
             if (a != primary)
                 this.backups.add(a);

http://git-wip-us.apache.org/repos/asf/ignite/blob/b3f25266/modules/core/src/test/java/org/apache/ignite/client/FunctionalTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/client/FunctionalTest.java 
b/modules/core/src/test/java/org/apache/ignite/client/FunctionalTest.java
index d69ac4d..b49f7e3 100644
--- a/modules/core/src/test/java/org/apache/ignite/client/FunctionalTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/client/FunctionalTest.java
@@ -39,21 +39,16 @@ import 
org.apache.ignite.cache.CacheWriteSynchronizationMode;
 import org.apache.ignite.cache.PartitionLossPolicy;
 import org.apache.ignite.cache.QueryEntity;
 import org.apache.ignite.cache.QueryIndex;
-import org.apache.ignite.client.ClientCache;
-import org.apache.ignite.client.ClientCacheConfiguration;
-import org.apache.ignite.client.Comparers;
-import org.apache.ignite.client.Config;
-import org.apache.ignite.client.IgniteClient;
 import org.apache.ignite.configuration.ClientConfiguration;
-import org.apache.ignite.client.LocalIgniteCluster;
-import org.apache.ignite.client.Person;
 import org.junit.Test;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 /**
  * Thin client functional tests.
@@ -380,6 +375,34 @@ public class FunctionalTest {
         }
     }
 
+    /**
+     * Test client fails on start if server is unavailable
+     */
+    @Test
+    public void testClientFailsOnStart() {
+        ClientConnectionException expEx = null;
+
+        try (IgniteClient ignored = 
Ignition.startClient(getClientConfiguration())) {
+            // No-op.
+        }
+        catch (ClientConnectionException connEx) {
+            expEx = connEx;
+        }
+        catch (Exception ex) {
+            fail(String.format(
+                "%s expected but %s was received: %s",
+                ClientConnectionException.class.getName(),
+                ex.getClass().getName(),
+                ex
+            ));
+        }
+
+        assertNotNull(
+            String.format("%s expected but no exception was received", 
ClientConnectionException.class.getName()),
+            expEx
+        );
+    }
+
     /** */
     private static ClientConfiguration getClientConfiguration() {
         return new ClientConfiguration()

http://git-wip-us.apache.org/repos/asf/ignite/blob/b3f25266/modules/indexing/src/test/java/org/apache/ignite/client/SecurityTest.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/client/SecurityTest.java 
b/modules/indexing/src/test/java/org/apache/ignite/client/SecurityTest.java
index dc57f0c..e2b11db 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/client/SecurityTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/client/SecurityTest.java
@@ -127,25 +127,23 @@ public class SecurityTest {
 
     /** Test valid user authentication. */
     @Test
-    public void testInvalidUserAuthentication() throws Exception {
+    public void testInvalidUserAuthentication() {
+        Exception authError = null;
+
         try (Ignite ignored = igniteWithAuthentication();
              IgniteClient client = Ignition.startClient(new 
ClientConfiguration().setAddresses(Config.SERVER)
                  .setUserName("JOE")
                  .setUserPassword("password")
              )
         ) {
-            Exception authError = null;
-
-            try {
-                client.getOrCreateCache("testAuthentication");
-            }
-            catch (Exception e) {
-                authError = e;
-            }
-
-            assertNotNull("Authentication with invalid credentials succeeded", 
authError);
-            assertTrue("Invalid type of authentication error", authError 
instanceof ClientAuthenticationException);
+            client.getOrCreateCache("testAuthentication");
+        }
+        catch (Exception e) {
+            authError = e;
         }
+
+        assertNotNull("Authentication with invalid credentials succeeded", 
authError);
+        assertTrue("Invalid type of authentication error", authError 
instanceof ClientAuthenticationException);
     }
 
     /** Test valid user authentication. */

Reply via email to