ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yzhda...@apache.org
Subject [1/2] ignite git commit: review ignite-1102 - IgniteSpringBean should have getConfiguration() method
Date Fri, 13 May 2016 07:34:24 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 093a3e00a -> 7c4111691


review ignite-1102 - IgniteSpringBean should have getConfiguration() method


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

Branch: refs/heads/master
Commit: dd756c0374d930e30caec9d1d1a117fcaf3388f4
Parents: 457d4f2
Author: Saikat Maitra <saikat.maitra@gmail.com>
Authored: Fri May 13 13:34:03 2016 +0600
Committer: Yakov Zhdanov <yzhdanov@gridgain.com>
Committed: Fri May 13 13:34:03 2016 +0600

----------------------------------------------------------------------
 .../src/main/java/org/apache/ignite/Ignite.java |   4 +-
 .../org/apache/ignite/IgniteSpringBean.java     | 134 ++++++++++++-------
 .../ignite/internal/IgniteSpringBeanTest.java   |  55 ++++++++
 .../testsuites/IgniteSpringTestSuite.java       |   2 +
 4 files changed, 144 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/dd756c03/modules/core/src/main/java/org/apache/ignite/Ignite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/Ignite.java b/modules/core/src/main/java/org/apache/ignite/Ignite.java
index b62672e..bd21468 100644
--- a/modules/core/src/main/java/org/apache/ignite/Ignite.java
+++ b/modules/core/src/main/java/org/apache/ignite/Ignite.java
@@ -85,7 +85,7 @@ public interface Ignite extends AutoCloseable {
     public IgniteLogger log();
 
     /**
-     * Gets the configuration of this grid instance.
+     * Gets the configuration of this Ignite instance.
      * <p>
      * <b>NOTE:</b>
      * <br>
@@ -95,7 +95,7 @@ public interface Ignite extends AutoCloseable {
      * via this method to check its configuration properties or call other non-SPI
      * methods.
      *
-     * @return Grid configuration instance.
+     * @return Ignite configuration instance.
      */
     public IgniteConfiguration configuration();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/dd756c03/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
index 03c7b0e..09e71a3 100644
--- a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
+++ b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
@@ -98,9 +98,31 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
     }
 
     /**
-     * Sets grid configuration.
+     * Gets the configuration of this Ignite instance.
+     * <p>
+     * This method is required for proper Spring integration and is the same as
+     * {@link #configuration()}.
+     * See https://issues.apache.org/jira/browse/IGNITE-1102 for details.
+     * <p>
+     * <b>NOTE:</b>
+     * <br>
+     * SPIs obtains through this method should never be used directly. SPIs provide
+     * internal view on the subsystem and is used internally by Ignite kernal. In rare use
cases when
+     * access to a specific implementation of this SPI is required - an instance of this
SPI can be obtained
+     * via this method to check its configuration properties or call other non-SPI
+     * methods.
      *
-     * @param cfg Grid configuration.
+     * @return Ignite configuration instance.
+     * @see #configuration()
+     */
+    public IgniteConfiguration getConfiguration() {
+        return cfg;
+    }
+
+    /**
+     * Sets Ignite configuration.
+     *
+     * @param cfg Ignite configuration.
      */
     public void setConfiguration(IgniteConfiguration cfg) {
         this.cfg = cfg;
@@ -130,112 +152,112 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
 
     /** {@inheritDoc} */
     @Override public IgniteLogger log() {
-        assert cfg != null;
+        checkIgnite();
 
         return cfg.getGridLogger();
     }
 
     /** {@inheritDoc} */
     @Override public IgniteProductVersion version() {
-        assert g != null;
+        checkIgnite();
 
         return g.version();
     }
 
     /** {@inheritDoc} */
     @Override public IgniteCompute compute() {
-        assert g != null;
+        checkIgnite();
 
         return g.compute();
     }
 
     /** {@inheritDoc} */
     @Override public IgniteServices services() {
-        assert g != null;
+        checkIgnite();
 
         return g.services();
     }
 
     /** {@inheritDoc} */
     @Override public IgniteMessaging message() {
-        assert g != null;
+        checkIgnite();
 
         return g.message();
     }
 
     /** {@inheritDoc} */
     @Override public IgniteEvents events() {
-        assert g != null;
+        checkIgnite();
 
         return g.events();
     }
 
     /** {@inheritDoc} */
     @Override public ExecutorService executorService() {
-        assert g != null;
+        checkIgnite();
 
         return g.executorService();
     }
 
     /** {@inheritDoc} */
     @Override public IgniteCluster cluster() {
-        assert g != null;
+        checkIgnite();
 
         return g.cluster();
     }
 
     /** {@inheritDoc} */
     @Override public IgniteCompute compute(ClusterGroup grp) {
-        assert g != null;
+        checkIgnite();
 
         return g.compute(grp);
     }
 
     /** {@inheritDoc} */
     @Override public IgniteMessaging message(ClusterGroup prj) {
-        assert g != null;
+        checkIgnite();
 
         return g.message(prj);
     }
 
     /** {@inheritDoc} */
     @Override public IgniteEvents events(ClusterGroup grp) {
-        assert g != null;
+        checkIgnite();
 
         return g.events(grp);
     }
 
     /** {@inheritDoc} */
     @Override public IgniteServices services(ClusterGroup grp) {
-        assert g != null;
+        checkIgnite();
 
         return g.services(grp);
     }
 
     /** {@inheritDoc} */
     @Override public ExecutorService executorService(ClusterGroup grp) {
-        assert g != null;
+        checkIgnite();
 
         return g.executorService(grp);
     }
 
     /** {@inheritDoc} */
     @Override public IgniteScheduler scheduler() {
-        assert g != null;
+        checkIgnite();
 
         return g.scheduler();
     }
 
     /** {@inheritDoc} */
     @Override public String name() {
-        assert g != null;
+        checkIgnite();
 
         return g.name();
     }
 
     /** {@inheritDoc} */
     @Override public <K, V> IgniteCache<K, V> cache(@Nullable String name) {
-        assert g != null;
+        checkIgnite();
 
         return g.cache(name);
     }
@@ -243,21 +265,21 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
 
     /** {@inheritDoc} */
     @Override public Collection<String> cacheNames() {
-        assert g != null;
+        checkIgnite();
 
         return g.cacheNames();
     }
 
     /** {@inheritDoc} */
     @Override public <K, V> IgniteCache<K, V> createCache(CacheConfiguration<K,
V> cacheCfg) {
-        assert g != null;
+        checkIgnite();
 
         return g.createCache(cacheCfg);
     }
 
     /** {@inheritDoc} */
     @Override public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K,
V> cacheCfg) {
-        assert g != null;
+        checkIgnite();
 
         return g.getOrCreateCache(cacheCfg);
     }
