@Test (timeout=300000) public void testTerminationAskedByReporter() throws IOException, CorruptedLogFileException { generateHLogs(1, 10, -1); FileStatus logfile = fs.listStatus(HLOGDIR)[0]; fs.initialize(fs.getUri(), conf); final AtomicInteger count = new AtomicInteger(); CancelableProgressable localReporter = new CancelableProgressable() { @Override public boolean progress() { count.getAndIncrement(); return false; } }; FileSystem spiedFs = Mockito.spy(fs); Mockito.doAnswer(new Answer<FSDataInputStream>() { public FSDataInputStream answer(InvocationOnMock invocation) throws Throwable { Thread.sleep(1500); // Sleep a while and wait report status invoked return (FSDataInputStream)invocation.callRealMethod(); } }).when(spiedFs).open(Mockito.<Path>any(), Mockito.anyInt()); try { conf.setInt("hbase.splitlog.report.period", 1000); boolean ret = HLogSplitter.splitLogFile( HBASEDIR, logfile, spiedFs, conf, localReporter, null, null); assertFalse("Log splitting should failed", ret); assertTrue(count.get() > 0); } catch (IOException e) { fail("There shouldn't be any exception but: " + e.toString()); } finally { // reset it back to its default value conf.setInt("hbase.splitlog.report.period", 59000); } }
@Test (timeout=300000) public void testTerminationAskedByReporter() throws IOException, CorruptedLogFileException { generateHLogs(1, 10, -1); FileStatus logfile = fs.listStatus(HLOGDIR)[0]; fs.initialize(fs.getUri(), conf); final AtomicInteger count = new AtomicInteger(); CancelableProgressable localReporter = new CancelableProgressable() { @Override public boolean progress() { count.getAndIncrement(); return false; } }; FileSystem spiedFs = Mockito.spy(fs); Mockito.doAnswer(new Answer<FSDataInputStream>() { public FSDataInputStream answer(InvocationOnMock invocation) throws Throwable { Thread.sleep(1500); // Sleep a while and wait report status invoked return (FSDataInputStream)invocation.callRealMethod(); } }).when(spiedFs).open(Mockito.<Path>any(), Mockito.anyInt()); try { conf.setInt("hbase.splitlog.report.period", 1000); boolean ret = HLogSplitter.splitLogFile( HBASEDIR, logfile, spiedFs, conf, localReporter, null, null, null); assertFalse("Log splitting should failed", ret); assertTrue(count.get() > 0); } catch (IOException e) { fail("There shouldn't be any exception but: " + e.toString()); } finally { // reset it back to its default value conf.setInt("hbase.splitlog.report.period", 59000); } }