/** * Test IndexBuilder from examples */ @SuppressWarnings("unchecked") @Test public void testIndexBuilder() throws Exception { Configuration configuration = new Configuration(); String[] args = { "tableName", "columnFamily", "column1", "column2" }; IndexBuilder.configureJob(configuration, args); assertEquals("tableName", configuration.get("index.tablename")); assertEquals("tableName", configuration.get(TableInputFormat.INPUT_TABLE)); assertEquals("column1,column2", configuration.get("index.fields")); Map map = new Map(); ImmutableBytesWritable rowKey = new ImmutableBytesWritable(Bytes.toBytes("test")); Mapper<ImmutableBytesWritable, Result, ImmutableBytesWritable, Put>.Context ctx = mock(Context.class); when(ctx.getConfiguration()).thenReturn(configuration); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { ImmutableBytesWritable writer = (ImmutableBytesWritable) invocation.getArguments()[0]; Put put = (Put) invocation.getArguments()[1]; assertEquals("tableName-column1", Bytes.toString(writer.get())); assertEquals("test", Bytes.toString(put.getRow())); return null; } }).when(ctx).write(any(ImmutableBytesWritable.class), any(Put.class)); Result result = mock(Result.class); when(result.getValue(Bytes.toBytes("columnFamily"), Bytes.toBytes("column1"))).thenReturn( Bytes.toBytes("test")); map.setup(ctx); map.map(rowKey, result, ctx); }
/** * Test IndexBuilder from examples */ @SuppressWarnings("unchecked") @Test public void testIndexBuilder() throws Exception { Configuration configuration = new Configuration(); String[] args = { "tableName", "columnFamily", "column1", "column2" }; IndexBuilder.configureJob(configuration, args); assertEquals("tableName", configuration.get("index.tablename")); assertEquals("tableName", configuration.get(TableInputFormat.INPUT_TABLE)); assertEquals("column1,column2", configuration.get("index.fields")); Map map = new Map(); ImmutableBytesWritable rowKey = new ImmutableBytesWritable(Bytes.toBytes("test")); Mapper<ImmutableBytesWritable, Result, ImmutableBytesWritable, Put>.Context ctx = mock(Context.class); when(ctx.getConfiguration()).thenReturn(configuration); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { ImmutableBytesWritable writer = (ImmutableBytesWritable) invocation.getArgument(0); Put put = (Put) invocation.getArgument(1); assertEquals("tableName-column1", Bytes.toString(writer.get())); assertEquals("test", Bytes.toString(put.getRow())); return null; } }).when(ctx).write(any(), any()); Result result = mock(Result.class); when(result.getValue(Bytes.toBytes("columnFamily"), Bytes.toBytes("column1"))).thenReturn( Bytes.toBytes("test")); map.setup(ctx); map.map(rowKey, result, ctx); }