Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-2703 .NET: Dynamic type registration #1664

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
792506a
IGNITE-2703 .NET: Dynamic type registration
ptupitsyn Feb 10, 2017
4588e45
Merge branch 'ignite-2.0' into ignite-2703
ptupitsyn Feb 15, 2017
d7c6a7f
Fix ExecutableTest
ptupitsyn Feb 15, 2017
8d6e996
Remove unused imports
ptupitsyn Feb 15, 2017
4ee6e26
Fix typos
ptupitsyn Feb 15, 2017
32a01d2
Merge branch 'ignite-2.0' into ignite-2703
ptupitsyn Feb 16, 2017
88e844b
Fix TestEchoTaskBinarizableNoClass
ptupitsyn Feb 16, 2017
827887f
Fix TestDelegate
ptupitsyn Feb 16, 2017
72ad8a5
Disable type registration in system marshaller to avoid unexpected co…
ptupitsyn Feb 16, 2017
706bba2
Remove unused BinaryStreamAdapter
ptupitsyn Feb 16, 2017
c205e6d
Merge branch 'master' into ignite-2703
ptupitsyn Mar 22, 2017
949f8ec
Fix merge
ptupitsyn Mar 22, 2017
078afe1
Merge branch 'master' into ignite-2703
ptupitsyn Mar 27, 2017
8c0ac9f
Fixing merge
ptupitsyn Mar 27, 2017
cc0e0fa
Fixing merge
ptupitsyn Mar 27, 2017
7891e46
Merge branch 'master' into ignite-2703
ptupitsyn Mar 30, 2017
ed9db21
Fix merge
ptupitsyn Mar 30, 2017
bbb5feb
Sort ISerializable fields by name
ptupitsyn Mar 30, 2017
3faaf4f
Minors.
Mar 30, 2017
a0c399f
Merge remote-tracking branch 'upstream/ignite-2703' into ignite-2703
Mar 30, 2017
89c5b19
Adding custom flag to the header
ptupitsyn Mar 30, 2017
0434b6c
Set custom type flag on write
ptupitsyn Mar 30, 2017
913ffa0
Check flag on read
ptupitsyn Mar 30, 2017
5c7da74
Fix fields retrieval
ptupitsyn Mar 30, 2017
0c2b386
Fix missing flag in builder
ptupitsyn Mar 30, 2017
8122409
Log warning for ISerializable
ptupitsyn Mar 30, 2017
e9f7f84
Adding SQL-DML test for ISerializable
ptupitsyn Mar 30, 2017
196987f
Fix logger injection in marshaller
ptupitsyn Mar 30, 2017
01b520c
TestLogWarning done
ptupitsyn Mar 30, 2017
bd05d60
DML test added
ptupitsyn Mar 30, 2017
72bf012
Adding metadata tests
ptupitsyn Mar 30, 2017
b1d48b4
Adding tests
ptupitsyn Mar 30, 2017
24c738d
wip proper types
ptupitsyn Mar 30, 2017
4e39748
wip
ptupitsyn Mar 30, 2017
3573e53
Fix dotnet type detection
ptupitsyn Mar 30, 2017
1fb9690
wip
ptupitsyn Mar 30, 2017
89bac64
Typed writing implemented
ptupitsyn Mar 30, 2017
c0ddb39
wip tests
ptupitsyn Mar 30, 2017
3fe2111
Type names test done
ptupitsyn Mar 30, 2017
dd26974
wip tests
ptupitsyn Mar 30, 2017
4a2711c
Fixing tests
ptupitsyn Mar 31, 2017
0fee029
Simple DML test done
ptupitsyn Mar 31, 2017
d5f8791
Merge branch 'master' into ignite-2703
ptupitsyn Mar 31, 2017
ceebad3
wip tests
ptupitsyn Mar 31, 2017
ecadb15
wip tests
ptupitsyn Mar 31, 2017
cc42767
Add DML test
ptupitsyn Mar 31, 2017
e152058
wip tests
ptupitsyn Mar 31, 2017
8938d18
tests done
ptupitsyn Mar 31, 2017
c7bb261
Merge branch 'master' into ignite-2703
Mar 31, 2017
e62e9f6
Minors.
Mar 31, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,6 +24,9 @@ public final class MarshallerPlatformIds {
/** */
public static final byte JAVA_ID = 0;

/** */
public static final byte DOTNET_ID = 1;

/** */
private MarshallerPlatformIds() {
}
Expand Down
Expand Up @@ -110,6 +110,10 @@ public class BinaryUtils {
/** Flag: compact footer, no field IDs. */
public static final short FLAG_COMPACT_FOOTER = 0x0020;

/** Flag: raw data contains .NET type information. Always 0 in Java. Keep it here for information only. */
@SuppressWarnings("unused")
public static final short FLAG_CUSTOM_DOTNET_TYPE = 0x0040;

/** Offset which fits into 1 byte. */
public static final int OFFSET_1 = 1;

Expand Down
Expand Up @@ -430,10 +430,12 @@ public PlatformContextImpl(GridKernalContext ctx, PlatformCallbackGateway gate,
if (schema == null) {
BinaryTypeImpl meta = (BinaryTypeImpl)cacheObjProc.metadata(typeId);

for (BinarySchema typeSchema : meta.metadata().schemas()) {
if (schemaId == typeSchema.schemaId()) {
schema = typeSchema;
break;
if (meta != null) {
for (BinarySchema typeSchema : meta.metadata().schemas()) {
if (schemaId == typeSchema.schemaId()) {
schema = typeSchema;
break;
}
}
}

Expand Down
Expand Up @@ -18,6 +18,8 @@
package org.apache.ignite.internal.processors.platform.binary;

import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.binary.BinaryObjectException;
import org.apache.ignite.internal.MarshallerPlatformIds;
import org.apache.ignite.internal.binary.BinaryRawReaderEx;
import org.apache.ignite.internal.binary.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
Expand All @@ -39,6 +41,12 @@ public class PlatformBinaryProcessor extends PlatformAbstractTarget {
/** */
private static final int OP_GET_SCHEMA = 4;

/** */
private static final int OP_REGISTER_TYPE = 5;

/** */
private static final int OP_GET_TYPE = 6;

/**
* Constructor.
*
Expand All @@ -50,10 +58,20 @@ public PlatformBinaryProcessor(PlatformContext platformCtx) {

/** {@inheritDoc} */
@Override public long processInStreamOutLong(int type, BinaryRawReaderEx reader) throws IgniteCheckedException {
if (type == OP_PUT_META) {
platformCtx.processMetadata(reader);
switch (type) {
case OP_PUT_META:
platformCtx.processMetadata(reader);

return TRUE;

case OP_REGISTER_TYPE: {
int typeId = reader.readInt();
String typeName = reader.readString();

return TRUE;
return platformContext().kernalContext().marshallerContext()
.registerClassName(MarshallerPlatformIds.DOTNET_ID, typeId, typeName)
? TRUE : FALSE;
}
}

return super.processInStreamOutLong(type, reader);
Expand Down Expand Up @@ -88,6 +106,22 @@ public PlatformBinaryProcessor(PlatformContext platformCtx) {
break;
}

case OP_GET_TYPE: {
int typeId = reader.readInt();

try {
String typeName = platformContext().kernalContext().marshallerContext()
.getClassName(MarshallerPlatformIds.DOTNET_ID, typeId);

writer.writeString(typeName);
}
catch (ClassNotFoundException e) {
throw new BinaryObjectException(e);
}

break;
}

default:
super.processInStreamOutStream(type, reader, writer);
break;
Expand Down
Expand Up @@ -69,9 +69,17 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Binary\BinaryEqualityComparerTest.cs" />
<Compile Include="Binary\BinaryBuilderSelfTestDynamicRegistration.cs" />
<Compile Include="Binary\BinaryReaderWriterTest.cs" />
<Compile Include="Binary\IO\BinaryStreamsTest.cs" />
<Compile Include="Binary\JavaBinaryInteropTest.cs" />
<Compile Include="Binary\JavaTypeMappingTest.cs" />
<Compile Include="Binary\Serializable\CallbacksTest.cs" />
<Compile Include="Binary\Serializable\DelegatesTest.cs" />
<Compile Include="Binary\Serializable\BasicSerializableObjectsTest.cs" />
<Compile Include="Binary\Serializable\ObjectReferenceTests.cs" />
<Compile Include="Binary\Serializable\PrimitivesTest.cs" />
<Compile Include="Binary\Serializable\SqlDmlTest.cs" />
<Compile Include="Binary\TypeResolverTest.cs" />
<Compile Include="Cache\Affinity\AffinityKeyTest.cs" />
<Compile Include="Cache\Affinity\AffinityTopologyVersionTest.cs" />
Expand Down Expand Up @@ -103,6 +111,7 @@
<Compile Include="TestAppConfig.cs" />
<Compile Include="Binary\BinaryBuilderSelfTestFullFooter.cs" />
<Compile Include="Binary\BinaryCompactFooterInteropTest.cs" />
<Compile Include="Binary\BinaryDynamicRegistrationTest.cs" />
<Compile Include="Binary\BinarySelfTestFullFooter.cs" />
<Compile Include="Binary\BinaryStringTest.cs" />
<Compile Include="Cache\Affinity\AffinityFieldTest.cs" />
Expand Down Expand Up @@ -190,7 +199,7 @@
<Compile Include="ProcessExtensions.cs" />
<Compile Include="ProjectFilesTest.cs" />
<Compile Include="ReconnectTest.cs" />
<Compile Include="SerializationTest.cs" />
<Compile Include="Binary\Serializable\AdvancedSerializationTest.cs" />
<Compile Include="IgniteStartStopTest.cs" />
<Compile Include="Services\ServicesTestFullFooter.cs" />
<Compile Include="TestUtils.cs" />
Expand Down
Expand Up @@ -56,36 +56,7 @@ public void SetUp()
{
BinaryConfiguration = new BinaryConfiguration
{
TypeConfigurations = new List<BinaryTypeConfiguration>
{
new BinaryTypeConfiguration(typeof(Empty)),
new BinaryTypeConfiguration(typeof(Primitives)),
new BinaryTypeConfiguration(typeof(PrimitiveArrays)),
new BinaryTypeConfiguration(typeof(StringDateGuidEnum)),
new BinaryTypeConfiguration(typeof(WithRaw)),
new BinaryTypeConfiguration(typeof(MetaOverwrite)),
new BinaryTypeConfiguration(typeof(NestedOuter)),
new BinaryTypeConfiguration(typeof(NestedInner)),
new BinaryTypeConfiguration(typeof(MigrationOuter)),
new BinaryTypeConfiguration(typeof(MigrationInner)),
new BinaryTypeConfiguration(typeof(InversionOuter)),
new BinaryTypeConfiguration(typeof(InversionInner)),
new BinaryTypeConfiguration(typeof(CompositeOuter)),
new BinaryTypeConfiguration(typeof(CompositeInner)),
new BinaryTypeConfiguration(typeof(CompositeArray)),
new BinaryTypeConfiguration(typeof(CompositeContainer)),
new BinaryTypeConfiguration(typeof(ToBinary)),
new BinaryTypeConfiguration(typeof(Remove)),
new BinaryTypeConfiguration(typeof(RemoveInner)),
new BinaryTypeConfiguration(typeof(BuilderInBuilderOuter)),
new BinaryTypeConfiguration(typeof(BuilderInBuilderInner)),
new BinaryTypeConfiguration(typeof(BuilderCollection)),
new BinaryTypeConfiguration(typeof(BuilderCollectionItem)),
new BinaryTypeConfiguration(typeof(DecimalHolder)),
new BinaryTypeConfiguration(TypeEmpty),
new BinaryTypeConfiguration(typeof(TestEnumRegistered)),
new BinaryTypeConfiguration(typeof(NameMapperTestType))
},
TypeConfigurations = GetTypeConfigurations(),
DefaultIdMapper = new IdMapper(),
DefaultNameMapper = new NameMapper(),
CompactFooter = GetCompactFooter()
Expand All @@ -97,6 +68,43 @@ public void SetUp()
_marsh = _grid.Marshaller;
}

/// <summary>
/// Gets the type configurations.
/// </summary>
protected virtual ICollection<BinaryTypeConfiguration> GetTypeConfigurations()
{
return new[]
{
new BinaryTypeConfiguration(typeof(Empty)),
new BinaryTypeConfiguration(typeof(Primitives)),
new BinaryTypeConfiguration(typeof(PrimitiveArrays)),
new BinaryTypeConfiguration(typeof(StringDateGuidEnum)),
new BinaryTypeConfiguration(typeof(WithRaw)),
new BinaryTypeConfiguration(typeof(MetaOverwrite)),
new BinaryTypeConfiguration(typeof(NestedOuter)),
new BinaryTypeConfiguration(typeof(NestedInner)),
new BinaryTypeConfiguration(typeof(MigrationOuter)),
new BinaryTypeConfiguration(typeof(MigrationInner)),
new BinaryTypeConfiguration(typeof(InversionOuter)),
new BinaryTypeConfiguration(typeof(InversionInner)),
new BinaryTypeConfiguration(typeof(CompositeOuter)),
new BinaryTypeConfiguration(typeof(CompositeInner)),
new BinaryTypeConfiguration(typeof(CompositeArray)),
new BinaryTypeConfiguration(typeof(CompositeContainer)),
new BinaryTypeConfiguration(typeof(ToBinary)),
new BinaryTypeConfiguration(typeof(Remove)),
new BinaryTypeConfiguration(typeof(RemoveInner)),
new BinaryTypeConfiguration(typeof(BuilderInBuilderOuter)),
new BinaryTypeConfiguration(typeof(BuilderInBuilderInner)),
new BinaryTypeConfiguration(typeof(BuilderCollection)),
new BinaryTypeConfiguration(typeof(BuilderCollectionItem)),
new BinaryTypeConfiguration(typeof(DecimalHolder)),
new BinaryTypeConfiguration(TypeEmpty),
new BinaryTypeConfiguration(typeof(TestEnumRegistered)),
new BinaryTypeConfiguration(typeof(NameMapperTestType))
};
}

/// <summary>
/// Gets the compact footer setting.
/// </summary>
Expand Down Expand Up @@ -213,7 +221,7 @@ public void TestToBinary()

// 2. Special types.
Assert.AreEqual("a", api.ToBinary<string>("a"));
Assert.AreEqual(date, api.ToBinary<DateTime>(date));
Assert.AreEqual(date, api.ToBinary<IBinaryObject>(date).Deserialize<DateTime>());
Assert.AreEqual(guid, api.ToBinary<Guid>(guid));
Assert.AreEqual(TestEnumRegistered.One, api.ToBinary<IBinaryObject>(TestEnumRegistered.One)
.Deserialize<TestEnumRegistered>());
Expand All @@ -231,7 +239,8 @@ public void TestToBinary()
Assert.AreEqual(new[] { 'a' }, api.ToBinary<char[]>(new[] { 'a' }));

Assert.AreEqual(new[] { "a" }, api.ToBinary<string[]>(new[] { "a" }));
Assert.AreEqual(new[] { date }, api.ToBinary<DateTime[]>(new[] { date }));
Assert.AreEqual(new[] {date}, api.ToBinary<IBinaryObject[]>(new[] {date})
.Select(x => x.Deserialize<DateTime>()));
Assert.AreEqual(new[] { guid }, api.ToBinary<Guid[]>(new[] { guid }));
Assert.AreEqual(new[] { TestEnumRegistered.One},
api.ToBinary<IBinaryObject[]>(new[] { TestEnumRegistered.One})
Expand Down Expand Up @@ -619,6 +628,11 @@ public void TestPrimitiveFields()

CheckPrimitiveFields1(binObj);

// Rebuild unchanged.
binObj = binObj.ToBuilder().Build();

CheckPrimitiveFields1(binObj);

// Specific setter methods.
var binObj2 = _grid.GetBinary().GetBuilder(typeof(Primitives))
.SetByteField("fByte", 1)
Expand Down Expand Up @@ -766,6 +780,11 @@ public void TestPrimitiveArrayFields()

CheckPrimitiveArrayFields1(binObj);

// Rebuild unchanged.
binObj = binObj.ToBuilder().Build();

CheckPrimitiveArrayFields1(binObj);

// Specific setters.
var binObj2 = _grid.GetBinary().GetBuilder(typeof(PrimitiveArrays))
.SetByteArrayField("fByte", new byte[] {1})
Expand Down Expand Up @@ -814,7 +833,7 @@ public void TestPrimitiveArrayFields()
.Build();

CheckPrimitiveArrayFields2(binObj);

// Check equality.
Assert.AreEqual(binObj, binObj2);
Assert.AreEqual(binObj.GetHashCode(), binObj2.GetHashCode());
Expand Down Expand Up @@ -918,6 +937,11 @@ public void TestStringDateGuidEnum()

CheckStringDateGuidEnum1(binObj, nDate, nGuid);

// Rebuild with no changes.
binObj = binObj.ToBuilder().Build();

CheckStringDateGuidEnum1(binObj, nDate, nGuid);

// Specific setters.
var binObj2 = _grid.GetBinary().GetBuilder(typeof(StringDateGuidEnum))
.SetStringField("fStr", "str")
Expand Down Expand Up @@ -1001,12 +1025,13 @@ private void CheckStringDateGuidEnum1(IBinaryObject binObj, DateTime? nDate, Gui
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<IBinaryObject>("fNDate").Deserialize<DateTime?>());
Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNTimestamp"));
Assert.AreEqual(nGuid, binObj.GetField<Guid?>("fNGuid"));
Assert.AreEqual(TestEnum.One, binObj.GetField<IBinaryObject>("fEnum").Deserialize<TestEnum>());
Assert.AreEqual(new[] {"str"}, binObj.GetField<string[]>("fStrArr"));
Assert.AreEqual(new[] {nDate}, binObj.GetField<DateTime?[]>("fDateArr"));
Assert.AreEqual(new[] {nDate}, binObj.GetField<IBinaryObject[]>("fDateArr")
.Select(x => x.Deserialize<DateTime?>()));
Assert.AreEqual(new[] {nDate}, binObj.GetField<DateTime?[]>("fTimestampArr"));
Assert.AreEqual(new[] {nGuid}, binObj.GetField<Guid?[]>("fGuidArr"));
Assert.AreEqual(new[] {TestEnum.One},
Expand All @@ -1028,12 +1053,13 @@ private void CheckStringDateGuidEnum1(IBinaryObject binObj, DateTime? nDate, Gui
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<IBinaryObjectBuilder>("fNDate").Build().Deserialize<DateTime?>());
Assert.AreEqual(nDate, builder.GetField<DateTime?>("fNTimestamp"));
Assert.AreEqual(nGuid, builder.GetField<Guid?>("fNGuid"));
Assert.AreEqual(TestEnum.One, builder.GetField<IBinaryObject>("fEnum").Deserialize<TestEnum>());
Assert.AreEqual(new[] {"str"}, builder.GetField<string[]>("fStrArr"));
Assert.AreEqual(new[] {nDate}, builder.GetField<DateTime?[]>("fDateArr"));
Assert.AreEqual(new[] {nDate}, builder.GetField<IBinaryObjectBuilder[]>("fDateArr")
.Select(x => x.Build().Deserialize<DateTime?>()));
Assert.AreEqual(new[] {nDate}, builder.GetField<DateTime?[]>("fTimestampArr"));
Assert.AreEqual(new[] {nGuid}, builder.GetField<Guid?[]>("fGuidArr"));
Assert.AreEqual(new[] {TestEnum.One},
Expand All @@ -1043,12 +1069,13 @@ private void CheckStringDateGuidEnum1(IBinaryObject binObj, DateTime? nDate, Gui
binObj = builder.Build();

Assert.AreEqual("str", binObj.GetField<string>("fStr"));
Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNDate"));
Assert.AreEqual(nDate, binObj.GetField<IBinaryObject>("fNDate").Deserialize<DateTime?>());
Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNTimestamp"));
Assert.AreEqual(nGuid, binObj.GetField<Guid?>("fNGuid"));
Assert.AreEqual(TestEnum.One, binObj.GetField<IBinaryObject>("fEnum").Deserialize<TestEnum>());
Assert.AreEqual(new[] {"str"}, binObj.GetField<string[]>("fStrArr"));
Assert.AreEqual(new[] {nDate}, binObj.GetField<DateTime?[]>("fDateArr"));
Assert.AreEqual(new[] {nDate}, binObj.GetField<IBinaryObject[]>("fDateArr")
.Select(x => x.Deserialize<DateTime?>()));
Assert.AreEqual(new[] {nDate}, binObj.GetField<DateTime?[]>("fTimestampArr"));
Assert.AreEqual(new[] {nGuid}, binObj.GetField<Guid?[]>("fGuidArr"));
Assert.AreEqual(new[] { TestEnum.One },
Expand All @@ -1073,12 +1100,13 @@ private void CheckStringDateGuidEnum1(IBinaryObject binObj, DateTime? nDate, Gui
private static void CheckStringDateGuidEnum2(IBinaryObject binObj, DateTime? nDate, Guid? nGuid)
{
Assert.AreEqual("str2", binObj.GetField<string>("fStr"));
Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNDate"));
Assert.AreEqual(nDate, binObj.GetField<IBinaryObject>("fNDate").Deserialize<DateTime?>());
Assert.AreEqual(nDate, binObj.GetField<DateTime?>("fNTimestamp"));
Assert.AreEqual(nGuid, binObj.GetField<Guid?>("fNGuid"));
Assert.AreEqual(TestEnum.Two, binObj.GetField<IBinaryObject>("fEnum").Deserialize<TestEnum>());
Assert.AreEqual(new[] { "str2" }, binObj.GetField<string[]>("fStrArr"));
Assert.AreEqual(new[] { nDate }, binObj.GetField<DateTime?[]>("fDateArr"));
Assert.AreEqual(new[] {nDate}, binObj.GetField<IBinaryObject[]>("fDateArr")
.Select(x => x.Deserialize<DateTime?>()));
Assert.AreEqual(new[] { nDate }, binObj.GetField<DateTime?[]>("fTimestampArr"));
Assert.AreEqual(new[] { nGuid }, binObj.GetField<Guid?[]>("fGuidArr"));
Assert.AreEqual(new[] {TestEnum.Two},
Expand Down Expand Up @@ -1659,7 +1687,7 @@ public void TestRemoteBinaryMode()
cache1[1] = new Primitives {FByte = 3};
var obj = cache2[1];

// Rebuild with no changes
// Rebuild with no changes.
cache2[2] = obj.ToBuilder().Build();
Assert.AreEqual(3, cache1[2].FByte);

Expand Down