/** {@inheritDoc} */ @Override public boolean matchType(CacheObject val) { if (val instanceof BinaryObject) return ((BinaryObject)val).type().typeId() == typeId; // Value type name can be manually set in QueryEntity to any random value, // also for some reason our conversion from setIndexedTypes sets a full class name // instead of a simple name there, thus we can have a typeId mismatch. // Also, if the type is not in binary format, we always must have it's class available. return val.value(coCtx, false).getClass() == valCls; }
/** */ 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()); } }
/** */ 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()); }
/** * Validate single value. * * @param obj Binary value. * @param val Expected value. */ private void validate(BinaryObject obj, DeclaredBodyEnum val) { assertTrue(obj.type().isEnum()); assertEquals(node1.binary().typeId(DeclaredBodyEnum.class.getName()), obj.type().typeId()); assertEquals(node2.binary().typeId(DeclaredBodyEnum.class.getName()), obj.type().typeId()); assertEquals(val.ordinal(), obj.enumOrdinal()); }
/** * @throws Exception If failed. */ @Test public void testUuidArrayField() throws Exception { BinaryObjectBuilder builder = builder("Class"); UUID[] arr = new UUID[] {UUID.randomUUID(), UUID.randomUUID()}; builder.setField("uuidArrayField", arr); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertTrue(Arrays.equals(arr, po.<UUID[]>field("uuidArrayField"))); }
/** * @throws Exception If failed. */ @Test public void testBuildAndDeserialize() throws Exception { BinaryObjectBuilder builder = builder(Value.class.getName()); builder.setField("i", 1); BinaryObject bo = builder.build(); assertEquals(expectedHashCode(Value.class.getName()), bo.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(bo), bo.hashCode()); assertEquals(1, bo.<Value>deserialize().i); }
/** * @throws Exception If failed. */ @Test public void testByteField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("byteField", (byte)1); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertEquals((byte) 1, po.<Byte>field("byteField").byteValue()); }
/** * @throws Exception If failed. */ @Test public void testShortField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("shortField", (short)1); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertEquals((short)1, po.<Short>field("shortField").shortValue()); }
/** * @throws Exception If failed. */ @Test public void testDoubleArrayField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("doubleArrayField", new double[] {1, 2, 3}); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertTrue(Arrays.equals(new double[] {1, 2, 3}, po.<double[]>field("doubleArrayField"))); }
/** * @throws Exception If failed. */ @Test public void testDecimalArrayField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("decimalArrayField", new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN}); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertTrue(Arrays.equals(new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN}, po.<String[]>field("decimalArrayField"))); }
/** * @throws Exception If failed. */ @Test public void testIntField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("intField", 1); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertEquals(1, po.<Integer>field("intField").intValue()); }
/** * @throws Exception If failed. */ @Test public void testFloatField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("floatField", 1.0f); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertEquals(1.0f, po.<Float>field("floatField").floatValue(), 0); }
/** * @throws Exception If failed. */ @Test public void testDoubleField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("doubleField", 1.0d); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertEquals(1.0d, po.<Double>field("doubleField").doubleValue(), 0); }
/** * @throws Exception If failed. */ @Test public void testByteArrayField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("byteArrayField", new byte[] {1, 2, 3}); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertTrue(Arrays.equals(new byte[] {1, 2, 3}, po.<byte[]>field("byteArrayField"))); }
/** * @throws Exception If failed. */ @Test public void testLongArrayField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("longArrayField", new long[] {1, 2, 3}); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertTrue(Arrays.equals(new long[] {1, 2, 3}, po.<long[]>field("longArrayField"))); }
/** * @throws Exception If failed. */ @Test public void testCharArrayField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("charArrayField", new char[] {1, 2, 3}); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertTrue(Arrays.equals(new char[] {1, 2, 3}, po.<char[]>field("charArrayField"))); }
/** * @throws Exception If failed. */ @Test public void testBooleanField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("booleanField", true); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertTrue(po.<Boolean>field("booleanField")); }
/** * @throws Exception If failed. */ @Test public void testDecimalField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("decimalField", BigDecimal.TEN); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertEquals(BigDecimal.TEN, po.<BigDecimal>field("decimalField")); }
/** * @throws Exception If failed. */ @Test public void testObjectField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("objectField", new Value(1)); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertEquals(1, po.<BinaryObject>field("objectField").<Value>deserialize().i); }
/** * @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")); }