List<TestRecord> records = splits.get(splitDataIndex).e1;
int itemIndex = 0;
// iterate and validate stuff ...
Text key = new Text();
ArcFileItem value = new ArcFileItem();
while (reader.next(key, value)) {
TestRecord testRecord = records.get(itemIndex++);
// get test key bytes as utf-8 bytes ...
byte[] testKeyBytes = testRecord.url.getBytes(Charset.forName("UTF-8"));
// compare against raw key bytes to validate key is the same (Text's utf-8 mapping code replaces invalid characters
// with ?, which causes our test case (which does use invalid characters to from the key, to break.
Assert.assertTrue(ArcFileReaderTests.compareTo(testKeyBytes,0,testKeyBytes.length,key.getBytes(),0,key.getLength()) == 0);
// retured bytes represent the header(encoded in utf-8), terminated by a \r\n\r\n. The content follows this terminator
// we search for this specific byte pattern to locate start of content, then compare it against source ...
Assert.assertTrue(ArcFileReaderTests.compareTo(testRecord.data,0,testRecord.data.length,value.getContent().getReadOnlyBytes(),value.getContent().getOffset(),value.getContent().getCount()) == 0);
NIOHttpHeaders headers = ArcFileItemUtils.buildHeaderFromArcFileItemHeaders(value.getHeaderItems());
// validate metadata
Assert.assertEquals("text/html",headers.findValue(Constants.ARCFileHeader_ARC_MimeType));
Assert.assertEquals(value.getArcFilePos(),testRecord.streamPos);
Assert.assertEquals(value.getArcFileSize(),testRecord.rawSize);
Assert.assertEquals("test-value", headers.findValue("test"));
Assert.assertEquals(value.getArcFileName(),((FileSplit)split).getPath().getName());
}
reader.close();
Assert.assertEquals(itemIndex,ArcFileReaderTests.BASIC_TEST_RECORD_COUNT);