recordType = typeManager.createRecordType(recordType);
// This is the failure scenario where creating the record fails after reserving the blob
byte[] bytes = new byte[3000];
random.nextBytes(bytes);
Blob blob = writeBlob(bytes, "aMediaType", "testCreate");
IdGeneratorImpl idGeneratorImpl = new IdGeneratorImpl();
RecordId recordId = idGeneratorImpl.newRecordId();
BlobReference blobReference = new BlobReference(blob, recordId, fieldType);
Set<BlobReference> blobs = new HashSet<BlobReference>();
blobs.add(blobReference);
repository.newRecord();
Record record = repository.newRecord();
record.setRecordType(recordType.getName());
record.setField(fieldName, blob);
record = repository.create(record);
// Faking failure
HTableInterface blobIncubatorTable = LilyHBaseSchema.getBlobIncubatorTable(repoSetup.getHbaseTableFactory(), true);
Put put = new Put(blob.getValue());
put.add(LilyHBaseSchema.BlobIncubatorCf.REF.bytes, LilyHBaseSchema.BlobIncubatorColumn.RECORD.bytes, record.getId().toBytes());
put.add(LilyHBaseSchema.BlobIncubatorCf.REF.bytes, LilyHBaseSchema.BlobIncubatorColumn.FIELD.bytes, fieldType.getId().getBytes());
blobIncubatorTable.put(put);
// Give time for the blob to expire
Thread.sleep(60);
BlobIncubatorMonitor monitor = new BlobIncubatorMonitor(repoSetup.getZk(), repoSetup.getHbaseTableFactory(),
repoSetup.getTableManager(), blobManager, typeManager, 50, 0, 0);
monitor.runMonitorOnce();
assertBlobDelete(false, blob);
Get get = new Get(blob.getValue());
Result result = blobIncubatorTable.get(get);
assertTrue(result == null || result.isEmpty());
}