/** {@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; }
/** * 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 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); }
/** */ 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()); }
/** * @throws Exception If failed. */ @Test public void testLongField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("longField", 1L); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertEquals(1L, po.<Long>field("longField").longValue()); }
/** * @throws Exception If failed. */ @Test public void testCharField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("charField", (char)1); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertEquals((char)1, po.<Character>field("charField").charValue()); }
/** * @throws Exception If failed. */ @Test public void testShortArrayField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("shortArrayField", new short[] {1, 2, 3}); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertTrue(Arrays.equals(new short[] {1, 2, 3}, po.<short[]>field("shortArrayField"))); }
/** * @throws Exception If failed. */ @Test public void testIntArrayField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("intArrayField", new int[] {1, 2, 3}); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertTrue(Arrays.equals(new int[] {1, 2, 3}, po.<int[]>field("intArrayField"))); }
/** * @throws Exception If failed. */ @Test public void testFloatArrayField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("floatArrayField", new float[] {1, 2, 3}); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertTrue(Arrays.equals(new float[] {1, 2, 3}, po.<float[]>field("floatArrayField"))); }
/** * @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 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 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 testStringField() throws Exception { BinaryObjectBuilder builder = builder("Class"); builder.setField("stringField", "str"); BinaryObject po = builder.build(); assertEquals(expectedHashCode("Class"), po.type().typeId()); assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), po.hashCode()); assertEquals("str", po.<String>field("stringField")); }
/** * @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")); }
/** */ 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 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); }