Source:
<code>public void testCopyWhileAppend() throws Exception { <START> deleteState(); <END> mkdirs(SOURCE_PATH + "/1"); touchFile(SOURCE_PATH + "/1/3"); CopyMapper copyMapper = new CopyMapper(); StubContext stubContext = new StubContext(getConfiguration(), null, 0); Mapper<Text, CopyListingFileStatus, Text, Text>.Context context = stubContext.getContext(); copyMapper.setup(context); final Path path = new Path(SOURCE_PATH + "/1/3"); int manyBytes = 100000000; appendFile(path, manyBytes); ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); Runnable task = new Runnable() { public void run() { try { int maxAppendAttempts = 20; int appendCount = 0; while (appendCount < maxAppendAttempts) { appendFile(path, 1000); Thread.sleep(200); appendCount++; } } catch (IOException | InterruptedException e) { e.printStackTrace(); } } }; scheduledExecutorService.schedule(task, 10, TimeUnit.MILLISECONDS); boolean isFileMismatchErrorPresent = false; try { copyMapper.map(new Text(DistCpUtils.getRelativePath(new Path(SOURCE_PATH), path)), new CopyListingFileStatus(cluster.getFileSystem().getFileStatus( path)), context); } catch (Exception ex) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); if (exceptionAsString.contains("Mismatch in length of source") || exceptionAsString.contains("Checksum mismatch")) { isFileMismatchErrorPresent = true; } } Assert.assertFalse(isFileMismatchErrorPresent); scheduledExecutorService.shutdown(); }</code><technical_language>add timeout</technical_language>

Target:
public void testCopyWhileAppend() throws Exception { deleteState(); mkdirs(SOURCE_PATH + "/1"); touchFile(SOURCE_PATH + "/1/3"); CopyMapper copyMapper = new CopyMapper(); StubContext stubContext = new StubContext(getConfiguration(), null, 0); Mapper<Text, CopyListingFileStatus, Text, Text>.Context context = stubContext.getContext(); copyMapper.setup(context); final Path path = new Path(SOURCE_PATH + "/1/3"); int manyBytes = 100000000; appendFile(path, manyBytes); ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); Runnable task = new Runnable() { public void run() { try { int maxAppendAttempts = 20; int appendCount = 0; while (appendCount < maxAppendAttempts) { appendFile(path, 1000); Thread.sleep(200); appendCount++; } } catch (IOException | InterruptedException e) { LOG.error("Exception encountered ", e); Assert.fail("Test failed: " + e.getMessage()); } } }; scheduledExecutorService.schedule(task, 10, TimeUnit.MILLISECONDS); try { copyMapper.map(new Text(DistCpUtils.getRelativePath( new Path(SOURCE_PATH), path)), new CopyListingFileStatus(cluster.getFileSystem().getFileStatus( path)), context); } catch (Exception ex) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); LOG.error("Exception encountered ", ex); if (exceptionAsString.contains(DistCpConstants.LENGTH_MISMATCH_ERROR_MSG) || exceptionAsString.contains(DistCpConstants.CHECKSUM_MISMATCH_ERROR_MSG)) { Assert.fail("Test failed: " + exceptionAsString); } } finally { scheduledExecutorService.shutdown(); } }