use of org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor in project apex-malhar by apache.
the class SerdeFieldsDescriptorTest method simpleTest.
@Test
public void simpleTest() {
Map<String, Type> fieldToType = Maps.newHashMap();
fieldToType.put("a", Type.INTEGER);
fieldToType.put("b", Type.CHAR);
FieldsDescriptor fd = new FieldsDescriptor(fieldToType);
byte[] bytes = SerdeFieldsDescriptor.INSTANCE.serializeObject(fd);
FieldsDescriptor newfd = (FieldsDescriptor) SerdeFieldsDescriptor.INSTANCE.deserializeObject(bytes, new MutableInt(0));
Assert.assertEquals(fd, newfd);
}
use of org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor in project apex-malhar by apache.
the class DimensionsEventTest method eventKeyEqualsHashCodeTest.
@Test
public void eventKeyEqualsHashCodeTest() {
Map<String, Type> fieldToTypeA = Maps.newHashMap();
fieldToTypeA.put("a", Type.LONG);
fieldToTypeA.put("b", Type.STRING);
FieldsDescriptor fdA = new FieldsDescriptor(fieldToTypeA);
GPOMutable gpoA = new GPOMutable(fdA);
gpoA.setField("a", 1L);
gpoA.setField("b", "hello");
EventKey eventKeyA = new EventKey(1, 1, 1, gpoA);
Map<String, Type> fieldToTypeB = Maps.newHashMap();
fieldToTypeB.put("a", Type.LONG);
fieldToTypeB.put("b", Type.STRING);
FieldsDescriptor fdB = new FieldsDescriptor(fieldToTypeB);
GPOMutable gpoB = new GPOMutable(fdB);
gpoB.setField("a", 1L);
gpoB.setField("b", "hello");
EventKey eventKeyB = new EventKey(1, 1, 1, gpoB);
Assert.assertEquals("The two hashcodes should equal", eventKeyA.hashCode(), eventKeyB.hashCode());
Assert.assertEquals("The two event keys should equal", eventKeyA, eventKeyB);
}
use of org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor in project apex-malhar by apache.
the class GPOUtilsTest method validDeserializeTest.
@Test
public void validDeserializeTest() throws Exception {
final Map<String, Type> fieldToType = Maps.newHashMap();
final String tboolean = "tboolean";
final Boolean tbooleanv = true;
final String tchar = "tchar";
final Character tcharv = 'A';
final String tstring = "tstring";
final String tstringv = "hello";
final String tfloat = "tfloat";
final Float tfloatv = 1.0f;
final String tdouble = "tdouble";
final Double tdoublev = 2.0;
final String tbyte = "tbyte";
final Byte tbytev = 50;
final String tshort = "tshort";
final Short tshortv = 1000;
final String tinteger = "tinteger";
final Integer tintegerv = 100000;
final String tlong = "tlong";
final Long tlongv = 10000000000L;
fieldToType.put(tboolean, Type.BOOLEAN);
fieldToType.put(tchar, Type.CHAR);
fieldToType.put(tstring, Type.STRING);
fieldToType.put(tfloat, Type.FLOAT);
fieldToType.put(tdouble, Type.DOUBLE);
fieldToType.put(tbyte, Type.BYTE);
fieldToType.put(tshort, Type.SHORT);
fieldToType.put(tinteger, Type.INTEGER);
fieldToType.put(tlong, Type.LONG);
JSONObject jo = new JSONObject();
jo.put(tboolean, tbooleanv);
jo.put(tchar, tcharv);
jo.put(tstring, tstringv);
jo.put(tfloat, tfloatv);
jo.put(tdouble, tdoublev);
jo.put(tbyte, tbytev);
jo.put(tshort, tshortv);
jo.put(tinteger, tintegerv);
jo.put(tlong, tlongv);
String json = jo.toString(2);
logger.debug("Input json: {}", json);
GPOMutable gpom = GPOUtils.deserialize(new FieldsDescriptor(fieldToType), jo);
Assert.assertEquals("Results must equal", tbooleanv, gpom.getField(tboolean));
Assert.assertEquals("Results must equal", tcharv, gpom.getField(tchar));
Assert.assertEquals("Results must equal", tfloatv, gpom.getField(tfloat));
Assert.assertEquals("Results must equal", tdoublev, gpom.getField(tdouble));
Assert.assertEquals("Results must equal", tbytev, gpom.getField(tbyte));
Assert.assertEquals("Results must equal", tshortv, gpom.getField(tshort));
Assert.assertEquals("Results must equal", tintegerv, gpom.getField(tinteger));
Assert.assertEquals("Results must equal", tlongv, gpom.getField(tlong));
}
use of org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor in project apex-malhar by apache.
the class GPOUtilsTest method simpleSerializeDeserializeTest.
@Test
public void simpleSerializeDeserializeTest() {
final Map<String, Type> fieldToType = Maps.newHashMap();
final String tboolean = "tboolean";
final Boolean tbooleanv = true;
final String tchar = "tchar";
final Character tcharv = 'A';
final String tstring = "tstring";
final String tstringv = "hello";
final String tfloat = "tfloat";
final Float tfloatv = 1.0f;
final String tdouble = "tdouble";
final Double tdoublev = 2.0;
final String tbyte = "tbyte";
final Byte tbytev = 50;
final String tshort = "tshort";
final Short tshortv = 1000;
final String tinteger = "tinteger";
final Integer tintegerv = 100000;
final String tlong = "tlong";
final Long tlongv = 10000000000L;
int totalBytes = // boolean
1 + // char
2 + 4 + // string
tstringv.getBytes().length + // float
4 + // double
8 + // byte
1 + // short
2 + // int
4 + // long
8;
logger.debug("Correct total bytes {}.", totalBytes);
fieldToType.put(tboolean, Type.BOOLEAN);
fieldToType.put(tchar, Type.CHAR);
fieldToType.put(tstring, Type.STRING);
fieldToType.put(tfloat, Type.FLOAT);
fieldToType.put(tdouble, Type.DOUBLE);
fieldToType.put(tbyte, Type.BYTE);
fieldToType.put(tshort, Type.SHORT);
fieldToType.put(tinteger, Type.INTEGER);
fieldToType.put(tlong, Type.LONG);
FieldsDescriptor fd = new FieldsDescriptor(fieldToType);
GPOMutable gpo = new GPOMutable(fd);
gpo.setFieldGeneric(tboolean, tbooleanv);
gpo.setFieldGeneric(tchar, tcharv);
gpo.setField(tstring, tstringv);
gpo.setFieldGeneric(tfloat, tfloatv);
gpo.setFieldGeneric(tdouble, tdoublev);
gpo.setFieldGeneric(tbyte, tbytev);
gpo.setFieldGeneric(tshort, tshortv);
gpo.setFieldGeneric(tinteger, tintegerv);
gpo.setFieldGeneric(tlong, tlongv);
GPOByteArrayList byteArrayList = new GPOByteArrayList();
byte[] gpoByte = GPOUtils.serialize(gpo, byteArrayList);
logger.debug("GPO num bytes: {}", gpoByte.length);
GPOMutable dgpo = GPOUtils.deserialize(fd, gpoByte, new MutableInt(0));
Assert.assertEquals("Values must equal", tbooleanv, dgpo.getField(tboolean));
Assert.assertEquals("Values must equal", tcharv, dgpo.getField(tchar));
Assert.assertEquals("Values must equal", tstringv, dgpo.getField(tstring));
Assert.assertEquals("Values must equal", tfloatv, dgpo.getField(tfloat));
Assert.assertEquals("Values must equal", tdoublev, dgpo.getField(tdouble));
Assert.assertEquals("Values must equal", tbytev, dgpo.getField(tbyte));
Assert.assertEquals("Values must equal", tshortv, dgpo.getField(tshort));
Assert.assertEquals("Values must equal", tintegerv, dgpo.getField(tinteger));
Assert.assertEquals("Values must equal", tlongv, dgpo.getField(tlong));
}
use of org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor in project apex-malhar by apache.
the class GPOUtilsTest method testCornerCaseSerializationLegnth.
@Test
public void testCornerCaseSerializationLegnth() {
final Map<String, Type> fieldToType = Maps.newHashMap();
fieldToType.put("a", Type.OBJECT);
fieldToType.put("b", Type.OBJECT);
GPOMutable gpo = new GPOMutable(new FieldsDescriptor(fieldToType));
int serializeLength = GPOUtils.serializedLength(gpo);
Assert.assertEquals(0, serializeLength);
}
Aggregations