You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2016/07/27 07:19:30 UTC
[1/7] ignite git commit: IGNITE-3504 .NET: Fix IBinaryObjectBuilder
setter methods
Repository: ignite
Updated Branches:
refs/heads/master a441bb9cc -> 42f42eac5
IGNITE-3504 .NET: Fix IBinaryObjectBuilder setter methods
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6917ec40
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6917ec40
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6917ec40
Branch: refs/heads/master
Commit: 6917ec403816416a6cbc7eb0a5a3696b692059e0
Parents: fd50502
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Mon Jul 25 16:12:51 2016 +0300
Committer: agura <ag...@gridgain.com>
Committed: Mon Jul 25 17:35:37 2016 +0300
----------------------------------------------------------------------
.../Binary/BinaryBuilderSelfTest.cs | 325 +++++++++++++++----
.../Binary/IBinaryObjectBuilder.cs | 2 +-
.../Impl/Binary/BinaryObjectBuilder.cs | 16 +-
.../Impl/Binary/BinaryWriter.cs | 133 +++++---
4 files changed, 345 insertions(+), 131 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/6917ec40/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
index 40ecc1e..80788a6 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/BinaryBuilderSelfTest.cs
@@ -595,7 +595,8 @@ namespace Apache.Ignite.Core.Tests.Binary
[Test]
public void TestPrimitiveFields()
{
- IBinaryObject binObj = _grid.GetBinary().GetBuilder(typeof(Primitives))
+ // Generic SetField method.
+ var binObj = _grid.GetBinary().GetBuilder(typeof(Primitives))
.SetField<byte>("fByte", 1)
.SetField("fBool", true)
.SetField<short>("fShort", 2)
@@ -604,16 +605,73 @@ namespace Apache.Ignite.Core.Tests.Binary
.SetField<long>("fLong", 4)
.SetField<float>("fFloat", 5)
.SetField<double>("fDouble", 6)
+ .SetField("fDecimal", 7.7m)
.SetHashCode(100)
.Build();
+ CheckPrimitiveFields1(binObj);
+
+ // Specific setter methods.
+ binObj = _grid.GetBinary().GetBuilder(typeof(Primitives))
+ .SetByteField("fByte", 1)
+ .SetBooleanField("fBool", true)
+ .SetShortField("fShort", 2)
+ .SetCharField("fChar", 'a')
+ .SetIntField("fInt", 3)
+ .SetLongField("fLong", 4)
+ .SetFloatField("fFloat", 5)
+ .SetDoubleField("fDouble", 6)
+ .SetDecimalField("fDecimal", 7.7m)
+ .SetHashCode(100)
+ .Build();
+
+ CheckPrimitiveFields1(binObj);
+
+ // Overwrite with generic methods.
+ binObj = binObj.ToBuilder()
+ .SetField<byte>("fByte", 7)
+ .SetField("fBool", false)
+ .SetField<short>("fShort", 8)
+ .SetField("fChar", 'b')
+ .SetField("fInt", 9)
+ .SetField<long>("fLong", 10)
+ .SetField<float>("fFloat", 11)
+ .SetField<double>("fDouble", 12)
+ .SetField("fDecimal", 13.13m)
+ .SetHashCode(200)
+ .Build();
+
+ CheckPrimitiveFields2(binObj);
+
+ // Overwrite with specific methods.
+ binObj = binObj.ToBuilder()
+ .SetByteField("fByte", 7)
+ .SetBooleanField("fBool", false)
+ .SetShortField("fShort", 8)
+ .SetCharField("fChar", 'b')
+ .SetIntField("fInt", 9)
+ .SetLongField("fLong", 10)
+ .SetFloatField("fFloat", 11)
+ .SetDoubleField("fDouble", 12)
+ .SetDecimalField("fDecimal", 13.13m)
+ .SetHashCode(200)
+ .Build();
+
+ CheckPrimitiveFields2(binObj);
+ }
+
+ /// <summary>
+ /// Checks the primitive fields values.
+ /// </summary>
+ private static void CheckPrimitiveFields1(IBinaryObject binObj)
+ {
Assert.AreEqual(100, binObj.GetHashCode());
IBinaryType meta = binObj.GetBinaryType();
Assert.AreEqual(typeof(Primitives).Name, meta.TypeName);
- Assert.AreEqual(8, meta.Fields.Count);
+ Assert.AreEqual(9, meta.Fields.Count);
Assert.AreEqual(BinaryTypeNames.TypeNameByte, meta.GetFieldTypeName("fByte"));
Assert.AreEqual(BinaryTypeNames.TypeNameBool, meta.GetFieldTypeName("fBool"));
@@ -623,6 +681,7 @@ namespace Apache.Ignite.Core.Tests.Binary
Assert.AreEqual(BinaryTypeNames.TypeNameLong, meta.GetFieldTypeName("fLong"));
Assert.AreEqual(BinaryTypeNames.TypeNameFloat, meta.GetFieldTypeName("fFloat"));
Assert.AreEqual(BinaryTypeNames.TypeNameDouble, meta.GetFieldTypeName("fDouble"));
+ Assert.AreEqual(BinaryTypeNames.TypeNameDecimal, meta.GetFieldTypeName("fDecimal"));
Assert.AreEqual(1, binObj.GetField<byte>("fByte"));
Assert.AreEqual(true, binObj.GetField<bool>("fBool"));
@@ -632,6 +691,7 @@ namespace Apache.Ignite.Core.Tests.Binary
Assert.AreEqual(4, binObj.GetField<long>("fLong"));
Assert.AreEqual(5, binObj.GetField<float>("fFloat"));
Assert.AreEqual(6, binObj.GetField<double>("fDouble"));
+ Assert.AreEqual(7.7m, binObj.GetField<decimal>("fDecimal"));
Primitives obj = binObj.Deserialize<Primitives>();
@@ -643,20 +703,14 @@ namespace Apache.Ignite.Core.Tests.Binary
Assert.AreEqual(4, obj.FLong);
Assert.AreEqual(5, obj.FFloat);
Assert.AreEqual(6, obj.FDouble);
+ Assert.AreEqual(7.7m, obj.FDecimal);
+ }
- // Overwrite.
- binObj = binObj.ToBuilder()
- .SetField<byte>("fByte", 7)
- .SetField("fBool", false)
- .SetField<short>("fShort", 8)
- .SetField("fChar", 'b')
- .SetField("fInt", 9)
- .SetField<long>("fLong", 10)
- .SetField<float>("fFloat", 11)
- .SetField<double>("fDouble", 12)
- .SetHashCode(200)
- .Build();
-
+ /// <summary>
+ /// Checks the primitive fields values.
+ /// </summary>
+ private static void CheckPrimitiveFields2(IBinaryObject binObj)
+ {
Assert.AreEqual(200, binObj.GetHashCode());
Assert.AreEqual(7, binObj.GetField<byte>("fByte"));
@@ -667,8 +721,9 @@ namespace Apache.Ignite.Core.Tests.Binary
Assert.AreEqual(10, binObj.GetField<long>("fLong"));
Assert.AreEqual(11, binObj.GetField<float>("fFloat"));
Assert.AreEqual(12, binObj.GetField<double>("fDouble"));
+ Assert.AreEqual(13.13m, binObj.GetField<decimal>("fDecimal"));
- obj = binObj.Deserialize<Primitives>();
+ var obj = binObj.Deserialize<Primitives>();
Assert.AreEqual(7, obj.FByte);
Assert.AreEqual(false, obj.FBool);
@@ -678,6 +733,7 @@ namespace Apache.Ignite.Core.Tests.Binary
Assert.AreEqual(10, obj.FLong);
Assert.AreEqual(11, obj.FFloat);
Assert.AreEqual(12, obj.FDouble);
+ Assert.AreEqual(13.13m, obj.FDecimal);
}
/// <summary>
@@ -686,7 +742,8 @@ namespace Apache.Ignite.Core.Tests.Binary
[Test]
public void TestPrimitiveArrayFields()
{
- IBinaryObject binObj = _grid.GetBinary().GetBuilder(typeof(PrimitiveArrays))
+ // Generic SetField method.
+ var binObj = _grid.GetBinary().GetBuilder(typeof(PrimitiveArrays))
.SetField("fByte", new byte[] { 1 })
.SetField("fBool", new[] { true })
.SetField("fShort", new short[] { 2 })
@@ -695,16 +752,71 @@ namespace Apache.Ignite.Core.Tests.Binary
.SetField("fLong", new long[] { 4 })
.SetField("fFloat", new float[] { 5 })
.SetField("fDouble", new double[] { 6 })
+ .SetField("fDecimal", new decimal?[] { 7.7m })
.SetHashCode(100)
.Build();
+ CheckPrimitiveArrayFields1(binObj);
+
+ // Specific setters.
+ binObj = _grid.GetBinary().GetBuilder(typeof(PrimitiveArrays))
+ .SetByteArrayField("fByte", new byte[] {1})
+ .SetBooleanArrayField("fBool", new[] {true})
+ .SetShortArrayField("fShort", new short[] {2})
+ .SetCharArrayField("fChar", new[] {'a'})
+ .SetIntArrayField("fInt", new[] {3})
+ .SetLongArrayField("fLong", new long[] {4})
+ .SetFloatArrayField("fFloat", new float[] {5})
+ .SetDoubleArrayField("fDouble", new double[] {6})
+ .SetDecimalArrayField("fDecimal", new decimal?[] {7.7m})
+ .SetHashCode(100)
+ .Build();
+
+ // Overwrite with generic setter.
+ binObj = _grid.GetBinary().GetBuilder(binObj)
+ .SetField("fByte", new byte[] { 7 })
+ .SetField("fBool", new[] { false })
+ .SetField("fShort", new short[] { 8 })
+ .SetField("fChar", new[] { 'b' })
+ .SetField("fInt", new[] { 9 })
+ .SetField("fLong", new long[] { 10 })
+ .SetField("fFloat", new float[] { 11 })
+ .SetField("fDouble", new double[] { 12 })
+ .SetField("fDecimal", new decimal?[] { 13.13m })
+ .SetHashCode(200)
+ .Build();
+
+ CheckPrimitiveArrayFields2(binObj);
+
+ // Overwrite with specific setters.
+ binObj = _grid.GetBinary().GetBuilder(binObj)
+ .SetByteArrayField("fByte", new byte[] { 7 })
+ .SetBooleanArrayField("fBool", new[] { false })
+ .SetShortArrayField("fShort", new short[] { 8 })
+ .SetCharArrayField("fChar", new[] { 'b' })
+ .SetIntArrayField("fInt", new[] { 9 })
+ .SetLongArrayField("fLong", new long[] { 10 })
+ .SetFloatArrayField("fFloat", new float[] { 11 })
+ .SetDoubleArrayField("fDouble", new double[] { 12 })
+ .SetDecimalArrayField("fDecimal", new decimal?[] { 13.13m })
+ .SetHashCode(200)
+ .Build();
+
+ CheckPrimitiveArrayFields2(binObj);
+ }
+
+ /// <summary>
+ /// Checks the primitive array fields.
+ /// </summary>
+ private static void CheckPrimitiveArrayFields1(IBinaryObject binObj)
+ {
Assert.AreEqual(100, binObj.GetHashCode());
IBinaryType meta = binObj.GetBinaryType();
Assert.AreEqual(typeof(PrimitiveArrays).Name, meta.TypeName);
- Assert.AreEqual(8, meta.Fields.Count);
+ Assert.AreEqual(9, meta.Fields.Count);
Assert.AreEqual(BinaryTypeNames.TypeNameArrayByte, meta.GetFieldTypeName("fByte"));
Assert.AreEqual(BinaryTypeNames.TypeNameArrayBool, meta.GetFieldTypeName("fBool"));
@@ -714,6 +826,7 @@ namespace Apache.Ignite.Core.Tests.Binary
Assert.AreEqual(BinaryTypeNames.TypeNameArrayLong, meta.GetFieldTypeName("fLong"));
Assert.AreEqual(BinaryTypeNames.TypeNameArrayFloat, meta.GetFieldTypeName("fFloat"));
Assert.AreEqual(BinaryTypeNames.TypeNameArrayDouble, meta.GetFieldTypeName("fDouble"));
+ Assert.AreEqual(BinaryTypeNames.TypeNameArrayDecimal, meta.GetFieldTypeName("fDecimal"));
Assert.AreEqual(new byte[] { 1 }, binObj.GetField<byte[]>("fByte"));
Assert.AreEqual(new[] { true }, binObj.GetField<bool[]>("fBool"));
@@ -723,6 +836,7 @@ namespace Apache.Ignite.Core.Tests.Binary
Assert.AreEqual(new long[] { 4 }, binObj.GetField<long[]>("fLong"));
Assert.AreEqual(new float[] { 5 }, binObj.GetField<float[]>("fFloat"));
Assert.AreEqual(new double[] { 6 }, binObj.GetField<double[]>("fDouble"));
+ Assert.AreEqual(new decimal?[] { 7.7m }, binObj.GetField<decimal?[]>("fDecimal"));
PrimitiveArrays obj = binObj.Deserialize<PrimitiveArrays>();
@@ -734,20 +848,14 @@ namespace Apache.Ignite.Core.Tests.Binary
Assert.AreEqual(new long[] { 4 }, obj.FLong);
Assert.AreEqual(new float[] { 5 }, obj.FFloat);
Assert.AreEqual(new double[] { 6 }, obj.FDouble);
+ Assert.AreEqual(new decimal?[] { 7.7m }, obj.FDecimal);
+ }
- // Overwrite.
- binObj = _grid.GetBinary().GetBuilder(binObj)
- .SetField("fByte", new byte[] { 7 })
- .SetField("fBool", new[] { false })
- .SetField("fShort", new short[] { 8 })
- .SetField("fChar", new[] { 'b' })
- .SetField("fInt", new[] { 9 })
- .SetField("fLong", new long[] { 10 })
- .SetField("fFloat", new float[] { 11 })
- .SetField("fDouble", new double[] { 12 })
- .SetHashCode(200)
- .Build();
-
+ /// <summary>
+ /// Checks the primitive array fields.
+ /// </summary>
+ private static void CheckPrimitiveArrayFields2(IBinaryObject binObj)
+ {
Assert.AreEqual(200, binObj.GetHashCode());
Assert.AreEqual(new byte[] { 7 }, binObj.GetField<byte[]>("fByte"));
@@ -758,8 +866,9 @@ namespace Apache.Ignite.Core.Tests.Binary
Assert.AreEqual(new long[] { 10 }, binObj.GetField<long[]>("fLong"));
Assert.AreEqual(new float[] { 11 }, binObj.GetField<float[]>("fFloat"));
Assert.AreEqual(new double[] { 12 }, binObj.GetField<double[]>("fDouble"));
+ Assert.AreEqual(new decimal?[] { 13.13m }, binObj.GetField<decimal?[]>("fDecimal"));
- obj = binObj.Deserialize<PrimitiveArrays>();
+ var obj = binObj.Deserialize<PrimitiveArrays>();
Assert.AreEqual(new byte[] { 7 }, obj.FByte);
Assert.AreEqual(new[] { false }, obj.FBool);
@@ -769,6 +878,7 @@ namespace Apache.Ignite.Core.Tests.Binary
Assert.AreEqual(new long[] { 10 }, obj.FLong);
Assert.AreEqual(new float[] { 11 }, obj.FFloat);
Assert.AreEqual(new double[] { 12 }, obj.FDouble);
+ Assert.AreEqual(new decimal?[] { 13.13m }, obj.FDecimal);
}
/// <summary>
@@ -777,69 +887,141 @@ namespace Apache.Ignite.Core.Tests.Binary
[Test]
public void TestStringDateGuidEnum()
{
- DateTime? nDate = DateTime.Now;
+ DateTime? nDate = DateTime.Now.ToUniversalTime();
Guid? nGuid = Guid.NewGuid();
+ // Generic setters.
IBinaryObject binObj = _grid.GetBinary().GetBuilder(typeof(StringDateGuidEnum))
.SetField("fStr", "str")
.SetField("fNDate", nDate)
- .SetGuidField("fNGuid", nGuid)
+ .SetTimestampField("fNTimestamp", nDate)
+ .SetField("fNGuid", nGuid)
.SetField("fEnum", TestEnum.One)
- .SetField("fStrArr", new[] { "str" })
+ .SetStringArrayField("fStrArr", new[] { "str" })
+ .SetArrayField("fDateArr", new[] { nDate })
+ .SetTimestampArrayField("fTimestampArr", new[] { nDate })
+ .SetGuidArrayField("fGuidArr", new[] { nGuid })
+ .SetEnumArrayField("fEnumArr", new[] { TestEnum.One })
+ .SetHashCode(100)
+ .Build();
+
+ CheckStringDateGuidEnum1(binObj, nDate, nGuid);
+
+ // Specific setters.
+ binObj = _grid.GetBinary().GetBuilder(typeof(StringDateGuidEnum))
+ .SetStringField("fStr", "str")
+ .SetField("fNDate", nDate)
+ .SetTimestampField("fNTimestamp", nDate)
+ .SetGuidField("fNGuid", nGuid)
+ .SetEnumField("fEnum", TestEnum.One)
+ .SetStringArrayField("fStrArr", new[] { "str" })
.SetArrayField("fDateArr", new[] { nDate })
+ .SetTimestampArrayField("fTimestampArr", new[] { nDate })
.SetGuidArrayField("fGuidArr", new[] { nGuid })
- .SetField("fEnumArr", new[] { TestEnum.One })
+ .SetEnumArrayField("fEnumArr", new[] { TestEnum.One })
.SetHashCode(100)
.Build();
+ CheckStringDateGuidEnum1(binObj, nDate, nGuid);
+
+ // Overwrite.
+ nDate = DateTime.Now.ToUniversalTime();
+ nGuid = Guid.NewGuid();
+
+ binObj = _grid.GetBinary().GetBuilder(typeof(StringDateGuidEnum))
+ .SetField("fStr", "str2")
+ .SetField("fNDate", nDate)
+ .SetTimestampField("fNTimestamp", nDate)
+ .SetField("fNGuid", nGuid)
+ .SetField("fEnum", TestEnum.Two)
+ .SetField("fStrArr", new[] { "str2" })
+ .SetArrayField("fDateArr", new[] { nDate })
+ .SetTimestampArrayField("fTimestampArr", new[] { nDate })
+ .SetField("fGuidArr", new[] { nGuid })
+ .SetField("fEnumArr", new[] { TestEnum.Two })
+ .SetHashCode(200)
+ .Build();
+
+ CheckStringDateGuidEnum2(binObj, nDate, nGuid);
+
+ // Overwrite with specific setters
+ binObj = _grid.GetBinary().GetBuilder(typeof(StringDateGuidEnum))
+ .SetStringField("fStr", "str2")
+ .SetField("fNDate", nDate)
+ .SetTimestampField("fNTimestamp", nDate)
+ .SetGuidField("fNGuid", nGuid)
+ .SetEnumField("fEnum", TestEnum.Two)
+ .SetStringArrayField("fStrArr", new[] { "str2" })
+ .SetArrayField("fDateArr", new[] { nDate })
+ .SetTimestampArrayField("fTimestampArr", new[] { nDate })
+ .SetGuidArrayField("fGuidArr", new[] { nGuid })
+ .SetEnumArrayField("fEnumArr", new[] { TestEnum.Two })
+ .SetHashCode(200)
+ .Build();
+
+ CheckStringDateGuidEnum2(binObj, nDate, nGuid);
+ }
+
+ /// <summary>
+ /// Checks the string date guid enum values.
+ /// </summary>
+ private void CheckStringDateGuidEnum1(IBinaryObject binObj, DateTime? nDate, Guid? nGuid)
+ {
Assert.AreEqual(100, binObj.GetHashCode());
IBinaryType meta = binObj.GetBinaryType();
Assert.AreEqual(typeof(StringDateGuidEnum).Name, meta.TypeName);
- Assert.AreEqual(8, meta.Fields.Count);
+ Assert.AreEqual(10, meta.Fields.Count);
Assert.AreEqual(BinaryTypeNames.TypeNameString, meta.GetFieldTypeName("fStr"));
Assert.AreEqual(BinaryTypeNames.TypeNameObject, meta.GetFieldTypeName("fNDate"));
+ Assert.AreEqual(BinaryTypeNames.TypeNameTimestamp, meta.GetFieldTypeName("fNTimestamp"));
Assert.AreEqual(BinaryTypeNames.TypeNameGuid, meta.GetFieldTypeName("fNGuid"));
Assert.AreEqual(BinaryTypeNames.TypeNameEnum, meta.GetFieldTypeName("fEnum"));
Assert.AreEqual(BinaryTypeNames.TypeNameArrayString, meta.GetFieldTypeName("fStrArr"));
Assert.AreEqual(BinaryTypeNames.TypeNameArrayObject, meta.GetFieldTypeName("fDateArr"));
+ Assert.AreEqual(BinaryTypeNames.TypeNameArrayTimestamp, meta.GetFieldTypeName("fTimestampArr"));
Assert.AreEqual(BinaryTypeNames.TypeNameArrayGuid, meta.GetFieldTypeName("fGuidArr"));
Assert.AreEqual(BinaryTypeNames.TypeNameArrayEnum, meta.GetFieldTypeName("fEnumArr"));
Assert.AreEqual("str", binObj.GetField<string>("fStr"));
Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNDate"));
+ Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNTimestamp"));
Assert.AreEqual(nGuid, binObj.GetField<Guid?>("fNGuid"));
Assert.AreEqual(TestEnum.One, binObj.GetField<TestEnum>("fEnum"));
- Assert.AreEqual(new[] { "str" }, binObj.GetField<string[]>("fStrArr"));
- Assert.AreEqual(new[] { nDate }, binObj.GetField<DateTime?[]>("fDateArr"));
- Assert.AreEqual(new[] { nGuid }, binObj.GetField<Guid?[]>("fGuidArr"));
+ Assert.AreEqual(new[] {"str"}, binObj.GetField<string[]>("fStrArr"));
+ Assert.AreEqual(new[] {nDate}, binObj.GetField<DateTime?[]>("fDateArr"));
+ Assert.AreEqual(new[] {nDate}, binObj.GetField<DateTime?[]>("fTimestampArr"));
+ Assert.AreEqual(new[] {nGuid}, binObj.GetField<Guid?[]>("fGuidArr"));
Assert.AreEqual(new[] {TestEnum.One}, binObj.GetField<TestEnum[]>("fEnumArr"));
StringDateGuidEnum obj = binObj.Deserialize<StringDateGuidEnum>();
Assert.AreEqual("str", obj.FStr);
Assert.AreEqual(nDate, obj.FnDate);
+ Assert.AreEqual(nDate, obj.FnTimestamp);
Assert.AreEqual(nGuid, obj.FnGuid);
Assert.AreEqual(TestEnum.One, obj.FEnum);
- Assert.AreEqual(new[] { "str" }, obj.FStrArr);
- Assert.AreEqual(new[] { nDate }, obj.FDateArr);
- Assert.AreEqual(new[] { nGuid }, obj.FGuidArr);
- Assert.AreEqual(new[] { TestEnum.One }, obj.FEnumArr);
+ Assert.AreEqual(new[] {"str"}, obj.FStrArr);
+ Assert.AreEqual(new[] {nDate}, obj.FDateArr);
+ Assert.AreEqual(new[] {nGuid}, obj.FGuidArr);
+ Assert.AreEqual(new[] {TestEnum.One}, obj.FEnumArr);
// Check builder field caching.
var builder = _grid.GetBinary().GetBuilder(binObj);
Assert.AreEqual("str", builder.GetField<string>("fStr"));
Assert.AreEqual(nDate, builder.GetField<DateTime?>("fNDate"));
+ Assert.AreEqual(nDate, builder.GetField<DateTime?>("fNTimestamp"));
Assert.AreEqual(nGuid, builder.GetField<Guid?>("fNGuid"));
Assert.AreEqual(TestEnum.One, builder.GetField<TestEnum>("fEnum"));
- Assert.AreEqual(new[] { "str" }, builder.GetField<string[]>("fStrArr"));
- Assert.AreEqual(new[] { nDate }, builder.GetField<DateTime?[]>("fDateArr"));
- Assert.AreEqual(new[] { nGuid }, builder.GetField<Guid?[]>("fGuidArr"));
+ Assert.AreEqual(new[] {"str"}, builder.GetField<string[]>("fStrArr"));
+ Assert.AreEqual(new[] {nDate}, builder.GetField<DateTime?[]>("fDateArr"));
+ Assert.AreEqual(new[] {nDate}, builder.GetField<DateTime?[]>("fTimestampArr"));
+ Assert.AreEqual(new[] {nGuid}, builder.GetField<Guid?[]>("fGuidArr"));
Assert.AreEqual(new[] {TestEnum.One}, builder.GetField<TestEnum[]>("fEnumArr"));
// Check reassemble.
@@ -847,55 +1029,51 @@ namespace Apache.Ignite.Core.Tests.Binary
Assert.AreEqual("str", binObj.GetField<string>("fStr"));
Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNDate"));
+ Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNTimestamp"));
Assert.AreEqual(nGuid, binObj.GetField<Guid?>("fNGuid"));
Assert.AreEqual(TestEnum.One, binObj.GetField<TestEnum>("fEnum"));
- Assert.AreEqual(new[] { "str" }, binObj.GetField<string[]>("fStrArr"));
- Assert.AreEqual(new[] { nDate }, binObj.GetField<DateTime?[]>("fDateArr"));
- Assert.AreEqual(new[] { nGuid }, binObj.GetField<Guid?[]>("fGuidArr"));
+ Assert.AreEqual(new[] {"str"}, binObj.GetField<string[]>("fStrArr"));
+ Assert.AreEqual(new[] {nDate}, binObj.GetField<DateTime?[]>("fDateArr"));
+ Assert.AreEqual(new[] {nDate}, binObj.GetField<DateTime?[]>("fTimestampArr"));
+ Assert.AreEqual(new[] {nGuid}, binObj.GetField<Guid?[]>("fGuidArr"));
Assert.AreEqual(new[] {TestEnum.One}, binObj.GetField<TestEnum[]>("fEnumArr"));
obj = binObj.Deserialize<StringDateGuidEnum>();
Assert.AreEqual("str", obj.FStr);
Assert.AreEqual(nDate, obj.FnDate);
+ Assert.AreEqual(nDate, obj.FnTimestamp);
Assert.AreEqual(nGuid, obj.FnGuid);
Assert.AreEqual(TestEnum.One, obj.FEnum);
- Assert.AreEqual(new[] { "str" }, obj.FStrArr);
- Assert.AreEqual(new[] { nDate }, obj.FDateArr);
- Assert.AreEqual(new[] { nGuid }, obj.FGuidArr);
- Assert.AreEqual(new[] { TestEnum.One }, obj.FEnumArr);
-
- // Overwrite.
- nDate = DateTime.Now.ToUniversalTime();
- nGuid = Guid.NewGuid();
-
- binObj = builder
- .SetField("fStr", "str2")
- .SetTimestampField("fNDate", nDate)
- .SetField("fNGuid", nGuid)
- .SetField("fEnum", TestEnum.Two)
- .SetField("fStrArr", new[] { "str2" })
- .SetArrayField("fDateArr", new[] { nDate })
- .SetField("fGuidArr", new[] { nGuid })
- .SetField("fEnumArr", new[] { TestEnum.Two })
- .SetHashCode(200)
- .Build();
+ Assert.AreEqual(new[] {"str"}, obj.FStrArr);
+ Assert.AreEqual(new[] {nDate}, obj.FDateArr);
+ Assert.AreEqual(new[] {nGuid}, obj.FGuidArr);
+ Assert.AreEqual(new[] {TestEnum.One}, obj.FEnumArr);
+ }
+ /// <summary>
+ /// Checks the string date guid enum values.
+ /// </summary>
+ private static void CheckStringDateGuidEnum2(IBinaryObject binObj, DateTime? nDate, Guid? nGuid)
+ {
Assert.AreEqual(200, binObj.GetHashCode());
Assert.AreEqual("str2", binObj.GetField<string>("fStr"));
Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNDate"));
+ Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNTimestamp"));
Assert.AreEqual(nGuid, binObj.GetField<Guid?>("fNGuid"));
Assert.AreEqual(TestEnum.Two, binObj.GetField<TestEnum>("fEnum"));
Assert.AreEqual(new[] { "str2" }, binObj.GetField<string[]>("fStrArr"));
Assert.AreEqual(new[] { nDate }, binObj.GetField<DateTime?[]>("fDateArr"));
+ Assert.AreEqual(new[] { nDate }, binObj.GetField<DateTime?[]>("fTimestampArr"));
Assert.AreEqual(new[] { nGuid }, binObj.GetField<Guid?[]>("fGuidArr"));
- Assert.AreEqual(new[] {TestEnum.Two}, binObj.GetField<TestEnum[]>("fEnumArr"));
+ Assert.AreEqual(new[] { TestEnum.Two }, binObj.GetField<TestEnum[]>("fEnumArr"));
- obj = binObj.Deserialize<StringDateGuidEnum>();
+ var obj = binObj.Deserialize<StringDateGuidEnum>();
Assert.AreEqual("str2", obj.FStr);
Assert.AreEqual(nDate, obj.FnDate);
+ Assert.AreEqual(nDate, obj.FnTimestamp);
Assert.AreEqual(nGuid, obj.FnGuid);
Assert.AreEqual(TestEnum.Two, obj.FEnum);
Assert.AreEqual(new[] { "str2" }, obj.FStrArr);
@@ -1524,6 +1702,7 @@ namespace Apache.Ignite.Core.Tests.Binary
public long FLong;
public float FFloat;
public double FDouble;
+ public decimal FDecimal;
}
/// <summary>
@@ -1539,6 +1718,7 @@ namespace Apache.Ignite.Core.Tests.Binary
public long[] FLong;
public float[] FFloat;
public double[] FDouble;
+ public decimal?[] FDecimal;
}
/// <summary>
@@ -1548,6 +1728,7 @@ namespace Apache.Ignite.Core.Tests.Binary
{
public string FStr;
public DateTime? FnDate;
+ public DateTime? FnTimestamp;
public Guid? FnGuid;
public TestEnum FEnum;
http://git-wip-us.apache.org/repos/asf/ignite/blob/6917ec40/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IBinaryObjectBuilder.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IBinaryObjectBuilder.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IBinaryObjectBuilder.cs
index abb9149..740706a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IBinaryObjectBuilder.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Binary/IBinaryObjectBuilder.cs
@@ -62,7 +62,7 @@ namespace Apache.Ignite.Core.Binary
/// <summary>
/// Set explicit hash code. If builder creating object from scratch,
/// then hash code initially set to 0. If builder is created from
- /// exising binary object, then hash code of that object is used
+ /// existing binary object, then hash code of that object is used
/// as initial value.
/// </summary>
/// <param name="hashCode">Hash code.</param>
http://git-wip-us.apache.org/repos/asf/ignite/blob/6917ec40/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryObjectBuilder.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryObjectBuilder.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryObjectBuilder.cs
index 083f557..646d563 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryObjectBuilder.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryObjectBuilder.cs
@@ -151,7 +151,7 @@ namespace Apache.Ignite.Core.Impl.Binary
public IBinaryObjectBuilder SetBooleanField(string fieldName, bool val)
{
return SetField0(fieldName, new BinaryBuilderField(typeof (bool), val, BinaryUtils.TypeBool,
- (w, o) => w.WriteBoolean((bool) o)));
+ (w, o) => w.WriteBooleanField((bool) o)));
}
/** <inheritDoc /> */
@@ -165,7 +165,7 @@ namespace Apache.Ignite.Core.Impl.Binary
public IBinaryObjectBuilder SetByteField(string fieldName, byte val)
{
return SetField0(fieldName, new BinaryBuilderField(typeof (byte), val, BinaryUtils.TypeByte,
- (w, o) => w.WriteByte((byte) o)));
+ (w, o) => w.WriteByteField((byte) o)));
}
/** <inheritDoc /> */
@@ -179,7 +179,7 @@ namespace Apache.Ignite.Core.Impl.Binary
public IBinaryObjectBuilder SetCharField(string fieldName, char val)
{
return SetField0(fieldName, new BinaryBuilderField(typeof (char), val, BinaryUtils.TypeChar,
- (w, o) => w.WriteChar((char) o)));
+ (w, o) => w.WriteCharField((char) o)));
}
/** <inheritDoc /> */
@@ -221,7 +221,7 @@ namespace Apache.Ignite.Core.Impl.Binary
public IBinaryObjectBuilder SetDoubleField(string fieldName, double val)
{
return SetField0(fieldName, new BinaryBuilderField(typeof (double), val, BinaryUtils.TypeDouble,
- (w, o) => w.WriteDouble((double) o)));
+ (w, o) => w.WriteDoubleField((double) o)));
}
/** <inheritDoc /> */
@@ -249,7 +249,7 @@ namespace Apache.Ignite.Core.Impl.Binary
public IBinaryObjectBuilder SetFloatField(string fieldName, float val)
{
return SetField0(fieldName, new BinaryBuilderField(typeof (float), val, BinaryUtils.TypeFloat,
- (w, o) => w.WriteFloat((float) o)));
+ (w, o) => w.WriteFloatField((float) o)));
}
/** <inheritDoc /> */
@@ -277,7 +277,7 @@ namespace Apache.Ignite.Core.Impl.Binary
public IBinaryObjectBuilder SetIntField(string fieldName, int val)
{
return SetField0(fieldName, new BinaryBuilderField(typeof (int), val, BinaryUtils.TypeInt,
- (w, o) => w.WriteInt((int) o)));
+ (w, o) => w.WriteIntField((int) o)));
}
/** <inheritDoc /> */
@@ -291,7 +291,7 @@ namespace Apache.Ignite.Core.Impl.Binary
public IBinaryObjectBuilder SetLongField(string fieldName, long val)
{
return SetField0(fieldName, new BinaryBuilderField(typeof (long), val, BinaryUtils.TypeLong,
- (w, o) => w.WriteLong((long) o)));
+ (w, o) => w.WriteLongField((long) o)));
}
/** <inheritDoc /> */
@@ -305,7 +305,7 @@ namespace Apache.Ignite.Core.Impl.Binary
public IBinaryObjectBuilder SetShortField(string fieldName, short val)
{
return SetField0(fieldName, new BinaryBuilderField(typeof (short), val, BinaryUtils.TypeShort,
- (w, o) => w.WriteShort((short) o)));
+ (w, o) => w.WriteShortField((short) o)));
}
/** <inheritDoc /> */
http://git-wip-us.apache.org/repos/asf/ignite/blob/6917ec40/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs
index 1ac98c4..a0b50ac 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryWriter.cs
@@ -26,6 +26,7 @@ namespace Apache.Ignite.Core.Impl.Binary
using Apache.Ignite.Core.Impl.Binary.IO;
using Apache.Ignite.Core.Impl.Binary.Metadata;
using Apache.Ignite.Core.Impl.Binary.Structure;
+ using Apache.Ignite.Core.Impl.Common;
/// <summary>
/// Binary writer implementation.
@@ -87,11 +88,19 @@ namespace Apache.Ignite.Core.Impl.Binary
public void WriteBoolean(string fieldName, bool val)
{
WriteFieldId(fieldName, BinaryUtils.TypeBool);
+ WriteBooleanField(val);
+ }
+ /// <summary>
+ /// Writes the boolean field.
+ /// </summary>
+ /// <param name="val">if set to <c>true</c> [value].</param>
+ internal void WriteBooleanField(bool val)
+ {
_stream.WriteByte(BinaryUtils.TypeBool);
_stream.WriteBool(val);
}
-
+
/// <summary>
/// Write boolean value.
/// </summary>
@@ -142,7 +151,15 @@ namespace Apache.Ignite.Core.Impl.Binary
public void WriteByte(string fieldName, byte val)
{
WriteFieldId(fieldName, BinaryUtils.TypeBool);
+ WriteByteField(val);
+ }
+ /// <summary>
+ /// Write byte field value.
+ /// </summary>
+ /// <param name="val">Byte value.</param>
+ internal void WriteByteField(byte val)
+ {
_stream.WriteByte(BinaryUtils.TypeByte);
_stream.WriteByte(val);
}
@@ -197,7 +214,15 @@ namespace Apache.Ignite.Core.Impl.Binary
public void WriteShort(string fieldName, short val)
{
WriteFieldId(fieldName, BinaryUtils.TypeShort);
+ WriteShortField(val);
+ }
+ /// <summary>
+ /// Write short field value.
+ /// </summary>
+ /// <param name="val">Short value.</param>
+ internal void WriteShortField(short val)
+ {
_stream.WriteByte(BinaryUtils.TypeShort);
_stream.WriteShort(val);
}
@@ -252,7 +277,15 @@ namespace Apache.Ignite.Core.Impl.Binary
public void WriteChar(string fieldName, char val)
{
WriteFieldId(fieldName, BinaryUtils.TypeChar);
+ WriteCharField(val);
+ }
+ /// <summary>
+ /// Write char field value.
+ /// </summary>
+ /// <param name="val">Char value.</param>
+ internal void WriteCharField(char val)
+ {
_stream.WriteByte(BinaryUtils.TypeChar);
_stream.WriteChar(val);
}
@@ -307,7 +340,15 @@ namespace Apache.Ignite.Core.Impl.Binary
public void WriteInt(string fieldName, int val)
{
WriteFieldId(fieldName, BinaryUtils.TypeInt);
+ WriteIntField(val);
+ }
+ /// <summary>
+ /// Writes the int field.
+ /// </summary>
+ /// <param name="val">The value.</param>
+ internal void WriteIntField(int val)
+ {
_stream.WriteByte(BinaryUtils.TypeInt);
_stream.WriteInt(val);
}
@@ -362,7 +403,15 @@ namespace Apache.Ignite.Core.Impl.Binary
public void WriteLong(string fieldName, long val)
{
WriteFieldId(fieldName, BinaryUtils.TypeLong);
+ WriteLongField(val);
+ }
+ /// <summary>
+ /// Writes the long field.
+ /// </summary>
+ /// <param name="val">The value.</param>
+ internal void WriteLongField(long val)
+ {
_stream.WriteByte(BinaryUtils.TypeLong);
_stream.WriteLong(val);
}
@@ -417,7 +466,15 @@ namespace Apache.Ignite.Core.Impl.Binary
public void WriteFloat(string fieldName, float val)
{
WriteFieldId(fieldName, BinaryUtils.TypeFloat);
+ WriteFloatField(val);
+ }
+ /// <summary>
+ /// Writes the float field.
+ /// </summary>
+ /// <param name="val">The value.</param>
+ internal void WriteFloatField(float val)
+ {
_stream.WriteByte(BinaryUtils.TypeFloat);
_stream.WriteFloat(val);
}
@@ -472,7 +529,15 @@ namespace Apache.Ignite.Core.Impl.Binary
public void WriteDouble(string fieldName, double val)
{
WriteFieldId(fieldName, BinaryUtils.TypeDouble);
+ WriteDoubleField(val);
+ }
+ /// <summary>
+ /// Writes the double field.
+ /// </summary>
+ /// <param name="val">The value.</param>
+ internal void WriteDoubleField(double val)
+ {
_stream.WriteByte(BinaryUtils.TypeDouble);
_stream.WriteDouble(val);
}
@@ -1215,72 +1280,40 @@ namespace Apache.Ignite.Core.Impl.Binary
// Types check sequence is designed to minimize comparisons for the most frequent types.
if (type == typeof(int))
- {
- _stream.WriteByte(BinaryUtils.TypeInt);
- _stream.WriteInt((int)(object)val);
- }
+ WriteIntField(TypeCaster<int>.Cast(val));
else if (type == typeof(long))
- {
- _stream.WriteByte(BinaryUtils.TypeLong);
- _stream.WriteLong((long)(object)val);
- }
+ WriteLongField(TypeCaster<long>.Cast(val));
else if (type == typeof(bool))
- {
- _stream.WriteByte(BinaryUtils.TypeBool);
- _stream.WriteBool((bool)(object)val);
- }
+ WriteBooleanField(TypeCaster<bool>.Cast(val));
else if (type == typeof(byte))
- {
- _stream.WriteByte(BinaryUtils.TypeByte);
- _stream.WriteByte((byte)(object)val);
- }
+ WriteByteField(TypeCaster<byte>.Cast(val));
else if (type == typeof(short))
- {
- _stream.WriteByte(BinaryUtils.TypeShort);
- _stream.WriteShort((short)(object)val);
- }
- else if (type == typeof (char))
- {
- _stream.WriteByte(BinaryUtils.TypeChar);
- _stream.WriteChar((char)(object)val);
- }
+ WriteShortField(TypeCaster<short>.Cast(val));
+ else if (type == typeof(char))
+ WriteCharField(TypeCaster<char>.Cast(val));
else if (type == typeof(float))
- {
- _stream.WriteByte(BinaryUtils.TypeFloat);
- _stream.WriteFloat((float)(object)val);
- }
+ WriteFloatField(TypeCaster<float>.Cast(val));
else if (type == typeof(double))
- {
- _stream.WriteByte(BinaryUtils.TypeDouble);
- _stream.WriteDouble((double)(object)val);
- }
+ WriteDoubleField(TypeCaster<double>.Cast(val));
else if (type == typeof(sbyte))
{
- sbyte val0 = (sbyte)(object)val;
-
- _stream.WriteByte(BinaryUtils.TypeByte);
- _stream.WriteByte(*(byte*)&val0);
+ var val0 = TypeCaster<sbyte>.Cast(val);
+ WriteByteField(*(byte*)&val0);
}
else if (type == typeof(ushort))
{
- ushort val0 = (ushort)(object)val;
-
- _stream.WriteByte(BinaryUtils.TypeShort);
- _stream.WriteShort(*(short*)&val0);
+ var val0 = TypeCaster<ushort>.Cast(val);
+ WriteShortField(*(short*) &val0);
}
else if (type == typeof(uint))
{
- uint val0 = (uint)(object)val;
-
- _stream.WriteByte(BinaryUtils.TypeInt);
- _stream.WriteInt(*(int*)&val0);
+ var val0 = TypeCaster<uint>.Cast(val);
+ WriteIntField(*(int*)&val0);
}
else if (type == typeof(ulong))
{
- ulong val0 = (ulong)(object)val;
-
- _stream.WriteByte(BinaryUtils.TypeLong);
- _stream.WriteLong(*(long*)&val0);
+ var val0 = TypeCaster<ulong>.Cast(val);
+ WriteLongField(*(long*)&val0);
}
else
throw new BinaryObjectException("Unsupported object type [type=" + type.FullName + ", object=" + val + ']');
[3/7] ignite git commit: IGNITE-3476 Node started within
SpringCacheManager does not inject Spring resources (cherry picked from
commit a39770a)
Posted by sb...@apache.org.
IGNITE-3476 Node started within SpringCacheManager does not inject Spring resources
(cherry picked from commit a39770a)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/14e33530
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/14e33530
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/14e33530
Branch: refs/heads/master
Commit: 14e33530de4a17f35f6aa665676c36db598937ef
Parents: ac31334
Author: EdShangGG <es...@gridgain.com>
Authored: Tue Jul 26 12:46:05 2016 +0300
Committer: EdShangGG <es...@gridgain.com>
Committed: Tue Jul 26 12:58:36 2016 +0300
----------------------------------------------------------------------
.../ignite/cache/spring/SpringCacheManager.java | 17 ++-
.../spring/SpringTransactionManager.java | 59 +++++----
.../test/java/config/spring-transactions.xml | 4 +-
.../ignite/TestInjectionLifecycleBean.java | 42 +++++++
.../org/apache/ignite/spring-injection-test.xml | 43 +++++++
.../SpringCacheManagerContextInjectionTest.java | 126 +++++++++++++++++++
.../testsuites/IgniteSpringTestSuite.java | 5 +
...gTransactionManagerContextInjectionTest.java | 125 ++++++++++++++++++
8 files changed, 393 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/14e33530/modules/spring/src/main/java/org/apache/ignite/cache/spring/SpringCacheManager.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/cache/spring/SpringCacheManager.java b/modules/spring/src/main/java/org/apache/ignite/cache/spring/SpringCacheManager.java
index 71b723f..6d1a9b6 100644
--- a/modules/spring/src/main/java/org/apache/ignite/cache/spring/SpringCacheManager.java
+++ b/modules/spring/src/main/java/org/apache/ignite/cache/spring/SpringCacheManager.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.ConcurrentMap;
import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteSpring;
import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
@@ -28,6 +29,8 @@ import org.apache.ignite.configuration.NearCacheConfiguration;
import org.jsr166.ConcurrentHashMap8;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cache.CacheManager;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
/**
* Implementation of Spring cache abstraction based on Ignite cache.
@@ -133,7 +136,7 @@ import org.springframework.cache.CacheManager;
* Ignite distribution, and all these nodes will participate
* in caching the data.
*/
-public class SpringCacheManager implements CacheManager, InitializingBean {
+public class SpringCacheManager implements CacheManager, InitializingBean, ApplicationContextAware {
/** Caches map. */
private final ConcurrentMap<String, SpringCache> caches = new ConcurrentHashMap8<>();
@@ -155,6 +158,14 @@ public class SpringCacheManager implements CacheManager, InitializingBean {
/** Ignite instance. */
private Ignite ignite;
+ /** Spring context */
+ private ApplicationContext springCtx;
+
+ /** {@inheritDoc} */
+ @Override public void setApplicationContext(ApplicationContext ctx) {
+ this.springCtx = ctx;
+ }
+
/**
* Gets configuration file path.
*
@@ -257,9 +268,9 @@ public class SpringCacheManager implements CacheManager, InitializingBean {
}
if (cfgPath != null)
- ignite = Ignition.start(cfgPath);
+ ignite = IgniteSpring.start(cfgPath, springCtx);
else if (cfg != null)
- ignite = Ignition.start(cfg);
+ ignite = IgniteSpring.start(cfg, springCtx);
else
ignite = Ignition.ignite(gridName);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/14e33530/modules/spring/src/main/java/org/apache/ignite/transactions/spring/SpringTransactionManager.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/transactions/spring/SpringTransactionManager.java b/modules/spring/src/main/java/org/apache/ignite/transactions/spring/SpringTransactionManager.java
index d8bbbbd..32a7b43 100644
--- a/modules/spring/src/main/java/org/apache/ignite/transactions/spring/SpringTransactionManager.java
+++ b/modules/spring/src/main/java/org/apache/ignite/transactions/spring/SpringTransactionManager.java
@@ -21,12 +21,15 @@ import java.util.concurrent.TimeUnit;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.IgniteSpring;
import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.transactions.Transaction;
import org.apache.ignite.transactions.TransactionConcurrency;
import org.apache.ignite.transactions.TransactionIsolation;
import org.springframework.beans.factory.InitializingBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
import org.springframework.transaction.CannotCreateTransactionException;
import org.springframework.transaction.InvalidIsolationLevelException;
import org.springframework.transaction.PlatformTransactionManager;
@@ -194,7 +197,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
* </pre>
*/
public class SpringTransactionManager extends AbstractPlatformTransactionManager
- implements ResourceTransactionManager, PlatformTransactionManager, InitializingBean {
+ implements ResourceTransactionManager, PlatformTransactionManager, InitializingBean, ApplicationContextAware {
/**
* Logger.
*/
@@ -225,6 +228,14 @@ public class SpringTransactionManager extends AbstractPlatformTransactionManager
*/
private Ignite ignite;
+ /** Spring context */
+ private ApplicationContext springCtx;
+
+ /** {@inheritDoc} */
+ @Override public void setApplicationContext(ApplicationContext ctx) {
+ this.springCtx = ctx;
+ }
+
/**
* Constructs the transaction manager with no target Ignite instance. An
* instance must be set before use.
@@ -319,9 +330,9 @@ public class SpringTransactionManager extends AbstractPlatformTransactionManager
}
if (cfgPath != null)
- ignite = Ignition.start(cfgPath);
+ ignite = IgniteSpring.start(cfgPath, springCtx);
else if (cfg != null)
- ignite = Ignition.start(cfg);
+ ignite = IgniteSpring.start(cfg, springCtx);
else
ignite = Ignition.ignite(gridName);
@@ -335,12 +346,12 @@ public class SpringTransactionManager extends AbstractPlatformTransactionManager
* {@inheritDoc}
*/
@Override protected Object doGetTransaction() throws TransactionException {
- IgniteTransactionObject txObject = new IgniteTransactionObject();
+ IgniteTransactionObject txObj = new IgniteTransactionObject();
- txObject.setTransactionHolder(
+ txObj.setTransactionHolder(
(IgniteTransactionHolder)TransactionSynchronizationManager.getResource(this.ignite), false);
- return txObject;
+ return txObj;
}
/**
@@ -350,11 +361,11 @@ public class SpringTransactionManager extends AbstractPlatformTransactionManager
if (definition.getIsolationLevel() == TransactionDefinition.ISOLATION_READ_UNCOMMITTED)
throw new InvalidIsolationLevelException("Ignite does not support READ_UNCOMMITTED isolation level.");
- IgniteTransactionObject txObject = (IgniteTransactionObject)transaction;
+ IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
Transaction tx = null;
try {
- if (txObject.getTransactionHolder() == null || txObject.getTransactionHolder().isSynchronizedWithTransaction()) {
+ if (txObj.getTransactionHolder() == null || txObj.getTransactionHolder().isSynchronizedWithTransaction()) {
long timeout = ignite.configuration().getTransactionConfiguration().getDefaultTxTimeout();
if (definition.getTimeout() > 0)
@@ -366,17 +377,17 @@ public class SpringTransactionManager extends AbstractPlatformTransactionManager
if (log.isDebugEnabled())
log.debug("Started Ignite transaction: " + newTx);
- txObject.setTransactionHolder(new IgniteTransactionHolder(newTx), true);
+ txObj.setTransactionHolder(new IgniteTransactionHolder(newTx), true);
}
- txObject.getTransactionHolder().setSynchronizedWithTransaction(true);
- txObject.getTransactionHolder().setTransactionActive(true);
+ txObj.getTransactionHolder().setSynchronizedWithTransaction(true);
+ txObj.getTransactionHolder().setTransactionActive(true);
- tx = txObject.getTransactionHolder().getTransaction();
+ tx = txObj.getTransactionHolder().getTransaction();
// Bind the session holder to the thread.
- if (txObject.isNewTransactionHolder())
- TransactionSynchronizationManager.bindResource(this.ignite, txObject.getTransactionHolder());
+ if (txObj.isNewTransactionHolder())
+ TransactionSynchronizationManager.bindResource(this.ignite, txObj.getTransactionHolder());
}
catch (Exception ex) {
if (tx != null)
@@ -390,8 +401,8 @@ public class SpringTransactionManager extends AbstractPlatformTransactionManager
* {@inheritDoc}
*/
@Override protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
- IgniteTransactionObject txObject = (IgniteTransactionObject)status.getTransaction();
- Transaction tx = txObject.getTransactionHolder().getTransaction();
+ IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+ Transaction tx = txObj.getTransactionHolder().getTransaction();
if (status.isDebug() && log.isDebugEnabled())
log.debug("Committing Ignite transaction: " + tx);
@@ -408,8 +419,8 @@ public class SpringTransactionManager extends AbstractPlatformTransactionManager
* {@inheritDoc}
*/
@Override protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
- IgniteTransactionObject txObject = (IgniteTransactionObject)status.getTransaction();
- Transaction tx = txObject.getTransactionHolder().getTransaction();
+ IgniteTransactionObject txObj = (IgniteTransactionObject)status.getTransaction();
+ Transaction tx = txObj.getTransactionHolder().getTransaction();
if (status.isDebug() && log.isDebugEnabled())
log.debug("Rolling back Ignite transaction: " + tx);
@@ -426,27 +437,27 @@ public class SpringTransactionManager extends AbstractPlatformTransactionManager
* {@inheritDoc}
*/
@Override protected void doCleanupAfterCompletion(Object transaction) {
- IgniteTransactionObject txObject = (IgniteTransactionObject)transaction;
+ IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
// Remove the transaction holder from the thread, if exposed.
- if (txObject.isNewTransactionHolder()) {
- Transaction tx = txObject.getTransactionHolder().getTransaction();
+ if (txObj.isNewTransactionHolder()) {
+ Transaction tx = txObj.getTransactionHolder().getTransaction();
TransactionSynchronizationManager.unbindResource(this.ignite);
if (log.isDebugEnabled())
log.debug("Releasing Ignite transaction: " + tx);
}
- txObject.getTransactionHolder().clear();
+ txObj.getTransactionHolder().clear();
}
/**
* {@inheritDoc}
*/
@Override protected boolean isExistingTransaction(Object transaction) throws TransactionException {
- IgniteTransactionObject txObject = (IgniteTransactionObject)transaction;
+ IgniteTransactionObject txObj = (IgniteTransactionObject)transaction;
- return (txObject.getTransactionHolder() != null && txObject.getTransactionHolder().isTransactionActive());
+ return (txObj.getTransactionHolder() != null && txObj.getTransactionHolder().isTransactionActive());
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/14e33530/modules/spring/src/test/java/config/spring-transactions.xml
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/config/spring-transactions.xml b/modules/spring/src/test/java/config/spring-transactions.xml
index ba90cb0..392bd84 100644
--- a/modules/spring/src/test/java/config/spring-transactions.xml
+++ b/modules/spring/src/test/java/config/spring-transactions.xml
@@ -27,7 +27,9 @@
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<tx:annotation-driven/>
- <context:component-scan base-package="org.apache.ignite.transactions.spring"/>
+ <context:component-scan base-package="org.apache.ignite.transactions.spring">
+ <context:exclude-filter type="annotation" expression="org.springframework.context.annotation.Configuration"/>
+ </context:component-scan>
<bean id="transactionManager" class="org.apache.ignite.transactions.spring.SpringTransactionManager">
<property name="transactionConcurrency" value="OPTIMISTIC"/>
http://git-wip-us.apache.org/repos/asf/ignite/blob/14e33530/modules/spring/src/test/java/org/apache/ignite/TestInjectionLifecycleBean.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/TestInjectionLifecycleBean.java b/modules/spring/src/test/java/org/apache/ignite/TestInjectionLifecycleBean.java
new file mode 100644
index 0000000..2b8c932
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/TestInjectionLifecycleBean.java
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import org.apache.ignite.lifecycle.LifecycleBean;
+import org.apache.ignite.lifecycle.LifecycleEventType;
+import org.apache.ignite.resources.SpringApplicationContextResource;
+import org.springframework.context.ApplicationContext;
+
+import static org.junit.Assert.assertNotNull;
+
+/** Lifecycle bean for testing. */
+public class TestInjectionLifecycleBean implements LifecycleBean {
+ /** */
+ @SpringApplicationContextResource
+ private ApplicationContext appCtx;
+
+ /** Checks that context was injected. */
+ public void checkState() {
+ assertNotNull(appCtx);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onLifecycleEvent(LifecycleEventType evt) {
+ checkState();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/14e33530/modules/spring/src/test/java/org/apache/ignite/spring-injection-test.xml
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/spring-injection-test.xml b/modules/spring/src/test/java/org/apache/ignite/spring-injection-test.xml
new file mode 100644
index 0000000..b8368a3
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/spring-injection-test.xml
@@ -0,0 +1,43 @@
+<?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.
+-->
+
+<!--
+ GridGain Spring configuration file to startup grid cache.
+-->
+<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="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+ <property name="lifecycleBeans">
+ <array>
+ <bean id="bean1" class="org.apache.ignite.TestInjectionLifecycleBean"/>
+ <bean id="bean2" class="org.apache.ignite.TestInjectionLifecycleBean"/>
+ </array>
+ </property>
+
+ <property name="localHost" value="127.0.0.1"/>
+
+ <property name="gridName" value="springInjectionTest"/>
+ </bean>
+</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/14e33530/modules/spring/src/test/java/org/apache/ignite/spring/SpringCacheManagerContextInjectionTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/spring/SpringCacheManagerContextInjectionTest.java b/modules/spring/src/test/java/org/apache/ignite/spring/SpringCacheManagerContextInjectionTest.java
new file mode 100644
index 0000000..1554198
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/spring/SpringCacheManagerContextInjectionTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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.Ignite;
+import org.apache.ignite.TestInjectionLifecycleBean;
+import org.apache.ignite.cache.spring.SpringCacheManager;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgnitionEx;
+import org.apache.ignite.lifecycle.LifecycleBean;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ *
+ */
+public class SpringCacheManagerContextInjectionTest extends GridCommonAbstractTest {
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBeanInjectionUsingConfigPath() throws Exception {
+ new AnnotationConfigApplicationContext(TestPathConfiguration.class);
+
+ Ignite grid = IgnitionEx.grid("springInjectionTest");
+
+ IgniteConfiguration cfg = grid.configuration();
+
+ LifecycleBean[] beans = cfg.getLifecycleBeans();
+
+ assertEquals(2, beans.length);
+
+ TestInjectionLifecycleBean bean1 = (TestInjectionLifecycleBean)beans[0];
+ TestInjectionLifecycleBean bean2 = (TestInjectionLifecycleBean)beans[1];
+
+ bean1.checkState();
+ bean2.checkState();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBeanInjectionUsingConfiguration() throws Exception {
+ BeanFactory factory = new AnnotationConfigApplicationContext(TestCfgConfiguration.class);
+
+ TestInjectionLifecycleBean bean1 = (TestInjectionLifecycleBean)factory.getBean("bean1");
+ TestInjectionLifecycleBean bean2 = (TestInjectionLifecycleBean)factory.getBean("bean2");
+
+ bean1.checkState();
+ bean2.checkState();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ super.afterTest();
+ }
+
+ /** */
+ @SuppressWarnings("WeakerAccess")
+ @Configuration
+ static class TestPathConfiguration {
+ /** */
+ @Bean(name = "mgr")
+ public SpringCacheManager springCacheManager() {
+ SpringCacheManager mgr = new SpringCacheManager();
+
+ mgr.setConfigurationPath("org/apache/ignite/spring-injection-test.xml");
+
+ return mgr;
+ }
+ }
+
+ /** */
+ @SuppressWarnings("WeakerAccess")
+ @Configuration
+ static class TestCfgConfiguration {
+ /** */
+ @Bean(name = "mgr")
+ public SpringCacheManager springCacheManager() {
+ IgniteConfiguration cfg = new IgniteConfiguration();
+
+ cfg.setLocalHost("127.0.0.1");
+
+ cfg.setGridName("scmt");
+
+ cfg.setLifecycleBeans(bean1(), bean2());
+
+ SpringCacheManager mgr = new SpringCacheManager();
+
+ mgr.setConfiguration(cfg);
+
+ return mgr;
+ }
+
+ /** */
+ @Bean(name = "bean1")
+ LifecycleBean bean1() {
+ return new TestInjectionLifecycleBean();
+ }
+
+ /** */
+ @Bean(name = "bean2")
+ LifecycleBean bean2() {
+ return new TestInjectionLifecycleBean();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/14e33530/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 4fc159e..9ae3423 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
@@ -28,8 +28,10 @@ import org.apache.ignite.p2p.GridP2PUserVersionChangeSelfTest;
import org.apache.ignite.spring.GridSpringCacheManagerSelfTest;
import org.apache.ignite.spring.IgniteExcludeInConfigurationTest;
import org.apache.ignite.spring.IgniteStartFromStreamConfigurationTest;
+import org.apache.ignite.spring.SpringCacheManagerContextInjectionTest;
import org.apache.ignite.spring.injection.GridServiceInjectionSpringResourceTest;
import org.apache.ignite.transactions.spring.GridSpringTransactionManagerSelfTest;
+import org.apache.ignite.transactions.spring.SpringTransactionManagerContextInjectionTest;
/**
* Spring tests.
@@ -68,6 +70,9 @@ public class IgniteSpringTestSuite extends TestSuite {
suite.addTestSuite(GridServiceInjectionSpringResourceTest.class);
+ suite.addTestSuite(SpringCacheManagerContextInjectionTest.class);
+ suite.addTestSuite(SpringTransactionManagerContextInjectionTest.class);
+
return suite;
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/14e33530/modules/spring/src/test/java/org/apache/ignite/transactions/spring/SpringTransactionManagerContextInjectionTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/transactions/spring/SpringTransactionManagerContextInjectionTest.java b/modules/spring/src/test/java/org/apache/ignite/transactions/spring/SpringTransactionManagerContextInjectionTest.java
new file mode 100644
index 0000000..467be20
--- /dev/null
+++ b/modules/spring/src/test/java/org/apache/ignite/transactions/spring/SpringTransactionManagerContextInjectionTest.java
@@ -0,0 +1,125 @@
+/*
+ * 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.transactions.spring;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.TestInjectionLifecycleBean;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgnitionEx;
+import org.apache.ignite.lifecycle.LifecycleBean;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ *
+ */
+public class SpringTransactionManagerContextInjectionTest extends GridCommonAbstractTest {
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBeanInjectionUsingConfigPath() throws Exception {
+ BeanFactory factory = new AnnotationConfigApplicationContext(TestPathConfiguration.class);
+
+ Ignite grid = IgnitionEx.grid("springInjectionTest");
+
+ IgniteConfiguration cfg = grid.configuration();
+
+ LifecycleBean[] beans = cfg.getLifecycleBeans();
+
+ assertEquals(2, beans.length);
+
+ TestInjectionLifecycleBean bean1 = (TestInjectionLifecycleBean)beans[0];
+ TestInjectionLifecycleBean bean2 = (TestInjectionLifecycleBean)beans[1];
+
+ bean1.checkState();
+ bean2.checkState();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBeanInjectionUsingConfig() throws Exception {
+ BeanFactory factory = new AnnotationConfigApplicationContext(TestCfgConfiguration.class);
+
+ TestInjectionLifecycleBean bean1 = (TestInjectionLifecycleBean)factory.getBean("bean1");
+ TestInjectionLifecycleBean bean2 = (TestInjectionLifecycleBean)factory.getBean("bean2");
+
+ bean1.checkState();
+ bean2.checkState();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ super.afterTest();
+ }
+
+ /** */
+ @SuppressWarnings("WeakerAccess")
+ @Configuration
+ static class TestPathConfiguration {
+ /** */
+ @Bean(name = "mgr")
+ public SpringTransactionManager springTransactionManager() {
+ SpringTransactionManager mgr = new SpringTransactionManager();
+
+ mgr.setConfigurationPath("org/apache/ignite/spring-injection-test.xml");
+
+ return mgr;
+ }
+ }
+
+ /** */
+ @SuppressWarnings("WeakerAccess")
+ @Configuration
+ static class TestCfgConfiguration {
+ /** */
+ @Bean(name = "mgr")
+ public SpringTransactionManager springTransactionManager() {
+ IgniteConfiguration cfg = new IgniteConfiguration();
+
+ cfg.setLocalHost("127.0.0.1");
+
+ cfg.setGridName("stmcit");
+
+ cfg.setLifecycleBeans(bean1(), bean2());
+
+ SpringTransactionManager mgr = new SpringTransactionManager();
+
+ mgr.setConfiguration(cfg);
+
+ return mgr;
+ }
+
+ /** */
+ @Bean(name = "bean1")
+ LifecycleBean bean1() {
+ return new TestInjectionLifecycleBean();
+ }
+
+ /** */
+ @Bean(name = "bean2")
+ LifecycleBean bean2() {
+ return new TestInjectionLifecycleBean();
+ }
+ }
+}
\ No newline at end of file
[5/7] ignite git commit: ignite-3300 Fixed issue with partition value
changing stored in KeyCacheObject. (cherry picked from commit a441bb9)
Posted by sb...@apache.org.
ignite-3300 Fixed issue with partition value changing stored in KeyCacheObject.
(cherry picked from commit a441bb9)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9d07e3e7
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9d07e3e7
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9d07e3e7
Branch: refs/heads/master
Commit: 9d07e3e7a34d1cbe67a9656630bc6215cd213f0a
Parents: f3e4f78
Author: sboikov <sb...@gridgain.com>
Authored: Wed Jul 27 09:19:12 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Jul 27 10:04:28 2016 +0300
----------------------------------------------------------------------
.../internal/binary/BinaryObjectImpl.java | 11 +
.../affinity/GridAffinityProcessor.java | 117 +++++---
.../processors/cache/CacheObjectContext.java | 12 +
.../processors/cache/GridCacheAdapter.java | 8 +-
.../cache/GridCacheAffinityManager.java | 24 +-
.../processors/cache/GridCacheContext.java | 26 +-
.../processors/cache/GridCacheEntryInfo.java | 2 +-
.../processors/cache/KeyCacheObject.java | 7 +
.../processors/cache/KeyCacheObjectImpl.java | 8 +
.../cache/binary/CacheObjectBinaryContext.java | 10 +-
.../binary/CacheObjectBinaryProcessorImpl.java | 38 ++-
.../dht/atomic/GridDhtAtomicCache.java | 6 +-
.../dht/atomic/GridNearAtomicUpdateFuture.java | 4 +-
.../cacheobject/IgniteCacheObjectProcessor.java | 15 +-
.../IgniteCacheObjectProcessorImpl.java | 69 ++++-
.../datastreamer/DataStreamerImpl.java | 6 +-
.../affinity/AffinityClientNodeSelfTest.java | 73 ++++-
.../binary/BinaryMarshallerSelfTest.java | 7 +-
.../BinaryObjectBuilderAdditionalSelfTest.java | 46 ++-
.../cache/CacheGetEntryAbstractTest.java | 2 +-
.../expiry/IgniteCacheTtlCleanupSelfTest.java | 2 +-
.../CacheBinaryKeyConcurrentQueryTest.java | 298 +++++++++++++++++++
.../IgniteCacheWithIndexingTestSuite.java | 2 +
23 files changed, 625 insertions(+), 168 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
index ae110f1..7b42c03 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@ -98,6 +98,17 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
}
/** {@inheritDoc} */
+ @Override public KeyCacheObject copy(int part) {
+ if (this.part == part)
+ return this;
+
+ BinaryObjectImpl cp = new BinaryObjectImpl(ctx, arr, start);
+ cp.part = part;
+
+ return cp;
+ }
+
+ /** {@inheritDoc} */
@Override public int partition() {
return part;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java
index 0d3d36d..19e0842 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java
@@ -47,6 +47,7 @@ import org.apache.ignite.internal.processors.cache.CacheObject;
import org.apache.ignite.internal.processors.cache.CacheObjectContext;
import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
import org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter;
import org.apache.ignite.internal.util.GridLeanMap;
import org.apache.ignite.internal.util.future.GridFinishedFuture;
@@ -144,6 +145,56 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
}
/**
+ * @param cacheName Cache name.
+ * @param key Key.
+ * @return Key partition.
+ * @throws IgniteCheckedException If failed.
+ */
+ public int partition(@Nullable String cacheName, Object key) throws IgniteCheckedException {
+ return partition(cacheName, key, null);
+ }
+
+ /**
+ * @param cacheName Cache name (needed only if {@code aff} is not provided.
+ * @param key Key.
+ * @param aff Affinity information.
+ * @return Key partition.
+ * @throws IgniteCheckedException If failed.
+ */
+ public int partition(@Nullable String cacheName,
+ Object key,
+ @Nullable AffinityInfo aff) throws IgniteCheckedException {
+ if (key instanceof KeyCacheObject) {
+ int part = ((KeyCacheObject)key).partition();
+
+ if (part >= 0)
+ return part;
+ }
+
+ return partition0(cacheName, key, aff);
+ }
+
+ /**
+ * @param cacheName Cache name (needed only if {@code aff} is not provided.
+ * @param key Key.
+ * @param aff Affinity.
+ * @return Key partition.
+ * @throws IgniteCheckedException If failed.
+ */
+ public int partition0(@Nullable String cacheName,
+ Object key,
+ @Nullable AffinityInfo aff) throws IgniteCheckedException {
+ if (aff == null) {
+ aff = affinityCache(cacheName, ctx.discovery().topologyVersionEx());
+
+ if (aff == null)
+ throw new IgniteCheckedException("Failed to get cache affinity.");
+ }
+
+ return aff.affFunc.partition(aff.affinityKey(key));
+ }
+
+ /**
* Maps keys to nodes for given cache.
*
* @param cacheName Cache name.
@@ -206,7 +257,9 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
if (affInfo == null)
return Collections.emptyList();
- return primaryAndBackups(affInfo, key);
+ int part = partition(cacheName, key, affInfo);
+
+ return affInfo.assignment.get(part);
}
/**
@@ -224,13 +277,10 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
AffinityInfo affInfo = affinityCache(cacheName, ctx.discovery().topologyVersionEx());
- if (affInfo == null || affInfo.mapper == null)
+ if (affInfo == null)
return null;
- if (key instanceof CacheObject)
- key = ((CacheObject)key).value(affInfo.cacheObjCtx, false);
-
- return affInfo.mapper.affinityKey(key);
+ return affInfo.affinityKey(key);
}
/**
@@ -484,10 +534,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
* @throws IgniteCheckedException In case of error.
*/
private <K> ClusterNode primary(AffinityInfo aff, K key) throws IgniteCheckedException {
- if (key instanceof CacheObject && !(key instanceof BinaryObject))
- key = ((CacheObject)key).value(aff.cacheObjCtx, false);
-
- int part = aff.affFunc.partition(aff.mapper.affinityKey(key));
+ int part = partition(null, key, aff);
Collection<ClusterNode> nodes = aff.assignment.get(part);
@@ -497,20 +544,6 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
return nodes.iterator().next();
}
- /**
- * @param aff Affinity function.
- * @param key Key to check.
- * @return Primary and backup nodes.
- */
- private <K> List<ClusterNode> primaryAndBackups(AffinityInfo aff, K key) {
- if (key instanceof CacheObject && !(key instanceof BinaryObject))
- key = ((CacheObject)key).value(aff.cacheObjCtx, false);
-
- int part = aff.affFunc.partition(aff.mapper.affinityKey(key));
-
- return aff.assignment.get(part);
- }
-
/** {@inheritDoc} */
@Override public void printMemoryStats() {
X.println(">>>");
@@ -551,6 +584,17 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
}
/**
+ * @param key Key.
+ * @return Affinity key.
+ */
+ private Object affinityKey(Object key) {
+ if (key instanceof CacheObject && !(key instanceof BinaryObject))
+ key = ((CacheObject)key).value(cacheObjCtx, false);
+
+ return mapper.affinityKey(key);
+ }
+
+ /**
* @return Cache affinity function.
*/
private AffinityFunction affinityFunction() {
@@ -564,13 +608,6 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
return assignment;
}
- /**
- * @return Key mapper.
- */
- private AffinityKeyMapper keyMapper() {
- return mapper;
- }
-
/** {@inheritDoc} */
@Override public String toString() {
return S.toString(AffinityInfo.class, this);
@@ -658,7 +695,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
ctx.gateway().readLock();
try {
- return cache().affinityFunction().partition(key);
+ return partition0(cacheName, key, cache());
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
@@ -769,10 +806,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
ctx.gateway().readLock();
try {
- if (key instanceof CacheObject)
- key = ((CacheObject)key).value(cache().cacheObjCtx, false);
-
- return cache().keyMapper().affinityKey(key);
+ return cache().affinityKey(key);
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
@@ -828,7 +862,9 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
ctx.gateway().readLock();
try {
- return cache().assignment().get(partition(key));
+ AffinityInfo aff = cache();
+
+ return aff.assignment().get(GridAffinityProcessor.this.partition(cacheName, key, aff));
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
@@ -861,12 +897,17 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
Map<Integer, ClusterNode> map = new HashMap<>();
if (!F.isEmpty(parts)) {
+ AffinityInfo aff = cache();
+
for (int p : parts)
- map.put(p, mapPartitionToNode(p));
+ map.put(p, F.first(aff.assignment().get(p)));
}
return map;
}
+ catch (IgniteCheckedException e) {
+ throw new IgniteException(e);
+ }
finally {
ctx.gateway().readUnlock();
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
index d7fdb83..c4203ef 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
@@ -41,6 +41,9 @@ import org.apache.ignite.internal.util.typedef.F;
private IgniteCacheObjectProcessor proc;
/** */
+ private String cacheName;
+
+ /** */
private AffinityKeyMapper dfltAffMapper;
/** */
@@ -63,11 +66,13 @@ import org.apache.ignite.internal.util.typedef.F;
* @param addDepInfo {@code true} if deployment info should be associated with the objects of this cache.
*/
public CacheObjectContext(GridKernalContext kernalCtx,
+ String cacheName,
AffinityKeyMapper dfltAffMapper,
boolean cpyOnGet,
boolean storeVal,
boolean addDepInfo) {
this.kernalCtx = kernalCtx;
+ this.cacheName = cacheName;
this.dfltAffMapper = dfltAffMapper;
this.cpyOnGet = cpyOnGet;
this.storeVal = storeVal;
@@ -78,6 +83,13 @@ import org.apache.ignite.internal.util.typedef.F;
}
/**
+ * @return Cache name.
+ */
+ public String cacheName() {
+ return cacheName;
+ }
+
+ /**
* @return {@code True} if peer class loading is enabled.
*/
public boolean p2pEnabled() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 90669e0..1ac94a4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -1387,15 +1387,15 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
long start = statsEnabled ? System.nanoTime() : 0L;
- boolean keeyBinary = ctx.keepBinary();
+ boolean keepBinary = ctx.keepBinary();
- if (keeyBinary)
+ if (keepBinary)
key = (K)ctx.toCacheKeyObject(key);
- V val = get(key, !keeyBinary, false);
+ V val = get(key, !keepBinary, false);
if (ctx.config().getInterceptor() != null) {
- key = keeyBinary ? (K) ctx.unwrapBinaryIfNeeded(key, true, false) : key;
+ key = keepBinary ? (K) ctx.unwrapBinaryIfNeeded(key, true, false) : key;
val = (V)ctx.config().getInterceptor().onGet(key, val);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java
index 5e843dc..71ae5c9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAffinityManager.java
@@ -187,28 +187,36 @@ public class GridCacheAffinityManager extends GridCacheManagerAdapter {
}
/**
+ * @param key Key.
+ * @return Partition.
+ */
+ public int partition(Object key) {
+ return partition(key, true);
+ }
+
+ /**
* NOTE: Use this method always when you need to calculate partition id for
* a key provided by user. It's required since we should apply affinity mapper
* logic in order to find a key that will eventually be passed to affinity function.
*
* @param key Key.
+ * @param useKeyPart If {@code true} can use pre-calculated partition stored in KeyCacheObject.
* @return Partition.
*/
- public int partition(Object key) {
+ public int partition(Object key, boolean useKeyPart) {
GridAffinityAssignmentCache aff0 = aff;
- if (key instanceof KeyCacheObject && ((KeyCacheObject)key).partition() != -1)
- return ((KeyCacheObject)key).partition();
-
if (aff0 == null)
throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
- int p = affFunction.partition(affinityKey(key));
+ if (useKeyPart && (key instanceof KeyCacheObject)) {
+ int part = ((KeyCacheObject)key).partition();
- if (key instanceof KeyCacheObject)
- ((KeyCacheObject)key).partition(p);
+ if (part != -1)
+ return part;
+ }
- return p;
+ return affFunction.partition(affinityKey(key));
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
index 36d9104..ba923df 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
@@ -1788,20 +1788,9 @@ public class GridCacheContext<K, V> implements Externalizable {
* @return Cache key object.
*/
public KeyCacheObject toCacheKeyObject(Object obj) {
- return toCacheKeyObject(obj, false);
- }
-
- /**
- * @param obj Object.
- * @return Cache key object.
- */
- public KeyCacheObject toCacheKeyObject(Object obj, boolean includePartition) {
assert validObjectForCache(obj) : obj;
- if (includePartition)
- return cacheObjects().toCacheKeyObject(cacheObjCtx, obj, true, affinity().partition(obj));
- else
- return cacheObjects().toCacheKeyObject(cacheObjCtx, obj, true);
+ return cacheObjects().toCacheKeyObject(cacheObjCtx, this, obj, true);
}
/**
@@ -1822,7 +1811,7 @@ public class GridCacheContext<K, V> implements Externalizable {
public KeyCacheObject toCacheKeyObject(byte[] bytes) throws IgniteCheckedException {
Object obj = ctx.cacheObjects().unmarshal(cacheObjCtx, bytes, deploy().localLoader());
- return cacheObjects().toCacheKeyObject(cacheObjCtx, obj, false);
+ return cacheObjects().toCacheKeyObject(cacheObjCtx, this, obj, false);
}
/**
@@ -1970,21 +1959,12 @@ public class GridCacheContext<K, V> implements Externalizable {
* @return Read-only collection of KeyCacheObject instances.
*/
public Collection<KeyCacheObject> cacheKeysView(Collection<?> keys) {
- return cacheKeysView(keys, false);
- }
-
- /**
- * @param keys Keys.
- * @param includePartition Include partition.
- * @return Read-only collection of KeyCacheObject instances.
- */
- public Collection<KeyCacheObject> cacheKeysView(Collection<?> keys, final boolean includePartition) {
return F.viewReadOnly(keys, new C1<Object, KeyCacheObject>() {
@Override public KeyCacheObject apply(Object key) {
if (key == null)
throw new NullPointerException("Null key.");
- return toCacheKeyObject(key, includePartition);
+ return toCacheKeyObject(key);
}
});
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java
index c42e788..f281227 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java
@@ -407,7 +407,7 @@ public class GridCacheEntryInfo implements Message {
Object key0 = ctx.cacheObjects().unmarshal(cacheObjCtx, keyBytes, clsLdr);
- key = ctx.cacheObjects().toCacheKeyObject(cacheObjCtx, key0, false);
+ key = ctx.cacheObjects().toCacheKeyObject(cacheObjCtx, ctx, key0, false);
}
else
key.finishUnmarshal(ctx.cacheObjectContext(), clsLdr);
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java
index ffb846c..21b1f89 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObject.java
@@ -38,7 +38,14 @@ public interface KeyCacheObject extends CacheObject {
/**
* Sets partition ID for this key.
+ *
* @param part Partition ID.
*/
public void partition(int part);
+
+ /**
+ * @param part Partition ID.
+ * @return Copy of this object with given partition set.
+ */
+ public KeyCacheObject copy(int part);
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
index 35e681c..146e554 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
@@ -61,6 +61,14 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
}
/** {@inheritDoc} */
+ @Override public KeyCacheObject copy(int part) {
+ if (this.part == part)
+ return this;
+
+ return new KeyCacheObjectImpl(val, valBytes, part);
+ }
+
+ /** {@inheritDoc} */
@Override public int partition() {
return part;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java
index ec01f48..26c713c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java
@@ -31,18 +31,24 @@ public class CacheObjectBinaryContext extends CacheObjectContext {
/**
* @param kernalCtx Kernal context.
+ * @param cacheName Cache name.
* @param binaryEnabled Binary enabled flag.
* @param cpyOnGet Copy on get flag.
* @param storeVal {@code True} if should store unmarshalled value in cache.
* @param depEnabled {@code true} if deployment is enabled for the given cache.
*/
public CacheObjectBinaryContext(GridKernalContext kernalCtx,
+ String cacheName,
boolean cpyOnGet,
boolean storeVal,
boolean binaryEnabled,
boolean depEnabled) {
- super(kernalCtx, binaryEnabled ? new CacheDefaultBinaryAffinityKeyMapper() :
- new GridCacheDefaultAffinityKeyMapper(), cpyOnGet, storeVal, depEnabled);
+ super(kernalCtx,
+ cacheName,
+ binaryEnabled ? new CacheDefaultBinaryAffinityKeyMapper() : new GridCacheDefaultAffinityKeyMapper(),
+ cpyOnGet,
+ storeVal,
+ depEnabled);
this.binaryEnabled = binaryEnabled;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
index 8400594..6d980a8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
@@ -728,6 +728,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
CacheObjectContext ctx0 = super.contextForCache(cfg);
CacheObjectContext res = new CacheObjectBinaryContext(ctx,
+ cfg.getName(),
ctx0.copyOnGet(),
ctx0.storeValue(),
binaryEnabled,
@@ -760,43 +761,38 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
}
/** {@inheritDoc} */
- @Override public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj) {
- return toCacheKeyObject(ctx, obj, userObj, -1);
- }
-
- /** {@inheritDoc} */
@Override public KeyCacheObject toCacheKeyObject(
CacheObjectContext ctx,
+ @Nullable GridCacheContext cctx,
Object obj,
- boolean userObj,
- int partition
+ boolean userObj
) {
if (!((CacheObjectBinaryContext)ctx).binaryEnabled())
- return super.toCacheKeyObject(ctx, obj, userObj, partition);
+ return super.toCacheKeyObject(ctx, cctx, obj, userObj);
if (obj instanceof KeyCacheObject) {
- if (obj instanceof BinaryObjectImpl) {
+ KeyCacheObject key = (KeyCacheObject)obj;
+
+ if (key instanceof BinaryObjectImpl) {
// Need to create a copy because the key can be reused at the application layer after that (IGNITE-3505).
- BinaryObjectImpl bObj = (BinaryObjectImpl)obj;
- obj = new BinaryObjectImpl(bObj.context(), bObj.array(), bObj.start());
+ key = key.copy(partition(ctx, cctx, key));
}
+ else if (key.partition() == -1)
+ // Assume others KeyCacheObjects can not be reused for another cache.
+ key.partition(partition(ctx, cctx, key));
- ((KeyCacheObject)obj).partition(partition);
-
- return (KeyCacheObject)obj;
+ return key;
}
- if (((CacheObjectBinaryContext)ctx).binaryEnabled()) {
- obj = toBinary(obj);
+ obj = toBinary(obj);
- if (obj instanceof KeyCacheObject) {
- ((KeyCacheObject)obj).partition(partition);
+ if (obj instanceof BinaryObjectImpl) {
+ ((BinaryObjectImpl)obj).partition(partition(ctx, cctx, obj));
- return (KeyCacheObject)obj;
- }
+ return (KeyCacheObject)obj;
}
- return toCacheKeyObject0(obj, userObj, partition);
+ return toCacheKeyObject0(ctx, cctx, obj, userObj);
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
index 561c6c6..3616082 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
@@ -344,7 +344,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
final boolean skipStore = opCtx != null && opCtx.skipStore();
try {
- return getAsync0(ctx.toCacheKeyObject(key, true),
+ return getAsync0(ctx.toCacheKeyObject(key),
!ctx.config().isReadFromBackup(),
subjId,
taskName,
@@ -390,7 +390,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
return asyncOp(new CO<IgniteInternalFuture<V>>() {
@Override public IgniteInternalFuture<V> apply() {
- return getAsync0(ctx.toCacheKeyObject(key, true),
+ return getAsync0(ctx.toCacheKeyObject(key),
forcePrimary,
subjId0,
taskName,
@@ -436,7 +436,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
return asyncOp(new CO<IgniteInternalFuture<Map<K, V>>>() {
@Override public IgniteInternalFuture<Map<K, V>> apply() {
- return getAllAsync0(ctx.cacheKeysView(keys, true),
+ return getAllAsync0(ctx.cacheKeysView(keys),
forcePrimary,
subjId0,
taskName,
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
index b2f2704..0d88ef8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
@@ -883,7 +883,7 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
if (val == null && op != GridCacheOperation.DELETE)
continue;
- KeyCacheObject cacheKey = cctx.toCacheKeyObject(key, true);
+ KeyCacheObject cacheKey = cctx.toCacheKeyObject(key);
if (remapKeys != null && !remapKeys.contains(cacheKey))
continue;
@@ -1000,7 +1000,7 @@ public class GridNearAtomicUpdateFuture extends GridNearAtomicAbstractUpdateFutu
if (val == null && op != GridCacheOperation.DELETE)
throw new NullPointerException("Null value.");
- KeyCacheObject cacheKey = cctx.toCacheKeyObject(key, true);
+ KeyCacheObject cacheKey = cctx.toCacheKeyObject(key);
if (op != TRANSFORM)
val = cctx.toCacheObject(val);
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
index b8ac301..27000b4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
@@ -133,23 +133,14 @@ public interface IgniteCacheObjectProcessor extends GridProcessor {
public CacheObjectContext contextForCache(CacheConfiguration ccfg) throws IgniteCheckedException;
/**
- * @param ctx Cache context.
- * @param obj Key value.
- * @param userObj If {@code true} then given object is object provided by user and should be copied
- * before stored in cache.
- * @return Cache key object.
- */
- public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj);
-
- /**
- * @param ctx Cache context.
+ * @param ctx Cache objects context.
+ * @param cctx Cache context if cache is available.
* @param obj Key value.
* @param userObj If {@code true} then given object is object provided by user and should be copied
* before stored in cache.
- * @param partition ID of partition this key belongs to.
* @return Cache key object.
*/
- public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj, int partition);
+ public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, @Nullable GridCacheContext cctx, Object obj, boolean userObj);
/**
* @param ctx Cache context.
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
index 3203548..9fd4c1f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
@@ -108,18 +108,21 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
}
/** {@inheritDoc} */
- @Override @Nullable public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj) {
- return toCacheKeyObject(ctx, obj, userObj, -1);
- }
-
- /** {@inheritDoc} */
- @Override public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj, int partition) {
+ @Override public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx,
+ @Nullable GridCacheContext cctx,
+ Object obj,
+ boolean userObj) {
if (obj instanceof KeyCacheObject) {
- ((KeyCacheObject)obj).partition(partition);
+ KeyCacheObject key = (KeyCacheObject)obj;
+
+ if (key.partition() == -1)
+ // Assume all KeyCacheObjects except BinaryObject can not be reused for another cache.
+ key.partition(partition(ctx, cctx, key));
+
return (KeyCacheObject)obj;
}
- return toCacheKeyObject0(obj, userObj, partition);
+ return toCacheKeyObject0(ctx, cctx, obj, userObj);
}
/**
@@ -129,11 +132,16 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
* @return Key cache object.
*/
@SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor")
- protected KeyCacheObject toCacheKeyObject0(Object obj, boolean userObj, int partititon) {
+ protected KeyCacheObject toCacheKeyObject0(CacheObjectContext ctx,
+ @Nullable GridCacheContext cctx,
+ Object obj,
+ boolean userObj) {
+ int part = partition(ctx, cctx, obj);
+
if (!userObj)
- return new KeyCacheObjectImpl(obj, null, partititon);
+ return new KeyCacheObjectImpl(obj, null, part);
- return new UserKeyCacheObjectImpl(obj, partititon);
+ return new UserKeyCacheObjectImpl(obj, part);
}
/** {@inheritDoc} */
@@ -207,6 +215,25 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
return new UserCacheObjectImpl(obj, null);
}
+ /**
+ * @param ctx Cache objects context.
+ * @param cctx Cache context.
+ * @param obj Object.
+ * @return Object partition.
+ */
+ protected final int partition(CacheObjectContext ctx, @Nullable GridCacheContext cctx, Object obj) {
+ try {
+ return cctx != null ?
+ cctx.affinity().partition(obj, false) :
+ ctx.kernalContext().affinity().partition0(ctx.cacheName(), obj, null);
+ }
+ catch (IgniteCheckedException e) {
+ U.error(log, "Failed to get partition");
+
+ return -1;
+ }
+ }
+
/** {@inheritDoc} */
@Override public CacheObjectContext contextForCache(CacheConfiguration ccfg) throws IgniteCheckedException {
assert ccfg != null;
@@ -218,6 +245,7 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
!ccfg.isCopyOnRead();
CacheObjectContext res = new CacheObjectContext(ctx,
+ ccfg.getName(),
ccfg.getAffinityMapper() != null ? ccfg.getAffinityMapper() : new GridCacheDefaultAffinityKeyMapper(),
ccfg.isCopyOnRead() && memMode != OFFHEAP_VALUES,
storeVal,
@@ -304,8 +332,23 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
/**
* @param key Key.
*/
- UserKeyCacheObjectImpl(Object key, int partition) {
- super(key, null, partition);
+ UserKeyCacheObjectImpl(Object key, int part) {
+ super(key, null, part);
+ }
+
+ /**
+ * @param key Key.
+ */
+ UserKeyCacheObjectImpl(Object key, byte[] valBytes, int part) {
+ super(key, valBytes, part);
+ }
+
+ /** {@inheritDoc} */
+ @Override public KeyCacheObject copy(int part) {
+ if (this.partition() == part)
+ return this;
+
+ return new UserKeyCacheObjectImpl(val, valBytes, part);
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
index 21df559..e565cba 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
@@ -519,12 +519,12 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
keys = new GridConcurrentHashSet<>(entries.size(), U.capacity(entries.size()), 1);
for (Map.Entry<K, V> entry : entries)
- keys.add(cacheObjProc.toCacheKeyObject(cacheObjCtx, entry.getKey(), true));
+ keys.add(cacheObjProc.toCacheKeyObject(cacheObjCtx, null, entry.getKey(), true));
}
Collection<? extends DataStreamerEntry> entries0 = F.viewReadOnly(entries, new C1<Entry<K, V>, DataStreamerEntry>() {
@Override public DataStreamerEntry apply(Entry<K, V> e) {
- KeyCacheObject key = cacheObjProc.toCacheKeyObject(cacheObjCtx, e.getKey(), true);
+ KeyCacheObject key = cacheObjProc.toCacheKeyObject(cacheObjCtx, null, e.getKey(), true);
CacheObject val = cacheObjProc.toCacheObject(cacheObjCtx, e.getValue(), true);
return new DataStreamerEntry(key, val);
@@ -619,7 +619,7 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
else
checkSecurityPermission(SecurityPermission.CACHE_PUT);
- KeyCacheObject key0 = cacheObjProc.toCacheKeyObject(cacheObjCtx, key, true);
+ KeyCacheObject key0 = cacheObjProc.toCacheKeyObject(cacheObjCtx, null, key, true);
CacheObject val0 = cacheObjProc.toCacheObject(cacheObjCtx, val, true);
return addDataInternal(Collections.singleton(new DataStreamerEntry(key0, val0)));
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/test/java/org/apache/ignite/cache/affinity/AffinityClientNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/affinity/AffinityClientNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/cache/affinity/AffinityClientNodeSelfTest.java
index 47b01f4..fc50541 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/affinity/AffinityClientNodeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/affinity/AffinityClientNodeSelfTest.java
@@ -57,15 +57,15 @@ public class AffinityClientNodeSelfTest extends GridCommonAbstractTest {
/** */
private static final String CACHE4 = "cache4";
+ /** */
+ private static final String CACHE5 = "cache5";
+
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
- if (gridName.equals(getTestGridName(NODE_CNT - 1)))
- cfg.setClientMode(true);
-
CacheConfiguration ccfg1 = new CacheConfiguration();
ccfg1.setBackups(1);
@@ -92,7 +92,18 @@ public class AffinityClientNodeSelfTest extends GridCommonAbstractTest {
ccfg4.setName(CACHE4);
ccfg4.setNodeFilter(new TestNodesFilter());
- cfg.setCacheConfiguration(ccfg1, ccfg2, ccfg3, ccfg4);
+ CacheConfiguration ccfg5 = new CacheConfiguration();
+
+ ccfg5.setBackups(1);
+ ccfg5.setName(CACHE5);
+
+ if (gridName.equals(getTestGridName(NODE_CNT - 1))) {
+ cfg.setClientMode(true);
+
+ cfg.setCacheConfiguration(ccfg5);
+ }
+ else
+ cfg.setCacheConfiguration(ccfg1, ccfg2, ccfg3, ccfg4);
return cfg;
}
@@ -123,6 +134,8 @@ public class AffinityClientNodeSelfTest extends GridCommonAbstractTest {
checkCache(CACHE4, 3);
+ checkCache(CACHE5, 2);
+
Ignite client = ignite(NODE_CNT - 1);
CacheConfiguration ccfg = new CacheConfiguration();
@@ -157,6 +170,8 @@ public class AffinityClientNodeSelfTest extends GridCommonAbstractTest {
private void checkCache(String cacheName, int expNodes) {
log.info("Test cache: " + cacheName);
+ Affinity<Object> aff0 = ignite(0).affinity(cacheName);
+
Ignite client = ignite(NODE_CNT - 1);
assertTrue(client.configuration().isClientMode());
@@ -166,14 +181,22 @@ public class AffinityClientNodeSelfTest extends GridCommonAbstractTest {
for (int i = 0; i < NODE_CNT; i++) {
Ignite ignite = ignite(i);
- Affinity<Integer> aff = ignite.affinity(cacheName);
+ Affinity<Object> aff = ignite.affinity(cacheName);
for (int part = 0; part < aff.partitions(); part++) {
Collection<ClusterNode> nodes = aff.mapPartitionToPrimaryAndBackups(part);
assertEquals(expNodes, nodes.size());
+ assertEquals(aff0.mapPartitionToPrimaryAndBackups(part), nodes);
assertFalse(nodes.contains(clientNode));
+
+ assertEquals(aff0.partition(part), aff.partition(part));
+
+ TestKey key = new TestKey(part, part + 1);
+
+ assertEquals(aff0.partition(key), aff.partition(key));
+ assertEquals(aff0.mapKeyToPrimaryAndBackups(key), aff.mapKeyToPrimaryAndBackups(key));
}
}
}
@@ -181,6 +204,46 @@ public class AffinityClientNodeSelfTest extends GridCommonAbstractTest {
/**
*
*/
+ static class TestKey {
+ /** */
+ private int id;
+
+ /** */
+ @AffinityKeyMapped
+ private int affId;
+
+ /**
+ * @param id ID.
+ * @param affId Affinity ID.
+ */
+ public TestKey(int id, int affId) {
+ this.id = id;
+ this.affId = affId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ TestKey testKey = (TestKey)o;
+
+ return id == testKey.id;
+
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return id;
+ }
+ }
+
+ /**
+ *
+ */
private static class TestNodesFilter implements IgnitePredicate<ClusterNode> {
/** {@inheritDoc} */
@Override public boolean apply(ClusterNode clusterNode) {
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
index 1285db7..f4c1bf7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
@@ -26,7 +26,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -90,13 +89,11 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jsr166.ConcurrentHashMap8;
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_BINARY_MARSHALLER_USE_STRING_SERIALIZATION_VER_2;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.ignite.internal.binary.streams.BinaryMemoryAllocator.INSTANCE;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotEquals;
-import static java.nio.charset.StandardCharsets.UTF_8;
-
/**
* Binary marshaller tests.
*/
@@ -2401,7 +2398,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
BinaryObjectImpl po = marshal(simpleObject(), marsh);
- CacheObjectContext coCtx = new CacheObjectContext(newContext(), null, false, true, false);
+ CacheObjectContext coCtx = new CacheObjectContext(newContext(), null, null, false, true, false);
assert po.value(coCtx, false) == po.value(coCtx, false);
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
index be2ce9b..f999ad3 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
@@ -21,6 +21,26 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
import junit.framework.TestCase;
import org.apache.ignite.IgniteBinary;
import org.apache.ignite.IgniteCache;
@@ -29,9 +49,6 @@ import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.binary.BinaryObjectBuilder;
import org.apache.ignite.binary.BinaryObjectException;
import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.CacheWriteSynchronizationMode;
import org.apache.ignite.configuration.BinaryConfiguration;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
@@ -46,27 +63,6 @@ import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.junit.Assert;
-import java.lang.reflect.Field;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Timestamp;
-import java.util.AbstractMap;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.UUID;
-
import static org.apache.ignite.cache.CacheMode.PARTITIONED;
import static org.apache.ignite.cache.CacheMode.REPLICATED;
@@ -1497,7 +1493,5 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
assert OBJ.equals(binaryObj.type().fieldTypeName("asListHint"));
assert OBJ.equals(binaryObj.type().fieldTypeName("asSetHint"));
assert OBJ.equals(binaryObj.type().fieldTypeName("asMapHint"));
-
}
-
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryAbstractTest.java
index c0ba42c..34480a2 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheGetEntryAbstractTest.java
@@ -463,7 +463,7 @@ public abstract class CacheGetEntryAbstractTest extends GridCacheAbstractSelfTes
CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext();
GridCacheMapEntry mapEntry = cacheAdapter.map().getEntry(cacheObjects.toCacheKeyObject(
- cacheObjCtx, e.getKey(), true));
+ cacheObjCtx, null, e.getKey(), true));
assertNotNull("No entry for key: " + e.getKey(), mapEntry);
assertEquals(mapEntry.version(), e.version());
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheTtlCleanupSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheTtlCleanupSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheTtlCleanupSelfTest.java
index e166acb..42027e4 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheTtlCleanupSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/expiry/IgniteCacheTtlCleanupSelfTest.java
@@ -82,6 +82,6 @@ public class IgniteCacheTtlCleanupSelfTest extends GridCacheAbstractSelfTest {
CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext();
for (int i = 0; i < 100; i++)
- assertNull(cacheAdapter.map().getEntry(cacheObjects.toCacheKeyObject(cacheObjCtx, i, true)));
+ assertNull(cacheAdapter.map().getEntry(cacheObjects.toCacheKeyObject(cacheObjCtx, null, i, true)));
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheBinaryKeyConcurrentQueryTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheBinaryKeyConcurrentQueryTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheBinaryKeyConcurrentQueryTest.java
new file mode 100644
index 0000000..e2de281
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/CacheBinaryKeyConcurrentQueryTest.java
@@ -0,0 +1,298 @@
+/*
+ * 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.processors.cache;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.cache.Cache;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheEntry;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+@SuppressWarnings("unchecked")
+public class CacheBinaryKeyConcurrentQueryTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private static final int NODES = 3;
+
+ /** */
+ private static final int KEYS = 1000;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+ cfg.setMarshaller(null);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ startGridsMultiThreaded(NODES);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPutAndQueries() throws Exception {
+ Ignite ignite = ignite(0);
+
+ IgniteCache cache1 = ignite.createCache(cacheConfiguration("cache1", ATOMIC));
+ IgniteCache cache2 = ignite.createCache(cacheConfiguration("cache2", TRANSACTIONAL));
+
+ insertData(ignite, cache1.getName());
+ insertData(ignite, cache2.getName());
+
+ IgniteInternalFuture<?> fut1 = startUpdate(cache1.getName());
+ IgniteInternalFuture<?> fut2 = startUpdate(cache2.getName());
+
+ fut1.get();
+ fut2.get();
+ }
+
+ /**
+ * @param cacheName Cache name.
+ * @return Future.
+ */
+ private IgniteInternalFuture<?> startUpdate(final String cacheName) {
+ final long stopTime = System.currentTimeMillis() + 30_000;
+
+ final AtomicInteger idx = new AtomicInteger();
+
+ return GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
+ @Override public Void call() {
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ IgniteCache cache = ignite(idx.getAndIncrement() % NODES).cache(cacheName).withKeepBinary();
+
+ while (System.currentTimeMillis() < stopTime) {
+ switch (rnd.nextInt(5)) {
+ case 0: {
+ TestKey key = new TestKey(rnd.nextInt(KEYS));
+
+ CacheEntry e = cache.getEntry(key);
+
+ assertNotNull(e);
+ assertTrue(e.getKey() instanceof BinaryObject);
+
+ cache.put(e.getKey(), new TestValue(rnd.nextInt(KEYS)));
+
+ break;
+ }
+
+ case 1: {
+ Iterator<Cache.Entry> it = cache.iterator();
+
+ for (int i = 0; i < 100 && it.hasNext(); i++) {
+ Cache.Entry e = it.next();
+
+ assertTrue(e.getKey() instanceof BinaryObject);
+
+ cache.put(e.getKey(), new TestValue(rnd.nextInt(KEYS)));
+ }
+
+ break;
+ }
+
+ case 2: {
+ SqlFieldsQuery qry = new SqlFieldsQuery("select _key " +
+ "from \"" + cache.getName() + "\".TestValue where id=?");
+
+ qry.setArgs(rnd.nextInt(KEYS));
+
+ List<List> res = cache.query(qry).getAll();
+
+ assertEquals(1, res.size());
+
+ BinaryObject key = (BinaryObject)res.get(0).get(0);
+
+ cache.put(key, new TestValue(rnd.nextInt(KEYS)));
+
+ break;
+ }
+
+ case 3: {
+ SqlQuery qry = new SqlQuery("TestValue", "id=?");
+
+ qry.setArgs(rnd.nextInt(KEYS));
+
+ List<Cache.Entry> res = cache.query(qry).getAll();
+
+ assertEquals(1, res.size());
+
+ break;
+ }
+
+ case 4: {
+ SqlQuery qry = new SqlQuery("TestValue", "order by id");
+
+ int cnt = 0;
+
+ for (Cache.Entry e : (Iterable<Cache.Entry>)cache.query(qry)) {
+ assertNotNull(cache.get(e.getKey()));
+
+ cnt++;
+ }
+
+ assertTrue(cnt > 0);
+
+ break;
+ }
+
+ default:
+ fail();
+ }
+ }
+
+ return null;
+ }
+ }, NODES * 2, "test-thread");
+ }
+
+ /**
+ * @param ignite Node.
+ * @param cacheName Cache name.
+ */
+ private void insertData(Ignite ignite, String cacheName) {
+ try (IgniteDataStreamer streamer = ignite.dataStreamer(cacheName)) {
+ for (int i = 0; i < KEYS; i++)
+ streamer.addData(new TestKey(i), new TestValue(i));
+ }
+ }
+
+ /**
+ * @param name Cache name.
+ * @param atomicityMode Cache atomicity mode.
+ * @return Cache configuration.
+ */
+ private CacheConfiguration cacheConfiguration(String name, CacheAtomicityMode atomicityMode) {
+ CacheConfiguration ccfg = new CacheConfiguration();
+
+ ccfg.setName(name);
+ ccfg.setCacheMode(PARTITIONED);
+ ccfg.setWriteSynchronizationMode(FULL_SYNC);
+ ccfg.setAtomicityMode(atomicityMode);
+ ccfg.setBackups(1);
+
+ QueryEntity qryEntity = new QueryEntity();
+
+ qryEntity.setKeyType(TestKey.class.getName());
+ qryEntity.setValueType(TestValue.class.getName());
+
+ qryEntity.addQueryField("id", Integer.class.getName(), null);
+ qryEntity.addQueryField("val", Integer.class.getName(), null);
+
+ qryEntity.setIndexes(F.asList(new QueryIndex("id"), new QueryIndex("val")));
+
+ ccfg.setQueryEntities(F.asList(qryEntity));
+
+ return ccfg;
+ }
+
+ /**
+ *
+ */
+ static class TestKey {
+ /** */
+ @QuerySqlField(index = true)
+ private int id;
+
+ /**
+ * @param id ID.
+ */
+ public TestKey(int id) {
+ this.id = id;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ TestKey testKey = (TestKey)o;
+
+ return id == testKey.id;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return id;
+ }
+ }
+
+ /**
+ *
+ */
+ static class TestValue {
+ /** */
+ @QuerySqlField(index = true)
+ private int val;
+
+ /**
+ * @param val Value.
+ */
+ public TestValue(int val) {
+ this.val = val;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9d07e3e7/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
index a85b7a6..96e8551 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
@@ -18,6 +18,7 @@
package org.apache.ignite.testsuites;
import junit.framework.TestSuite;
+import org.apache.ignite.internal.processors.cache.CacheBinaryKeyConcurrentQueryTest;
import org.apache.ignite.internal.processors.cache.CacheConfigurationP2PTest;
import org.apache.ignite.internal.processors.cache.CacheIndexStreamerTest;
import org.apache.ignite.internal.processors.cache.CacheOperationsWithExpirationTest;
@@ -76,6 +77,7 @@ public class IgniteCacheWithIndexingTestSuite extends TestSuite {
suite.addTestSuite(CacheRandomOperationsMultithreadedTest.class);
suite.addTestSuite(IgniteCacheStarvationOnRebalanceTest.class);
suite.addTestSuite(CacheOperationsWithExpirationTest.class);
+ suite.addTestSuite(CacheBinaryKeyConcurrentQueryTest.class);
return suite;
}
[6/7] ignite git commit: Merge remote-tracking branch
'remotes/community/ignite-1.6.3'
Posted by sb...@apache.org.
Merge remote-tracking branch 'remotes/community/ignite-1.6.3'
# Conflicts:
# modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
# modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/da563701
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/da563701
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/da563701
Branch: refs/heads/master
Commit: da563701caec058db4a264a4b08f0a35c4cd9b17
Parents: a441bb9 9d07e3e
Author: sboikov <sb...@gridgain.com>
Authored: Wed Jul 27 10:17:16 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Jul 27 10:17:16 2016 +0300
----------------------------------------------------------------------
.../org/apache/ignite/internal/IgnitionEx.java | 2 +
.../distributed/dht/GridDhtLocalPartition.java | 2 +-
.../dht/GridDhtPartitionTopologyImpl.java | 52 +++++++-
.../ServicePredicateAccessCacheTest.java | 4 +-
.../ignite/cache/spring/SpringCacheManager.java | 17 ++-
.../spring/SpringTransactionManager.java | 59 +++++----
.../test/java/config/spring-transactions.xml | 4 +-
.../ignite/TestInjectionLifecycleBean.java | 42 +++++++
.../org/apache/ignite/spring-injection-test.xml | 43 +++++++
.../SpringCacheManagerContextInjectionTest.java | 126 +++++++++++++++++++
.../testsuites/IgniteSpringTestSuite.java | 5 +
...gTransactionManagerContextInjectionTest.java | 125 ++++++++++++++++++
12 files changed, 448 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/da563701/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
index 3692022,50f7f0f..1299d20
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
@@@ -23,16 -23,17 +23,18 @@@ import java.util.Collections
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Set;
import java.util.UUID;
+import java.util.concurrent.atomic.AtomicReferenceArray;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
+ import org.apache.ignite.IgniteSystemProperties;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.events.DiscoveryEvent;
+ import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.affinity.GridAffinityAssignment;
@@@ -178,10 -179,27 +181,27 @@@ class GridDhtPartitionTopologyImpl impl
private boolean waitForRent() throws IgniteCheckedException {
boolean changed = false;
+ GridDhtLocalPartition[] locPartsCopy = new GridDhtLocalPartition[locParts.length];
+
+ lock.readLock().lock();
+
+ try {
+ for (int i = 0; i < locParts.length; i++)
+ locPartsCopy[i] = locParts[i];
+ }
+ finally {
+ lock.readLock().unlock();
+ }
+
+ final long longOpDumpTimeout =
+ IgniteSystemProperties.getLong(IgniteSystemProperties.IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT, 60_000);
+
+ int dumpCnt = 0;
+
GridDhtLocalPartition part;
- for (int i = 0; i < locParts.length(); i++) {
- part = locParts.get(i);
- for (int i = 0; i < locPartsCopy.length; i++) {
- part = locPartsCopy[i];
++ for (int i = 0; i < locPartsCopy.length(); i++) {
++ part = locPartsCopy.get(i);
if (part == null)
continue;
http://git-wip-us.apache.org/repos/asf/ignite/blob/da563701/modules/spring/src/test/java/org/apache/ignite/testsuites/IgniteSpringTestSuite.java
----------------------------------------------------------------------
[7/7] ignite git commit: Merge remote-tracking branch
'remotes/community/ignite-1.6.3'
Posted by sb...@apache.org.
Merge remote-tracking branch 'remotes/community/ignite-1.6.3'
# Conflicts:
# modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
# modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/42f42eac
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/42f42eac
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/42f42eac
Branch: refs/heads/master
Commit: 42f42eac58c718f7debdd5f6e1ed989bae48de69
Parents: da56370
Author: sboikov <sb...@gridgain.com>
Authored: Wed Jul 27 10:17:36 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Wed Jul 27 10:17:36 2016 +0300
----------------------------------------------------------------------
.../dht/GridDhtPartitionTopologyImpl.java | 16 ++--------------
.../org/apache/ignite/spring-injection-test.xml | 2 +-
2 files changed, 3 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/42f42eac/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
index 1299d20..558a654 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
@@ -181,18 +181,6 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
private boolean waitForRent() throws IgniteCheckedException {
boolean changed = false;
- GridDhtLocalPartition[] locPartsCopy = new GridDhtLocalPartition[locParts.length];
-
- lock.readLock().lock();
-
- try {
- for (int i = 0; i < locParts.length; i++)
- locPartsCopy[i] = locParts[i];
- }
- finally {
- lock.readLock().unlock();
- }
-
final long longOpDumpTimeout =
IgniteSystemProperties.getLong(IgniteSystemProperties.IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT, 60_000);
@@ -200,8 +188,8 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
GridDhtLocalPartition part;
- for (int i = 0; i < locPartsCopy.length(); i++) {
- part = locPartsCopy.get(i);
+ for (int i = 0; i < locParts.length(); i++) {
+ part = locParts.get(i);
if (part == null)
continue;
http://git-wip-us.apache.org/repos/asf/ignite/blob/42f42eac/modules/spring/src/test/java/org/apache/ignite/spring-injection-test.xml
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/spring-injection-test.xml b/modules/spring/src/test/java/org/apache/ignite/spring-injection-test.xml
index b8368a3..7401986 100644
--- a/modules/spring/src/test/java/org/apache/ignite/spring-injection-test.xml
+++ b/modules/spring/src/test/java/org/apache/ignite/spring-injection-test.xml
@@ -18,7 +18,7 @@
-->
<!--
- GridGain Spring configuration file to startup grid cache.
+ Ignite Spring configuration file to startup grid cache.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
[4/7] ignite git commit: Print debug information on 'waitForRent'
timeout. (cherry picked from commit 7cf26d9)
Posted by sb...@apache.org.
Print debug information on 'waitForRent' timeout.
(cherry picked from commit 7cf26d9)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f3e4f78f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f3e4f78f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f3e4f78f
Branch: refs/heads/master
Commit: f3e4f78fc96c98f4376ff86ab3e76ba54d6b09a4
Parents: 14e3353
Author: sboikov <sb...@gridgain.com>
Authored: Tue Jul 26 15:48:36 2016 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Tue Jul 26 16:05:13 2016 +0300
----------------------------------------------------------------------
.../distributed/dht/GridDhtLocalPartition.java | 2 +-
.../dht/GridDhtPartitionTopologyImpl.java | 36 +++++++++++++++++++-
2 files changed, 36 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/f3e4f78f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
index f587adb..5061136 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
@@ -518,7 +518,7 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
/**
* @return {@code true} If there is a group reservation.
*/
- private boolean groupReserved() {
+ boolean groupReserved() {
for (GridDhtPartitionsReservation reservation : reservations) {
if (!reservation.invalidate())
return true; // Failed to invalidate reservation -> we are reserved.
http://git-wip-us.apache.org/repos/asf/ignite/blob/f3e4f78f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
index c95817d..50f7f0f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
@@ -30,8 +30,10 @@ import java.util.Set;
import java.util.UUID;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.IgniteSystemProperties;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.affinity.GridAffinityAssignment;
@@ -51,6 +53,7 @@ import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.jetbrains.annotations.Nullable;
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT;
import static org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST;
import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.EVICTED;
import static org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState.MOVING;
@@ -188,6 +191,11 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
lock.readLock().unlock();
}
+ final long longOpDumpTimeout =
+ IgniteSystemProperties.getLong(IgniteSystemProperties.IGNITE_LONG_OPERATIONS_DUMP_TIMEOUT, 60_000);
+
+ int dumpCnt = 0;
+
GridDhtLocalPartition part;
for (int i = 0; i < locPartsCopy.length; i++) {
@@ -203,7 +211,33 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
log.debug("Waiting for renting partition: " + part);
// Wait for partition to empty out.
- part.rent(true).get();
+ if (longOpDumpTimeout > 0) {
+ while (true) {
+ try {
+ part.rent(true).get(longOpDumpTimeout);
+
+ break;
+ }
+ catch (IgniteFutureTimeoutCheckedException e) {
+ if (dumpCnt++ < GridDhtPartitionsExchangeFuture.DUMP_PENDING_OBJECTS_THRESHOLD) {
+ U.warn(log, "Failed to wait for partition eviction [" +
+ "topVer=" + topVer +
+ ", cache=" + cctx.name() +
+ ", part=" + part.id() +
+ ", partState=" + part.state() +
+ ", size=" + part.size() +
+ ", reservations=" + part.reservations() +
+ ", grpReservations=" + part.groupReserved() +
+ ", node=" + cctx.localNodeId() + "]");
+
+ if (IgniteSystemProperties.getBoolean(IGNITE_THREAD_DUMP_ON_EXCHANGE_TIMEOUT, false))
+ U.dumpThreads(log);
+ }
+ }
+ }
+ }
+ else
+ part.rent(true).get();
if (log.isDebugEnabled())
log.debug("Finished waiting for renting partition: " + part);
[2/7] ignite git commit: IGNITE-3569 - Set copyOnRead property to
FALSE for marshaller cache.
Posted by sb...@apache.org.
IGNITE-3569 - Set copyOnRead property to FALSE for marshaller cache.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ac31334b
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ac31334b
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ac31334b
Branch: refs/heads/master
Commit: ac31334b1072a810bc7f8e0e782ec6e84a9edd66
Parents: 6917ec4
Author: dkarachentsev <dk...@gridgain.com>
Authored: Tue Jul 26 12:54:32 2016 +0300
Committer: dkarachentsev <dk...@gridgain.com>
Committed: Tue Jul 26 12:54:32 2016 +0300
----------------------------------------------------------------------
.../src/main/java/org/apache/ignite/internal/IgnitionEx.java | 2 ++
.../processors/service/ServicePredicateAccessCacheTest.java | 4 +++-
2 files changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/ac31334b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
index 8062e6b..30f1d15 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
@@ -2164,6 +2164,7 @@ public class IgnitionEx {
cache.setNodeFilter(CacheConfiguration.ALL_NODES);
cache.setStartSize(300);
cache.setRebalanceOrder(-2);//Prior to other system caches.
+ cache.setCopyOnRead(false);
return cache;
}
@@ -2185,6 +2186,7 @@ public class IgnitionEx {
cache.setAffinity(new RendezvousAffinityFunction(false, 100));
cache.setNodeFilter(CacheConfiguration.ALL_NODES);
cache.setRebalanceOrder(-2); //Prior to user caches.
+ cache.setCopyOnRead(false);
return cache;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/ac31334b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ServicePredicateAccessCacheTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ServicePredicateAccessCacheTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ServicePredicateAccessCacheTest.java
index c91d9f1..5b446cc 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ServicePredicateAccessCacheTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ServicePredicateAccessCacheTest.java
@@ -19,7 +19,9 @@ package org.apache.ignite.internal.processors.service;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
+
import org.apache.ignite.Ignite;
+import org.apache.ignite.Ignition;
import org.apache.ignite.cluster.ClusterGroup;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.configuration.CacheConfiguration;
@@ -105,7 +107,7 @@ public class ServicePredicateAccessCacheTest extends GridCommonAbstractTest {
System.out.println("Call contains key [thread=" + Thread.currentThread().getName() + ']');
- boolean ret = ignite0.cache("testCache").containsKey(node.id().toString());
+ boolean ret = Ignition.localIgnite().cache("testCache").containsKey(node.id().toString());
System.out.println("After contains key [ret=" + ret +
", thread=" + Thread.currentThread().getName() + ']');