BinaryObject binObj = binary.toBinary(obj); assertBinaryObjectsEqual(refBinObj, binObj); assertBinaryTypesEqual(refBinary.type(typeId), binary.type(typeId)); assertBinaryTypesEqual(refBinary.type(Person.class), binary.type(Person.class)); assertBinaryTypesEqual(refBinary.type(Person.class.getName()), binary.type(Person.class.getName())); BinaryObject enm = binary.buildEnum(Enum.class.getName(), Enum.DEFAULT.ordinal()); assertBinaryObjectsEqual(refEnm, enm); BinaryType enumType = binary.registerEnum(Enum.class.getName(), enumMap); assertBinaryTypesEqual(refEnumType, enumType); assertBinaryObjectsEqual(refEnm, enm);
/** */ private void assertBinaryObjectsEqual(BinaryObject exp, BinaryObject actual) throws Exception { assertBinaryTypesEqual(exp.type(), actual.type()); for (String f : exp.type().fieldNames()) { Object expVal = exp.field(f); Class<?> cls = expVal.getClass(); if (cls.getMethod("equals", Object.class).getDeclaringClass() == cls) assertEquals(expVal, actual.field(f)); } if (exp.type().isEnum()) assertEquals(exp.enumOrdinal(), actual.enumOrdinal()); }
/** * Put/get operations with Ignite Binary Object API */ @Test public void testBinaryObjectPutGet() throws Exception { int key = 1; try (Ignite ignored = Ignition.start(Config.getServerConfiguration())) { try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)) ) { IgniteBinary binary = client.binary(); BinaryObject val = binary.builder("Person") .setField("id", 1, int.class) .setField("name", "Joe", String.class) .build(); ClientCache<Integer, BinaryObject> cache = client.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary(); cache.put(key, val); BinaryObject cachedVal = client.cache(Config.DEFAULT_CACHE_NAME).<Integer, BinaryObject>withKeepBinary().get(key); assertBinaryObjectsEqual(val, cachedVal); } } }