@@ -265,98 +287,98 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
     /** {@inheritDoc} */
     @Override public <K, V> IgniteCache<K, V> createCache(CacheConfiguration<K,
V> cacheCfg,
         NearCacheConfiguration<K, V> nearCfg) {
-        assert g != null;
+        checkIgnite();
 
         return g.createCache(cacheCfg, nearCfg);
     }
 
     /** {@inheritDoc} */
     @Override public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K,
V> cacheCfg, NearCacheConfiguration<K, V> nearCfg) {
-        assert g != null;
+        checkIgnite();
 
         return g.getOrCreateCache(cacheCfg, nearCfg);
     }
 
     /** {@inheritDoc} */
     @Override public <K, V> IgniteCache<K, V> createNearCache(String cacheName,
NearCacheConfiguration<K, V> nearCfg) {
-        assert g != null;
+        checkIgnite();
 
         return g.createNearCache(cacheName, nearCfg);
     }
 
     /** {@inheritDoc} */
     @Override public <K, V> IgniteCache<K, V> getOrCreateNearCache(@Nullable
String cacheName, NearCacheConfiguration<K, V> nearCfg) {
-        assert g != null;
+        checkIgnite();
 
         return g.getOrCreateNearCache(cacheName, nearCfg);
     }
 
     /** {@inheritDoc} */
     @Override public <K, V> IgniteCache<K, V> getOrCreateCache(String cacheName)
{
-        assert g != null;
+        checkIgnite();
 
         return g.getOrCreateCache(cacheName);
     }
 
     /** {@inheritDoc} */
     @Override public <K, V> IgniteCache<K, V> createCache(String cacheName) {
-        assert g != null;
+        checkIgnite();
 
         return g.createCache(cacheName);
     }
 
     /** {@inheritDoc} */
     @Override public <K, V> void addCacheConfiguration(CacheConfiguration<K, V>
cacheCfg) {
-        assert g != null;
+        checkIgnite();
 
         g.addCacheConfiguration(cacheCfg);
     }
 
     /** {@inheritDoc} */
     @Override public void destroyCache(String cacheName) {
-        assert g != null;
+        checkIgnite();
 
         g.destroyCache(cacheName);
     }
 
     /** {@inheritDoc} */
     @Override public IgniteTransactions transactions() {
-        assert g != null;
+        checkIgnite();
 
         return g.transactions();
     }
 
     /** {@inheritDoc} */
     @Override public <K, V> IgniteDataStreamer<K, V> dataStreamer(@Nullable String
cacheName) {
-        assert g != null;
+        checkIgnite();
 
         return g.dataStreamer(cacheName);
     }
 
     /** {@inheritDoc} */
     @Override public IgniteFileSystem fileSystem(String name) {
-        assert g != null;
+        checkIgnite();
 
         return g.fileSystem(name);
     }
 
     /** {@inheritDoc} */
     @Override public Collection<IgniteFileSystem> fileSystems() {
-        assert g != null;
+        checkIgnite();
 
         return g.fileSystems();
     }
 
     /** {@inheritDoc} */
     @Override public <T extends IgnitePlugin> T plugin(String name) throws PluginNotFoundException
{
-        assert g != null;
+        checkIgnite();
 
         return g.plugin(name);
     }
 
     /** {@inheritDoc} */
     @Override public IgniteBinary binary() {
-        assert g != null;
+        checkIgnite();
 
         return g.binary();
     }
