TestWorker r = new TestWorker(testWorkers.size(), startingGun, failureHasOccurred, numberOfIterations,
new TestTask()
{
@Override
public void run() throws Exception {
final BlobId blobId = blobIdsInTheStore.peek();
log("Attempting to read " + blobId);
if (blobId == null) {
return;
}
final Blob blob = underTest.get(blobId);
if (blob == null) {
log("Attempted to obtain blob, but it was deleted:" + blobId);
return;
}
try (InputStream inputStream = blob.getInputStream()) {
readContentAndValidateMetrics(blobId, inputStream, blob.getMetrics());
}
catch (BlobStoreException e) {
// This is normal operation if another thread deletes your blob after you obtain a Blob reference
log("Concurrent deletion suspected while calling blob.getInputStream().", e);
}
}
}
);
testWorkers.add(r);
}
for (int i = 0; i < numberOfDeleters; i++) {
testWorkers
.add(new TestWorker(testWorkers.size(), startingGun, failureHasOccurred, numberOfIterations, new TestTask()
{
@Override
public void run() throws Exception {
final BlobId blobId = blobIdsInTheStore.poll();
if (blobId == null) {
log("deleter: null blob id");
return;
}
underTest.delete(blobId);
}
}));
}
// Shufflers pull blob IDs off the front of the queue and stick them on the back, to make the blobID queue a bit less orderly
for (int i = 0; i < numberOfShufflers; i++) {
testWorkers.add(
new TestWorker(testWorkers.size(), startingGun, failureHasOccurred, numberOfIterations, new TestTask()
{
@Override
public void run() throws Exception {
final BlobId blobId = blobIdsInTheStore.poll();
if (blobId != null) {
blobIdsInTheStore.add(blobId);
}
}
}));