Random r = new Random(12121);
long size = 65536; // Exact multiple, so no last block
LockableRandomAccessBuffer data = generateData(r, size, smallRAFFactory);
HashResult[] hashes = getHashes(data);
NullSendableInsert insert = new NullSendableInsert(false, false);
MyCallback cb = new MyCallback(insert);
InsertContext context = baseContext.clone();
context.maxInsertRetries = 2;
ClientRequestSelector keys = new ClientRequestSelector(true, false, false, null);
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();
cb.waitForFinishedEncode();
assertEquals(storage.segments.length, 1);
SplitFileInserterSegmentStorage segment = storage.segments[0];
assertEquals(segment.dataBlockCount, 2);
assertEquals(segment.checkBlockCount, 3);
assertEquals(segment.crossCheckBlockCount, 0);
assertEquals(storage.getStatus(), Status.ENCODED);
boolean[] chosenBlocks = new boolean[segment.totalBlockCount];
// Choose and fail all blocks.
for(int i=0;i<segment.totalBlockCount;i++) {
BlockInsert chosen = segment.chooseBlock();
assertTrue(chosen != null);
keys.addRunningInsert(chosen);
assertFalse(chosenBlocks[chosen.blockNumber]);
chosenBlocks[chosen.blockNumber] = true;
segment.onFailure(chosen.blockNumber, new InsertException(InsertExceptionMode.ROUTE_NOT_FOUND));
}
BlockInsert chosen = segment.chooseBlock();
assertTrue(chosen == null);
for(int i=0;i<segment.totalBlockCount;i++)
keys.removeRunningInsert(new BlockInsert(segment, i));
// Choose and succeed all blocks.
chosenBlocks = new boolean[segment.totalBlockCount];
for(int i=0;i<segment.totalBlockCount;i++) {
chosen = segment.chooseBlock();
keys.addRunningInsert(chosen);
assertTrue(chosen != null);
assertFalse(chosenBlocks[chosen.blockNumber]);
chosenBlocks[chosen.blockNumber] = true;
segment.onInsertedBlock(chosen.blockNumber, segment.encodeBlock(chosen.blockNumber).getClientKey());
}
cb.waitForSucceededInsert();
assertEquals(storage.getStatus(), Status.SUCCEEDED);
}