You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by tl...@apache.org on 2022/05/18 07:54:46 UTC
[ignite] branch master updated: IGNITE-16318 Fix write empty binary object (#10021)
This is an automated email from the ASF dual-hosted git repository.
tledkov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new f22b5204708 IGNITE-16318 Fix write empty binary object (#10021)
f22b5204708 is described below
commit f22b52047083444dbb5e8cb1f85eb7df6b67f350
Author: Taras Ledkov <tl...@gridgain.com>
AuthorDate: Wed May 18 10:54:40 2022 +0300
IGNITE-16318 Fix write empty binary object (#10021)
---
.../ignite/internal/binary/BinaryWriterExImpl.java | 11 +--
.../internal/binary/BinaryMarshallerSelfTest.java | 90 ++++++++++++++++++++++
2 files changed, 93 insertions(+), 8 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
index 7ad25c28902..a28c0682474 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
@@ -292,11 +292,9 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
useCompactFooter = false;
}
- int finalSchemaId;
int offset;
if (fieldCnt != 0) {
- finalSchemaId = schemaId;
offset = out.position() - start;
// Write the schema.
@@ -318,16 +316,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
}
else {
if (rawOffPos != 0) {
- finalSchemaId = 0;
offset = rawOffPos - start;
// If there is no schema, we are free to write raw offset to schema offset.
flags |= BinaryUtils.FLAG_HAS_RAW;
}
- else {
- finalSchemaId = 0;
- offset = 0;
- }
+ else
+ offset = GridBinaryMarshaller.DFLT_HDR_LEN;
}
// Actual write.
@@ -341,7 +336,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
out.unsafeWriteInt(registered ? typeId : GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
out.unsafePosition(start + GridBinaryMarshaller.TOTAL_LEN_POS);
out.unsafeWriteInt(retPos - start);
- out.unsafeWriteInt(finalSchemaId);
+ out.unsafeWriteInt(schemaId);
out.unsafeWriteInt(offset);
out.unsafePosition(retPos);
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 4431e886bf9..55e08d3640f 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
@@ -1178,6 +1178,36 @@ public class BinaryMarshallerSelfTest extends AbstractBinaryArraysTest {
}
}
+ /** */
+ @Test
+ public void emptyObjectBuilder() throws IgniteCheckedException {
+ BinaryObject emptyBinObj = builder("test_type").build();
+
+ BinaryObjectBuilder bob2 = emptyBinObj.toBuilder();
+
+ // Check any field is null at the empty object.
+ assertNull(bob2.getField("a"));
+
+ // Modify empty object: add field.
+ BinaryObjectImpl o1 = (BinaryObjectImpl)bob2.setField("a", 1).build();
+ BinaryObjectImpl o2 = (BinaryObjectImpl)builder("test_type").setField("a", 1).build();
+
+ // Check that modified empty object and the new object with the sanme field are equals.
+ assertEquals(o1.schemaId(), o2.schemaId());
+ assertEquals(o1, o2);
+ }
+
+ /** */
+ @Test
+ public void emptyObjectBinarylizable() throws IgniteCheckedException {
+ BinaryMarshaller m = binaryMarshaller();
+
+ BinaryObjectBuilder bob = marshal(new ObjectRaw(), m).toBuilder();
+
+ // Check any field is null at the empty object.
+ assertNull(bob.getField("a"));
+ }
+
/**
*
*/
@@ -4155,6 +4185,66 @@ public class BinaryMarshallerSelfTest extends AbstractBinaryArraysTest {
return marsh;
}
+ /**
+ * @return Binary object builder.
+ */
+ protected BinaryObjectBuilder builder(
+ String typeName
+ ) throws IgniteCheckedException {
+ return builder(typeName, null, null, null, null, null);
+ }
+
+ /**
+ * @return Binary object builder.
+ */
+ protected BinaryObjectBuilder builder(
+ String typeName,
+ BinaryNameMapper nameMapper,
+ BinaryIdMapper mapper,
+ BinarySerializer serializer,
+ Collection<BinaryTypeConfiguration> cfgs,
+ Collection<String> excludedClasses
+ ) throws IgniteCheckedException {
+ IgniteConfiguration iCfg = new IgniteConfiguration();
+
+ BinaryConfiguration bCfg = new BinaryConfiguration();
+
+ bCfg.setNameMapper(nameMapper);
+ bCfg.setIdMapper(mapper);
+ bCfg.setSerializer(serializer);
+ bCfg.setCompactFooter(compactFooter());
+
+ bCfg.setTypeConfigurations(cfgs);
+
+ iCfg.setBinaryConfiguration(bCfg);
+ iCfg.setClientMode(false);
+ iCfg.setDiscoverySpi(new TcpDiscoverySpi() {
+ @Override public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException {
+ //No-op.
+ }
+ });
+ iCfg.setSystemViewExporterSpi(new JmxSystemViewExporterSpi());
+
+ BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), iCfg, new NullLogger());
+
+ BinaryMarshaller marsh = new BinaryMarshaller();
+
+ MarshallerContextTestImpl marshCtx = new MarshallerContextTestImpl(null, excludedClasses);
+
+ GridTestKernalContext kernCtx = new GridTestKernalContext(log, iCfg);
+
+ kernCtx.add(new GridSystemViewManager(kernCtx));
+ kernCtx.add(new GridDiscoveryManager(kernCtx));
+
+ marshCtx.onMarshallerProcessorStarted(kernCtx, null);
+
+ marsh.setContext(marshCtx);
+
+ marsh.setBinaryContext(ctx, iCfg);
+
+ return new BinaryObjectBuilderImpl(ctx, typeName);
+ }
+
/**
* @param exp Expected.
* @param act Actual.