found = storage.segments[i].onGotKey((NodeCHK)key, (CHKBlock)block); } catch (IOException e) { fetcher.failOnDiskError(e);
/** Add a random block that has not been added already or decoded already. * @throws IOException */ private boolean addRandomBlock(SplitFileInserterStorage storage, SplitFileFetcherStorage fetcherStorage, Random random) throws IOException { int segCount = storage.segments.length; boolean[] exhaustedSegments = new boolean[segCount]; for(int i=0;i<segCount;i++) { while(true) { int segNo = random.nextInt(segCount); if(exhaustedSegments[segNo]) continue; SplitFileFetcherSegmentStorage segment = fetcherStorage.segments[segNo]; if(segment.isDecodingOrFinished()) { exhaustedSegments[segNo] = true; break; } while(true) { int blockNo = random.nextInt(segment.totalBlocks()); if(segment.hasBlock(blockNo)) { continue; } ClientCHKBlock block = storage.segments[segNo].encodeBlock(blockNo); boolean success = segment.onGotKey(block.getClientKey().getNodeCHK(), block.getBlock()); assertTrue(success); return true; } } } return false; }
for(int blockNo=0;blockNo<inserterSegment.dataBlockCount;blockNo++) { ClientCHKBlock block = inserterSegment.encodeBlock(blockNo); boolean success = fetcherSegment.onGotKey(block.getClientKey().getNodeCHK(), block.getBlock()); assertTrue(success);
private void testDataBlocksOnly(TestSplitfile test) throws IOException, CHKEncodeException, FetchException, MetadataParseException { StorageCallback cb = test.createStorageCallback(); SplitFileFetcherStorage storage = test.createStorage(cb); SplitFileFetcherSegmentStorage segment = storage.segments[0]; for(int i=0;i<test.checkBlocks.length;i++) { segment.onNonFatalFailure(test.dataBlocks.length+i); } for(int i=0;i<test.dataBlocks.length;i++) { assertFalse(segment.hasStartedDecode()); assertTrue(segment.onGotKey(test.dataKeys[i].getNodeCHK(), test.encodeDataBlock(i))); cb.markDownloadedBlock(i); } cb.checkFailed(); assertTrue(segment.hasStartedDecode()); cb.checkFailed(); waitForDecode(segment); cb.checkFailed(); cb.waitForFinished(); cb.checkFailed(); test.verifyOutput(storage); cb.checkFailed(); storage.finishedFetcher(); cb.checkFailed(); waitForFinished(segment); cb.checkFailed(); cb.waitForFree(storage); cb.checkFailed(); }
assertTrue(segment.onGotKey(test.checkKeys[i].getNodeCHK(), test.encodeCheckBlock(i))); cb.markDownloadedBlock(i + test.dataBlocks.length);
hits[block] = true; assertFalse(segment.hasStartedDecode()); assertTrue(segment.onGotKey(test.getCHK(block), test.encodeBlock(block))); cb.markDownloadedBlock(block);
continue; assertTrue(segment.onGotKey(test.getCHK(block), test.encodeBlock(block))); cb.markDownloadedBlock(block);
ClientCHKBlock block = inserterSegment.encodeBlock(blockNo); assertFalse(fetcherSegment.hasStartedDecode()); boolean success = fetcherSegment.onGotKey(block.getClientKey().getNodeCHK(), block.getBlock()); assertTrue(success); fcb.checkFailed();
hits[block] = true; assertFalse(segment.hasStartedDecode()); assertTrue(segment.onGotKey(test.getCHK(block), test.encodeBlock(block))); cb.markDownloadedBlock(block);
hits[block] = true; assertFalse(segment.hasStartedDecode()); assertTrue(segment.onGotKey(test.getCHK(block), test.encodeBlock(block))); cb.markDownloadedBlock(block); if(i != test.dataBlocks.length-1) {