Random r = new Random(0xb395f44d);
testCancelAlt(r, CHKBlock.DATA_LENGTH*128*21);
}
private void testCancelAlt(Random r, long size) throws IOException, InsertException {
BarrierRandomAccessBuffer data = new BarrierRandomAccessBuffer(generateData(r, size, smallRAFFactory));
HashResult[] hashes = getHashes(data);
data.pause();
MyCallback cb = new MyCallback();
InsertContext context = baseContext.clone();
context.earlyEncode = true;
KeysFetchingLocally keys = new MyKeysFetchingLocally();
SplitFileInserterStorage storage = new SplitFileInserterStorage(data, size, cb, null,
new ClientMetadata(), false, null, smallRAFFactory, false, context,
cryptoAlgorithm, cryptoKey, null, hashes, smallBucketFactory, checker,
r, memoryLimitedJobRunner, jobRunner, ticker, keys, false, 0, 0, 0, 0);
storage.start();
assertEquals(storage.getStatus(), Status.STARTED);
if(storage.crossSegments != null)
assertTrue(allCrossSegmentsEncoding(storage));
else
assertTrue(allSegmentsEncoding(storage));
SplitFileInserterSegmentStorage segment = storage.segments[0];
assertTrue(memoryLimitedJobRunner.getRunningThreads() > 0);
segment.onFailure(0, new InsertException(InsertExceptionMode.INTERNAL_ERROR));
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
// Ignore.
}
data.waitForWaiting();
assertFalse(cb.hasFailed()); // Callback must not have been called yet.
data.proceed(); // Now it will complete encoding, and then report in, and then fail.
try {
cb.waitForFinishedEncode();
assertFalse(true); // Should have failed now.
} catch (InsertException e) {
if(storage.segments.length > 2) {