コード例 #1
0
 @Test
 public void testHBColumnMultiVersion() {
   Double[] testNumbers = new Double[] {3.14159, 2.71828, 0.0};
   for (Double n : testNumbers) {
     // Written as unversioned, read as versioned
     Result result = hbMapper.writeValueAsResult(new CrawlNoVersion("key").setF1(n));
     Crawl versioned = hbMapper.readValue(result, Crawl.class);
     NavigableMap<Long, Double> columnHistory = versioned.getF1();
     assertEquals("Column history size mismatch", 1, columnHistory.size());
     assertEquals(
         String.format(
             "Inconsistency between %s and %s",
             HBColumn.class.getSimpleName(), HBColumnMultiVersion.class.getSimpleName()),
         n,
         columnHistory.lastEntry().getValue());
     // Written as versioned, read as unversioned
     Result result1 =
         hbMapper.writeValueAsResult(
             new Crawl("key")
                 .addF1(Double.MAX_VALUE)
                 .addF1(Double.MAX_VALUE)
                 .addF1(Double.MAX_VALUE)
                 .addF1(n));
     CrawlNoVersion unversioned = hbMapper.readValue(result1, CrawlNoVersion.class);
     Double f1 = unversioned.getF1();
     assertEquals(
         String.format(
             "Inconsistency between %s and %s",
             HBColumnMultiVersion.class.getSimpleName(), HBColumn.class.getSimpleName()),
         n,
         f1);
   }
 }
コード例 #2
0
 @Test
 public void testEmptyPuts() {
   Put nullPut = null, emptyPut = new Put(), putWithBlankRowKey = new Put(new byte[] {});
   Citizen nullCitizen = hbMapper.readValue(nullPut, Citizen.class);
   assertNull("Null Put object should return null", nullCitizen);
   Citizen emptyCitizen = hbMapper.readValue(emptyPut, Citizen.class);
   assertNull("Empty Put object should return null", emptyCitizen);
   assertNull(hbMapper.readValue(putWithBlankRowKey, Citizen.class));
 }
コード例 #3
0
 @Test
 public void testEmptyResults() {
   Result nullResult = null,
       emptyResult = new Result(),
       resultWithBlankRowKey = new Result(new ImmutableBytesWritable(new byte[] {}));
   Citizen nullCitizen = hbMapper.readValue(nullResult, Citizen.class);
   assertNull("Null Result object should return null", nullCitizen);
   Citizen emptyCitizen = hbMapper.readValue(emptyResult, Citizen.class);
   assertNull("Empty Result object should return null", emptyCitizen);
   assertNull(hbMapper.readValue(resultWithBlankRowKey, Citizen.class));
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 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);
 }
コード例 #6
0
 public void testResult(HBRecord p) {
   long start, end;
   start = System.currentTimeMillis();
   Result result = hbMapper.writeValueAsResult(p);
   end = System.currentTimeMillis();
   System.out.printf("Time taken for POJO->Result = %dms%n", end - start);
   start = System.currentTimeMillis();
   Citizen pFromResult = hbMapper.readValue(result, Citizen.class);
   end = System.currentTimeMillis();
   assertEquals("Data mismatch after deserialization from Result", p, pFromResult);
   System.out.printf("Time taken for Result->POJO = %dms%n%n", end - start);
 }
コード例 #7
0
  @Test
  public void testUninstantiatableClass() {
    try {
      hbMapper.readValue(someResult, UninstantiatableClass.class);
      fail(
          "If class can't be instantiated, a "
              + ObjectNotInstantiatableException.class.getName()
              + " was expected");
    } catch (ObjectNotInstantiatableException e) {

    }
  }
コード例 #8
0
 public void testPut(HBRecord p) {
   long start, end;
   start = System.currentTimeMillis();
   Put put = hbMapper.writeValueAsPut(Arrays.asList(p)).get(0);
   end = System.currentTimeMillis();
   System.out.printf("Time taken for POJO->Put = %dms%n", end - start);
   start = System.currentTimeMillis();
   Citizen pFromPut = hbMapper.readValue(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);
 }
