Search in sources :

Example 1 with StormTestBolt

use of ypf412.storm.StormTestUtil.StormTestBolt in project storm-hbase by ypf412.

the class HBaseSpoutTest method testHBaseSpout.

@Test
public void testHBaseSpout() throws Exception {
    hbaseUtil.cleanupTestDir();
    HBaseTestUtil.writeLocalHBaseXml(hbaseUtil);
    PropConfig hbasePropConfig;
    try {
        hbasePropConfig = new PropConfig("hbase.properties");
    } catch (IOException e1) {
        throw new RuntimeException(e1);
    }
    String tableName = Constants.HBASE_DEFAULT_TABLE_NAME;
    String tableNameStr = hbasePropConfig.getProperty("hbase.table.name");
    if (tableNameStr != null && !tableNameStr.equals(""))
        tableName = tableNameStr;
    String columnFamily = Constants.HBASE_DEFAULT_COLUMN_FAMILY;
    String columnFamilyStr = hbasePropConfig.getProperty("hbase.table.column_family");
    if (columnFamilyStr != null && !columnFamilyStr.equals(""))
        columnFamily = columnFamilyStr;
    HTable htable = hbaseUtil.createTable(Bytes.toBytes(tableName), Bytes.toBytes(columnFamily));
    HBaseTestUtil.loadStreamDataToHBase(ClassLoader.getSystemResource("datasource.txt").getPath(), htable, hbasePropConfig);
    int count = hbaseUtil.countRows(htable);
    assertTrue(count > 0);
    System.out.println("*** load " + count + " rows into hbase test table: " + tableName);
    stormUtil.getConfig().put(Constants.STORM_PROP_CONF_FILE, "storm.properties");
    stormUtil.getConfig().put(Constants.HBASE_PROP_CONF_FILE, "hbase.properties");
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("hbaseSpout", new HBaseSpout());
    StormTestBolt sinkBolt = new StormTestBolt();
    List<Object[]> tuples = StormTestUtil.loadTuples("datasource.txt");
    for (Object[] tuple : tuples) {
        sinkBolt.expectSeq(tuple);
    }
    builder.setBolt("sinkBolt", sinkBolt).fieldsGrouping("hbaseSpout", new Fields("sharding"));
    stormUtil.submitTopology(builder, 5000);
    hbaseUtil.deleteTable(Bytes.toBytes(tableName));
}
Also used : StormTestBolt(ypf412.storm.StormTestUtil.StormTestBolt) TopologyBuilder(backtype.storm.topology.TopologyBuilder) PropConfig(ypf412.storm.util.PropConfig) IOException(java.io.IOException) HTable(org.apache.hadoop.hbase.client.HTable) HBaseSpout(ypf412.storm.spout.HBaseSpout) Fields(backtype.storm.tuple.Fields) Test(org.junit.Test)

Aggregations

TopologyBuilder (backtype.storm.topology.TopologyBuilder)1 Fields (backtype.storm.tuple.Fields)1 IOException (java.io.IOException)1 HTable (org.apache.hadoop.hbase.client.HTable)1 Test (org.junit.Test)1 StormTestBolt (ypf412.storm.StormTestUtil.StormTestBolt)1 HBaseSpout (ypf412.storm.spout.HBaseSpout)1 PropConfig (ypf412.storm.util.PropConfig)1