TableInputAnnotationHandler extends AnnotationHandlerBase { @Override public void process(Annotation annotation, Job job, Object target) throws ToolException { TableInput tableInput = (TableInput)annotation; Configuration conf = job.getConfiguration(); HBaseConfiguration.merge(conf, HBaseConfiguration.create(conf)); try { TableMapReduceUtil.addDependencyJars(job); String tableName = getTableName(tableInput); Scan scan = getScan(tableInput); job.setInputFormatClass(TableInputFormat.class); conf.set(TableInputFormat.INPUT_TABLE, tableName); conf.set(TableInputFormat.SCAN, convertScanToString(scan)); } catch (IOException e) { throw new ToolException(e); } }  @Override boolean accept(Annotation annotation); @Override void process(Annotation annotation, Job job, Object target);  }
@Test public void testProcessDefaults() { try { Annotation annotation = setupDriver(new TableDriverDefaults()); handler.process(annotation, job, null); verify(job, times(1)).setInputFormatClass(TableInputFormat.class); assertThat(conf.get(TableInputFormat.INPUT_TABLE), equalTo(TEST_INPUT)); assertThat(conf.get(TableInputFormat.SCAN), equalTo("AgAAAAAAAf } catch (ToolException | NoSuchFieldException | SecurityException e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testProcessExplicitTable() { try { Annotation annotation = setupDriver(new TableDriverExplicitTable()); handler.process(annotation, job, null); verify(job, times(1)).setInputFormatClass(TableInputFormat.class); assertThat(conf.get(TableInputFormat.INPUT_TABLE), equalTo("my_table")); assertThat(conf.get(TableInputFormat.SCAN), equalTo("AgAAAAAAAf } catch (ToolException | NoSuchFieldException | SecurityException e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testProcessCustomScan() { try { Annotation annotation = setupDriver(new TableDriverWithScan()); handler.process(annotation, job, null); verify(job, times(1)).setInputFormatClass(TableInputFormat.class); assertThat(conf.get(TableInputFormat.INPUT_TABLE), equalTo("test.my_table")); assertThat(conf.get(TableInputFormat.SCAN), equalTo("AgAAAAAAAv } catch (ToolException | NoSuchFieldException | SecurityException e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testConditionalName() { try { Annotation annotation = setupDriver(new TableDriverNameExpr()); handler.process(annotation, job, null); verify(job, times(1)).setInputFormatClass(TableInputFormat.class); assertThat(conf.get(TableInputFormat.INPUT_TABLE), equalTo("myTable")); TableDriverNameExpr.PREFIX = "test"; handler.process(annotation, job, null); assertThat(conf.get(TableInputFormat.INPUT_TABLE), equalTo("test.myTable")); } catch (ToolException | NoSuchFieldException | SecurityException e) { e.printStackTrace(); fail(e.getMessage()); } }