IGNITE-6598 .NET: Implement IIgnite.AddCacheConfiguration
authorPavel Tupitsyn <ptupitsyn@apache.org>
Wed, 17 Jan 2018 07:57:09 +0000 (10:57 +0300)
committerPavel Tupitsyn <ptupitsyn@apache.org>
Wed, 17 Jan 2018 07:57:09 +0000 (10:57 +0300)
This closes #3387

15 files changed:
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
modules/platforms/dotnet/Apache.Ignite.Core.Tests.DotNetCore/Apache.Ignite.Core.Tests.DotNetCore.csproj
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
modules/platforms/dotnet/Apache.Ignite.Core.Tests/ApiParity/IgniteParityTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Affinity/AffinityFunctionSpringTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheCreateTest.cs [new file with mode: 0644]
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/CancellationTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/DataStructures/AtomicLongTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/DataStructures/AtomicReferenceTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/DataStructures/AtomicSequenceTest.cs
modules/platforms/dotnet/Apache.Ignite.Core.Tests/SpringTestBase.cs [moved from modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteTestBase.cs with 93% similarity]
modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestBase.cs [new file with mode: 0644]
modules/platforms/dotnet/Apache.Ignite.Core/IIgnite.cs
modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs

index 612f154..0d88fbb 100644 (file)
@@ -137,6 +137,9 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
     /** */
     private static final int OP_RELEASE_START = 22;
 
+    /** */
+    private static final int OP_ADD_CACHE_CONFIGURATION = 23;
+
     /** Start latch. */
     private final CountDownLatch startLatch = new CountDownLatch(1);
 
@@ -424,6 +427,13 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
 
                 return 0;
             }
+
+            case OP_ADD_CACHE_CONFIGURATION:
+                CacheConfiguration cfg = PlatformConfigurationUtils.readCacheConfiguration(reader);
+
+                ctx.grid().addCacheConfiguration(cfg);
+
+                return 0;
         }
 
         return PlatformAbstractTarget.throwUnsupported(type);
index 8278365..67ece47 100644 (file)
@@ -63,6 +63,7 @@
     <Compile Include="..\Apache.Ignite.Core.Tests\Cache\CacheAbstractTest.cs" Link="Cache\CacheAbstractTest.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Cache\CacheAbstractTransactionalTest.cs" Link="Cache\CacheAbstractTransactionalTest.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Cache\CacheConfigurationTest.cs" Link="Cache\CacheConfigurationTest.cs" />
+    <Compile Include="..\Apache.Ignite.Core.Tests\Cache\CacheCreateTest.cs" Link="Cache\CacheCreateTest.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Cache\CachePartitionedTest.cs" Link="Cache\CachePartitionedTest.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Cache\CacheTestAsyncWrapper.cs" Link="Cache\CacheTestAsyncWrapper.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Cache\CacheTestKey.cs" Link="Cache\CacheTestKey.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\DataStructures\AtomicSequenceTest.cs" Link="DataStructures\AtomicSequenceTest.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\EventsTestLocalListeners.cs" Link="Common\EventsTestLocalListeners.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\IgniteConfigurationTest.cs" Link="Common\IgniteConfigurationTest.cs" />
-    <Compile Include="..\Apache.Ignite.Core.Tests\IgniteTestBase.cs" Link="Common\IgniteTestBase.cs" />
+    <Compile Include="..\Apache.Ignite.Core.Tests\TestBase.cs" Link="Common\TestBase.cs" />
+    <Compile Include="..\Apache.Ignite.Core.Tests\SpringTestBase.cs" Link="Common\SpringTestBase.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Log\CustomLoggerTest.cs" Link="Log\CustomLoggerTest.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\MessagingTest.cs" Link="Common\MessagingTest.cs" />
     <Compile Include="..\Apache.Ignite.Core.Tests\Plugin\PluginTest.cs" Link="Plugin\PluginTest.cs" />
index 6d6e014..22f4ad9 100644 (file)
     <Compile Include="Binary\EnumsTestOnline.cs" />
     <Compile Include="Binary\Serializable\GenericCollectionsTest.cs" />
     <Compile Include="Cache\Affinity\AffinityAttributeTest.cs" />
