????hadoop????????mock????????
???????????? ???????[ 2012/12/26 10:42:44 ] ????????
????????????????????????????????????main_process??????????????????mock??????????????????????????????????
????1?????????private????
????2????main_process??????????????setup????????????????и?????????????????map??????????????????????mock???????mock setup?????
????3????setup?????У???????HTable???????????????????zookeeper??hbase???????????????mock HTable??
????4????setup?????У?????????Configuration??????????mock??
????5????setup?????У????и?????Counter??????????new??????????????????protected??????????涼mock??????£????????mock Counter??
????6????main_process?????У??????????HTable????????????????????mock??HTable?????????????mock get????????????????ò??????
???????????????????????mock??Context?????????????????????????????Context?????????????????????????????????mock???????????????????????????????????????????????????
????????????????
??????????????????mock??????????
????1??Private???????????????????????????????public int mainProcess???????÷??????????main_process????????????????÷???????á????PowerMock?????mock??з?????????????????????????????????
????2???????powermock???????????????????
@RunWith(PowerMockRunner.class)
@PrepareForTest({ ShopScanMap.class })
public class TestMockito {
@Test
public void test01() throws Exception {…}
??????setup?????漰????????????????????????mock
Mapper.Context context = mock(Mapper.Context.class);
Counter counter = mock(Counter.class);
Configuration config = mock(Configuration.class);
????3????HTable????mock?????????shop_info??????????????????mock????thenReturn??????new????????mock???HTable????PowerMockito????????????????whenNew???????new???????withArguments????????????????thenReturn???????????????
HTable shop_info = PowerMockito.mock(HTable.class);
PowerMockito.whenNew(HTable.class)
.withArguments(config?? "sp_shopinfo".getBytes())
.thenReturn(shop_info);
????4?????setup?????е?????getConfiguration?????????????????mock???????????????????????
when(context.getConfiguration()).thenReturn(config);
????5??????getConfiguration??????????????????????????????????????????????????????????????з????????????
when(context.getCounter("Statistics"?? "sp_bmw_shops")).thenReturn(counter);
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11