/** * @param obj Instance of the BinaryObjectImpl to offheap marshalling. * @param marsh Binary marshaller. * @return Instance of BinaryObjectOffheapImpl. */ private BinaryObjectOffheapImpl marshalOffHeap(BinaryObjectImpl obj, BinaryMarshaller marsh) { long ptr = copyOffheap(obj); return new BinaryObjectOffheapImpl(binaryContext(marsh), ptr, 0, obj.array().length); }
/** * @throws Exception If failed. */ @Test public void testPredefinedTypeIds() throws Exception { BinaryMarshaller marsh = binaryMarshaller(); BinaryContext bCtx = binaryContext(marsh); Field field = bCtx.getClass().getDeclaredField("predefinedTypeNames"); field.setAccessible(true); Map<String, Integer> map = (Map<String, Integer>)field.get(bCtx); assertTrue(!map.isEmpty()); for (Map.Entry<String, Integer> entry : map.entrySet()) { int id = entry.getValue(); if (id == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) continue; BinaryClassDescriptor desc = bCtx.descriptorForTypeId(false, entry.getValue(), null, false); assertEquals(desc.typeId(), bCtx.typeId(desc.describedClass().getName())); } }
/** * @throws Exception If failed. */ @Test public void testCustomTypeRegistration() throws Exception { BinaryTypeConfiguration customType = new BinaryTypeConfiguration(Value.class.getName()); BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(customType)); BinaryContext ctx = binaryContext(marsh); int typeId = ctx.typeId(Value.class.getName()); BinaryClassDescriptor descriptor = ctx.descriptorForTypeId(true, typeId, null, false); assertEquals(Value.class, descriptor.describedClass()); assertEquals(true, descriptor.registered()); assertEquals(true, descriptor.userType()); // Custom explicit types must be registered in 'predefinedTypes' in order not to break the interoperability. Field field = ctx.getClass().getDeclaredField("predefinedTypes"); field.setAccessible(true); Map<Integer, BinaryClassDescriptor> map = (Map<Integer, BinaryClassDescriptor>)field.get(ctx); assertTrue(!map.isEmpty()); assertNotNull(map.get(typeId)); // Custom explicit types must NOT be registered in 'predefinedTypeNames'. field = ctx.getClass().getDeclaredField("predefinedTypeNames"); field.setAccessible(true); Map<String, Integer> map2 = (Map<String, Integer>)field.get(ctx); assertTrue(!map2.isEmpty()); assertNull(map2.get(ctx.userTypeName(Value.class.getName()))); }
customType2)); BinaryContext ctx = binaryContext(marsh);
/** * The test must be refactored after {@link IgniteSystemProperties#IGNITE_BINARY_SORT_OBJECT_FIELDS} * is removed. * * @throws Exception If failed. */ @Test public void testFieldOrderByBuilder() throws Exception { if (BinaryUtils.FIELDS_SORTED_ORDER) return; BinaryMarshaller m = binaryMarshaller(); BinaryObjectBuilder builder = new BinaryObjectBuilderImpl(binaryContext(m), "MyFakeClass"); String[] fieldNames = {"field9", "field8", "field0", "field1", "field2"}; for (String fieldName : fieldNames) builder.setField(fieldName, 0); BinaryObject binObj = builder.build(); Collection<String> fieldsBin = binObj.type().fieldNames(); assertEquals(fieldNames.length, fieldsBin.size()); int i = 0; for (String fieldName : fieldsBin) { assertEquals(fieldNames[i], fieldName); ++i; } }
)); BinaryContext ctx = binaryContext(marsh);
)); BinaryContext ctx = binaryContext(marsh);
)); BinaryContext ctx = binaryContext(marsh);
)); BinaryContext ctx = binaryContext(marsh);
/** * @throws IgniteCheckedException If failed. */ @Test public void testThreadLocalArrayReleased() throws Exception { // Checking the writer directly. assertEquals(false, INSTANCE.isAcquired()); BinaryMarshaller marsh = binaryMarshaller(); try (BinaryWriterExImpl writer = new BinaryWriterExImpl(binaryContext(marsh))) { assertEquals(true, INSTANCE.isAcquired()); writer.writeString("Thread local test"); writer.array(); assertEquals(true, INSTANCE.isAcquired()); } // Checking the binary marshaller. assertEquals(false, INSTANCE.isAcquired()); marsh = binaryMarshaller(); marsh.marshal(new SimpleObject()); assertEquals(false, INSTANCE.isAcquired()); marsh = binaryMarshaller(); // Checking the builder. BinaryObjectBuilder builder = new BinaryObjectBuilderImpl(binaryContext(marsh), "org.gridgain.foo.bar.TestClass"); builder.setField("a", "1"); BinaryObject binaryObj = builder.build(); assertEquals(false, INSTANCE.isAcquired()); }
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName()))); BinaryContext ctx = binaryContext(marsh);