plan.add(op);
plan.connect(prj, op);
prj.setResultType(DataType.BYTEARRAY);
TupleFactory tf = TupleFactory.getInstance();
// Plan to test when result type is ByteArray and casting is requested
// for example casting of values coming out of map lookup.
POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);
{
Tuple t = tf.newTuple();
t.append(new DataByteArray((new Integer(r.nextInt())).toString().getBytes()));
plan.attachInput(t);
Integer i = Integer.valueOf(((DataByteArray) t.get(0)).toString());
Result res = op.getNext(i);
if(res.returnStatus == POStatus.STATUS_OK) {
//System.out.println(res.result + " : " + i);
assertEquals(i, res.result);
}
planToTestBACasts.attachInput(t);
res = opWithInputTypeAsBA.getNext(i);
if(res.returnStatus == POStatus.STATUS_OK)
assertEquals(i, res.result);
}
{
Tuple t = tf.newTuple();
t.append(new DataByteArray((new Float(r.nextFloat())).toString().getBytes()));
plan.attachInput(t);
Float i = Float.valueOf(((DataByteArray) t.get(0)).toString());
Result res = op.getNext(i);
if(res.returnStatus == POStatus.STATUS_OK) {
//System.out.println(res.result + " : " + i);
assertEquals(i, res.result);
}
planToTestBACasts.attachInput(t);
res = opWithInputTypeAsBA.getNext(i);
if(res.returnStatus == POStatus.STATUS_OK)
assertEquals(i, res.result);
}
{
Tuple t = tf.newTuple();
t.append(new DataByteArray((new Long(r.nextLong())).toString().getBytes()));
plan.attachInput(t);
Long i = Long.valueOf(((DataByteArray) t.get(0)).toString());
Result res = op.getNext(i);
if(res.returnStatus == POStatus.STATUS_OK) {
//System.out.println(res.result + " : " + i);
assertEquals(i, res.result);
}
planToTestBACasts.attachInput(t);
res = opWithInputTypeAsBA.getNext(i);
if(res.returnStatus == POStatus.STATUS_OK)
assertEquals(i, res.result);
}
{
Tuple t = tf.newTuple();
t.append(new DataByteArray((new Double(r.nextDouble())).toString().getBytes()));
plan.attachInput(t);
Double i = Double.valueOf(((DataByteArray) t.get(0)).toString());
Result res = op.getNext(i);
if(res.returnStatus == POStatus.STATUS_OK) {
//System.out.println(res.result + " : " + i);
assertEquals(i, res.result);
}
planToTestBACasts.attachInput(t);
res = opWithInputTypeAsBA.getNext(i);
if(res.returnStatus == POStatus.STATUS_OK)
assertEquals(i, res.result);
}
{
Tuple t = tf.newTuple();
t.append(new DataByteArray(GenRandomData.genRandString(r).getBytes()));
plan.attachInput(t);
String str = ((DataByteArray) t.get(0)).toString();
Result res = op.getNext(str);
if(res.returnStatus == POStatus.STATUS_OK) {
//System.out.println(res.result + " : " + str);
assertEquals(str, res.result);
}
planToTestBACasts.attachInput(t);
res = opWithInputTypeAsBA.getNext(str);
if(res.returnStatus == POStatus.STATUS_OK)
assertEquals(str, res.result);
}
{
Tuple t = tf.newTuple();
t.append(new DataByteArray(GenRandomData.genRandString(r).getBytes()));
plan.attachInput(t);
DataByteArray dba = (DataByteArray) t.get(0);
Result res = op.getNext(dba);
assertEquals(POStatus.STATUS_ERR, res.returnStatus);
planToTestBACasts.attachInput(t);
res = opWithInputTypeAsBA.getNext(dba);
if(res.returnStatus == POStatus.STATUS_OK)
assertEquals(POStatus.STATUS_ERR, res.returnStatus);
}
{
Tuple t = tf.newTuple();
t.append(new DataByteArray(GenRandomData.genRandString(r).getBytes()));
plan.attachInput(t);
Map map = null;
Result res = op.getNext(map);
//assertEquals(POStatus.STATUS_ERR, res.returnStatus);
assertEquals(POStatus.STATUS_OK, res.returnStatus);
assertEquals(null, res.result);
planToTestBACasts.attachInput(t);
res = opWithInputTypeAsBA.getNext(map);
assertEquals(POStatus.STATUS_OK, res.returnStatus);
assertEquals(null, res.result);
}
{
Tuple t = tf.newTuple();
t.append(new DataByteArray(GenRandomData.genRandString(r).getBytes()));
plan.attachInput(t);
Result res = op.getNext(t);
//assertEquals(POStatus.STATUS_ERR, res.returnStatus);
assertEquals(POStatus.STATUS_OK, res.returnStatus);
assertEquals(null, res.result);
planToTestBACasts.attachInput(t);
res = opWithInputTypeAsBA.getNext(t);
assertEquals(POStatus.STATUS_OK, res.returnStatus);
assertEquals(null, res.result);
}
{
Tuple t = tf.newTuple();
t.append(new DataByteArray(GenRandomData.genRandString(r).getBytes()));
plan.attachInput(t);
DataBag b = null;
Result res = op.getNext(b);
//assertEquals(POStatus.STATUS_ERR, res.returnStatus);