use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class InMemoryDataRecordTest method testGetInstance.
@Test
public void testGetInstance() throws Exception {
int length = 400;
byte[] data = new byte[length];
new Random().nextBytes(data);
DataRecord dr = InMemoryDataRecord.getInstance(data);
assertTrue(InMemoryDataRecord.isInstance(dr.getIdentifier().toString()));
DataRecord dr2 = InMemoryDataRecord.getInstance(dr.getIdentifier().toString());
assertTrue(IOUtils.contentEquals(dr.getStream(), dr2.getStream()));
assertTrue(IOUtils.contentEquals(dr.getStream(), new ByteArrayInputStream(data)));
assertEquals(length, dr.getLength());
assertEquals(dr2.getLength(), dr.getLength());
assertEquals(dr, dr2);
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class AbstractDataStoreTest method assertReference.
/**
* Assert inputstream read from reference.
*/
protected void assertReference(byte[] expected, String reference, DataStore store) throws Exception {
DataRecord record = store.getRecordFromReference(reference);
assertNotNull(record);
Assert.assertEquals(expected.length, record.getLength());
InputStream stream = record.getStream();
try {
assertTrue("binary not equal", org.apache.commons.io.IOUtils.contentEquals(new ByteArrayInputStream(expected), stream));
} finally {
stream.close();
}
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class AbstractDataStoreTest method doGetRecordTest.
/**
* Test {@link DataStore#getRecord(DataIdentifier)} and assert length and
* inputstream.
*/
protected void doGetRecordTest() throws Exception {
byte[] data = new byte[dataLength];
randomGen.nextBytes(data);
DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
rec = ds.getRecord(rec.getIdentifier());
Assert.assertEquals(data.length, rec.getLength());
assertRecord(data, rec);
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class AzureDataStoreTest method testBackendAddMetadataRecordsFromInputStream.
// AddMetadataRecord (Backend)
@Test
public void testBackendAddMetadataRecordsFromInputStream() throws DataStoreException, IOException, NoSuchAlgorithmException {
for (boolean fromInputStream : Lists.newArrayList(false, true)) {
String prefix = String.format("%s.META.", getClass().getSimpleName());
for (int count : Lists.newArrayList(1, 3)) {
Map<String, String> records = Maps.newHashMap();
for (int i = 0; i < count; i++) {
String recordName = String.format("%sname.%d", prefix, i);
String data = String.format("testData%d", i);
records.put(recordName, data);
if (fromInputStream) {
backend.addMetadataRecord(new ByteArrayInputStream(data.getBytes()), recordName);
} else {
File testFile = folder.newFile();
copyInputStreamToFile(new ByteArrayInputStream(data.getBytes()), testFile);
backend.addMetadataRecord(testFile, recordName);
}
}
assertEquals(count, backend.getAllMetadataRecords(prefix).size());
for (Map.Entry<String, String> entry : records.entrySet()) {
DataRecord record = backend.getMetadataRecord(entry.getKey());
StringWriter writer = new StringWriter();
IOUtils.copy(record.getStream(), writer);
backend.deleteMetadataRecord(entry.getKey());
assertTrue(writer.toString().equals(entry.getValue()));
}
assertEquals(0, backend.getAllMetadataRecords(prefix).size());
}
}
}
use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.
the class AzureDataStoreTest method testBackendGetAllRecordsReturnsAll.
// GetAllRecords (Backend)
@Test
public void testBackendGetAllRecordsReturnsAll() throws DataStoreException, IOException {
for (int recCount : Lists.newArrayList(0, 1, 2, 5)) {
Map<DataIdentifier, String> addedRecords = Maps.newHashMap();
if (0 < recCount) {
for (int i = 0; i < recCount; i++) {
String data = String.format("testData%d", i);
DataRecord record = ds.addRecord(new ByteArrayInputStream(data.getBytes()));
addedRecords.put(record.getIdentifier(), data);
}
}
Iterator<DataRecord> iter = backend.getAllRecords();
List<DataIdentifier> identifiers = Lists.newArrayList();
int actualCount = 0;
while (iter.hasNext()) {
DataRecord record = iter.next();
identifiers.add(record.getIdentifier());
assertTrue(addedRecords.containsKey(record.getIdentifier()));
StringWriter writer = new StringWriter();
IOUtils.copy(record.getStream(), writer);
assertTrue(writer.toString().equals(addedRecords.get(record.getIdentifier())));
actualCount++;
}
for (DataIdentifier identifier : identifiers) {
ds.deleteRecord(identifier);
}
assertEquals(recCount, actualCount);
}
}
Aggregations