ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [35/50] [abbrv] incubator-ignite git commit: #ignite-556: Add tests.
Date Mon, 23 Mar 2015 15:38:43 GMT
#ignite-556: Add tests.


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

Branch: refs/heads/ignite-45-gridcache
Commit: 36cfb495644954e7580f83ce9230f4583fbf2fa5
Parents: 624567b
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Mon Mar 23 16:45:59 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Mon Mar 23 16:45:59 2015 +0300

----------------------------------------------------------------------
 .../apache/ignite/internal/IgniteKernal.java    |   2 +-
 modules/core/src/test/config/invalid-cache.xml  |  78 ++++++++
 .../internal/IgniteDynamicCacheConfigTest.java  | 181 ++++++++++++++++++-
 .../apache/ignite/internal/TestNodeFilter.java  |  32 ++++
 .../apache/ignite/internal/filtered-cache.xml   |  62 +++++++
 5 files changed, 350 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36cfb495/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 6a8ae43..f56c8b4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -2882,7 +2882,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
             IgniteBiTuple<Collection<T>, ? extends GridSpringResourceContext>
cfgMap =
                 spring.loadConfigurations(url, cl);
 
-            if (cfgMap.size() != 1)
+            if (cfgMap.get1().size() != 1)
                 throw new IgniteException("File " + url.toString() + " should have one cache
configuration");
 
             return F.first(cfgMap.get1());

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36cfb495/modules/core/src/test/config/invalid-cache.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/invalid-cache.xml b/modules/core/src/test/config/invalid-cache.xml
new file mode 100644
index 0000000..13a0b75
--- /dev/null
+++ b/modules/core/src/test/config/invalid-cache.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<!--
+    Ignite Spring configuration file to startup grid cache.
+
+    When starting a standalone Ignite node, you need to execute the following command:
+    {IGNITE_HOME}/bin/ignite.{bat|sh} examples/config/example-cache.xml
+
+    When starting Ignite from Java IDE, pass path to this file to Ignite:
+    Ignition.start("examples/config/example-cache.xml");
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="
+        http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd
+        http://www.springframework.org/schema/util
+        http://www.springframework.org/schema/util/spring-util.xsd">
+    <bean id="cache-configuration" class="org.apache.ignite.configuration.CacheConfiguration">
+        <!-- Initial cache size. -->
+        <property name="startSize" value="3000000"/>
+
+        <!-- Set synchronous rebalancing (default is asynchronous). -->
+        <property name="rebalanceMode" value="SYNC"/>
+
+        <!-- Set to FULL_SYNC for examples, default is PRIMARY_SYNC. -->
+        <property name="writeSynchronizationMode" value="FULL_SYNC"/>
+
+        <property name="name" value="TestDynamicCache"/>
+
+        <property name="cacheMode" value="PARTITIONED"/>
+
+        <property name="atomicityMode" value="ATOMIC"/>
+
+        <property name="backups" value="1"/>
+    </bean>
+
+    <bean id="cache-configuration1" class="org.apache.ignite.configuration.CacheConfiguration">
+        <!-- Initial cache size. -->
+        <property name="startSize" value="3000000"/>
+
+        <!-- Set synchronous rebalancing (default is asynchronous). -->
+        <property name="rebalanceMode" value="SYNC"/>
+
+        <!-- Set to FULL_SYNC for examples, default is PRIMARY_SYNC. -->
+        <property name="writeSynchronizationMode" value="FULL_SYNC"/>
+
+        <property name="name" value="TestDynamicCache1"/>
+
+        <property name="cacheMode" value="PARTITIONED"/>
+
+        <property name="atomicityMode" value="ATOMIC"/>
+
+        <property name="backups" value="1"/>
+    </bean>
+
+    <bean id="nearCache-configuration" class="org.apache.ignite.configuration.NearCacheConfiguration">
+    </bean>
+</beans>
+

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36cfb495/modules/spring/src/test/java/org/apache/ignite/internal/IgniteDynamicCacheConfigTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/IgniteDynamicCacheConfigTest.java
b/modules/spring/src/test/java/org/apache/ignite/internal/IgniteDynamicCacheConfigTest.java
index 0b12068..e17bcad 100644
--- a/modules/spring/src/test/java/org/apache/ignite/internal/IgniteDynamicCacheConfigTest.java
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/IgniteDynamicCacheConfigTest.java
@@ -19,17 +19,42 @@ package org.apache.ignite.internal;
 
 
 import org.apache.ignite.*;
+import org.apache.ignite.cache.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.events.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.testframework.*;
+import org.apache.ignite.testframework.http.*;
 import org.apache.ignite.testframework.junits.common.*;
 
 /**
  * Test for dynamic cache start from config file.
  */
 public class IgniteDynamicCacheConfigTest extends GridCommonAbstractTest {
+    /** */
+    public static final String CACHE_NAME = "TestDynamicCache";
+
+    /** */
+    private static final String STATIC_CACHE_NAME = "TestStaticCache";
+
+    /** */
+    private static final String TEST_ATTRIBUTE_NAME = "TEST_ATTRIBUTE_NAME";
+
+    /** */
+    private boolean testAttribute = true;
+
+    /**
+     * @return Number of nodes for this test.
+     */
+    public int nodeCount() {
+        return 1;
+    }
+
     /** {@inheritDoc} */
     @Override protected void beforeTest() throws Exception {
         super.beforeTest();
 
-        startGrids(1);
+        startGrids(nodeCount());
     }
 
     /** {@inheritDoc} */
@@ -40,6 +65,27 @@ public class IgniteDynamicCacheConfigTest extends GridCommonAbstractTest
{
     }
 
     /**
+     * {@inheritDoc}
+     */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setUserAttributes(F.asMap(TEST_ATTRIBUTE_NAME, testAttribute));
+
+        CacheConfiguration cacheCfg = new CacheConfiguration();
+
+        cacheCfg.setCacheMode(CacheMode.REPLICATED);
+
+        cacheCfg.setName(STATIC_CACHE_NAME);
+
+        cfg.setCacheConfiguration(cacheCfg);
+
+        cfg.setIncludeEventTypes(EventType.EVT_CACHE_STARTED, EventType.EVT_CACHE_STOPPED,
EventType.EVT_CACHE_NODES_LEFT);
+
+        return cfg;
+    }
+
+    /**
      * @throws Exception If failed.
      */
     public void testDynamicCacheStartFromConfig() throws Exception {
@@ -56,9 +102,136 @@ public class IgniteDynamicCacheConfigTest extends GridCommonAbstractTest
{
      * @throws Exception If failed.
      */
     public void testDynamicNearCacheStartFromConfig() throws Exception {
-        IgniteCache cache1 = ignite(0).getOrCreateCache("modules/core/src/test/config/cache.xml",
-            "modules/core/src/test/config/cache.xml");
+        testAttribute = false;
+
+        try {
+            startGrid(nodeCount() + 1);
+
+            IgniteCache cache = ignite(0).createCache(
+                "modules/spring/src/test/java/org/apache/ignite/internal/filtered-cache.xml");
+
+            assertEquals(CACHE_NAME, cache.getName());
+
+            IgniteCache clientCache1 = ignite(nodeCount() + 1).createNearCache(CACHE_NAME,
+                "modules/core/src/test/config/cache.xml");
+
+            IgniteCache clientCache2 = ignite(nodeCount() + 1).getOrCreateNearCache(CACHE_NAME,
+                "modules/core/src/test/config/cache.xml");
+
+            assertEquals(clientCache1, clientCache2);
+        }
+        finally {
+            stopGrid(nodeCount() + 1);
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCreateNearCache() throws Exception {
+        testAttribute = false;
+
+        try {
+            int clientNode = nodeCount() + 1;
+
+            startGrid(clientNode);
+
+            IgniteCache cache = ignite(clientNode).createCache(
+                "modules/spring/src/test/java/org/apache/ignite/internal/filtered-cache.xml",
+                "modules/core/src/test/config/cache.xml");
+
+            assertEquals(cache.getName(), CACHE_NAME);
+
+            IgniteCache clientCache1 = ignite(clientNode).createNearCache(CACHE_NAME,
+                "modules/core/src/test/config/cache.xml");
+
+            IgniteCache clientCache2 = ignite(clientNode).getOrCreateNearCache(CACHE_NAME,
+                "modules/core/src/test/config/cache.xml");
+
+            assertEquals(clientCache1, clientCache2);
+        }
+        finally {
+            stopGrid(nodeCount() + 1);
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetOrCreateNearCache() throws Exception {
+        testAttribute = false;
+        IgniteCache cache = ignite(0).createCache(
+            "modules/spring/src/test/java/org/apache/ignite/internal/filtered-cache.xml");
+
+        try {
+            int clientNode = nodeCount() + 1;
+
+            startGrid(clientNode);
+
+            IgniteCache cache1 = ignite(clientNode).getOrCreateCache(
+                "modules/spring/src/test/java/org/apache/ignite/internal/filtered-cache.xml",
+                "modules/core/src/test/config/cache.xml");
+
+            assertEquals(cache.getName(), cache1.getName());
+
+            IgniteCache clientCache1 = ignite(clientNode).createNearCache(CACHE_NAME,
+                "modules/core/src/test/config/cache.xml");
+
+            IgniteCache clientCache2 = ignite(clientNode).getOrCreateNearCache(CACHE_NAME,
+                "modules/core/src/test/config/cache.xml");
+
+            assertEquals(clientCache1, clientCache2);
+        }
+        finally {
+            stopGrid(nodeCount() + 1);
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDynamicCacheStartFromNotExistConfig() throws Exception {
+        try {
+            ignite(0).getOrCreateCache("config/cache.xml");
+
+            fail();
+        }
+        catch (IgniteException e) {
+            // No-op.
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDynamicCacheStartFromInvalidConfig() throws Exception {
+        try {
+            ignite(0).getOrCreateCache("modules/core/src/test/config/invalid-cache.xml");
+
+            fail();
+        }
+        catch (IgniteException e) {
+            // No-op.
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStartCachedWithConfigUrlString() throws Exception {
+        GridEmbeddedHttpServer srv = null;
+
+        try {
+            srv = GridEmbeddedHttpServer.startHttpServer().withFileDownloadingHandler(null,
+                GridTestUtils.resolveIgnitePath("/modules/core/src/test/config/cache.xml"));
+
+            IgniteCache cache = ignite(0).createCache(srv.getBaseUrl());
 
-        assertEquals("TestDynamicCache", cache1.getName());
+            assertEquals("TestDynamicCache", cache.getName());
+        }
+        finally {
+            if (srv != null)
+                srv.stop(1);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36cfb495/modules/spring/src/test/java/org/apache/ignite/internal/TestNodeFilter.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/TestNodeFilter.java b/modules/spring/src/test/java/org/apache/ignite/internal/TestNodeFilter.java
new file mode 100644
index 0000000..f81fc28
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/TestNodeFilter.java
@@ -0,0 +1,32 @@
+/*
+ * 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.cluster.*;
+import org.apache.ignite.lang.*;
+
+/**
+ *
+ */
+public class TestNodeFilter implements IgnitePredicate<ClusterNode> {
+    @Override public boolean apply(ClusterNode n) {
+        Boolean val = n.attribute("TEST_ATTRIBUTE_NAM");
+
+        return val != null && val;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/36cfb495/modules/spring/src/test/java/org/apache/ignite/internal/filtered-cache.xml
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/filtered-cache.xml b/modules/spring/src/test/java/org/apache/ignite/internal/filtered-cache.xml
new file mode 100644
index 0000000..df2a4dd
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/filtered-cache.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<!--
+    Ignite Spring configuration file to startup grid cache.
+
+    When starting a standalone Ignite node, you need to execute the following command:
+    {IGNITE_HOME}/bin/ignite.{bat|sh} examples/config/example-cache.xml
+
+    When starting Ignite from Java IDE, pass path to this file to Ignite:
+    Ignition.start("examples/config/example-cache.xml");
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:util="http://www.springframework.org/schema/util"
+       xsi:schemaLocation="
+        http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd
+        http://www.springframework.org/schema/util
+        http://www.springframework.org/schema/util/spring-util.xsd">
+    <bean id="cache-configuration" class="org.apache.ignite.configuration.CacheConfiguration">
+        <!-- Initial cache size. -->
+        <property name="startSize" value="3000000"/>
+
+        <!-- Set synchronous rebalancing (default is asynchronous). -->
+        <property name="rebalanceMode" value="SYNC"/>
+
+        <!-- Set to FULL_SYNC for examples, default is PRIMARY_SYNC. -->
+        <property name="writeSynchronizationMode" value="FULL_SYNC"/>
+
+        <property name="name" value="TestDynamicCache"/>
+
+        <property name="cacheMode" value="PARTITIONED"/>
+
+        <property name="atomicityMode" value="ATOMIC"/>
+
+        <property name="backups" value="1"/>
+
+        <property name="nodeFilter">
+            <bean class="org.apache.ignite.internal.TestNodeFilter"/>
+        </property>
+    </bean>
+    <bean id="nearCache-configuration" class="org.apache.ignite.configuration.NearCacheConfiguration">
+    </bean>
+</beans>
+


Mime
View raw message