forked from apache/ignite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IGN-2810 .Net: Enable RegisterSameJavaType mode for platform cache up…
…date Merge in OSPT/ignite from IGN-2810 to master Squashed commit of the following: commit 4c97a66ae0ed7f264b66e7f798bad548807b0503 Author: Nikolay Izhikov <nizhikov@apache.org> Date: Fri Mar 5 11:09:03 2021 +0300 IGN-2810 Fix. commit 2313da33c5d83a0185abb8cf8e66aa66ec4f42e2 Author: Nikolay Izhikov <nizhikov@apache.org> Date: Thu Mar 4 19:39:36 2021 +0300 IGN-2810 Fix. commit a19b9798c3902f5270e171def552152cca1c2a23 Author: Nikolay Izhikov <nizhikov@apache.org> Date: Wed Mar 3 22:48:29 2021 +0300 IGN-2810 .Net test to reproduce LoadCache issue. commit 875362740de6238ea20d25094f8f2e7e65eb79eb Author: Nikolay Izhikov <nizhikov@apache.org> Date: Wed Mar 3 22:30:37 2021 +0300 IGN-2810 .Net test to reproduce LoadCache issue. commit a041b1a1b7d1a5d2a12cbe8bfc1a9813e711a176 Author: Nikolay Izhikov <nizhikov@apache.org> Date: Wed Mar 3 21:58:30 2021 +0300 IGN-2810 .Net test to reproduce LoadCache issue.
- Loading branch information
Showing
10 changed files
with
467 additions
and
1 deletion.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
modules/core/src/test/java/org/apache/ignite/platform/V17CacheStoreFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <K> | ||
* @param <V> | ||
*/ | ||
public class V17CacheStoreFactory<K, V> implements Factory<VCacheStore<K, V>> { | ||
/** */ | ||
private static final long serialVersionUID = 0L; | ||
|
||
/** {@inheritDoc} */ | ||
@Override public VCacheStore<K, V> create() { | ||
return new VCacheStore<>("apache.ignite.platform.model.V17"); | ||
} | ||
} | ||
|
37 changes: 37 additions & 0 deletions
37
modules/core/src/test/java/org/apache/ignite/platform/V18CacheStoreFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <K> | ||
* @param <V> | ||
*/ | ||
public class V18CacheStoreFactory<K, V> implements Factory<VCacheStore<K, V>> { | ||
/** */ | ||
private static final long serialVersionUID = 0L; | ||
|
||
/** {@inheritDoc} */ | ||
@Override public VCacheStore<K, V> create() { | ||
return new VCacheStore<>("apache.ignite.platform.model.V18"); | ||
} | ||
} | ||
|
95 changes: 95 additions & 0 deletions
95
modules/core/src/test/java/org/apache/ignite/platform/VCacheStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <K> | ||
* @param <V> | ||
*/ | ||
public class VCacheStore<K, V> implements CacheStore<K, V> { | ||
/** 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<K, V> 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<K, V> loadAll(Iterable<? extends K> iterable) throws CacheLoaderException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public void write(Cache.Entry<? extends K, ? extends V> entry) throws CacheWriterException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public void writeAll(Collection<Cache.Entry<? extends K, ? extends V>> 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/LoadCacheTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
/// <summary> | ||
/// Tests checks ability to execute loadCache method without explicit registration of binary type. | ||
/// </summary> | ||
public class LoadCacheTest | ||
{ | ||
/** */ | ||
private IIgnite _grid1; | ||
|
||
/** */ | ||
private IIgnite _client; | ||
|
||
[TestFixtureTearDown] | ||
public void FixtureTearDown() | ||
{ | ||
StopGrids(); | ||
} | ||
|
||
/// <summary> | ||
/// Executes before each test. | ||
/// </summary> | ||
[SetUp] | ||
public void SetUp() | ||
{ | ||
StartGrids(); | ||
} | ||
|
||
/// <summary> | ||
/// Executes after each test. | ||
/// </summary> | ||
[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 | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Starts the grids. | ||
/// </summary> | ||
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} | ||
} | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the Ignite configuration. | ||
/// </summary> | ||
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} | ||
} | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Replaces the footer setting. | ||
/// </summary> | ||
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; | ||
} | ||
|
||
/// <summary> | ||
/// Stops the grids. | ||
/// </summary> | ||
private void StopGrids() | ||
{ | ||
_grid1 = null; | ||
|
||
Ignition.StopAll(true); | ||
} | ||
|
||
[Test] | ||
public void LoadCacheOnServer() | ||
{ | ||
var cache = _grid1.GetCache<int, V17>("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<int, V18>( | ||
"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); | ||
} | ||
} | ||
} |
Oops, something went wrong.