From 59f97db795eea3a35180cc578faae2a8a0cd0368 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Fri, 25 Dec 2020 12:19:46 +0300 Subject: [PATCH 01/11] IGNITE-13897: Bug reproducer. --- .../platform/PlatformDeployServiceTask.java | 19 +++++++++++++++++++ .../Services/IJavaService.cs | 6 ++++++ .../Services/JavaServiceDynamicProxy.cs | 12 ++++++++++++ .../Services/ServiceTypeAutoResolveTest.cs | 16 +++++++++++----- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java index 688b3b125452c..246128f883950 100644 --- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java +++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java @@ -441,6 +441,25 @@ public Address testAddress(Address addr) { return addr; } + /** */ + public int testOverload(Integer count, Employee[] emps) { + assertNotNull(emps); + assertEquals((int)count, emps.length); + + assertEquals("Sarah Connor", emps[0].getFio()); + assertEquals(1, emps[0].getSalary()); + + assertEquals("John Connor", emps[1].getFio()); + assertEquals(2, emps[1].getSalary()); + + return 42; + } + + /** */ + public int testOverload(int first, int second) { + return first + second; + } + /** */ public Employee[] testEmployees(Employee[] emps) { if (emps == null) diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs index 07db779b2c8c4..2ad9bed65f1e0 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/IJavaService.cs @@ -168,6 +168,12 @@ public interface IJavaService /** */ Address testAddress(Address addr); + /** */ + int testOverload(int count, Employee[] emps); + + /** */ + int testOverload(int first, int second); + /** */ Employee[] testEmployees(Employee[] emps); diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs index 41566020355e9..033485863f145 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/JavaServiceDynamicProxy.cs @@ -313,6 +313,18 @@ public Address testAddress(Address addr) return _svc.testAddress(addr); } + /** */ + public int testOverload(int count, Employee[] emps) + { + return _svc.testOverload(count, emps); + } + + /** */ + public int testOverload(int first, int second) + { + return _svc.testOverload(first, second); + } + /** */ public Employee[] testEmployees(Employee[] emps) { diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServiceTypeAutoResolveTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServiceTypeAutoResolveTest.cs index c99a19870604b..e79ed4fa908d7 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServiceTypeAutoResolveTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServiceTypeAutoResolveTest.cs @@ -127,13 +127,19 @@ private void doTestService(IJavaService svc) Assert.AreEqual("127000", addr.Zip); Assert.AreEqual("Moscow Akademika Koroleva 12", addr.Addr); + Employee[] emps = new[] + { + new Employee {Fio = "Sarah Connor", Salary = 1}, + new Employee {Fio = "John Connor", Salary = 2} + }; + + Assert.AreEqual(42, svc.testOverload(2, emps)); + Assert.AreEqual(3, svc.testOverload(1, 2)); + Assert.AreEqual(5, svc.testOverload(3, 2)); + Assert.IsNull(svc.testEmployees(null)); - Employee[] emps = svc.testEmployees(new[] - { - new Employee { Fio = "Sarah Connor", Salary = 1 }, - new Employee { Fio = "John Connor", Salary = 2 } - }); + emps = svc.testEmployees(emps); Assert.NotNull(emps); Assert.AreEqual(1, emps.Length); From da985e953f081042980c0a7e0f54b8f58a478ba0 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Fri, 25 Dec 2020 18:37:23 +0300 Subject: [PATCH 02/11] IGNITE-13897: WIP --- .../ignite/internal/binary/BinaryRawReaderEx.java | 7 +++++++ .../ignite/internal/binary/BinaryReaderExImpl.java | 5 +++++ .../apache/ignite/internal/binary/BinaryUtils.java | 13 +++++++++++-- .../platform/services/PlatformServices.java | 3 ++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawReaderEx.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawReaderEx.java index 603275ecc6809..c1785497c00b9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawReaderEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawReaderEx.java @@ -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; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java index 6011217fa05fc..1169480fc3854 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java @@ -1333,6 +1333,11 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Nullable @Override public Object readObjectDetached() throws BinaryObjectException { + return readObjectDetached(false); + } + + /** {@inheritDoc} */ + @Nullable @Override public Object readObjectDetached(boolean deserialize) throws BinaryObjectException { return BinaryUtils.unmarshal(in, ctx, ldr, this, true); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java index 0b649b4367795..6d1312b321ff9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java @@ -1853,6 +1853,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(); @@ -1871,7 +1880,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); } @@ -1992,7 +2001,7 @@ 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); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java index 21c3d722faabc..e4d4ae3618382 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java @@ -279,7 +279,8 @@ private ServiceDescriptor findDescriptor(String name) { args = new Object[reader.readInt()]; for (int i = 0; i < args.length; i++) - args[i] = reader.readObjectDetached(); + //TODO: check this flag! + args[i] = reader.readObjectDetached(srvKeepBinary); } else args = null; From b95f64ba9bff0d1ed3a2f1256a4f3e2a10a056c5 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Sat, 26 Dec 2020 19:48:37 +0300 Subject: [PATCH 03/11] IGNITE-13897: WIP. Dirty fix of the bug. --- .../internal/binary/BinaryReaderExImpl.java | 2 +- .../ignite/internal/binary/BinaryUtils.java | 4 +-- .../platform/services/PlatformServices.java | 26 +++++++++++++++---- .../platform/utils/PlatformUtils.java | 14 +++++++--- .../binary/BinaryMarshallerSelfTest.java | 18 +++++++++---- 5 files changed, 48 insertions(+), 16 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java index 1169480fc3854..b0bb4f446938e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java @@ -1338,7 +1338,7 @@ float readFloat(int fieldId) throws BinaryObjectException { /** {@inheritDoc} */ @Nullable @Override public Object readObjectDetached(boolean deserialize) throws BinaryObjectException { - return BinaryUtils.unmarshal(in, ctx, ldr, this, true); + return BinaryUtils.unmarshal(in, ctx, ldr, this, true, deserialize); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java index 6d1312b321ff9..d531d04a0d5d0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java @@ -2004,10 +2004,10 @@ public static Object doReadOptimized(BinaryInputStream in, BinaryContext ctx, @N 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); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java index e4d4ae3618382..712f598062639 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java @@ -279,8 +279,7 @@ private ServiceDescriptor findDescriptor(String name) { args = new Object[reader.readInt()]; for (int i = 0; i < args.length; i++) - //TODO: check this flag! - args[i] = reader.readObjectDetached(srvKeepBinary); + args[i] = reader.readObjectDetached(!srvKeepBinary); } else args = null; @@ -671,7 +670,7 @@ private static Method getMethod(Class clazz, String mthdName, Object[] args) thr } if (methods.isEmpty()) - throw new NoSuchMethodException("Could not find proxy method '" + mthdName + "' in class " + clazz); + throw new NoSuchMethodException("Could not find proxy method '" + mthdName + argsStr(args) + "' in class " + clazz); // Filter by param types for (int i = 0; i < methods.size(); i++) @@ -682,9 +681,26 @@ private static Method getMethod(Class clazz, String mthdName, Object[] args) thr return methods.get(0); if (methods.isEmpty()) - throw new NoSuchMethodException("Could not find proxy method '" + mthdName + "' in class " + clazz); + throw new NoSuchMethodException("Could not find proxy method '" + mthdName + argsStr(args) + "' in class " + clazz); - throw new NoSuchMethodException("Ambiguous proxy method '" + mthdName + "' in class " + clazz); + throw new NoSuchMethodException("Ambiguous proxy method '" + mthdName + argsStr(args) + "' in class " + clazz); + } + + /** + * @param args Service method arguments. + * @return String representation of method signature. + */ + private static String argsStr(Object[] args) { + StringBuilder res = new StringBuilder().append('('); + for (int i=0; i 0) + res.append(", "); + + res.append(args[i] == null ? "null" : args[i].getClass().getName()); + } + res.append(')'); + + return res.toString(); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java index 38308229bc85b..d672a38385d96 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.processors.platform.utils; +import java.lang.reflect.Array; import java.lang.reflect.Field; import java.math.BigDecimal; import java.sql.Timestamp; @@ -921,9 +922,9 @@ else if (BinaryUtils.knownCollection(o)) return unwrapKnownCollection((Collection)o); else if (BinaryUtils.knownMap(o)) return unwrapBinariesIfNeeded((Map)o); - else if (o instanceof Object[]) + else if (o instanceof Object[]) { return unwrapBinariesInArray((Object[])o); - else if (o instanceof BinaryObject) + } else if (o instanceof BinaryObject) return ((BinaryObject)o).deserialize(); return o; @@ -989,7 +990,14 @@ private static Collection unwrapKnownCollection(Collection col) * @return Result. */ public static Object[] unwrapBinariesInArray(Object[] arr) { - Object[] res = new Object[arr.length]; + Object[] res; + + Class compType = arr.getClass().getComponentType(); + + if (compType == Object.class) + res = new Object[arr.length]; + else + res = (Object[])Array.newInstance(compType, arr.length); for (int i = 0; i < arr.length; i++) res[i] = unwrapBinary(arr[i]); 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 1c92e8dff4f0d..4419f7e44528e 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 @@ -2969,7 +2969,7 @@ public void testReadDetachedMap() throws Exception { assertTrue(map.containsKey(key)); assertEquals(val, map.get(key)); }); - }); + }, false); } /** @@ -2989,7 +2989,15 @@ public void testReadDetachedCollection() throws Exception { assertTrue(col.contains(val)); }); - }); + }, false); + } + + /** @throws Exception If failed. */ + @Test + public void testReadDetachedTypedArray() throws Exception { + Value[] arr = IntStream.range(0, 1000).mapToObj(Value::new).toArray(Value[]::new); + + testReadDetachObjectProperly(arr, obj -> assertArrayEquals(arr, (Value[])obj), true); } /** @@ -3009,7 +3017,7 @@ public void testReadDetachedArray() throws Exception { assertEquals(arr[i], new Value(val.field("val"))); } - }); + }, false); } /** @@ -3019,7 +3027,7 @@ public void testReadDetachedArray() throws Exception { * @param action Action to perform on object. * @throws Exception If failed. */ - private void testReadDetachObjectProperly(Object obj, IgniteThrowableConsumer action) throws Exception { + private void testReadDetachObjectProperly(Object obj, IgniteThrowableConsumer action, boolean deserialize) throws Exception { BinaryMarshaller marsh = binaryMarshaller(); BinaryHeapOutputStream os = new BinaryHeapOutputStream(1024); @@ -3032,7 +3040,7 @@ private void testReadDetachObjectProperly(Object obj, IgniteThrowableConsumer Date: Sat, 26 Dec 2020 19:50:08 +0300 Subject: [PATCH 04/11] IGNITE-13897: WIP. Dirty fix of the bug. --- .../internal/processors/platform/utils/PlatformUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java index d672a38385d96..9b22656b97dd9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java @@ -922,9 +922,9 @@ else if (BinaryUtils.knownCollection(o)) return unwrapKnownCollection((Collection)o); else if (BinaryUtils.knownMap(o)) return unwrapBinariesIfNeeded((Map)o); - else if (o instanceof Object[]) { + else if (o instanceof Object[]) return unwrapBinariesInArray((Object[])o); - } else if (o instanceof BinaryObject) + else if (o instanceof BinaryObject) return ((BinaryObject)o).deserialize(); return o; From 03b4085f85bb9e0ca47186ed1cc383994e1828d2 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Sat, 26 Dec 2020 19:52:27 +0300 Subject: [PATCH 05/11] IGNITE-13897: WIP. Dirty fix of the bug. --- .../internal/processors/platform/utils/PlatformUtils.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java index 9b22656b97dd9..1c8f51b5dbaab 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java @@ -990,14 +990,9 @@ private static Collection unwrapKnownCollection(Collection col) * @return Result. */ public static Object[] unwrapBinariesInArray(Object[] arr) { - Object[] res; - Class compType = arr.getClass().getComponentType(); - if (compType == Object.class) - res = new Object[arr.length]; - else - res = (Object[])Array.newInstance(compType, arr.length); + Object[] res = (Object[])Array.newInstance(compType, arr.length); for (int i = 0; i < arr.length; i++) res[i] = unwrapBinary(arr[i]); From f096e42f7e565db4dac4f0c7b7e84d50ffefefc5 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Sat, 26 Dec 2020 19:54:50 +0300 Subject: [PATCH 06/11] IGNITE-13897: WIP. Dirty fix of the bug. --- .../platform/services/PlatformServices.java | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java index 712f598062639..47c523d0948cb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java @@ -670,7 +670,7 @@ private static Method getMethod(Class clazz, String mthdName, Object[] args) thr } if (methods.isEmpty()) - throw new NoSuchMethodException("Could not find proxy method '" + mthdName + argsStr(args) + "' in class " + clazz); + throw new NoSuchMethodException("Could not find proxy method '" + mthdName + "' in class " + clazz); // Filter by param types for (int i = 0; i < methods.size(); i++) @@ -681,26 +681,9 @@ private static Method getMethod(Class clazz, String mthdName, Object[] args) thr return methods.get(0); if (methods.isEmpty()) - throw new NoSuchMethodException("Could not find proxy method '" + mthdName + argsStr(args) + "' in class " + clazz); + throw new NoSuchMethodException("Could not find proxy method '" + mthdName + "' in class " + clazz); - throw new NoSuchMethodException("Ambiguous proxy method '" + mthdName + argsStr(args) + "' in class " + clazz); - } - - /** - * @param args Service method arguments. - * @return String representation of method signature. - */ - private static String argsStr(Object[] args) { - StringBuilder res = new StringBuilder().append('('); - for (int i=0; i 0) - res.append(", "); - - res.append(args[i] == null ? "null" : args[i].getClass().getName()); - } - res.append(')'); - - return res.toString(); + throw new NoSuchMethodException("Ambiguous proxy method '" + mthdName + "' in class " + clazz); } /** From ac2deaf1c6789a702de53be155cdc6d0bfdd9fff Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Mon, 28 Dec 2020 11:57:23 +0300 Subject: [PATCH 07/11] IGNITE-13897: Tests fixes. --- .../platform/services/PlatformServices.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java index 47c523d0948cb..7fa4bb92efde2 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java @@ -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; @@ -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(!srvKeepBinary); + args[i] = reader.readObjectDetached(!srvKeepBinary && !svc.isPlatforService()); } else args = null; try { - Object result = ((ServiceProxyHolder)arg).invoke(mthdName, srvKeepBinary, args); + Object result = svc.invoke(mthdName, srvKeepBinary, args); PlatformUtils.writeInvocationResult(writer, result, null); } @@ -559,7 +561,7 @@ public static void convertArrayArgs(Object[] args, Method mtd) { @SuppressWarnings({"unchecked", "rawtypes"}) private static class ServiceProxyHolder extends PlatformAbstractTarget { /** */ - private final Object proxy; + public final Object proxy; /** */ private final Class serviceClass; @@ -610,7 +612,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 (isPlatforService()) return ((PlatformService)proxy).invokeMethod(mthdName, srvKeepBinary, args); else { assert proxy instanceof GridServiceProxy; @@ -715,6 +717,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 isPlatforService() { + return proxy instanceof PlatformService; + } } /** From cf8bc6c00706d3fa37762f65489c491bc3a0fec8 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Mon, 28 Dec 2020 12:01:00 +0300 Subject: [PATCH 08/11] IGNITE-13897: Tests fixes. --- .../processors/platform/services/PlatformServices.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java index 7fa4bb92efde2..52611530c7f4a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java @@ -281,7 +281,7 @@ private ServiceDescriptor findDescriptor(String name) { args = new Object[reader.readInt()]; for (int i = 0; i < args.length; i++) - args[i] = reader.readObjectDetached(!srvKeepBinary && !svc.isPlatforService()); + args[i] = reader.readObjectDetached(!srvKeepBinary && !svc.isPlatformService()); } else args = null; @@ -612,7 +612,7 @@ private ServiceProxyHolder(Object proxy, Class clazz, PlatformContext ctx) { */ public Object invoke(String mthdName, boolean srvKeepBinary, Object[] args) throws IgniteCheckedException, NoSuchMethodException { - if (isPlatforService()) + if (isPlatformService()) return ((PlatformService)proxy).invokeMethod(mthdName, srvKeepBinary, args); else { assert proxy instanceof GridServiceProxy; @@ -719,7 +719,7 @@ private static Class wrap(Class c) { } /** @return {@code True} if service is platform service. */ - public boolean isPlatforService() { + public boolean isPlatformService() { return proxy instanceof PlatformService; } } From 2fd079a577e63781bb65829d5fb82bdaf0589b80 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Mon, 28 Dec 2020 14:59:36 +0300 Subject: [PATCH 09/11] IGNITE-13897: Code review fixes. --- .../internal/processors/platform/services/PlatformServices.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java index 52611530c7f4a..f1836377f0d71 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java @@ -561,7 +561,7 @@ public static void convertArrayArgs(Object[] args, Method mtd) { @SuppressWarnings({"unchecked", "rawtypes"}) private static class ServiceProxyHolder extends PlatformAbstractTarget { /** */ - public final Object proxy; + private final Object proxy; /** */ private final Class serviceClass; From 7b97b457497cf6e348e78f905be74215b310818d Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Tue, 29 Dec 2020 11:08:55 +0300 Subject: [PATCH 10/11] IGNITE-13897: Code review fixes. --- .../ignite/internal/binary/BinaryUtils.java | 2 +- .../platform/utils/PlatformUtils.java | 3 + .../binary/BinaryMarshallerSelfTest.java | 72 ++++++++++--------- 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java index d531d04a0d5d0..22a95fa62b776 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java @@ -2199,7 +2199,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); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java index 1c8f51b5dbaab..823929b2701e4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java @@ -990,6 +990,9 @@ private static Collection unwrapKnownCollection(Collection col) * @return Result. */ public static Object[] unwrapBinariesInArray(Object[] arr) { + if (arr.getClass().getComponentType() != Object.class) + return arr; + Class compType = arr.getClass().getComponentType(); Object[] res = (Object[])Array.newInstance(compType, arr.length); 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 4419f7e44528e..ab2fa88e9075e 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 @@ -85,6 +85,7 @@ import org.apache.ignite.internal.managers.systemview.GridSystemViewManager; import org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi; 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; @@ -2997,26 +2998,50 @@ public void testReadDetachedCollection() throws Exception { public void testReadDetachedTypedArray() throws Exception { Value[] arr = IntStream.range(0, 1000).mapToObj(Value::new).toArray(Value[]::new); - testReadDetachObjectProperly(arr, obj -> assertArrayEquals(arr, (Value[])obj), true); + testReadDetachObjectProperly(arr, obj -> { + assertArrayEquals(arr, (Value[])obj); + + Object[] args = new Object[] {obj}; + + assertTrue(args[0] instanceof Value[]); + + args = PlatformUtils.unwrapBinariesInArray(args); + + assertTrue(args[0] instanceof Value[]); + assertArrayEquals(arr, (Value[])args[0]); + }, true); } - /** - * @throws Exception If failed. - */ + /** @throws Exception If failed. */ @Test - public void testReadDetachedArray() throws Exception { - Value[] arr = IntStream.range(0, 1000).mapToObj(Value::new).toArray(Value[]::new); - + public void testReadArrayOfCollections() throws Exception { + Collection[] arr = new Collection[] { Arrays.asList(new Value(1), new Value(2), new Value(3)) }; testReadDetachObjectProperly(arr, obj -> { - Object[] desArr = (Object[])obj; + assertArrayEquals(arr, (Collection[])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 Collection[]); - assertEquals(arr[i], new Value(val.field("val"))); - } + 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); } @@ -5515,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 { From 9012c944bfcc74d69566f4974b45a644c8fea7d2 Mon Sep 17 00:00:00 2001 From: Nikolay Izhikov Date: Tue, 29 Dec 2020 12:21:48 +0300 Subject: [PATCH 11/11] IGNITE-13897: Code review fixes. --- .../internal/processors/platform/utils/PlatformUtils.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java index 823929b2701e4..a97934fc12466 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java @@ -17,7 +17,6 @@ package org.apache.ignite.internal.processors.platform.utils; -import java.lang.reflect.Array; import java.lang.reflect.Field; import java.math.BigDecimal; import java.sql.Timestamp; @@ -993,9 +992,7 @@ public static Object[] unwrapBinariesInArray(Object[] arr) { if (arr.getClass().getComponentType() != Object.class) return arr; - Class compType = arr.getClass().getComponentType(); - - Object[] res = (Object[])Array.newInstance(compType, arr.length); + Object[] res = new Object[arr.length]; for (int i = 0; i < arr.length; i++) res[i] = unwrapBinary(arr[i]);