ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [06/40] incubator-ignite git commit: # ignite-gg-10416 Exclude nested beans only if exclude properties exists(visor).
Date Fri, 03 Jul 2015 15:08:24 GMT
# ignite-gg-10416 Exclude nested beans only if exclude properties exists(visor).


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

Branch: refs/heads/ignite-gg-7813
Commit: 0acdc2f9f56d1c1f104de82211b38e36388ddb43
Parents: e5fba8b
Author: Andrey <anovikov@gridgain.com>
Authored: Thu Jun 18 18:15:53 2015 +0700
Committer: Andrey <anovikov@gridgain.com>
Committed: Thu Jun 18 18:21:49 2015 +0700

----------------------------------------------------------------------
 .../util/spring/IgniteSpringHelperImpl.java     | 93 +++++++++++---------
 .../IgniteExcludeInConfigurationTest.java       | 78 ++++++++++++++++
 .../IgniteStartExcludesConfigurationTest.java   | 80 -----------------
 .../testsuites/IgniteSpringTestSuite.java       |  2 +-
 4 files changed, 129 insertions(+), 124 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0acdc2f9/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java
b/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java
index df53ca7..6cfca36 100644
--- a/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java
+++ b/modules/spring/src/main/java/org/apache/ignite/internal/util/spring/IgniteSpringHelperImpl.java
@@ -421,63 +421,70 @@ public class IgniteSpringHelperImpl implements IgniteSpringHelper {
     private static GenericApplicationContext prepareSpringContext(final String... excludedProps){
         GenericApplicationContext springCtx = new GenericApplicationContext();
 
-        BeanFactoryPostProcessor postProc = new BeanFactoryPostProcessor() {
-            /**
-             * @param def Registered BeanDefinition.
-             * @throws BeansException in case of errors.
-             */
-            private void processNested(BeanDefinition def) throws BeansException {
-                MutablePropertyValues vals = def.getPropertyValues();
-
-                for (PropertyValue val : new ArrayList<>(vals.getPropertyValueList()))
{
-                    for (String excludedProp : excludedProps) {
-                        if (val.getName().equals(excludedProp)) {
-                            vals.removePropertyValue(val);
-
-                            return;
+        if (excludedProps.length > 0) {
+            BeanFactoryPostProcessor postProc = new BeanFactoryPostProcessor() {
+                /**
+                 * @param def Registered BeanDefinition.
+                 * @throws BeansException in case of errors.
+                 */
+                private void processNested(BeanDefinition def) throws BeansException {
+                    Iterator<PropertyValue> iterVals = def.getPropertyValues().getPropertyValueList().iterator();
+
+                    while (iterVals.hasNext()) {
+                        PropertyValue val = iterVals.next();
+
+                        for (String excludedProp : excludedProps) {
+                            if (val.getName().equals(excludedProp)) {
+                                iterVals.remove();
+
+                                return;
+                            }
                         }
-                    }
 
-                    if (val.getValue() instanceof Collection) {
-                        Collection<?> nestedVals = (Collection) val.getValue();
+                        if (val.getValue() instanceof Iterable) {
+                            Iterator iterNested = ((Iterable)val.getValue()).iterator();
 
-                        for (Object item : new ArrayList<>(nestedVals))
-                            if (item instanceof BeanDefinitionHolder) {
-                                BeanDefinitionHolder holder = (BeanDefinitionHolder)item;
+                            while (iterNested.hasNext()) {
+                                Object item = iterNested.next();
 
-                                try {
-                                    if (holder.getBeanDefinition().getBeanClassName() !=
null)
-                                        Class.forName(holder.getBeanDefinition().getBeanClassName());
+                                if (item instanceof BeanDefinitionHolder) {
+                                    BeanDefinitionHolder h = (BeanDefinitionHolder)item;
 
-                                    processNested(holder.getBeanDefinition());
-                                }
-                                catch (ClassNotFoundException ignored) {
-                                    nestedVals.remove(item);
+                                    try {
+                                        if (h.getBeanDefinition().getBeanClassName() != null)
+                                            Class.forName(h.getBeanDefinition().getBeanClassName());
+
+                                        processNested(h.getBeanDefinition());
+                                    }
+                                    catch (ClassNotFoundException ignored) {
+                                        iterNested.remove();
+                                    }
                                 }
                             }
+                        }
                     }
                 }
-            }
 
-            /** {@inheritDoc} */
-            @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory
beanFactory)
-                throws BeansException {
-                for (String beanName : beanFactory.getBeanDefinitionNames())
-                    try {
-                        BeanDefinition def = beanFactory.getBeanDefinition(beanName);
+                @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory
beanFactory)
+                    throws BeansException {
+                    for (String beanName : beanFactory.getBeanDefinitionNames()) {
+                        try {
+                            BeanDefinition def = beanFactory.getBeanDefinition(beanName);
 
-                        if (def.getBeanClassName() != null)
-                            Class.forName(def.getBeanClassName());
+                            if (def.getBeanClassName() != null)
+                                Class.forName(def.getBeanClassName());
 
-                        processNested(def);
-                    }
-                    catch (ClassNotFoundException ignored) {
-                        ((BeanDefinitionRegistry)beanFactory).removeBeanDefinition(beanName);
+                            processNested(def);
+                        }
+                        catch (ClassNotFoundException ignored) {
+                            ((BeanDefinitionRegistry)beanFactory).removeBeanDefinition(beanName);
+                        }
                     }
-            }
-        };
+                }
+            };
 
-        springCtx.addBeanFactoryPostProcessor(postProc);
+            springCtx.addBeanFactoryPostProcessor(postProc);
+        }
 
         return springCtx;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0acdc2f9/modules/spring/src/test/java/org/apache/ignite/spring/IgniteExcludeInConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/IgniteExcludeInConfigurationTest.java
b/modules/spring/src/test/java/org/apache/ignite/spring/IgniteExcludeInConfigurationTest.java
new file mode 100644
index 0000000..1edca77
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/spring/IgniteExcludeInConfigurationTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.spring;
+
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.spring.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.net.*;
+import java.util.*;
+
+import static org.apache.ignite.internal.IgniteComponentType.*;
+
+/**
+ * Checks excluding properties, beans with not existing classes in spring.
+ */
+public class IgniteExcludeInConfigurationTest extends GridCommonAbstractTest {
+    private URL cfgLocation = U.resolveIgniteUrl(
+        "modules/spring/src/test/java/org/apache/ignite/spring/sprint-exclude.xml");
+
+    /** Spring should exclude properties by list and ignore beans with class not existing
in classpath. */
+    public void testExclude() throws Exception {
+         IgniteSpringHelper spring = SPRING.create(false);
+
+        Collection<IgniteConfiguration> cfgs = spring.loadConfigurations(cfgLocation,
"typeMetadata").get1();
+
+        assertNotNull(cfgs);
+        assertEquals(1, cfgs.size());
+
+        IgniteConfiguration cfg = cfgs.iterator().next();
+
+        assertEquals(1, cfg.getCacheConfiguration().length);
+        assertNull(cfg.getCacheConfiguration()[0].getTypeMetadata());
+
+        cfgs = spring.loadConfigurations(cfgLocation, "keyType").get1();
+
+        assertNotNull(cfgs);
+        assertEquals(1, cfgs.size());
+
+        cfg = cfgs.iterator().next();
+
+        assertEquals(1, cfg.getCacheConfiguration().length);
+
+        Collection<CacheTypeMetadata> typeMetadatas = cfg.getCacheConfiguration()[0].getTypeMetadata();
+
+        assertEquals(1, typeMetadatas.size());
+        assertNull(typeMetadatas.iterator().next().getKeyType());
+    }
+
+    /** Spring should fail if bean class not exist in classpath. */
+    public void testFail() throws Exception {
+        IgniteSpringHelper spring = SPRING.create(false);
+
+        try {
+             assertNotNull(spring.loadConfigurations(cfgLocation).get1());
+        } catch (Exception e) {
+            assertTrue(X.hasCause(e, ClassNotFoundException.class));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0acdc2f9/modules/spring/src/test/java/org/apache/ignite/spring/IgniteStartExcludesConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/IgniteStartExcludesConfigurationTest.java
b/modules/spring/src/test/java/org/apache/ignite/spring/IgniteStartExcludesConfigurationTest.java
deleted file mode 100644
index f1332e0..0000000
--- a/modules/spring/src/test/java/org/apache/ignite/spring/IgniteStartExcludesConfigurationTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.spring;
-
-import org.apache.ignite.cache.*;
-import org.apache.ignite.configuration.*;
-import org.apache.ignite.internal.util.spring.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.testframework.junits.common.*;
-
-import java.net.*;
-import java.util.*;
-
-import static org.apache.ignite.internal.IgniteComponentType.*;
-
-/**
- * Checks exclude properties in spring, exclude beans with not existing classes.
- */
-public class IgniteStartExcludesConfigurationTest extends GridCommonAbstractTest {
-    /** Tests spring exclude properties. */
-    public void testExcludes() throws Exception {
-        URL cfgLocation = U.resolveIgniteUrl(
-            "modules/spring/src/test/java/org/apache/ignite/spring/sprint-exclude.xml");
-
-        IgniteSpringHelper spring = SPRING.create(false);
-
-        Collection<IgniteConfiguration> cfgs = spring.loadConfigurations(cfgLocation,
"typeMetadata").get1();
-
-        assert cfgs != null && cfgs.size() == 1;
-
-        IgniteConfiguration cfg = cfgs.iterator().next();
-
-        assert cfg.getCacheConfiguration().length == 1;
-
-        assert cfg.getCacheConfiguration()[0].getTypeMetadata() == null;
-
-        cfgs = spring.loadConfigurations(cfgLocation, "keyType").get1();
-
-        assert cfgs != null && cfgs.size() == 1;
-
-        cfg = cfgs.iterator().next();
-
-        assert cfg.getCacheConfiguration().length == 1;
-
-        Collection<CacheTypeMetadata> typeMetadatas = cfg.getCacheConfiguration()[0].getTypeMetadata();
-
-        assert typeMetadatas.size() == 1;
-
-        assert typeMetadatas.iterator().next().getKeyType() == null;
-
-        cfgs = spring.loadConfigurations(cfgLocation).get1();
-
-        assert cfgs != null && cfgs.size() == 1;
-
-        cfg = cfgs.iterator().next();
-
-        assert cfg.getCacheConfiguration().length == 1;
-
-        typeMetadatas = cfg.getCacheConfiguration()[0].getTypeMetadata();
-
-        assert typeMetadatas.size() == 1;
-
-        assert "java.lang.Integer".equals(typeMetadatas.iterator().next().getKeyType());
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0acdc2f9/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 3ff927a..75d29fb 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
@@ -40,7 +40,7 @@ public class IgniteSpringTestSuite extends TestSuite {
 
         suite.addTest(IgniteResourceSelfTestSuite.suite());
 
-        suite.addTest(new TestSuite(IgniteStartExcludesConfigurationTest.class));
+        suite.addTest(new TestSuite(IgniteExcludeInConfigurationTest.class));
 
         // Tests moved to this suite since they require Spring functionality.
         suite.addTest(new TestSuite(GridP2PUserVersionChangeSelfTest.class));


Mime
View raw message