Search in sources :

Example 61 with DataRecord

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);
}
Also used : Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord) Test(org.junit.Test)

Example 62 with DataRecord

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();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) RandomInputStream(org.apache.jackrabbit.core.data.RandomInputStream) InputStream(java.io.InputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 63 with DataRecord

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 64 with DataRecord

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());
        }
    }
}
Also used : StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) DataRecord(org.apache.jackrabbit.core.data.DataRecord) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile) File(java.io.File) Map(java.util.Map) Test(org.junit.Test)

Example 65 with DataRecord

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);
    }
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) DataRecord(org.apache.jackrabbit.core.data.DataRecord) Test(org.junit.Test)

Aggregations

DataRecord (org.apache.jackrabbit.core.data.DataRecord)76 Test (org.junit.Test)43 ByteArrayInputStream (java.io.ByteArrayInputStream)34 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)30 File (java.io.File)24 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)19 FileInputStream (java.io.FileInputStream)16 Random (java.util.Random)12 InputStream (java.io.InputStream)9 ArrayList (java.util.ArrayList)6 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)6 FileDataStore (org.apache.jackrabbit.core.data.FileDataStore)6 IOException (java.io.IOException)4 AbstractBlobStoreTest (org.apache.jackrabbit.oak.spi.blob.AbstractBlobStoreTest)4 Function (com.google.common.base.Function)3 SequenceInputStream (java.io.SequenceInputStream)3 RepositoryException (javax.jcr.RepositoryException)3 DataStore (org.apache.jackrabbit.core.data.DataStore)3 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)2 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)2