diff --git a/modules/core/src/test/java/org/apache/ignite/platform/V17CacheStoreFactory.java b/modules/core/src/test/java/org/apache/ignite/platform/V17CacheStoreFactory.java new file mode 100644 index 0000000000000..8fcdf30507756 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/platform/V17CacheStoreFactory.java @@ -0,0 +1,37 @@ +/* + * 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.platform; + +import javax.cache.configuration.Factory; + +/** + * Cache store factory for .Net tests. + * + * @param + * @param + */ +public class V17CacheStoreFactory implements Factory> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public VCacheStore create() { + return new VCacheStore<>("apache.ignite.platform.model.V17"); + } +} + diff --git a/modules/core/src/test/java/org/apache/ignite/platform/V18CacheStoreFactory.java b/modules/core/src/test/java/org/apache/ignite/platform/V18CacheStoreFactory.java new file mode 100644 index 0000000000000..250ec85ad0fbc --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/platform/V18CacheStoreFactory.java @@ -0,0 +1,37 @@ +/* + * 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.platform; + +import javax.cache.configuration.Factory; + +/** + * Cache store factory for .Net tests. + * + * @param + * @param + */ +public class V18CacheStoreFactory implements Factory> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public VCacheStore create() { + return new VCacheStore<>("apache.ignite.platform.model.V18"); + } +} + diff --git a/modules/core/src/test/java/org/apache/ignite/platform/VCacheStore.java b/modules/core/src/test/java/org/apache/ignite/platform/VCacheStore.java new file mode 100644 index 0000000000000..9c75a405f3acd --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/platform/VCacheStore.java @@ -0,0 +1,95 @@ +/* + * 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.platform; + +import java.util.Collection; +import java.util.Map; +import javax.cache.Cache; +import javax.cache.integration.CacheLoaderException; +import javax.cache.integration.CacheWriterException; +import org.apache.ignite.Ignite; +import org.apache.ignite.cache.store.CacheStore; +import org.apache.ignite.lang.IgniteBiInClosure; +import org.apache.ignite.resources.IgniteInstanceResource; +import org.jetbrains.annotations.Nullable; + +/** + * Cache store for .Net tests. + * + * @param + * @param + */ +public class VCacheStore implements CacheStore { + /** Ignite instance. */ + @IgniteInstanceResource + protected Ignite ignite; + + /** */ + private final String typeName; + + /** */ + public VCacheStore(String typeName) { + this.typeName = typeName; + } + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override public void loadCache(IgniteBiInClosure clo, @Nullable Object... args) throws CacheLoaderException { + Integer key = 1; + + clo.apply((K)key, (V)ignite.binary().builder(typeName) + .setField("id", key, Integer.class) + .setField("name", "v1", String.class) + .build()); + } + + /** {@inheritDoc} */ + @Override public void sessionEnd(boolean commit) throws CacheWriterException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public V load(K k) throws CacheLoaderException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public Map loadAll(Iterable iterable) throws CacheLoaderException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public void write(Cache.Entry entry) throws CacheWriterException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public void writeAll(Collection> collection) throws CacheWriterException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public void delete(Object o) throws CacheWriterException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override public void deleteAll(Collection collection) throws CacheWriterException { + throw new UnsupportedOperationException(); + } +} diff --git a/modules/core/src/test/java/org/apache/ignite/platform/model/V16.java b/modules/core/src/test/java/org/apache/ignite/platform/model/V16.java index bf70834d99ebc..014d7ec3bd5aa 100644 --- a/modules/core/src/test/java/org/apache/ignite/platform/model/V16.java +++ b/modules/core/src/test/java/org/apache/ignite/platform/model/V16.java @@ -17,7 +17,7 @@ package org.apache.ignite.platform.model; -/** Test V15 object. */ +/** Test V16 object. */ public class V16 { /** */ private final String name; diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.DotNetCore.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.DotNetCore.csproj index a1dd4f11a9ec2..e2ec6b01a3c62 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.DotNetCore.csproj +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.DotNetCore.csproj @@ -90,6 +90,7 @@ + PreserveNewest diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj index b4a8699e60bbe..5bba414989b93 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj @@ -106,6 +106,7 @@ + diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/LoadCacheTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/LoadCacheTest.cs new file mode 100644 index 0000000000000..9e7739ef78481 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/LoadCacheTest.cs @@ -0,0 +1,186 @@ +/* + * 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 System.IO; + using System.Reflection; + using Apache.Ignite.Core.Binary; + using Apache.Ignite.Core.Cache; + using Apache.Ignite.Core.Cache.Configuration; + using Apache.Ignite.Platform.Model; + using NUnit.Framework; + + /// + /// Tests checks ability to execute loadCache method without explicit registration of binary type. + /// + public class LoadCacheTest + { + /** */ + private IIgnite _grid1; + + /** */ + private IIgnite _client; + + [TestFixtureTearDown] + public void FixtureTearDown() + { + StopGrids(); + } + + /// + /// Executes before each test. + /// + [SetUp] + public void SetUp() + { + StartGrids(); + } + + /// + /// Executes after each test. + /// + [TearDown] + public void TearDown() + { + try + { + TestUtils.AssertHandleRegistryIsEmpty(1000, _grid1); + } + catch (Exception) + { + // Restart grids to cleanup + StopGrids(); + + throw; + } + finally + { + if (TestContext.CurrentContext.Test.Name.StartsWith("TestEventTypes")) + StopGrids(); // clean events for other tests + } + } + + /// + /// Starts the grids. + /// + private void StartGrids() + { + if (_grid1 != null) + return; + + var path = Path.Combine("Config", "Cache", "load-cache-config.xml"); + + _grid1 = Ignition.Start(GetConfiguration(path)); + + var clientWorkDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), + "client_work"); + + _client = Ignition.Start(new IgniteConfiguration(TestUtils.GetTestConfiguration()) + { + WorkDirectory = clientWorkDir, + ClientMode = true, + IgniteInstanceName = "client", + BinaryConfiguration = new BinaryConfiguration + { + NameMapper = new BinaryBasicNameMapper {NamespaceToLower = true} + } + }); + } + + /// + /// Gets the Ignite configuration. + /// + private IgniteConfiguration GetConfiguration(string springConfigUrl) + { + springConfigUrl = ReplaceFooterSetting(springConfigUrl); + + return new IgniteConfiguration(TestUtils.GetTestConfiguration()) + { + IgniteInstanceName = "server", + SpringConfigUrl = springConfigUrl, + BinaryConfiguration = new BinaryConfiguration + { + NameMapper = new BinaryBasicNameMapper {NamespaceToLower = true} + } + }; + } + + /// + /// Replaces the footer setting. + /// + internal static string ReplaceFooterSetting(string path) + { + var text = File.ReadAllText(path).Replace( + "property name=\"compactFooter\" value=\"true\"", + "property name=\"compactFooter\" value=\"false\""); + + path += "_fullFooter"; + + File.WriteAllText(path, text); + + Assert.IsTrue(File.Exists(path)); + + return path; + } + + /// + /// Stops the grids. + /// + private void StopGrids() + { + _grid1 = null; + + Ignition.StopAll(true); + } + + [Test] + public void LoadCacheOnServer() + { + var cache = _grid1.GetCache("V17"); + + cache.LoadCache(null); + + var v = cache.LocalPeek(1, CachePeekMode.Platform); + + Assert.AreEqual(1, v.Id); + Assert.AreEqual("v1", v.Name); + } + + [Test] + public void LoadCacheOnClient() + { + var cache = _client.GetOrCreateNearCache( + "V18", + new NearCacheConfiguration(), + new PlatformCacheConfiguration + { + KeyTypeName = typeof(int).FullName, + ValueTypeName = typeof(V18).FullName + } + ); + + cache.LoadCache(null); + + var v = cache.Get(1); + + Assert.AreEqual(1, v.Id); + Assert.AreEqual("v1", v.Name); + } + } +} diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Cache/load-cache-config.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Cache/load-cache-config.xml new file mode 100644 index 0000000000000..41f97284803f5 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Cache/load-cache-config.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 127.0.0.1:47500 + + + + + + + + diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/Model.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/Model.cs index 24ea696f94e0b..bfe7bab2acdca 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/Model.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/Model.cs @@ -260,4 +260,22 @@ public class V15 { public String Name { get; set; } } /// A class is a clone of Java class V16 with the same namespace. /// public class V16 { public String Name { get; set; } } + + /// + /// V17. + /// + public class V17 + { + public int Id { get; set; } + public String Name { get; set; } + } + + /// + /// V18. + /// + public class V18 + { + public int Id { get; set; } + public String Name { get; set; } + } } diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Platform/PlatformCache.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Platform/PlatformCache.cs index 42393c97699d8..b6f3d037a4f03 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Platform/PlatformCache.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Platform/PlatformCache.cs @@ -127,6 +127,28 @@ public int GetSize(int? partition) /** */ public void Update(IBinaryStream stream, Marshaller marshaller) + { + if (_keepBinary) + Update0(stream, marshaller); + + bool locRegisterSameJavaType = Marshaller.RegisterSameJavaTypeTl.Value; + + Marshaller.RegisterSameJavaTypeTl.Value = true; + + try + { + Update0(stream, marshaller); + } + finally + { + Marshaller.RegisterSameJavaTypeTl.Value = locRegisterSameJavaType; + } + } + + /// + /// Updates entry in platform cache. + /// + private void Update0(IBinaryStream stream, Marshaller marshaller) { Debug.Assert(stream != null); Debug.Assert(marshaller != null);