+    <Compile Include="Cache\CacheCreateTest.cs" />
     <Compile Include="Cache\DataRegionMetricsTest.cs" />
     <Compile Include="Cache\DataStorageMetricsTest.cs" />
     <Compile Include="Cache\PersistenceTest.cs" />
     <Compile Include="IgniteConfigurationSectionTest.cs" />
     <Compile Include="IgniteConfigurationSerializerTest.cs" />
     <Compile Include="IgniteConfigurationTest.cs" />
-    <Compile Include="IgniteTestBase.cs" />
+    <Compile Include="SpringTestBase.cs" />
     <Compile Include="JavaHomeTest.cs" />
     <Compile Include="LifecycleTest.cs" />
     <Compile Include="LoadDllTest.cs" />
     <Compile Include="Binary\Serializable\AdvancedSerializationTest.cs" />
     <Compile Include="IgniteStartStopTest.cs" />
     <Compile Include="Services\ServicesTestFullFooter.cs" />
+    <Compile Include="TestBase.cs" />
     <Compile Include="TestUtils.Common.cs" />
     <Compile Include="Memory\InteropMemoryTest.cs" />
     <Compile Include="Binary\BinaryBuilderSelfTest.cs" />
     <Compile Include="TestUtils.Windows.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  
   <Target Name="AfterBuild">
     <Copy SourceFiles="$(SolutionDir)Apache.Ignite\bin\$(ConfigurationName)\Apache.Ignite.exe;$(SolutionDir)Apache.Ignite\bin\$(ConfigurationName)\Apache.Ignite.exe.config" DestinationFolder="$(ProjectDir)$(OutDir)" SkipUnchangedFiles="false" />
   </Target>
-
-  
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
   <Target Name="BeforeBuild">
index 29cfda3..e467907 100644 (file)
@@ -44,8 +44,6 @@ namespace Apache.Ignite.Core.Tests.ApiParity
             "orCreateCaches", // IGNITE-7100
             "destroyCaches",  // IGNITE-7100
 
-            "addCacheConfiguration", // IGNITE-7102
-
             // Data structures.
             "atomicStamped", // IGNITE-7104
             "countDownLatch", // IGNITE-1418
index de4d2ec..78de671 100644 (file)
@@ -32,7 +32,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Affinity
     /// <summary>
     /// Tests AffinityFunction defined in Spring XML.
     /// </summary>
-    public class AffinityFunctionSpringTest : IgniteTestBase
+    public class AffinityFunctionSpringTest : SpringTestBase
     {
         /// <summary>
         /// Initializes a new instance of the <see cref="AffinityFunctionSpringTest"/> class.
index afe0a9a..fea37f7 100644 (file)
@@ -2261,78 +2261,6 @@ namespace Apache.Ignite.Core.Tests.Cache
         }
 
         [Test]
