/** {@inheritDoc} */ @Override public String typeName() { return target().typeName(); }
/** * Default constructor. */ public VisorBinaryMetadata(IgniteBinary binary, BinaryType binaryType) { typeName = binaryType.typeName(); typeId = binary.typeId(typeName); affinityKeyFieldName = binaryType.affinityKeyFieldName(); Collection<String> binaryTypeFields = binaryType.fieldNames(); fields = new ArrayList<>(binaryTypeFields.size()); for (String metaField : binaryTypeFields) fields.add(new VisorBinaryMetadataField(metaField, binaryType.fieldTypeName(metaField), null)); }
/** */ private String binaryTypeName(BinaryObject bObj) { return bObj.type().typeName(); }
@Override public void apply(Object k, Object v) { if (binaryEnable) { if (k instanceof BinaryObject && v instanceof BinaryObject) { BinaryObject key = (BinaryObject)k; BinaryObject val = (BinaryObject)v; String keyType = key.type().typeName(); String valType = val.type().typeName(); if (PersonComplexKey.class.getName().equals(keyType) && Person.class.getName().equals(valType)) prnComplexKeys.add(key); } } else { if (k instanceof PersonComplexKey && v instanceof Person) prnComplexKeys.add(k); else fail("Unexpected entry [key=" + k + ", value=" + v + "]"); } } };
@Override public void examine(IgniteCache cache) { BinaryObject bo = (BinaryObject) cache.get(2); BinaryType type = bo.type(); assertFalse(bo.type().isEnum()); assertEquals(DYNAMIC_TYPE_NAME, type.typeName()); Collection<String> fieldNames = type.fieldNames(); assertEquals(2, fieldNames.size()); assertTrue(fieldNames.contains(DYNAMIC_INT_FIELD_NAME)); assertTrue(fieldNames.contains(DYNAMIC_STR_FIELD_NAME)); } };
@Override public void examine(IgniteCache cache) { BinaryObject bo = (BinaryObject) cache.get(2); BinaryType type = bo.type(); assertFalse(type.isEnum()); assertEquals(DYNAMIC_TYPE_NAME, type.typeName()); Collection<String> fieldNames = type.fieldNames(); assertEquals(1, fieldNames.size()); assertTrue(fieldNames.contains(DYNAMIC_INT_FIELD_NAME)); assertEquals(DYNAMIC_INT_FIELD_NAME, type.affinityKeyFieldName()); } };
@Override public void examine(IgniteCache cache) { BinaryObject enumBo = (BinaryObject) cache.get(4); assertEquals(EnumType.ENUM_VAL_0.ordinal(), enumBo.enumOrdinal()); BinaryType type = enumBo.type(); assertTrue(type.isEnum()); assertEquals(EnumType.class.getName(), type.typeName()); Collection<BinaryObject> enumVals = type.enumValues(); assertEquals(2, enumVals.size()); int i = 0; for (BinaryObject bo : enumVals) { assertEquals(i, bo.enumOrdinal()); assertEquals("ENUM_VAL_" + (i++), bo.enumName()); } } };
/** {@inheritDoc} */ @Override protected void checkMap(Map<Object, Object> map, int... idxs) { assert map != null; assert idxs != null; assertEquals(idxs.length, map.size()); for (int idx : idxs) { Object val = map.get(binary(new Key(idx))); assertTrue(String.valueOf(val), val instanceof BinaryObject); BinaryObject po = (BinaryObject)val; assertEquals(expectedTypeName(Value.class.getName()), po.type().typeName()); assertEquals(new Integer(idx), po.field("idx")); } }
SB buf = new SB(meta.typeName());
/** {@inheritDoc} */ @Override public String toString() { if (!S.INCLUDE_SENSITIVE) return ord >= 0 ? "BinaryEnum" : "null"; // 1. Try deserializing the object. try { Object val = deserialize(); return new SB().a(val).toString(); } catch (Exception ignored) { // No-op. } // 2. Try getting meta. BinaryType type; try { type = rawType(); } catch (Exception ignored) { type = null; } if (type != null) return S.toString(type.typeName(), "ordinal", ord, true); else { if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) return S.toString("BinaryEnum", "clsName", clsName, true, "ordinal", ord, true); else return S.toString("BinaryEnum", "typeId", typeId, true, "ordinal", ord, true); } }
/** */ private void assertBinaryTypesEqual(BinaryType exp, BinaryType actual) { assertEquals(exp.typeId(), actual.typeId()); assertEquals(exp.typeName(), actual.typeName()); assertArrayEquals(exp.fieldNames().toArray(), actual.fieldNames().toArray()); for (String f : exp.fieldNames()) assertEquals(exp.fieldTypeName(f), actual.fieldTypeName(f)); assertEquals(exp.affinityKeyFieldName(), actual.affinityKeyFieldName()); assertEquals(exp.isEnum(), actual.isEnum()); }
/** * @param nodesCnt Number of nodes in grid. */ private void examineStaticMetadata(int nodesCnt) { for (int i = 0; i < nodesCnt; i++) { IgniteCache cache = grid(i).cache(CACHE_NAME).withKeepBinary(); BinaryObject o1 = (BinaryObject) cache.get(0); TestValue1 t1 = o1.deserialize(); assertEquals(0, t1.getValue()); BinaryObject o2 = (BinaryObject) cache.get(1); TestValue2 t2 = o2.deserialize(); assertEquals("value", t2.getValue()); assertEquals(TestValue1.class.getName(), o1.type().typeName()); assertEquals(TestValue2.class.getName(), o2.type().typeName()); assertEquals("val", o1.type().affinityKeyFieldName()); } }
/** * @param expTypeName Type name. * @throws Exception If failed. */ private void checkProperty(String expTypeName) throws Exception { String marshBackup = GridTestProperties.getProperty(MARSH_CLASS_NAME); try { GridTestProperties.setProperty(MARSH_CLASS_NAME, BinaryMarshaller.class.getName()); IgniteBinary binary = startGrid().binary(); BinaryObjectBuilder builder = binary.builder("org.ignite.test.TestClass"); BinaryObject bObj = builder.build(); assertEquals(expTypeName, bObj.type().typeName()); } finally { if (marshBackup != null) GridTestProperties.setProperty(MARSH_CLASS_NAME, marshBackup); } } }
/** * @throws Exception If failed. */ @Test public void testReflection() throws Exception { BinaryType meta = binaries().type(TestObject1.class); assertNotNull(meta); assertEquals(expectedTypeName(TestObject1.class.getName()), meta.typeName()); Collection<String> fields = meta.fieldNames(); assertEquals(7, fields.size()); assertTrue(fields.contains("intVal")); assertTrue(fields.contains("strVal")); assertTrue(fields.contains("arrVal")); assertTrue(fields.contains("obj1Val")); assertTrue(fields.contains("obj2Val")); assertTrue(fields.contains("decVal")); assertTrue(fields.contains("decArrVal")); assertEquals("int", meta.fieldTypeName("intVal")); assertEquals("String", meta.fieldTypeName("strVal")); assertEquals("byte[]", meta.fieldTypeName("arrVal")); assertEquals("Object", meta.fieldTypeName("obj1Val")); assertEquals("Object", meta.fieldTypeName("obj2Val")); assertEquals("decimal", meta.fieldTypeName("decVal")); assertEquals("decimal[]", meta.fieldTypeName("decArrVal")); }
/** */ private void assertBinaryTypesEqual(BinaryType exp, BinaryType actual) { assertEquals(exp.typeId(), actual.typeId()); assertEquals(exp.typeName(), actual.typeName()); assertEquals(exp.fieldNames(), actual.fieldNames()); for (String f : exp.fieldNames()) assertEquals(exp.fieldTypeName(f), actual.fieldTypeName(f)); assertEquals(exp.affinityKeyFieldName(), actual.affinityKeyFieldName()); assertEquals(exp.isEnum(), actual.isEnum()); }
/** * @throws Exception If failed. */ @Test public void testMetaData2() throws Exception { BinaryObjectBuilder builder = builder("org.test.MetaTest2"); builder.setField("objectField", "a", Object.class); BinaryObject bo = builder.build(); BinaryType meta = bo.type(); assertEquals(expectedTypeName("org.test.MetaTest2"), meta.typeName()); assertEquals("Object", meta.fieldTypeName("objectField")); }
/** * @throws Exception If failed. */ @Test public void testBinaryMarshalAware() throws Exception { binaries().toBinary(new TestObject2()); BinaryType meta = binaries().type(TestObject2.class); assertNotNull(meta); assertEquals(expectedTypeName(TestObject2.class.getName()), meta.typeName()); Collection<String> fields = meta.fieldNames(); assertEquals(7, fields.size()); assertTrue(fields.contains("boolVal")); assertTrue(fields.contains("dateVal")); assertTrue(fields.contains("uuidArrVal")); assertTrue(fields.contains("objVal")); assertTrue(fields.contains("mapVal")); assertTrue(fields.contains("decVal")); assertTrue(fields.contains("decArrVal")); assertEquals("boolean", meta.fieldTypeName("boolVal")); assertEquals("Date", meta.fieldTypeName("dateVal")); assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal")); assertEquals("Object", meta.fieldTypeName("objVal")); assertEquals("Map", meta.fieldTypeName("mapVal")); assertEquals("decimal", meta.fieldTypeName("decVal")); assertEquals("decimal[]", meta.fieldTypeName("decArrVal")); }
/** * Checks correct serialization/deserialization of enums in builder. * * @throws Exception If failed. */ @Test public void testEnum() throws Exception { BinaryObjectBuilder builder = newWrapper("TestType"); final TestEnum exp = TestEnum.A; final TestEnum[] expArr = {TestEnum.A, TestEnum.B}; BinaryObject enumObj = builder.setField("testEnum", exp).setField("testEnumArr", expArr).build(); assertEquals(exp, ((BinaryObject)enumObj.field("testEnum")).deserialize()); Assert.assertArrayEquals(expArr, (Object[])deserializeEnumBinaryArray(enumObj.field("testEnumArr"))); builder = newWrapper(enumObj.type().typeName()); enumObj = builder.setField("testEnum", (Object)enumObj.field("testEnum")) .setField("testEnumArr", (Object)enumObj.field("testEnumArr")).build(); assertEquals(exp, ((BinaryObject)enumObj.field("testEnum")).deserialize()); Assert.assertArrayEquals(expArr, (Object[])deserializeEnumBinaryArray(enumObj.field("testEnumArr"))); }