@Test
public void testBlob() throws Exception {
LilyClient client = lilyProxy.getLilyServerProxy().getClient();
// Obtain a repository
Repository repository = client.getRepository();
String NS = "org.lilyproject.client.test";
// Create a blob field type and record type
TypeManager typeManager = repository.getTypeManager();
ValueType blobType = typeManager.getValueType("BLOB");
FieldType blobFieldType = typeManager.newFieldType(blobType, new QName(NS, "data"), Scope.VERSIONED);
blobFieldType = typeManager.createFieldType(blobFieldType);
RecordType recordType = typeManager.newRecordType(new QName(NS, "file"));
recordType.addFieldTypeEntry(blobFieldType.getId(), true);
recordType = typeManager.createRecordType(recordType);
// Upload a blob that, based upon the current default config, should end up in HBase
// (> 5000 bytes and < 200000 bytes)
byte[] data = makeBlobData(10000);
Blob blob = new Blob("application/octet-stream", (long) data.length, null);
OutputStream blobStream = repository.getOutputStream(blob);
IOUtils.copy(new ByteArrayInputStream(data), blobStream);
blobStream.close();
assertTrue(blob.getValue() != null);
// Create a record with this blob
Record record = repository.newRecord();
record.setRecordType(new QName(NS, "file"));
record.setField(new QName(NS, "data"), blob);
record = repository.create(record);
}