Search in sources :

Example 51 with DataIdentifier

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

the class AzureDataStoreTest method testListBlobs.

@Test
public void testListBlobs() throws DataStoreException, IOException {
    final Set<DataIdentifier> identifiers = Sets.newHashSet();
    final Set<String> testStrings = Sets.newHashSet("test1", "test2", "test3");
    for (String s : testStrings) {
        identifiers.add(ds.addRecord(new ByteArrayInputStream(s.getBytes())).getIdentifier());
    }
    Iterator<DataIdentifier> iter = ds.getAllIdentifiers();
    while (iter.hasNext()) {
        DataIdentifier identifier = iter.next();
        assertTrue(identifiers.contains(identifier));
        ds.deleteRecord(identifier);
    }
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) ByteArrayInputStream(java.io.ByteArrayInputStream) Hex.encodeHexString(org.apache.commons.codec.binary.Hex.encodeHexString) Test(org.junit.Test)

Example 52 with DataIdentifier

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

the class AzureDataStoreTest method testBackendWriteRecordFileNotFoundThrowsException.

@Test
public void testBackendWriteRecordFileNotFoundThrowsException() throws IOException, NoSuchAlgorithmException {
    File testFile = folder.newFile();
    copyInputStreamToFile(randomStream(0, 10), testFile);
    DataIdentifier identifier = new DataIdentifier(getIdForInputStream(new FileInputStream(testFile)));
    assertTrue(testFile.delete());
    try {
        backend.write(identifier, testFile);
        fail();
    } catch (DataStoreException e) {
        assertTrue(e.getCause() instanceof FileNotFoundException);
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) FileNotFoundException(java.io.FileNotFoundException) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 53 with DataIdentifier

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

the class AzureDataStoreTest method testBackendWriteRecordNullIdentifierThrowsNullPointerException.

@Test
public void testBackendWriteRecordNullIdentifierThrowsNullPointerException() throws IOException, DataStoreException {
    DataIdentifier identifier = null;
    File testFile = folder.newFile();
    copyInputStreamToFile(randomStream(0, 10), testFile);
    try {
        backend.write(identifier, testFile);
        fail();
    } catch (NullPointerException e) {
        assertEquals("identifier", e.getMessage());
    }
}
Also used : DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) FileUtils.copyInputStreamToFile(org.apache.commons.io.FileUtils.copyInputStreamToFile) File(java.io.File) Test(org.junit.Test)

Example 54 with DataIdentifier

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

the class CachingDataStoreTest method reference.

@Test
public void reference() throws Exception {
    LOG.info("Starting reference");
    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());
    //start & finish
    taskLatch.countDown();
    callbackLatch.countDown();
    waitFinish();
    // Now record in download cache
    rec = dataStore.getRecordIfStored(new DataIdentifier(id));
    assertNotNull(rec);
    assertFile(rec.getStream(), f, folder);
    assertEquals(backend.getReferenceFromIdentifier(rec.getIdentifier()), rec.getReference());
    LOG.info("Finished reference");
}
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 55 with DataIdentifier

use of org.apache.jackrabbit.core.data.DataIdentifier 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)

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