-        public void TestCreate()
-        {
-            // Create a cache with random name
-            var randomName = "template" + Guid.NewGuid();
-
-            // Can't get non-existent cache with Cache method
-            Assert.Throws<ArgumentException>(() => GetIgnite(0).GetCache<int, int>(randomName));
-            Assert.IsFalse(GetIgnite(0).GetCacheNames().Contains(randomName));
-
-            var cache = GetIgnite(0).CreateCache<int, int>(randomName);
-            Assert.IsTrue(GetIgnite(0).GetCacheNames().Contains(randomName));
-
-            cache.Put(1, 10);
-
-            Assert.AreEqual(10, cache.Get(1));
-
-            // Can't create again
-            Assert.Throws<IgniteException>(() => GetIgnite(0).CreateCache<int, int>(randomName));
-
-            var cache0 = GetIgnite(0).GetCache<int, int>(randomName);
-
-            Assert.AreEqual(10, cache0.Get(1));
-        }
-
-        [Test]
-        public void TestGetOrCreate()
-        {
-            // Create a cache with random name
-            var randomName = "template" + Guid.NewGuid();
-
-            // Can't get non-existent cache with Cache method
-            Assert.Throws<ArgumentException>(() => GetIgnite(0).GetCache<int, int>(randomName));
-
-            var cache = GetIgnite(0).GetOrCreateCache<int, int>(randomName);
-
-            cache.Put(1, 10);
-
-            Assert.AreEqual(10, cache.Get(1));
-
-            var cache0 = GetIgnite(0).GetOrCreateCache<int, int>(randomName);
-
-            Assert.AreEqual(10, cache0.Get(1));
-
-            var cache1 = GetIgnite(0).GetCache<int, int>(randomName);
-
-            Assert.AreEqual(10, cache1.Get(1));
-        }
-
-        [Test]
-        public void TestDestroy()
-        {
-            var cacheName = "template" + Guid.NewGuid();
-
-            var ignite = GetIgnite(0);
-
-            var cache = ignite.CreateCache<int, int>(cacheName);
-
-            Assert.IsNotNull(ignite.GetCache<int, int>(cacheName));
-            Assert.IsTrue(GetIgnite(0).GetCacheNames().Contains(cacheName));
-
-            ignite.DestroyCache(cache.Name);
-
-            Assert.IsFalse(GetIgnite(0).GetCacheNames().Contains(cacheName));
-
-            var ex = Assert.Throws<ArgumentException>(() => ignite.GetCache<int, int>(cacheName));
-
-            Assert.IsTrue(ex.Message.StartsWith("Cache doesn't exist"));
-
-            Assert.Throws<InvalidOperationException>(() => cache.Get(1));
-        }
-
-        [Test]
         public void TestCacheNames()
         {
             var cacheNames = GetIgnite(0).GetCacheNames();
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheCreateTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheCreateTest.cs
new file mode 100644 (file)
index 0000000..5800a4e
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Cache
+{
+    using System;
+    using Apache.Ignite.Core.Cache.Configuration;
+    using Apache.Ignite.Core.Common;
+    using NUnit.Framework;
+
+    /// <summary>
+    /// Tests CreateCache overloads.
+    /// </summary>
+    public class CacheCreateTest : TestBase
+    {
+        /// <summary>
+        /// Tests cache creation.
+        /// </summary>
+        [Test]
+        public void TestCreateFromTemplate()
+        {
+            // Create a cache with random name
+            var randomName = "template" + Guid.NewGuid();
+
+            // Can't get non-existent cache with Cache method
+            Assert.Throws<ArgumentException>(() => Ignite.GetCache<int, int>(randomName));
+            Assert.IsFalse(Ignite.GetCacheNames().Contains(randomName));
+
+            // Create cache and verify template setting.
+            var cache = Ignite.CreateCache<int, int>(randomName);
+            Assert.AreEqual(3, cache.GetConfiguration().Backups);
+            Assert.IsTrue(Ignite.GetCacheNames().Contains(randomName));
+
+            cache.Put(1, 10);
+            Assert.AreEqual(10, cache.Get(1));
+
+            // Can't create again
+            Assert.Throws<IgniteException>(() => Ignite.CreateCache<int, int>(randomName));
+
+            var cache0 = Ignite.GetCache<int, int>(randomName);
+            Assert.AreEqual(10, cache0.Get(1));
+        }
+
+        /// <summary>
+        /// Tests GetOrCreate.
+        /// </summary>
+        [Test]
+        public void TestGetOrCreateFromTemplate()
+        {
+            // Create a cache with random name
+            var randomName = "template" + Guid.NewGuid();
+
+            // Can't get non-existent cache with Cache method
+            Assert.Throws<ArgumentException>(() => Ignite.GetCache<int, int>(randomName));
+            
+            // Create cache and verify template setting.
+            var cache = Ignite.GetOrCreateCache<int, int>(randomName);
+            Assert.AreEqual(3, cache.GetConfiguration().Backups);
+
+            cache.Put(1, 10);
+            Assert.AreEqual(10, cache.Get(1));
+
+            var cache0 = Ignite.GetOrCreateCache<int, int>(randomName);
+
+            Assert.AreEqual(10, cache0.Get(1));
+
+            var cache1 = Ignite.GetCache<int, int>(randomName);
+
+            Assert.AreEqual(10, cache1.Get(1));
+        }
+
+        /// <summary>
+        /// Tests dynamic template creation.
+        /// </summary>
+        [Test]
+        public void TestDynamicTemplate()
+        {
+            var template = new CacheConfiguration
+            {
+                Name = "dynTempl*",
+                Backups = 7,
+                RebalanceBatchSize = 1234
+            };
+
+            // Register template.
+            Ignite.AddCacheConfiguration(template);
+            
+            // Double registration is allowed.
+            Ignite.AddCacheConfiguration(template);
+            
+            var cache = Ignite.CreateCache<int, int>("dynTempl1");
+            Assert.AreEqual(7, cache.GetConfiguration().Backups);
+            Assert.AreEqual(1234, cache.GetConfiguration().RebalanceBatchSize);
+        }
+
+        /// <summary>
+        /// Tests cache destroy.
+        /// </summary>
+        [Test]
+        public void TestDestroy()
+        {
+            var cacheName = "template" + Guid.NewGuid();
+
+            var ignite = Ignite;
+
+            var cache = ignite.CreateCache<int, int>(cacheName);
+
+            Assert.IsNotNull(ignite.GetCache<int, int>(cacheName));
+            Assert.IsTrue(Ignite.GetCacheNames().Contains(cacheName));
+
+            ignite.DestroyCache(cache.Name);
+
+            Assert.IsFalse(Ignite.GetCacheNames().Contains(cacheName));
+
+            var ex = Assert.Throws<ArgumentException>(() => ignite.GetCache<int, int>(cacheName));
+
+            Assert.IsTrue(ex.Message.StartsWith("Cache doesn't exist"));
+
+            Assert.Throws<InvalidOperationException>(() => cache.Get(1));
+        }
+
+        /** <inheritdoc /> */
+        protected override IgniteConfiguration GetConfig()
+        {
+            return new IgniteConfiguration(base.GetConfig())
+            {
+                CacheConfiguration = new []
+                {
+                    new CacheConfiguration
+                    {
+                        Name = "template*",
+                        Backups = 3
+                    } 
+                }
+            };
+        }
+    }
+}
\ No newline at end of file
index a8a99ce..67f602e 100644 (file)
@@ -28,7 +28,7 @@ namespace Apache.Ignite.Core.Tests.Compute
     /// <summary>
     /// Cancellation tests.
     /// </summary>
-    public class CancellationTest : IgniteTestBase
+    public class CancellationTest : SpringTestBase
     {
         public CancellationTest() 
             : base("config\\compute\\compute-grid1.xml", "config\\compute\\compute-grid2.xml")
index 4550a18..c4c2239 100644 (file)
@@ -23,7 +23,7 @@ namespace Apache.Ignite.Core.Tests.DataStructures
     /// <summary>
     /// Atomic long test.
     /// </summary>
-    public class AtomicLongTest : IgniteTestBase
+    public class AtomicLongTest : SpringTestBase
     {
         /** */
         private const string AtomicLongName = "testAtomicLong";
index 0b16785..185a7c0 100644 (file)
@@ -25,7 +25,7 @@ namespace Apache.Ignite.Core.Tests.DataStructures
     /// <summary>
     /// Atomic reference test.
     /// </summary>
-    public class AtomicReferenceTest : IgniteTestBase
+    public class AtomicReferenceTest : SpringTestBase
     {
         /** */
         private const string AtomicRefName = "testAtomicRef";
index 7633021..fe0519f 100644 (file)
@@ -23,7 +23,7 @@ namespace Apache.Ignite.Core.Tests.DataStructures
     /// <summary>
     /// Atomic sequence test.
     /// </summary>
-    public class AtomicSequenceTest : IgniteTestBase
+    public class AtomicSequenceTest : SpringTestBase
     {
         /** */
         private const string AtomicSeqName = "testAtomicSeq";
@@ -22,11 +22,12 @@ namespace Apache.Ignite.Core.Tests
     using Apache.Ignite.Core.Compute;
     using NUnit.Framework;
 
+
     /// <summary>
     /// Base class for all grid tests.
     /// </summary>
     [Serializable]
-    public abstract class IgniteTestBase
+    public abstract class SpringTestBase
     {
         /** Grids. */
         [NonSerialized]
@@ -41,21 +42,21 @@ namespace Apache.Ignite.Core.Tests
         private readonly int _expectedHandleRegistryEntries;
 
         /// <summary>
-        /// Initializes a new instance of the <see cref="IgniteTestBase"/> class.
+        /// Initializes a new instance of the <see cref="SpringTestBase"/> class.
         /// </summary>
         /// <param name="springUrls">The spring urls.</param>
-        protected IgniteTestBase(params string[] springUrls)
+        protected SpringTestBase(params string[] springUrls)
             : this(0, springUrls)
         {
             // No-op.
         }
 
         /// <summary>
-        /// Initializes a new instance of the <see cref="IgniteTestBase"/> class.
+        /// Initializes a new instance of the <see cref="SpringTestBase"/> class.
         /// </summary>
         /// <param name="springUrls">The spring urls.</param>
         /// <param name="expectedHandleRegistryEntries">The expected handle registry entries.</param>
-        protected IgniteTestBase(int expectedHandleRegistryEntries, params string[] springUrls)
+        protected SpringTestBase(int expectedHandleRegistryEntries, params string[] springUrls)
         {
             _springUrls = springUrls.ToArray();
 
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestBase.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestBase.cs
new file mode 100644 (file)
index 0000000..cdccd54
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests
+{
+    using NUnit.Framework;
+
+    /// <summary>
+    /// Code configuration test base.
+    /// </summary>
+    public class TestBase
+    {
+        /// <summary>
+        /// Sets up the fixture.
+        /// </summary>
+        [TestFixtureSetUp]
+        public void TestFixtureSetUp()
+        {
+            Ignition.Start(GetConfig());
+        }
+
+        /// <summary>
+        /// Tears down the fixture.
+        /// </summary>
+        [TestFixtureTearDown]
+        public void TestFixtureTearDown()
+        {
+            Ignition.StopAll(true);
+        }
+
+        /// <summary>
+        /// Gets the configuration.
+        /// </summary>
+        protected virtual IgniteConfiguration GetConfig()
+        {
+            return TestUtils.GetTestConfiguration();
+        }
+
+        /// <summary>
+        /// Gets an Ignite instance.
+        /// </summary>
+        protected IIgnite Ignite
+        {
+            get { return Ignition.GetIgnite(); }
+        }
+    }
+}
\ No newline at end of file
index bf6a227..035d4b5 100644 (file)
@@ -400,5 +400,13 @@ namespace Apache.Ignite.Core
         /// in <see cref="IgniteConfiguration.DataStorageConfiguration"/>.
         /// </summary>
         IDataStorageMetrics GetDataStorageMetrics();
+
+        /// <summary>
+        /// Adds cache configuration template. Name should contain *.
+        /// Template settins are applied to a cache created with <see cref="CreateCache{K,V}(string)"/> if specified
+        /// name matches the template name.
+        /// </summary>
+        /// <param name="configuration">Configuration.</param>
+        void AddCacheConfiguration(CacheConfiguration configuration);
     }
 }
index ae751a4..eb7f627 100644 (file)
@@ -83,7 +83,8 @@ namespace Apache.Ignite.Core.Impl
             LoggerIsLevelEnabled = 19,
             LoggerLog = 20,
             GetBinaryProcessor = 21,
-            ReleaseStart = 22
+            ReleaseStart = 22,
+            AddCacheConfiguration = 23
         }
 
         /** */
@@ -805,6 +806,15 @@ namespace Apache.Ignite.Core.Impl
             return _prj.GetDataStorageMetrics();
         }
 
+        /** <inheritdoc /> */
+        public void AddCacheConfiguration(CacheConfiguration configuration)
+        {
+            IgniteArgumentCheck.NotNull(configuration, "configuration");
+
+            DoOutOp((int) Op.AddCacheConfiguration,
+                s => configuration.Write(BinaryUtils.Marshaller.StartMarshal(s)));
+        }
+
         /// <summary>
         /// Gets or creates near cache.
         /// </summary>