You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2017/03/23 06:27:20 UTC

ignite git commit: IGNITE-4829 Fixed review notes.

Repository: ignite
Updated Branches:
  refs/heads/ignite-4829 4248e30b9 -> 4c2beeedf


IGNITE-4829 Fixed review notes.


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

Branch: refs/heads/ignite-4829
Commit: 4c2beeedf54e3629879669ab94bf938662668609
Parents: 4248e30
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Thu Mar 23 11:58:38 2017 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Thu Mar 23 13:27:32 2017 +0700

----------------------------------------------------------------------
 .../src/test/config/jdbc-config-cache-store.xml |  6 --
 .../internal/jdbc2/JdbcConnectionSelfTest.java  | 28 +++++----
 .../internal/jdbc2/JdbcSpringSelfTest.java      | 66 ++++++++++++++++----
 .../testframework/junits/GridAbstractTest.java  |  8 ++-
 4 files changed, 76 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4c2beeed/modules/clients/src/test/config/jdbc-config-cache-store.xml
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/config/jdbc-config-cache-store.xml b/modules/clients/src/test/config/jdbc-config-cache-store.xml
index e5d8cb1..1e2db3b 100644
--- a/modules/clients/src/test/config/jdbc-config-cache-store.xml
+++ b/modules/clients/src/test/config/jdbc-config-cache-store.xml
@@ -41,12 +41,6 @@
 
         <property name="localHost" value="127.0.0.1"/>
 
-        <property name="marshaller">
-            <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
-                <property name="requireSerializable" value="false"/>
-            </bean>
-        </property>
-
         <property name="discoverySpi">
             <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                 <property name="ipFinder">