@@ -368,14 +390,14 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
 
     /** {@inheritDoc} */
     @Nullable @Override public IgniteAtomicSequence atomicSequence(String name, long initVal,
boolean create) {
-        assert g != null;
+        checkIgnite();
 
         return g.atomicSequence(name, initVal, create);
     }
 
     /** {@inheritDoc} */
     @Nullable @Override public IgniteAtomicLong atomicLong(String name, long initVal, boolean
create) {
-        assert g != null;
+        checkIgnite();
 
         return g.atomicLong(name, initVal, create);
     }
@@ -385,7 +407,7 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
         @Nullable T initVal,
         boolean create)
     {
-        assert g != null;
+        checkIgnite();
 
         return g.atomicReference(name, initVal, create);
     }
@@ -396,7 +418,7 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
         @Nullable S initStamp,
         boolean create)
     {
-        assert g != null;
+        checkIgnite();
 
         return g.atomicStamped(name, initVal, initStamp, create);
     }
@@ -407,7 +429,7 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
         boolean autoDel,
         boolean create)
     {
-        assert g != null;
+        checkIgnite();
 
         return g.countDownLatch(name, cnt, autoDel, create);
     }
@@ -418,7 +440,7 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
         boolean failoverSafe,
         boolean create)
     {
-        assert g != null;
+        checkIgnite();
 
         return g.semaphore(name, cnt,
             failoverSafe, create);
@@ -430,7 +452,7 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
         boolean fair,
         boolean create)
     {
-        assert g != null;
+        checkIgnite();
 
         return g.reentrantLock(name, failoverSafe, create, fair);
     }
@@ -440,7 +462,7 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
         int cap,
         CollectionConfiguration cfg)
     {
-        assert g != null;
+        checkIgnite();
 
         return g.queue(name, cap, cfg);
     }
@@ -449,7 +471,7 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
     @Nullable @Override public <T> IgniteSet<T> set(String name,
         CollectionConfiguration cfg)
     {
-        assert g != null;
+        checkIgnite();
 
         return g.set(name, cfg);
     }
@@ -460,11 +482,6 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
     }
 
     /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(IgniteSpringBean.class, this);
-    }
-
-    /** {@inheritDoc} */
     @Override public void writeExternal(ObjectOutput out) throws IOException {
         out.writeObject(g);
     }
@@ -475,4 +492,23 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
 
         cfg = g.configuration();
     }
+
+    /**
+     * Checks if this bean is valid.
+     *
+     * @throws IllegalStateException If bean is not valid, i.e. Ignite has already been stopped
+     *      or has not yet been started.
+     */
+    protected void checkIgnite() throws IllegalStateException {
+        if (g == null) {
+            throw new IllegalStateException("Ignite is in invalid state to perform this operation.
" +
+                "It either not started yet or has already being or have stopped " +
+                "[ignite=" + g + ", cfg=" + cfg + ']');
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(IgniteSpringBean.class, this);
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/dd756c03/modules/spring/src/test/java/org/apache/ignite/internal/IgniteSpringBeanTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/IgniteSpringBeanTest.java
b/modules/spring/src/test/java/org/apache/ignite/internal/IgniteSpringBeanTest.java
new file mode 100644
index 0000000..d465904
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/IgniteSpringBeanTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import org.apache.ignite.IgniteSpringBean;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public class IgniteSpringBeanTest extends GridCommonAbstractTest {
+    /**
+     * @throws Exception If failed.
+     */
+    public void testInitialization() throws Exception {
+        try (IgniteSpringBean bean = new IgniteSpringBean()) {
+            bean.setConfiguration(getConfiguration("test"));
+
+            bean.afterPropertiesSet();
+
+            bean.compute();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIllegalState() throws Exception {
+        IgniteSpringBean bean = new IgniteSpringBean();
+
+        try {
+            bean.compute();
+
+            fail("Failed as Ignite should not have been initialized");
+        }
+        catch (IllegalStateException e) {
+            info("Caught expected exception: " + e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/dd756c03/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
b/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
index 4fc159e..8dcdf66 100644
--- a/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
+++ b/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
+import org.apache.ignite.internal.IgniteSpringBeanTest;
 import org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStoreFactorySelfTest;
 import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactorySelfTest;
 import org.apache.ignite.cache.store.spring.CacheSpringStoreSessionListenerSelfTest;
@@ -43,6 +44,7 @@ public class IgniteSpringTestSuite extends TestSuite {
         TestSuite suite = new TestSuite("Spring Test Suite");
 
         suite.addTestSuite(GridSpringBeanSerializationSelfTest.class);
+        suite.addTestSuite(IgniteSpringBeanTest.class);
         suite.addTestSuite(GridFactorySelfTest.class);
 
         suite.addTest(IgniteResourceSelfTestSuite.suite());


Mime
View raw message