/** * Sets class names of binary objects explicitly. * * @param clsNames Class names. * @return {@code this} for chaining. */ public BinaryConfiguration setClassNames(Collection<String> clsNames) { if (typeCfgs == null) typeCfgs = new ArrayList<>(clsNames.size()); for (String clsName : clsNames) typeCfgs.add(new BinaryTypeConfiguration(clsName)); return this; }
/** * @throws Exception If failed. */ @Test public void testWriteReplaceInheritable() throws Exception { ImmutableList<String> obj = ImmutableList.of("This is a test"); BinaryMarshaller marsh = binaryMarshaller(Collections.singleton( new BinaryTypeConfiguration(obj.getClass().getName()) )); BinaryObject po = marshal(obj, marsh); Object des = po.deserialize(); assertEquals(obj, des); }
/** * @throws Exception If failed. */ @Test public void testEnum() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(TestEnum.class.getName()))); assertEquals(TestEnum.B, marshalUnmarshal(TestEnum.B, marsh)); }
/** * */ @Test public void testReadResolve() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Arrays.asList( new BinaryTypeConfiguration(MySingleton.class.getName()), new BinaryTypeConfiguration(SingletonMarker.class.getName()))); BinaryObjectImpl binaryObj = marshal(MySingleton.INSTANCE, marsh); assertTrue(binaryObj.array().length <= 1024); // Check that big string was not serialized. MySingleton singleton = binaryObj.deserialize(); assertSame(MySingleton.INSTANCE, singleton); }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); cfg.setMarshaller(new BinaryMarshaller()); BinaryConfiguration binCfg = new BinaryConfiguration(); BinaryTypeConfiguration binTypCfg1 = new BinaryTypeConfiguration(); BinaryTypeConfiguration binTypCfg2 = new BinaryTypeConfiguration(); binTypCfg1.setTypeName(InnerClass.class.getName()); binTypCfg2.setTypeName(InnerClassBinarylizable.class.getName()); List<BinaryTypeConfiguration> binTypCfgs = new ArrayList<>(); binTypCfgs.add(binTypCfg1); binTypCfgs.add(binTypCfg2); binCfg.setTypeConfigurations(binTypCfgs); cfg.setBinaryConfiguration(binCfg); return cfg; }
/** * * @param nameMapper Name mapper. * @param idMapper ID mapper. * @throws IgniteCheckedException If failed. */ private void checkTypeConfigurations(BinaryNameMapper nameMapper, BinaryIdMapper idMapper) throws IgniteCheckedException { BinaryMarshaller marsh = binaryMarshaller(nameMapper, idMapper, Arrays.asList( new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"), new BinaryTypeConfiguration("unknown.*") )); BinaryContext ctx = binaryContext(marsh); ConcurrentMap<Integer, BinaryInternalMapper> types = U.field(ctx, "typeId2Mapper"); assertEquals(3, types.size()); assertTrue(types.containsKey(typeId(CLASS1_FULL_NAME, nameMapper, idMapper))); assertTrue(types.containsKey(typeId(CLASS2_FULL_NAME, nameMapper, idMapper))); assertTrue(types.containsKey(typeId(INNER_CLASS_FULL_NAME, nameMapper, idMapper))); }
/** * @throws Exception If failed. */ @Test public void testCycleLink() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Arrays.asList( new BinaryTypeConfiguration(CycleLinkObject.class.getName()) )); CycleLinkObject obj = new CycleLinkObject(); obj.self = obj; BinaryObject po = marshal(obj, marsh); CycleLinkObject obj0 = po.deserialize(); assert obj0.self == obj0; }
/** * */ @Test public void testReadResolveOnBinaryAware() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Collections.singletonList( new BinaryTypeConfiguration(MyTestClass.class.getName()))); BinaryObjectImpl binaryObj = marshal(new MyTestClass(), marsh); MyTestClass obj = binaryObj.deserialize(); assertEquals("readResolve", obj.s); }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(); typeCfg.setTypeName(AffinityTestKey.class.getName()); CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(AffinityTestKey.class.getName(), "affKey"); cfg.setCacheKeyConfiguration(keyCfg); BinaryConfiguration bCfg = new BinaryConfiguration(); bCfg.setTypeConfigurations(Collections.singleton(typeCfg)); cfg.setBinaryConfiguration(bCfg); cfg.setMarshaller(new BinaryMarshaller()); return cfg; } }
/** * @throws Exception If failed. */ @Test public void testCustomSerializer() throws Exception { BinaryTypeConfiguration type = new BinaryTypeConfiguration(CustomSerializedObject1.class.getName()); type.setSerializer(new CustomSerializer1()); BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(type)); CustomSerializedObject1 obj1 = new CustomSerializedObject1(10); BinaryObject po1 = marshal(obj1, marsh); assertEquals(20, po1.<CustomSerializedObject1>deserialize().val); }
/** * @throws Exception If failed. */ @Test public void testWriteReplacePrivate() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Collections.singleton( new BinaryTypeConfiguration(TestObject.class.getName()) )); TestObject obj = new TestObject(); BinaryObject po = marshal(obj, marsh); assertEquals(obj, po.deserialize()); assertEquals(obj.val, ((BinaryObject)po.field("val")).deserialize()); }
/** * @throws Exception If failed. */ @Test public void testBinaryCopyIntArray() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Arrays.asList( new BinaryTypeConfiguration(SimpleObject.class.getName()) )); SimpleObject obj = simpleObject(); BinaryObject po = marshal(obj, marsh); BinaryObject copy = copy(po, F.<String, Object>asMap("iArr", new int[] {1, 2, 3})); assertArrayEquals(new int[] {1, 2, 3}, copy.<int[]>field("iArr")); SimpleObject obj0 = copy.deserialize(); assertArrayEquals(new int[] {1, 2, 3}, obj0.iArr); }
/** * @throws Exception If failed. */ @Test public void testBinaryCopyByteArray() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Arrays.asList( new BinaryTypeConfiguration(SimpleObject.class.getName()) )); SimpleObject obj = simpleObject(); BinaryObject po = marshal(obj, marsh); BinaryObject copy = copy(po, F.<String, Object>asMap("bArr", new byte[] {1, 2, 3})); assertArrayEquals(new byte[] {1, 2, 3}, copy.<byte[]>field("bArr")); SimpleObject obj0 = copy.deserialize(); assertArrayEquals(new byte[] {1, 2, 3}, obj0.bArr); }
/** * @throws Exception If failed. */ @Test public void testBinaryCopyDoubleArray() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Arrays.asList( new BinaryTypeConfiguration(SimpleObject.class.getName()) )); SimpleObject obj = simpleObject(); BinaryObject po = marshal(obj, marsh); BinaryObject copy = copy(po, F.<String, Object>asMap("dArr", new double[] {1, 2, 3})); assertArrayEquals(new double[] {1, 2, 3}, copy.<double[]>field("dArr"), 0); SimpleObject obj0 = copy.deserialize(); assertArrayEquals(new double[] {1, 2, 3}, obj0.dArr, 0); }
/** * @throws Exception If failed. */ @Test public void testBinaryCopyString() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Arrays.asList( new BinaryTypeConfiguration(SimpleObject.class.getName()) )); SimpleObject obj = simpleObject(); BinaryObject po = marshal(obj, marsh); BinaryObject copy = copy(po, F.<String, Object>asMap("str", "str3")); assertEquals("str3", copy.<String>field("str")); SimpleObject obj0 = copy.deserialize(); assertEquals("str3", obj0.str); }
/** * @throws Exception If failed. */ @Test public void testBinaryCopyLongArray() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Arrays.asList( new BinaryTypeConfiguration(SimpleObject.class.getName()) )); SimpleObject obj = simpleObject(); BinaryObject po = marshal(obj, marsh); BinaryObject copy = copy(po, F.<String, Object>asMap("lArr", new long[] {1, 2, 3})); assertArrayEquals(new long[] {1, 2, 3}, copy.<long[]>field("lArr")); SimpleObject obj0 = copy.deserialize(); assertArrayEquals(new long[] {1, 2, 3}, obj0.lArr); }
/** * @throws Exception If failed. */ @Test public void testBinaryCopyCharArray() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Arrays.asList( new BinaryTypeConfiguration(SimpleObject.class.getName()) )); SimpleObject obj = simpleObject(); BinaryObject po = marshal(obj, marsh); BinaryObject copy = copy(po, F.<String, Object>asMap("cArr", new char[] {1, 2, 3})); assertArrayEquals(new char[] {1, 2, 3}, copy.<char[]>field("cArr")); SimpleObject obj0 = copy.deserialize(); assertArrayEquals(new char[] {1, 2, 3}, obj0.cArr); }
/** * @throws Exception If failed. */ @Test public void testBinaryCopyStringArray() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Arrays.asList( new BinaryTypeConfiguration(SimpleObject.class.getName()) )); SimpleObject obj = simpleObject(); BinaryObject po = marshal(obj, marsh); BinaryObject copy = copy(po, F.<String, Object>asMap("strArr", new String[] {"str1", "str2"})); assertArrayEquals(new String[] {"str1", "str2"}, copy.<String[]>field("strArr")); SimpleObject obj0 = copy.deserialize(); assertArrayEquals(new String[] {"str1", "str2"}, obj0.strArr); }
/** * @throws Exception If failed. */ @Test public void testKeepDeserialized() throws Exception { BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName()))); BinaryObjectImpl po = marshal(simpleObject(), marsh); CacheObjectContext coCtx = new CacheObjectContext(newContext(), null, null, false, false, true, false, false); assert po.value(coCtx, false) == po.value(coCtx, false); po = marshal(simpleObject(), marsh); assert po.deserialize() != po.deserialize(); }
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration(), new NullLogger()); marsh = new BinaryMarshaller(); IgniteConfiguration iCfg = new IgniteConfiguration(); BinaryConfiguration bCfg = new BinaryConfiguration(); bCfg.setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(TestObject.class.getName()))); bCfg.setCompactFooter(compactFooter()); iCfg.setBinaryConfiguration(bCfg); marsh.setContext(new MarshallerContextTestImpl(null)); IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, iCfg); }