コード例 #9
0
 @Test
 public void testInvalidRowKey() {
   Citizen e = TestObjects.validObjs.get(0);
   try {
     hbMapper.readValue("invalid row key", hbMapper.writeValueAsPut(e), Citizen.class);
     fail("Invalid row key should've thrown " + RowKeyCouldNotBeParsedException.class.getName());
   } catch (RowKeyCouldNotBeParsedException ex) {
     System.out.println(
         "For a simulate HBase row with invalid row key, below Exception was thrown as expected:\n"
             + ex.getMessage()
             + "\n");
   }
 }
コード例 #10
0
 @Test
 public void testInvalidClasses() {
   Set<String> exceptionMessages = new HashSet<String>();
   for (Triplet<HBRecord, String, Class<? extends IllegalArgumentException>> p :
       invalidRecordsAndErrorMessages) {
     HBRecord record = p.getValue0();
     Class recordClass = record.getClass();
     assertFalse(
         "Object mapper couldn't detect invalidity of class " + recordClass.getName(),
         hbMapper.isValid(recordClass));
     String errorMessage =
         p.getValue1()
             + " ("
             + recordClass.getName()
             + ") should have thrown an "
             + IllegalArgumentException.class.getName();
     String exMsgObjToResult = null,
         exMsgObjToPut = null,
         exMsgResultToObj = null,
         exMsgPutToObj = null;
     try {
       hbMapper.writeValueAsResult(record);
       fail(errorMessage + " while converting bean to Result");
     } catch (IllegalArgumentException ex) {
       assertEquals(
           "Mismatch in type of exception thrown for " + recordClass.getSimpleName(),
           p.getValue2(),
           ex.getClass());
       exMsgObjToResult = ex.getMessage();
     }
     try {
       hbMapper.writeValueAsPut(record);
       fail(errorMessage + " while converting bean to Put");
     } catch (IllegalArgumentException ex) {
       assertEquals(
           "Mismatch in type of exception thrown for " + recordClass.getSimpleName(),
           p.getValue2(),
           ex.getClass());
       exMsgObjToPut = ex.getMessage();
     }
     try {
       hbMapper.readValue(someResult, recordClass);
       fail(errorMessage + " while converting Result to bean");
     } catch (IllegalArgumentException ex) {
       assertEquals(
           "Mismatch in type of exception thrown for " + recordClass.getSimpleName(),
           p.getValue2(),
           ex.getClass());
       exMsgResultToObj = ex.getMessage();
     }
     try {
       hbMapper.readValue(
           new ImmutableBytesWritable(someResult.getRow()), someResult, recordClass);
       fail(errorMessage + " while converting Result to bean");
     } catch (IllegalArgumentException ex) {
       assertEquals(
           "Mismatch in type of exception thrown for " + recordClass.getSimpleName(),
           p.getValue2(),
           ex.getClass());
     }
     try {
       hbMapper.readValue(somePut, recordClass);
       fail(errorMessage + " while converting Put to bean");
     } catch (IllegalArgumentException ex) {
       assertEquals(
           "Mismatch in type of exception thrown for " + recordClass.getSimpleName(),
           p.getValue2(),
           ex.getClass());
       exMsgPutToObj = ex.getMessage();
     }
     try {
       hbMapper.readValue(new ImmutableBytesWritable(somePut.getRow()), somePut, recordClass);
       fail(errorMessage + " while converting row key and Put combo to bean");
     } catch (IllegalArgumentException ex) {
       assertEquals("Mismatch in type of exception thrown", p.getValue2(), ex.getClass());
     }
     assertEquals(
         "Validation for 'conversion to Result' and 'conversion to Put' differ in code path",
         exMsgObjToResult,
         exMsgObjToPut);
     assertEquals(
         "Validation for 'conversion from Result' and 'conversion from Put' differ in code path",
         exMsgResultToObj,
         exMsgPutToObj);
     assertEquals(
         "Validation for 'conversion from bean' and 'conversion to bean' differ in code path",
         exMsgObjToResult,
         exMsgResultToObj);
     System.out.printf(
         "%s threw below Exception as expected:\n%s\n%n", p.getValue1(), exMsgObjToResult);
     if (!exceptionMessages.add(exMsgObjToPut)) {
       fail("Same error message for different invalid inputs");
     }
   }
 }