http://git-wip-us.apache.org/repos/asf/ignite/blob/4c2beeed/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcConnectionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcConnectionSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcConnectionSelfTest.java
index 8c05df3..e0b7ebe 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcConnectionSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcConnectionSelfTest.java
@@ -44,9 +44,6 @@ public class JdbcConnectionSelfTest extends GridCommonAbstractTest {
     /** Custom cache name. */
     private static final String CUSTOM_CACHE_NAME = "custom-cache";
 
-    /** Ignite configuration URL. */
-    private static final String CFG_URL = "modules/clients/src/test/config/jdbc-config.xml";
-
     /** Grid count. */
     private static final int GRID_CNT = 2;
 
@@ -56,6 +53,13 @@ public class JdbcConnectionSelfTest extends GridCommonAbstractTest {
     /** Client node flag. */
     private boolean client;
 
+    /**
+     * @return Config URL to use in test.
+     */
+    protected String configURL() {
+        return "modules/clients/src/test/config/jdbc-config.xml";
+    }
+
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
@@ -104,7 +108,7 @@ public class JdbcConnectionSelfTest extends GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     public void testDefaults() throws Exception {
-        String url = CFG_URL_PREFIX + CFG_URL;
+        String url = CFG_URL_PREFIX + configURL();
 
         try (Connection conn = DriverManager.getConnection(url)) {
             assertNotNull(conn);
@@ -121,13 +125,13 @@ public class JdbcConnectionSelfTest extends GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     public void testNodeId() throws Exception {
-        String url = CFG_URL_PREFIX + "nodeId=" + grid(0).localNode().id() + '@' + CFG_URL;
+        String url = CFG_URL_PREFIX + "nodeId=" + grid(0).localNode().id() + '@' + configURL();
 
         try (Connection conn = DriverManager.getConnection(url)) {
             assertNotNull(conn);
         }
 
-        url = CFG_URL_PREFIX + "cache=" + CUSTOM_CACHE_NAME + ":nodeId=" + grid(0).localNode().id() + '@' + CFG_URL;
+        url = CFG_URL_PREFIX + "cache=" + CUSTOM_CACHE_NAME + ":nodeId=" + grid(0).localNode().id() + '@' + configURL();
 
         try (Connection conn = DriverManager.getConnection(url)) {
             assertNotNull(conn);
@@ -140,7 +144,7 @@ public class JdbcConnectionSelfTest extends GridCommonAbstractTest {
     public void testWrongNodeId() throws Exception {
         UUID wrongId = UUID.randomUUID();
 
-        final String url = CFG_URL_PREFIX + "nodeId=" + wrongId + '@' + CFG_URL;
+        final String url = CFG_URL_PREFIX + "nodeId=" + wrongId + '@' + configURL();
 
         GridTestUtils.assertThrows(
                 log,
@@ -166,7 +170,7 @@ public class JdbcConnectionSelfTest extends GridCommonAbstractTest {
 
         UUID clientId = client.localNode().id();
 
-        final String url = CFG_URL_PREFIX + "nodeId=" + clientId + '@' + CFG_URL;
+        final String url = CFG_URL_PREFIX + "nodeId=" + clientId + '@' + configURL();
 
         GridTestUtils.assertThrows(
                 log,
@@ -192,7 +196,7 @@ public class JdbcConnectionSelfTest extends GridCommonAbstractTest {
 
         UUID daemonId = daemon.localNode().id();
 
-        final String url = CFG_URL_PREFIX + "nodeId=" + daemonId + '@' + CFG_URL;
+        final String url = CFG_URL_PREFIX + "nodeId=" + daemonId + '@' + configURL();
 
         GridTestUtils.assertThrows(
             log,
@@ -212,7 +216,7 @@ public class JdbcConnectionSelfTest extends GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     public void testCustomCache() throws Exception {
-        String url = CFG_URL_PREFIX + "cache=" + CUSTOM_CACHE_NAME + '@' + CFG_URL;
+        String url = CFG_URL_PREFIX + "cache=" + CUSTOM_CACHE_NAME + '@' + configURL();
 
         try (Connection conn = DriverManager.getConnection(url)) {
             assertNotNull(conn);
@@ -223,7 +227,7 @@ public class JdbcConnectionSelfTest extends GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     public void testWrongCache() throws Exception {
-        final String url = CFG_URL_PREFIX + "cache=wrongCacheName@" + CFG_URL;
+        final String url = CFG_URL_PREFIX + "cache=wrongCacheName@" + configURL();
 
         GridTestUtils.assertThrows(
             log,
@@ -243,7 +247,7 @@ public class JdbcConnectionSelfTest extends GridCommonAbstractTest {
      * @throws Exception If failed.
      */
     public void testClose() throws Exception {
-        String url = CFG_URL_PREFIX + CFG_URL;
+        String url = CFG_URL_PREFIX + configURL();
 
         try(final Connection conn = DriverManager.getConnection(url)) {
             assertNotNull(conn);

http://git-wip-us.apache.org/repos/asf/ignite/blob/4c2beeed/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcSpringSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcSpringSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcSpringSelfTest.java
index 1e8e198..1a1c1f2 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcSpringSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcSpringSelfTest.java
@@ -17,14 +17,19 @@
 
 package org.apache.ignite.internal.jdbc2;
 
-import org.apache.ignite.internal.IgniteEx;
-import org.apache.ignite.testframework.GridTestUtils;
-
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.util.UUID;
 import java.util.concurrent.Callable;
+import javax.sql.DataSource;
+import org.apache.ignite.internal.IgniteComponentType;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.resource.GridResourceIoc;
+import org.apache.ignite.internal.util.spring.IgniteSpringHelper;
+import org.apache.ignite.resources.SpringApplicationContextResource;
+import org.apache.ignite.testframework.GridTestUtils;
 
 import static org.apache.ignite.IgniteJdbcDriver.CFG_URL_PREFIX;
 
@@ -35,25 +40,25 @@ public class JdbcSpringSelfTest extends JdbcConnectionSelfTest {
     /** Grid count. */
     private static final int GRID_CNT = 2;
 
-    /** Ignite configuration URL. */
-    private static final String CFG_URL = "modules/clients/src/test/config/jdbc-config-cache-store.xml";
+    /** {@inheritDoc} */
+    @Override protected String configURL() {
+        return "modules/clients/src/test/config/jdbc-config-cache-store.xml";
+    }
 
     /** {@inheritDoc} */
     @Override protected void beforeTestsStarted() throws Exception {
-        startGridsWithSpringCtx(GRID_CNT, false, CFG_URL);
+        startGridsWithSpringCtx(GRID_CNT, false, configURL());
 
         Class.forName("org.apache.ignite.IgniteJdbcDriver");
     }
 
-    /**
-     * @throws Exception If failed.
-     */
+    /** {@inheritDoc} */
     @Override public void testClientNodeId() throws Exception {
-        IgniteEx client = (IgniteEx) startGridWithSpringCtx(getTestGridName(), true, CFG_URL);
+        IgniteEx client = (IgniteEx) startGridWithSpringCtx(getTestGridName(), true, configURL());
 
         UUID clientId = client.localNode().id();
 
-        final String url = CFG_URL_PREFIX + "nodeId=" + clientId + '@' + CFG_URL;
+        final String url = CFG_URL_PREFIX + "nodeId=" + clientId + '@' + configURL();
 
         GridTestUtils.assertThrows(
                 log,
@@ -68,4 +73,43 @@ public class JdbcSpringSelfTest extends JdbcConnectionSelfTest {
                 "Failed to establish connection with node (is it a server node?): " + clientId
         );
     }
+
+    /**
+     * Special class to test Spring context injection.
+     */
+    private static class TestInjectTarget {
+        /** */
+        @SpringApplicationContextResource
+        private Object appCtx;
+    }
+
+    /**
+     * Test that we have valid Spring context and also could create beans from it.
+     *
+     * @throws Exception If test failed.
+     */
+    public void testSpringBean() throws Exception {
+        String url = CFG_URL_PREFIX + configURL();
+
+        // Create connection.
+        try (Connection conn = DriverManager.getConnection(url)) {
+            assertNotNull(conn);
+
+            TestInjectTarget target = new TestInjectTarget();
+
+            IgniteKernal kernal = (IgniteKernal)((JdbcConnection)conn).ignite();
+
+            // Inject Spring context.
+            kernal.context().resource().inject(target, GridResourceIoc.AnnotationSet.GENERIC);
+
+            assertNotNull(target.appCtx);
+
+            IgniteSpringHelper spring = IgniteComponentType.SPRING.create(false);
+
+            // Load bean by name.
+            DataSource ds = spring.loadBeanFromAppContext(target.appCtx, "dsTest");
+
+            assertNotNull(ds);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/4c2beeed/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
index 45483b7..57b8d22 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
@@ -851,11 +851,12 @@ public abstract class GridAbstractTest extends TestCase {
 
         Ignite ignite = null;
 
-        for (int i = 0; i < cnt; i++)
+        for (int i = 0; i < cnt; i++) {
             if (ignite == null)
                 ignite = startGridWithSpringCtx(i, client, cfgUrl);
             else
                 startGridWithSpringCtx(i, client, cfgUrl);
+        }
 
         checkTopology(cnt);
 
@@ -1890,7 +1891,7 @@ public abstract class GridAbstractTest extends TestCase {
      * @param store Store.
      */
     protected <T> Factory<T> singletonFactory(T store) {
-        return notSerializableProxy(new FactoryBuilder.SingletonFactory<T>(store), Factory.class);
+        return notSerializableProxy(new FactoryBuilder.SingletonFactory<>(store), Factory.class);
     }
 
     /**
@@ -2210,7 +2211,8 @@ public abstract class GridAbstractTest extends TestCase {
     }
 
     /** */
-    public static abstract class TestIgniteIdxCallable<R> implements Serializable {
+    public abstract static class TestIgniteIdxCallable<R> implements Serializable {
+        /** */
         @IgniteInstanceResource
         protected Ignite ignite;