use of org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl in project ignite by apache.
the class BinaryObjectBuilderAdditionalSelfTest method testStringArrayModification.
/**
*
*/
public void testStringArrayModification() {
GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
obj.strArr = new String[] { "a", "a", "a" };
BinaryObjectBuilderImpl mutObj = wrap(obj);
String[] arr = mutObj.getField("strArr");
arr[0] = "b";
GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
Assert.assertArrayEquals(new String[] { "b", "a", "a" }, res.strArr);
}
use of org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl in project ignite by apache.
the class BinaryObjectBuilderAdditionalSelfTest method testMapModification.
/**
*
*/
public void testMapModification() {
GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
obj.foo = Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b"));
BinaryObjectBuilderImpl mutObj = wrap(obj);
Map<Object, Object> map = mutObj.getField("foo");
map.put(3, mutObj);
Object rmv = map.remove(1);
assertEquals("a", rmv);
GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
assertEquals(ImmutableMap.of(2, "b", 3, res), res.foo);
}
use of org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl in project ignite by apache.
the class GridCacheUtilsSelfTest method testCacheKeyValidation.
/**
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
public void testCacheKeyValidation() throws IgniteCheckedException {
CU.validateCacheKey("key");
CU.validateCacheKey(1);
CU.validateCacheKey(1L);
CU.validateCacheKey(1.0);
CU.validateCacheKey(new ExtendsClassWithEqualsAndHashCode());
CU.validateCacheKey(new ExtendsClassWithEqualsAndHashCode2());
assertThrowsForInvalidKey(new NoEqualsAndHashCode());
assertThrowsForInvalidKey(new NoEquals());
assertThrowsForInvalidKey(new NoHashCode());
assertThrowsForInvalidKey(new WrongEquals());
BinaryObjectBuilderImpl binBuilder = new BinaryObjectBuilderImpl(binaryContext(), EqualsAndHashCode.class.getName());
BinaryObject binObj = binBuilder.build();
CU.validateCacheKey(binObj);
BinaryObjectBuilderImpl binBuilder2 = new BinaryObjectBuilderImpl((BinaryObjectImpl) binObj);
CU.validateCacheKey(binBuilder2.build());
}
use of org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl in project ignite by apache.
the class BinaryMarshallerSelfTest method testFieldOrderByBuilder.
/**
* The test must be refactored after {@link IgniteSystemProperties#IGNITE_BINARY_SORT_OBJECT_FIELDS}
* is removed.
*
* @throws Exception If failed.
*/
public void testFieldOrderByBuilder() throws Exception {
if (BinaryUtils.FIELDS_SORTED_ORDER)
return;
BinaryMarshaller m = binaryMarshaller();
BinaryObjectBuilder builder = new BinaryObjectBuilderImpl(binaryContext(m), "MyFakeClass");
String[] fieldNames = { "field9", "field8", "field0", "field1", "field2" };
for (String fieldName : fieldNames) builder.setField(fieldName, 0);
BinaryObject binObj = builder.build();
Collection<String> fieldsBin = binObj.type().fieldNames();
assertEquals(fieldNames.length, fieldsBin.size());
int i = 0;
for (String fieldName : fieldsBin) {
assertEquals(fieldNames[i], fieldName);
++i;
}
}
use of org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl in project ignite by apache.
the class BinaryObjectBuilderAdditionalSelfTest method testTimestampArrayOverride.
/**
*
*/
@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
public void testTimestampArrayOverride() {
GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
BinaryObjectBuilderImpl mutableObj = wrap(obj);
Timestamp[] arr = { new Timestamp(100020003) };
mutableObj.setField("foo", arr, Object.class);
GridBinaryTestClasses.TestObjectContainer res = mutableObj.build().deserialize();
assertEquals(Timestamp[].class, res.foo.getClass());
assertTrue(Objects.deepEquals(arr, res.foo));
}
Aggregations