use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class BinaryMarshallerSelfTest method testThreadLocalArrayReleased.
/**
* @throws IgniteCheckedException If failed.
*/
public void testThreadLocalArrayReleased() throws Exception {
// Checking the writer directly.
assertEquals(false, INSTANCE.isAcquired());
BinaryMarshaller marsh = binaryMarshaller();
try (BinaryWriterExImpl writer = new BinaryWriterExImpl(binaryContext(marsh))) {
assertEquals(true, INSTANCE.isAcquired());
writer.writeString("Thread local test");
writer.array();
assertEquals(true, INSTANCE.isAcquired());
}
// Checking the binary marshaller.
assertEquals(false, INSTANCE.isAcquired());
marsh = binaryMarshaller();
marsh.marshal(new SimpleObject());
assertEquals(false, INSTANCE.isAcquired());
marsh = binaryMarshaller();
// Checking the builder.
BinaryObjectBuilder builder = new BinaryObjectBuilderImpl(binaryContext(marsh), "org.gridgain.foo.bar.TestClass");
builder.setField("a", "1");
BinaryObject binaryObj = builder.build();
assertEquals(false, INSTANCE.isAcquired());
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class BinaryMarshallerSelfTest method testBinaryCopyStringArray.
/**
* @throws Exception If failed.
*/
public void testBinaryCopyStringArray() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
SimpleObject obj = simpleObject();
BinaryObject po = marshal(obj, marsh);
BinaryObject copy = copy(po, F.<String, Object>asMap("strArr", new String[] { "str1", "str2" }));
assertArrayEquals(new String[] { "str1", "str2" }, copy.<String[]>field("strArr"));
SimpleObject obj0 = copy.deserialize();
assertArrayEquals(new String[] { "str1", "str2" }, obj0.strArr);
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class BinaryObjectBuilderAdditionalSelfTest method testBuildFromObjectWithoutSchema.
/**
* Ensure that object w/o schema can be re-built.
*/
public void testBuildFromObjectWithoutSchema() {
BinaryObjectBuilderImpl binBuilder = wrap(new GridBinaryTestClass2());
BinaryObject binObj = binBuilder.build();
BinaryObjectBuilderImpl binBuilder2 = wrap(binObj);
binBuilder2.build();
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class BinaryObjectBuilderAdditionalSelfTest method testCollectionsSerialization.
/**
* Check that correct type is stored in binary object.
*/
public void testCollectionsSerialization() {
final BinaryObjectBuilder root = newWrapper(BigInteger.class);
final List<Integer> arrList = new ArrayList<>();
arrList.add(Integer.MAX_VALUE);
final List<Integer> linkedList = new LinkedList<>();
linkedList.add(Integer.MAX_VALUE);
final Set<Integer> hashSet = new HashSet<>();
hashSet.add(Integer.MAX_VALUE);
final Set<Integer> linkedHashSet = new LinkedHashSet<>();
linkedHashSet.add(Integer.MAX_VALUE);
final Map<String, String> hashMap = new HashMap<>();
hashMap.put("key", "val");
final Map<String, String> linkedHashMap = new LinkedHashMap<>();
linkedHashMap.put("key", "val");
// collections
root.setField("arrayList", arrList);
root.setField("linkedList", linkedList);
root.setField("hashSet", hashSet);
root.setField("linkedHashSet", linkedHashSet);
root.setField("singletonList", Collections.singletonList(Integer.MAX_VALUE), Collection.class);
root.setField("singletonSet", Collections.singleton(Integer.MAX_VALUE), Collection.class);
// maps
root.setField("hashMap", hashMap);
root.setField("linkedHashMap", linkedHashMap);
root.setField("singletonMap", Collections.singletonMap("key", "val"), Map.class);
// objects
root.setField("asList", Collections.singletonList(Integer.MAX_VALUE));
root.setField("asSet", Collections.singleton(Integer.MAX_VALUE));
root.setField("asMap", Collections.singletonMap("key", "val"));
root.setField("asListHint", Collections.singletonList(Integer.MAX_VALUE), List.class);
root.setField("asSetHint", Collections.singleton(Integer.MAX_VALUE), Set.class);
root.setField("asMapHint", (AbstractMap) Collections.singletonMap("key", "val"), AbstractMap.class);
BinaryObject binaryObj = root.build();
final String COL = "Collection";
final String MAP = "Map";
final String OBJ = "Object";
assert COL.equals(binaryObj.type().fieldTypeName("arrayList"));
assert COL.equals(binaryObj.type().fieldTypeName("linkedList"));
assert COL.equals(binaryObj.type().fieldTypeName("hashSet"));
assert COL.equals(binaryObj.type().fieldTypeName("linkedHashSet"));
assert COL.equals(binaryObj.type().fieldTypeName("linkedHashSet"));
assert COL.equals(binaryObj.type().fieldTypeName("linkedHashSet"));
assert COL.equals(binaryObj.type().fieldTypeName("singletonList"));
assert COL.equals(binaryObj.type().fieldTypeName("singletonSet"));
assert MAP.equals(binaryObj.type().fieldTypeName("singletonMap"));
assert COL.equals(binaryObj.type().fieldTypeName("asList"));
assert OBJ.equals(binaryObj.type().fieldTypeName("asSet"));
assert OBJ.equals(binaryObj.type().fieldTypeName("asMap"));
assert OBJ.equals(binaryObj.type().fieldTypeName("asListHint"));
assert OBJ.equals(binaryObj.type().fieldTypeName("asSetHint"));
assert OBJ.equals(binaryObj.type().fieldTypeName("asMapHint"));
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class BinaryObjectBuilderAdditionalSelfTest method testWrongMetadataNullField2.
/**
*/
public void testWrongMetadataNullField2() {
BinaryObjectBuilder builder = binaries().builder("SomeType1");
builder.setField("dateField", null);
builder.setField("objectField", null, Integer.class);
BinaryObject obj = builder.build();
try {
builder = binaries().builder(obj);
builder.setField("dateField", new Date());
builder.build();
} catch (BinaryObjectException ex) {
assertTrue(ex.getMessage().startsWith("Wrong value has been set"));
}
builder = binaries().builder(obj);
try {
builder.setField("objectField", new GridBinaryTestClasses.Company());
builder.build();
fail("BinaryObjectBuilder accepted wrong metadata");
} catch (BinaryObjectException ex) {
assertTrue(ex.getMessage().startsWith("Wrong value has been set"));
}
}
Aggregations