Search in sources :

Example 56 with DataRecord

use of org.apache.jackrabbit.core.data.DataRecord in project jackrabbit-oak by apache.

the class ConsolidatedDataStoreStatsTest method assertSyncedTrue.

private void assertSyncedTrue(ConsolidatedDataStoreCacheStats mBean, AbstractSharedCachingDataStore s3ds, InputStream... streams) throws DataStoreException {
    taskLatch.countDown();
    callbackLatch.countDown();
    List<DataRecord> recs = Lists.newArrayList();
    try {
        for (InputStream is : streams) {
            recs.add(s3ds.addRecord(is));
            IOUtils.closeQuietly(is);
        }
        waitFinish();
        assertTrue(mBean.isFileSynced(testNodePathName));
    } finally {
        delete(s3ds, recs);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 57 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 58 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 59 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 60 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)

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