LockableRandomAccessBuffer data = generateData(r, size, bigRAFFactory);
HashResult[] hashes = getHashes(data);
MyCallback cb = new MyCallback();
MyKeysFetchingLocally keys = new MyKeysFetchingLocally();
// Only enough for one segment at a time.
MemoryLimitedJobRunner memoryLimitedJobRunner = new MemoryLimitedJobRunner(9*1024*1024L, 1, executor);
SplitFileInserterStorage storage = new SplitFileInserterStorage(data, size, cb, null,
new ClientMetadata(), false, null, smallRAFFactory, true, baseContext.clone(),
cryptoAlgorithm, cryptoKey, null, hashes, smallBucketFactory, checker,
r, memoryLimitedJobRunner, jobRunner, ticker, keys, false, 0, 0, 0, 0);
executor.waitForIdle();
// Has not encoded anything.
for(SplitFileInserterSegmentStorage segment : storage.segments)
assert(!segment.isFinishedEncoding());
SplitFileInserterStorage resumed = null;
if(storage.crossSegments != null) {
for(int i=0;i<storage.crossSegments.length;i++) {
memoryLimitedJobRunner = new MemoryLimitedJobRunner(9*1024*1024L, 1, executor);
resumed = new SplitFileInserterStorage(storage.getRAF(), data, cb, r,
memoryLimitedJobRunner, jobRunner, ticker, keys, fg, persistentFileTracker, null);
assertEquals(i, countEncodedCrossSegments(resumed));
resumed.start();
// The memoryLimitedJobRunner will only encode one segment at a time.
// Wait for it to encode one segment.
memoryLimitedJobRunner.shutdown();
memoryLimitedJobRunner.waitForShutdown();
executor.waitForIdle();
assertEquals(i+1, countEncodedCrossSegments(resumed));
}
}
for(int i=0;i<storage.segments.length;i++) {
memoryLimitedJobRunner = new MemoryLimitedJobRunner(9*1024*1024L, 1, executor);
resumed = new SplitFileInserterStorage(storage.getRAF(), data, cb, r,
memoryLimitedJobRunner, jobRunner, ticker, keys, fg, persistentFileTracker, null);
assertEquals(i, countEncodedSegments(resumed));
if(storage.crossSegments != null) {
assertEquals(resumed.crossSegments.length, countEncodedCrossSegments(resumed));
assertTrue(resumed.getStatus() == Status.ENCODED_CROSS_SEGMENTS);
}
resumed.start();
// The memoryLimitedJobRunner will only encode one segment at a time.
// Wait for it to encode one segment.
memoryLimitedJobRunner.shutdown();
memoryLimitedJobRunner.waitForShutdown();
executor.waitForIdle();
assertEquals(i+1, countEncodedSegments(resumed));
}
cb.waitForFinishedEncode();