Search in sources :

Example 71 with DataRecord

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

the class CachingDataStoreTest method syncAddGetDelete.

/**
     * Add, get, delete with synchronous option.
     * @throws Exception
     */
@Test
public void syncAddGetDelete() throws Exception {
    LOG.info("Starting syncAddGetDelete");
    File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile());
    String id = getIdForInputStream(f);
    FileInputStream fin = new FileInputStream(f);
    closer.register(fin);
    DataRecord rec = dataStore.addRecord(fin, new BlobOptions().setUpload(SYNCHRONOUS));
    assertEquals(id, rec.getIdentifier().toString());
    assertFile(rec.getStream(), f, folder);
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertEquals(id, rec.getIdentifier().toString());
    assertFile(rec.getStream(), f, folder);
    assertEquals(1, Iterators.size(dataStore.getAllIdentifiers()));
    dataStore.deleteRecord(new DataIdentifier(id));
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertNull(rec);
    LOG.info("Finished syncAddGetDelete");
}
Also used : BlobOptions(org.apache.jackrabbit.oak.spi.blob.BlobOptions) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) DataRecord(org.apache.jackrabbit.core.data.DataRecord) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 72 with DataRecord

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

the class OakFileDataStore method getAllMetadataRecords.

@Override
public List<DataRecord> getAllMetadataRecords(String prefix) {
    File root = new File(getPath());
    List<DataRecord> rootRecords = new ArrayList<DataRecord>();
    for (File file : FileFilterUtils.filterList(FileFilterUtils.prefixFileFilter(prefix), root.listFiles())) {
        if (!file.isDirectory()) {
            // skip directories which are actual data store files
            rootRecords.add(new FileDataRecord(this, new DataIdentifier(file.getName()), file));
        }
    }
    return rootRecords;
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) ArrayList(java.util.ArrayList) FileDataRecord(org.apache.jackrabbit.core.data.FileDataRecord) FileDataRecord(org.apache.jackrabbit.core.data.FileDataRecord) DataRecord(org.apache.jackrabbit.core.data.DataRecord) File(java.io.File)

Example 73 with DataRecord

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

the class CachingDataStoreTest method addDelete.

/**
     * Add in datastore.
     */
@Test
public void addDelete() throws Exception {
    LOG.info("Starting addDelete");
    File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile());
    String id = getIdForInputStream(f);
    FileInputStream fin = new FileInputStream(f);
    closer.register(fin);
    DataRecord rec = dataStore.addRecord(fin);
    assertEquals(id, rec.getIdentifier().toString());
    //start & finish
    taskLatch.countDown();
    callbackLatch.countDown();
    waitFinish();
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertNotNull(rec);
    assertFile(rec.getStream(), f, folder);
    dataStore.deleteRecord(new DataIdentifier(id));
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertNull(rec);
    LOG.info("Finished addDelete");
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) DataRecord(org.apache.jackrabbit.core.data.DataRecord) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 74 with DataRecord

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

the class CachingDataStoreTest method referenceNoCache.

@Test
public void referenceNoCache() throws Exception {
    LOG.info("Starting referenceNoCache");
    dataStore.close();
    init(1, 0, 0);
    File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile());
    String id = getIdForInputStream(f);
    FileInputStream fin = new FileInputStream(f);
    closer.register(fin);
    // Record still in staging
    DataRecord rec = dataStore.addRecord(fin);
    assertEquals(id, rec.getIdentifier().toString());
    assertFile(rec.getStream(), f, folder);
    assertEquals(backend.getReferenceFromIdentifier(rec.getIdentifier()), rec.getReference());
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertNotNull(rec);
    assertFile(rec.getStream(), f, folder);
    assertEquals(backend.getReferenceFromIdentifier(rec.getIdentifier()), rec.getReference());
    LOG.info("Finished referenceNoCache");
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) DataRecord(org.apache.jackrabbit.core.data.DataRecord) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 75 with DataRecord

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

the class DataStoreTextWriterTest method nonExistingEntry.

@Test
public void nonExistingEntry() throws Exception {
    File fdsDir = temporaryFolder.newFolder();
    FileDataStore fds = DataStoreUtils.createFDS(fdsDir, 0);
    ByteArrayInputStream is = new ByteArrayInputStream("hello".getBytes());
    DataRecord dr = fds.addRecord(is);
    File writerDir = temporaryFolder.newFolder();
    DataStoreTextWriter w = new DataStoreTextWriter(writerDir, false);
    String id = dr.getIdentifier().toString();
    assertFalse(w.isProcessed(id));
    assertNull(w.getText("/a", new IdBlob("foo", id)));
    w.write(id, "foo");
    assertTrue(w.isProcessed(id));
    ExtractedText et = w.getText("/a", new IdBlob("foo", id));
    assertEquals("foo", et.getExtractedText());
    assertEquals(ExtractionResult.SUCCESS, et.getExtractionResult());
    w.markEmpty("a");
    assertTrue(w.isProcessed("a"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataRecord(org.apache.jackrabbit.core.data.DataRecord) File(java.io.File) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) ExtractedText(org.apache.jackrabbit.oak.plugins.index.fulltext.ExtractedText) 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