use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class IgniteBinaryObjectFieldsQuerySelfTest method checkQuery.
/**
* @throws Exception If failed.
*/
private void checkQuery(CacheMode cacheMode, CacheAtomicityMode atomicity) throws Exception {
IgniteCache<Object, Object> cache = grid(GRID_CNT - 1).getOrCreateCache(cache(cacheMode, atomicity));
try {
populate(cache);
QueryCursor<Cache.Entry<Object, Object>> cur = cache.query(new SqlQuery("Person", "order " + "by id asc"));
List<Cache.Entry<Object, Object>> all = cur.getAll();
assertEquals(100, all.size());
for (int i = 0; i < 100; i++) {
Object person = all.get(i).getValue();
assertEquals(Integer.valueOf(i), U.field(person, "id"));
assertEquals("person-" + i, U.field(person, "name"));
assertEquals("person-last-" + i, U.field(person, "lastName"));
assertEquals((double) (i * 25), U.field(person, "salary"));
}
int max = 49;
// Check local scan query with keepBinary flag set.
ScanQuery<BinaryObject, BinaryObject> scanQry = new ScanQuery<>(new PersonKeyFilter(max));
QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> curs = grid(GRID_CNT - 1).cache(DEFAULT_CACHE_NAME).withKeepBinary().query(scanQry);
List<Cache.Entry<BinaryObject, BinaryObject>> records = curs.getAll();
assertEquals(50, records.size());
for (Cache.Entry<BinaryObject, BinaryObject> entry : records) {
BinaryObject key = entry.getKey();
assertTrue(key.<Integer>field("id") <= max);
assertEquals(PERSON_KEY_CLS_NAME, key.deserialize().getClass().getName());
}
} finally {
grid(GRID_CNT - 1).cache(DEFAULT_CACHE_NAME).removeAll();
grid(GRID_CNT - 1).destroyCache(DEFAULT_CACHE_NAME);
}
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class BinaryMarshallerSelfTest method testBinaryCopyString.
/**
* @throws Exception If failed.
*/
public void testBinaryCopyString() 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("str", "str3"));
assertEquals("str3", copy.<String>field("str"));
SimpleObject obj0 = copy.deserialize();
assertEquals("str3", obj0.str);
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class BinaryMarshallerSelfTest method testCustomSerializer.
/**
* @throws Exception If failed.
*/
public void testCustomSerializer() throws Exception {
BinaryTypeConfiguration type = new BinaryTypeConfiguration(CustomSerializedObject1.class.getName());
type.setSerializer(new CustomSerializer1());
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(type));
CustomSerializedObject1 obj1 = new CustomSerializedObject1(10);
BinaryObject po1 = marshal(obj1, marsh);
assertEquals(20, po1.<CustomSerializedObject1>deserialize().val);
}
use of org.apache.ignite.binary.BinaryObject in project ignite by apache.
the class BinaryFieldsAbstractSelfTest method check0.
/**
* Internal check routine.
*
* @param fieldName Field name.
* @param ctx Context.
* @param exists Whether field should exist.
* @throws Exception If failed.
*/
private void check0(String fieldName, TestContext ctx, boolean exists) throws Exception {
Object val = ctx.field.value(ctx.portObj);
if (exists) {
assertTrue(ctx.field.exists(ctx.portObj));
Object expVal = U.field(ctx.obj, fieldName);
if (val instanceof BinaryObject)
val = ((BinaryObject) val).deserialize();
if (val != null && val.getClass().isArray()) {
assertNotNull(expVal);
if (val instanceof byte[])
assertTrue(Arrays.equals((byte[]) expVal, (byte[]) val));
else if (val instanceof boolean[])
assertTrue(Arrays.equals((boolean[]) expVal, (boolean[]) val));
else if (val instanceof short[])
assertTrue(Arrays.equals((short[]) expVal, (short[]) val));
else if (val instanceof char[])
assertTrue(Arrays.equals((char[]) expVal, (char[]) val));
else if (val instanceof int[])
assertTrue(Arrays.equals((int[]) expVal, (int[]) val));
else if (val instanceof long[])
assertTrue(Arrays.equals((long[]) expVal, (long[]) val));
else if (val instanceof float[])
assertTrue(Arrays.equals((float[]) expVal, (float[]) val));
else if (val instanceof double[])
assertTrue(Arrays.equals((double[]) expVal, (double[]) val));
else {
Object[] expVal0 = (Object[]) expVal;
Object[] val0 = (Object[]) val;
assertEquals(expVal0.length, val0.length);
for (int i = 0; i < expVal0.length; i++) {
Object expItem = expVal0[i];
Object item = val0[i];
if (item instanceof BinaryObject)
item = ((BinaryObject) item).deserialize();
assertEquals(expItem, item);
}
}
} else
assertEquals(expVal, val);
} else {
assertFalse(ctx.field.exists(ctx.portObj));
assert val == null;
}
}
use of org.apache.ignite.binary.BinaryObject 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;
}
}
Aggregations