Search in sources :

Example 16 with DataIdentifier

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

the class CachingDataStoreTest method getAllIdentifiers.

/**
     * Get all Identifiers.
     */
@Test
public void getAllIdentifiers() throws Exception {
    LOG.info("Starting getAllIdentifiers");
    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());
    assertTrue(Iterators.contains(dataStore.getAllIdentifiers(), new DataIdentifier(id)));
    //start & finish
    taskLatch.countDown();
    callbackLatch.countDown();
    waitFinish();
    assertTrue(Iterators.contains(dataStore.getAllIdentifiers(), new DataIdentifier(id)));
    LOG.info("Finished getAllIdentifiers");
}
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 17 with DataIdentifier

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

the class CachingDataStoreTest method lazyLoadStream.

/**
     * Add in datastore, invalidate from cache and lazy load record stream.
     */
@Test
public void lazyLoadStream() throws Exception {
    LOG.info("Starting lazyLoadStream");
    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();
    // Invalidate from the local cache
    dataStore.getCache().invalidate(id);
    // retrieve record from the datastore
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertNotNull(rec);
    assertEquals(id, rec.getIdentifier().toString());
    // the file should not be in cache
    File cached = dataStore.getCache().getIfPresent(id);
    assertNull(cached);
    // assert stream
    assertFile(rec.getStream(), f, folder);
    // Now should be available in the cache
    cached = dataStore.getCache().getIfPresent(id);
    assertNotNull(cached);
    assertTrue(Files.equal(f, cached));
    dataStore.deleteRecord(new DataIdentifier(id));
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertNull(rec);
    LOG.info("Finished lazyLoadStream");
}
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 18 with DataIdentifier

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

the class CachingDataStoreTest method zeroCacheAddGetDelete.

/**
     * Add, get, delete when zero cache size.
     * @throws Exception
     */
@Test
public void zeroCacheAddGetDelete() throws Exception {
    LOG.info("Starting zeroCacheAddGetDelete");
    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);
    DataRecord rec = dataStore.addRecord(fin);
    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 zeroCacheAddGetDelete");
}
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 19 with DataIdentifier

use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit by apache.

the class DbDataStore method getAllIdentifiers.

public Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException {
    ArrayList<DataIdentifier> list = new ArrayList<DataIdentifier>();
    ResultSet rs = null;
    try {
        // SELECT ID FROM DATASTORE
        rs = conHelper.query(selectAllSQL);
        while (rs.next()) {
            String id = rs.getString(1);
            if (!id.startsWith(TEMP_PREFIX)) {
                DataIdentifier identifier = new DataIdentifier(id);
                list.add(identifier);
            }
        }
        log.debug("Found " + list.size() + " identifiers.");
        return list.iterator();
    } catch (Exception e) {
        throw convert("Can not read records", e);
    } finally {
        DbUtility.close(rs);
    }
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) SQLException(java.sql.SQLException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 20 with DataIdentifier

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

the class AzureBlobStoreBackend method getMetadataRecord.

@Override
public DataRecord getMetadataRecord(String name) {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    long start = System.currentTimeMillis();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(META_DIR_NAME);
        CloudBlockBlob blob = metaDir.getBlockBlobReference(name);
        if (!blob.exists()) {
            LOG.warn("Trying to read missing metadata. metadataName={}", name);
            return null;
        }
        blob.downloadAttributes();
        long lastModified = blob.getProperties().getLastModified().getTime();
        long length = blob.getProperties().getLength();
        AzureBlobStoreDataRecord record = new AzureBlobStoreDataRecord(this, connectionString, containerName, new DataIdentifier(name), lastModified, length, true);
        LOG.debug("Metadata record read. metadataName={} duration={} record={}", name, (System.currentTimeMillis() - start), record);
        return record;
    } catch (StorageException e) {
        LOG.info("Error reading metadata record. metadataName={}", name, e);
        throw new RuntimeException(e);
    } catch (Exception e) {
        LOG.debug("Error reading metadata record. metadataName={}", name, e);
        throw new RuntimeException(e);
    } finally {
        if (null != contextClassLoader) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) CloudBlobDirectory(com.microsoft.azure.storage.blob.CloudBlobDirectory) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) StorageException(com.microsoft.azure.storage.StorageException) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)60 Test (org.junit.Test)31 DataRecord (org.apache.jackrabbit.core.data.DataRecord)30 File (java.io.File)22 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)16 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)13 FileInputStream (java.io.FileInputStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ArrayList (java.util.ArrayList)8 FileUtils.copyInputStreamToFile (org.apache.commons.io.FileUtils.copyInputStreamToFile)5 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)4 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)4 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 RepositoryException (javax.jcr.RepositoryException)4 Function (com.google.common.base.Function)3 StorageException (com.microsoft.azure.storage.StorageException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 SQLException (java.sql.SQLException)3 HashSet (java.util.HashSet)3