public void testResultWithRow(HBRecord p) { long start, end; Result result = hbMapper.writeValueAsResult(Arrays.asList(p)).get(0); ImmutableBytesWritable rowKey = Util.strToIbw(p.composeRowKey()); start = System.currentTimeMillis(); Citizen pFromResult = hbMapper.readValue(rowKey, result, Citizen.class); end = System.currentTimeMillis(); assertEquals("Data mismatch after deserialization from Result+Row", p, pFromResult); System.out.printf("Time taken for Result+Row->POJO = %dms%n%n", end - start); }
public void testPutWithRow(HBRecord p) { long start, end; Put put = hbMapper.writeValueAsPut(p); ImmutableBytesWritable rowKey = Util.strToIbw(p.composeRowKey()); start = System.currentTimeMillis(); Citizen pFromPut = hbMapper.readValue(rowKey, put, Citizen.class); end = System.currentTimeMillis(); assertEquals("Data mismatch after deserialization from Put", p, pFromPut); System.out.printf("Time taken for Put->POJO = %dms%n%n", end - start); }
@Test public void testGetRowKey() { ImmutableBytesWritable rowKey = hbMapper.getRowKey( new HBRecord() { @Override public String composeRowKey() { return "rowkey"; } @Override public void parseRowKey(String rowKey) {} }); assertEquals("Row keys don't match", rowKey, Util.strToIbw("rowkey")); try { hbMapper.getRowKey( new HBRecord() { @Override public String composeRowKey() { return null; } @Override public void parseRowKey(String rowKey) {} }); fail("null row key should've thrown a " + RowKeyCantBeEmptyException.class.getName()); } catch (RowKeyCantBeEmptyException ignored) { } try { hbMapper.getRowKey( new HBRecord() { @Override public String composeRowKey() { throw new RuntimeException("Some blah"); } @Override public void parseRowKey(String rowKey) {} }); fail( "If row key can't be composed, an " + RowKeyCantBeComposedException.class.getName() + " was expected"); } catch (RowKeyCantBeComposedException ignored) { } try { hbMapper.getRowKey(null); fail("If object is null, a " + NullPointerException.class.getName() + " was expected"); } catch (NullPointerException ignored) { } }