Skip to content

Commit

Permalink
IGN-2262 .NET: Net fixes for CashFlow
Browse files Browse the repository at this point in the history
Merge in OSPT/ignite from net_fixes_cherry_pick to master

* commit 'd6a200fed13ae8834ef1f84f275d7ff7ba71d60a':
  IGN-2322: Compilation fix.
  IGNITE-13897 .NET: Service can't assign correct type to passed array parameters (apache#8614)
  IGNITE-13734 .NET: Register service return type on method invocation (apache#8602)
  IGNITE-12824 .NET: Add BinaryConfiguration.TimestampConverter (apache#8568)
  IGNITE-13865 Support  DateTime as a key or value in .NET and Java (apache#8580)
  IGNITE-10075 .NET Avoid binary configurations of Ignite Java service params (apache#8509)
  • Loading branch information
nizhikov committed Jan 11, 2021
2 parents 017870e + d6a200f commit e91cff6
Show file tree
Hide file tree
Showing 44 changed files with 2,348 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ public interface BinaryRawReaderEx extends BinaryRawReader {
* @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
@Nullable public Object readObjectDetached() throws BinaryObjectException;

/**
* @param deserialize {@code True} if object should be deserialized during reading.
* @return Object.
* @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
@Nullable public Object readObjectDetached(boolean deserialize) throws BinaryObjectException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,12 @@ float readFloat(int fieldId) throws BinaryObjectException {

/** {@inheritDoc} */
@Nullable @Override public Object readObjectDetached() throws BinaryObjectException {
return BinaryUtils.unmarshal(in, ctx, ldr, this, true);
return readObjectDetached(false);
}

/** {@inheritDoc} */
@Nullable @Override public Object readObjectDetached(boolean deserialize) throws BinaryObjectException {
return BinaryUtils.unmarshal(in, ctx, ldr, this, true, deserialize);
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,15 @@ public static Object doReadOptimized(BinaryInputStream in, BinaryContext ctx, @N
*/
@Nullable public static Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
BinaryReaderHandlesHolder handles, boolean detach) throws BinaryObjectException {
return unmarshal(in, ctx, ldr, handles, detach, false);
}

/**
* @return Unmarshalled value.
* @throws BinaryObjectException In case of error.
*/
@Nullable public static Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize) throws BinaryObjectException {
int start = in.position();

byte flag = in.readByte();
Expand All @@ -1843,7 +1852,7 @@ public static Object doReadOptimized(BinaryInputStream in, BinaryContext ctx, @N

in.position(handlePos);

obj = unmarshal(in, ctx, ldr, handles, detach);
obj = unmarshal(in, ctx, ldr, handles, detach, deserialize);

in.position(retPos);
}
Expand Down Expand Up @@ -1964,13 +1973,13 @@ public static Object doReadOptimized(BinaryInputStream in, BinaryContext ctx, @N
return doReadTimeArray(in);

case GridBinaryMarshaller.OBJ_ARR:
return doReadObjectArray(in, ctx, ldr, handles, detach, false);
return doReadObjectArray(in, ctx, ldr, handles, detach, deserialize);

case GridBinaryMarshaller.COL:
return doReadCollection(in, ctx, ldr, handles, detach, false, null);
return doReadCollection(in, ctx, ldr, handles, detach, deserialize, null);

case GridBinaryMarshaller.MAP:
return doReadMap(in, ctx, ldr, handles, detach, false, null);
return doReadMap(in, ctx, ldr, handles, detach, deserialize, null);

case GridBinaryMarshaller.BINARY_OBJ:
return doReadBinaryObject(in, ctx, detach);
Expand Down Expand Up @@ -2162,7 +2171,7 @@ public static Collection<?> doReadCollection(BinaryInputStream in, BinaryContext
*/
private static Object deserializeOrUnmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize) {
return deserialize ? doReadObject(in, ctx, ldr, handles) : unmarshal(in, ctx, ldr, handles, detach);
return deserialize ? doReadObject(in, ctx, ldr, handles) : unmarshal(in, ctx, ldr, handles, detach, deserialize);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,19 @@ public PlatformBinaryProcessor(PlatformContext platformCtx) {
case OP_REGISTER_TYPE: {
int typeId = reader.readInt();
String typeName = reader.readString();
boolean registerSameJavaType = reader.readBoolean();

return platformContext().kernalContext().marshallerContext()
int res = platformContext().kernalContext().marshallerContext()
.registerClassName(MarshallerPlatformIds.DOTNET_ID, typeId, typeName, false)
? TRUE : FALSE;

if (registerSameJavaType && res == TRUE) {
res = platformContext().kernalContext().marshallerContext()
.registerClassName(MarshallerPlatformIds.JAVA_ID, typeId, typeName, false)
? TRUE : FALSE;
}

return res;
}
}

Expand Down Expand Up @@ -125,10 +134,11 @@ public PlatformBinaryProcessor(PlatformContext platformCtx) {

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

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

writer.writeString(typeName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ private ServiceDescriptor findDescriptor(String name) {
assert arg != null;
assert arg instanceof ServiceProxyHolder;

ServiceProxyHolder svc = (ServiceProxyHolder)arg;

String mthdName = reader.readString();

Object[] args;
Expand All @@ -279,13 +281,13 @@ private ServiceDescriptor findDescriptor(String name) {
args = new Object[reader.readInt()];

for (int i = 0; i < args.length; i++)
args[i] = reader.readObjectDetached();
args[i] = reader.readObjectDetached(!srvKeepBinary && !svc.isPlatformService());
}
else
args = null;

try {
Object result = ((ServiceProxyHolder)arg).invoke(mthdName, srvKeepBinary, args);
Object result = svc.invoke(mthdName, srvKeepBinary, args);

PlatformUtils.writeInvocationResult(writer, result, null);
}
Expand Down Expand Up @@ -583,7 +585,7 @@ private ServiceProxyHolder(Object proxy, Class clazz, PlatformContext ctx) {
*/
public Object invoke(String mthdName, boolean srvKeepBinary, Object[] args)
throws IgniteCheckedException, NoSuchMethodException {
if (proxy instanceof PlatformService)
if (isPlatformService())
return ((PlatformService)proxy).invokeMethod(mthdName, srvKeepBinary, args);
else {
assert proxy instanceof GridServiceProxy;
Expand Down Expand Up @@ -707,6 +709,11 @@ private static boolean areMethodArgsCompatible(Class[] argTypes, Object[] args)
private static Class wrap(Class c) {
return c.isPrimitive() ? PRIMITIVES_TO_WRAPPERS.get(c) : c;
}

/** @return {@code True} if service is platform service. */
public boolean isPlatformService() {
return proxy instanceof PlatformService;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,9 @@ private static Collection<Object> unwrapKnownCollection(Collection<Object> col)
* @return Result.
*/
public static Object[] unwrapBinariesInArray(Object[] arr) {
if (arr.getClass().getComponentType() != Object.class)
return arr;

Object[] res = new Object[arr.length];

for (int i = 0; i < arr.length; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
import org.apache.ignite.internal.managers.systemview.GridSystemViewManager;
import org.apache.ignite.internal.processors.cache.CacheObjectContext;
import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
import org.apache.ignite.internal.util.GridUnsafe;
import org.apache.ignite.internal.util.IgniteUtils;
import org.apache.ignite.internal.util.lang.GridMapEntry;
Expand Down Expand Up @@ -2969,7 +2970,7 @@ public void testReadDetachedMap() throws Exception {
assertTrue(map.containsKey(key));
assertEquals(val, map.get(key));
});
});
}, false);
}

/**
Expand All @@ -2989,27 +2990,59 @@ public void testReadDetachedCollection() throws Exception {

assertTrue(col.contains(val));
});
});
}, false);
}

/**
* @throws Exception If failed.
*/
/** @throws Exception If failed. */
@Test
public void testReadDetachedArray() throws Exception {
public void testReadDetachedTypedArray() throws Exception {
Value[] arr = IntStream.range(0, 1000).mapToObj(Value::new).toArray(Value[]::new);

testReadDetachObjectProperly(arr, obj -> {
Object[] desArr = (Object[])obj;
assertArrayEquals(arr, (Value[])obj);

assertEquals(arr.length, desArr.length);
Object[] args = new Object[] {obj};

for (int i = 0; i < arr.length; i++) {
BinaryObject val = (BinaryObject)desArr[i];
assertTrue(args[0] instanceof Value[]);

assertEquals(arr[i], new Value(val.field("val")));
}
});
args = PlatformUtils.unwrapBinariesInArray(args);

assertTrue(args[0] instanceof Value[]);
assertArrayEquals(arr, (Value[])args[0]);
}, true);
}

/** @throws Exception If failed. */
@Test
public void testReadArrayOfCollections() throws Exception {
Collection[] arr = new Collection[] { Arrays.asList(new Value(1), new Value(2), new Value(3)) };
testReadDetachObjectProperly(arr, obj -> {
assertArrayEquals(arr, (Collection[])obj);

Object[] args = new Object[] {obj};

assertTrue(args[0] instanceof Collection[]);

args = PlatformUtils.unwrapBinariesInArray(args);

assertTrue(args[0] instanceof Collection[]);
assertArrayEquals(arr, (Collection[])args[0]);
}, true);
}


/** @throws Exception If failed. */
@Test
public void testReadArrayOfBinaryCollections() throws Exception {
Collection[] arr = new Collection[] { new ArrayList<>(Arrays.asList(new Value(1), new Value(2), new Value(3))) };

testReadDetachObjectProperly(arr, obj -> {
Object[] args = PlatformUtils.unwrapBinariesInArray(new Object[] {obj});

Collection deserVals = (Collection)((Object[])args[0])[0];

assertEqualsCollections(arr[0], deserVals);
}, false);
}

/**
Expand All @@ -3019,7 +3052,7 @@ public void testReadDetachedArray() throws Exception {
* @param action Action to perform on object.
* @throws Exception If failed.
*/
private void testReadDetachObjectProperly(Object obj, IgniteThrowableConsumer<Object> action) throws Exception {
private void testReadDetachObjectProperly(Object obj, IgniteThrowableConsumer<Object> action, boolean deserialize) throws Exception {
BinaryMarshaller marsh = binaryMarshaller();

BinaryHeapOutputStream os = new BinaryHeapOutputStream(1024);
Expand All @@ -3032,7 +3065,7 @@ private void testReadDetachObjectProperly(Object obj, IgniteThrowableConsumer<Ob

BinaryReaderExImpl reader = marsh.binaryMarshaller().reader(is);

Object bObj = reader.readObjectDetached();
Object bObj = reader.readObjectDetached(deserialize);

Arrays.fill(os.array(), (byte)0);

Expand Down Expand Up @@ -5507,27 +5540,6 @@ private static class DecimalMarshalAware extends DecimalReflective implements Bi
}
}

/**
* Wrapper object.
*/
private static class Wrapper {

/** Value. */
private final Object value;

/** Constructor. */
public Wrapper(Object value) {
this.value = value;
}

/**
* @return Value.
*/
public Object getValue() {
return value;
}
}

/**
*/
private static class SingleHandleA {
Expand Down
Loading

0 comments on commit e91cff6

Please sign in to comment.