/** * @param builder Builder. * @param desc Descriptor with parameters of BinaryObject to build. * @return BinaryObject built by provided description */ private static BinaryObject newBinaryObject(BinaryObjectBuilder builder, BinaryUpdateDescription desc) { builder.setField(SEQ_NUM_FLD, desc.itemId + 1); builder.setField(desc.fieldName, desc.val); return builder.build(); }
/** * @throws Exception If failed. */ @Test public void testTimestampArrayField() throws Exception { Timestamp ts1 = new Timestamp(new Date().getTime()); Timestamp ts2 = new Timestamp(new Date().getTime() + 1000); ts1.setNanos(1000); ts2.setNanos(2000); Timestamp[] tsArr = new Timestamp[] { ts1, ts2 }; assertTrue(Arrays.equals(tsArr, builder("C").setField("ta", tsArr).build().<Timestamp[]>field("ta"))); }
/** */ public BinaryObject testBinaryObject(BinaryObject o) { if (o == null) return null; return o.toBuilder().setField("field", 15).build(); } }
/** * @throws Exception If failed. */ @Test public void testDateArrayField() throws Exception { Date date1 = new Date(); Date date2 = new Date(date1.getTime() + 1000); Date[] dateArr = new Date[] { date1, date2 }; assertTrue(Arrays.equals(dateArr, builder("C").setField("da", dateArr).build().<Date[]>field("da"))); }
/** * Create key object. * * @param ignite Ignite instance. * @param id ID. * @return Key object. */ protected static BinaryObject key(Ignite ignite, long id) { return ignite.binary().builder(KeyClass.class.getName()).setField(FIELD_KEY, id).build(); }
/** * @throws Exception If failed. */ @Test public void testDateField() throws Exception { Date date = new Date(); assertEquals(date, builder("C").setField("d", date).build().<Date>field("d")); }
/** * */ @Test public void testRemoveFromNewObject() { BinaryObjectBuilder builder = builder(GridBinaryTestClasses.TestObjectAllTypes.class.getName()); builder.setField("str", "a"); builder.removeField("str"); Assert.assertNull(builder.build().<GridBinaryTestClasses.TestObjectAllTypes>deserialize().str); }
/** * @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 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 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 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")); }
/** * @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); }