Search in sources :

Example 1 with TestPOJO

use of org.apache.apex.malhar.contrib.util.TestPOJO in project apex-malhar by apache.

the class MemcachePOJOOperatorTest method testMemcacheOutputOperatorInternal.

@SuppressWarnings("unchecked")
@Test
public void testMemcacheOutputOperatorInternal() throws Exception {
    MemcachePOJOOutputOperator operator = new MemcachePOJOOutputOperator();
    operator.setStore(store);
    TableInfo tableInfo = new TableInfo();
    tableInfo.setRowOrIdExpression(TestPOJO.getRowExpression());
    tableInfo.setFieldsInfo(TestPOJO.getFieldsInfo());
    tableInfo.setRowOrIdExpression(TestPOJO.getRowExpression());
    operator.setTableInfo(tableInfo);
    operator.setup(null);
    TupleGenerator<TestPOJO> generator = new TupleGenerator<TestPOJO>(TestPOJO.class);
    for (int i = 0; i < TUPLE_SIZE; ++i) {
        operator.processTuple(generator.getNextTuple());
    }
    readDataAndVerify(operator.getStore(), generator);
}
Also used : TupleGenerator(org.apache.apex.malhar.contrib.util.TupleGenerator) TableInfo(org.apache.apex.malhar.lib.util.TableInfo) TestPOJO(org.apache.apex.malhar.contrib.util.TestPOJO) Test(org.junit.Test)

Example 2 with TestPOJO

use of org.apache.apex.malhar.contrib.util.TestPOJO in project apex-malhar by apache.

the class GeodePOJOOperatorTest method testGeodeOutputOperatorInternal.

@SuppressWarnings("unchecked")
@Test
public void testGeodeOutputOperatorInternal() throws Exception {
    GeodePOJOOutputOperator operator = new GeodePOJOOutputOperator();
    operator.setStore(store);
    TableInfo tableInfo = new TableInfo();
    tableInfo.setRowOrIdExpression(TestPOJO.getRowExpression());
    tableInfo.setFieldsInfo(TestPOJO.getFieldsInfo());
    tableInfo.setRowOrIdExpression(TestPOJO.getRowExpression());
    operator.setTableInfo(tableInfo);
    operator.setup(null);
    TupleGenerator<TestPOJO> generator = new TupleGenerator<TestPOJO>(TestPOJO.class);
    for (int i = 0; i < TUPLE_SIZE; ++i) {
        operator.processTuple(generator.getNextTuple());
    }
    generator.reset();
    for (int i = 0; i < TUPLE_SIZE; ++i) {
        operator.processTuple(generator.getNextTuple());
    }
// readDataAndVerify(operator.getStore(), generator);
}
Also used : TupleGenerator(org.apache.apex.malhar.contrib.util.TupleGenerator) TableInfo(org.apache.apex.malhar.lib.util.TableInfo) TestPOJO(org.apache.apex.malhar.contrib.util.TestPOJO) Test(org.junit.Test)

Example 3 with TestPOJO

use of org.apache.apex.malhar.contrib.util.TestPOJO in project apex-malhar by apache.

the class MemcachePOJOOperatorTest method readDataAndVerify.

public void readDataAndVerify(MemcacheStore store, TupleGenerator<TestPOJO> generator) {
    generator.reset();
    for (int i = 0; i < TUPLE_SIZE; ++i) {
        TestPOJO expected = generator.getNextTuple();
        TestPOJO read = (TestPOJO) store.get(expected.getRow());
        Assert.assertTrue(String.format("expected={%s}, actually={%s}", expected.toString(), read.toString()), expected.completeEquals(read));
    }
}
Also used : TestPOJO(org.apache.apex.malhar.contrib.util.TestPOJO)

Example 4 with TestPOJO

use of org.apache.apex.malhar.contrib.util.TestPOJO in project apex-malhar by apache.

the class HBasePOJOPutOperatorTest method readRecordsAndVerify.

protected void readRecordsAndVerify() {
    int[] rowIds = new int[TEST_SIZE];
    for (int i = 1; i <= TEST_SIZE; ++i) {
        rowIds[i - 1] = 1;
    }
    try {
        HTable table = operator.getStore().getTable();
        Scan scan = new Scan();
        ResultScanner resultScanner = table.getScanner(scan);
        int recordCount = 0;
        while (true) {
            Result result = resultScanner.next();
            if (result == null) {
                break;
            }
            int rowId = Integer.valueOf(Bytes.toString(result.getRow()));
            Assert.assertTrue("rowId=" + rowId + " aut of range", (rowId > 0 && rowId <= TEST_SIZE));
            Assert.assertTrue("the rowId=" + rowId + " already processed.", rowIds[rowId - 1] == 1);
            rowIds[rowId - 1] = 0;
            List<Cell> cells = result.listCells();
            Map<String, byte[]> map = new HashMap<>();
            for (Cell cell : cells) {
                String columnName = Bytes.toString(CellUtil.cloneQualifier(cell));
                byte[] value = CellUtil.cloneValue(cell);
                map.put(columnName, value);
            }
            TestPOJO read = TestPOJO.from(map);
            read.setRowId((long) rowId);
            TestPOJO expected = new TestPOJO(rowId);
            Assert.assertTrue(String.format("expected %s, get %s ", expected.toString(), read.toString()), expected.completeEquals(read));
            recordCount++;
        }
        int missedCount = 0;
        if (recordCount != TEST_SIZE) {
            logger.error("unsaved records: ");
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < TEST_SIZE; ++i) {
                if (rowIds[i] != 0) {
                    sb.append(i + 1).append(", ");
                    missedCount++;
                }
                if (missedCount > 0 && (missedCount % 20 == 0)) {
                    logger.error(sb.toString());
                    sb.delete(0, sb.length());
                }
            }
            logger.error(sb.toString());
            logger.error("End of unsaved records");
        }
        Assert.assertTrue("expected total records = " + TEST_SIZE + ", got " + recordCount + ", missed " + missedCount, recordCount == TEST_SIZE);
    } catch (Exception e) {
        throw new RuntimeException("exception", e);
    }
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) HashMap(java.util.HashMap) TestPOJO(org.apache.apex.malhar.contrib.util.TestPOJO) HTable(org.apache.hadoop.hbase.client.HTable) Result(org.apache.hadoop.hbase.client.Result) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell)

Example 5 with TestPOJO

use of org.apache.apex.malhar.contrib.util.TestPOJO in project apex-malhar by apache.

the class GeodePOJOOperatorTest method readDataAndVerify.

public void readDataAndVerify(GeodeStore store, TupleGenerator<TestPOJO> generator) {
    generator.reset();
    for (int i = 0; i < TUPLE_SIZE; ++i) {
        TestPOJO expected = generator.getNextTuple();
        TestPOJO read = (TestPOJO) store.get(expected.getRow());
        Assert.assertTrue(String.format("expected={%s}, actually={%s}", expected.toString(), read.toString()), expected.completeEquals(read));
    }
}
Also used : TestPOJO(org.apache.apex.malhar.contrib.util.TestPOJO)

Aggregations

TestPOJO (org.apache.apex.malhar.contrib.util.TestPOJO)5 TupleGenerator (org.apache.apex.malhar.contrib.util.TupleGenerator)2 TableInfo (org.apache.apex.malhar.lib.util.TableInfo)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Cell (org.apache.hadoop.hbase.Cell)1 HTable (org.apache.hadoop.hbase.client.HTable)1 Result (org.apache.hadoop.hbase.client.Result)1 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)1 Scan (org.apache.hadoop.hbase.client.Scan)1