Пример #1
0
  private void writePayload(String messageKey, byte[] messageBodyBytes)
      throws ActionProcessingException {
    if (configuration.getDataStore().equals(DataStore.CASSANDRA)) {
      ColumnFamilyUpdater<String, String> updater = cfTemplate.createUpdater(messageKey);
      updater.setByteArray("body", messageBodyBytes);
      updater.setLong("timestamp", System.currentTimeMillis());

      try {
        cfTemplate.update(updater);
      } catch (HectorException ex) {
        throw new ActionProcessingException(
            "Got HectorException writing " + "message to data storage: " + ex.getMessage());
      }
    } else if (configuration.getDataStore().equals(DataStore.HBASE)) {
      try {
        // TODO need to write timestamp too?
        messagePersister.writeMessage(messageKey, messageBodyBytes);
      } catch (HBaseException ex) {
        throw new ActionProcessingException(
            "Got HBaseException writing " + "message to data storage: " + ex.getMessage());
      }
    }
  }
Пример #2
0
  /**
   * IMPORTANT - cannot run this test two times in a row without disabling and dropping the test
   * table.
   *
   * @throws HBaseException
   */
  @Test
  public void createTable() throws HBaseException {
    String testCF = "testCF";
    String testDataVal = "This is some data.";
    String testTable = "testTable";
    String testField = "testField";
    String testKey = "testKey";

    List<String> colFamilies = new ArrayList<String>();
    colFamilies.add(testCF);

    HBaseFacade hbs = new HBaseFacade();
    try {
      hbs.createTable(testTable, colFamilies);
    } catch (HBaseException ex) {
      if (ex.getCause() instanceof TableExistsException) {
        System.err.println(
            "Cannot test createTable because the " + testTable + " table already exists.");
        return;
      } else {
        throw ex;
      }
    }

    Map<String, Map<String, byte[]>> testData = new HashMap<String, Map<String, byte[]>>();

    Map<String, byte[]> dataCells1 = new HashMap<String, byte[]>();
    dataCells1.put(testField, testDataVal.getBytes());
    testData.put(colFamilies.get(0), dataCells1);
    hbs.addRow(testTable, testKey, testData);

    testData = hbs.readRow(testTable, testKey, colFamilies);
    assertTrue(
        Arrays.equals(testData.get(colFamilies.get(0)).get(testField), testDataVal.getBytes()));

    hbs.removeRow(testTable, testKey);
  }