Search in sources :

Example 6 with ArrayBasedBlob

use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.

the class ExtractedTextCacheTest method cacheEnabledNonIdBlob.

@Test
public void cacheEnabledNonIdBlob() throws Exception {
    ExtractedTextCache cache = new ExtractedTextCache(10 * FileUtils.ONE_MB, 100);
    Blob b = new ArrayBasedBlob("hello".getBytes());
    String text = cache.get("/a", "foo", b, false);
    assertNull(text);
    cache.put(b, new ExtractedText(ExtractionResult.SUCCESS, "test hello"));
    text = cache.get("/a", "foo", b, false);
    assertNull(text);
}
Also used : Blob(org.apache.jackrabbit.oak.api.Blob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Matchers.anyString(org.mockito.Matchers.anyString) ExtractedText(org.apache.jackrabbit.oak.plugins.index.fulltext.ExtractedText) Test(org.junit.Test)

Example 7 with ArrayBasedBlob

use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.

the class IndexDefinitionPrinterTest method binaryProps.

@Test
public void binaryProps() throws Exception {
    NodeBuilder builder = store.getRoot().builder();
    builder.child("a").setProperty("foo", new ArrayBasedBlob("hello".getBytes()));
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    when(pathService.getIndexPaths()).thenReturn(Lists.newArrayList("/a"));
    String json = getJSON();
    IndexDefinitionUpdater updater = new IndexDefinitionUpdater(json);
    assertTrue(updater.getIndexPaths().contains("/a"));
}
Also used : IndexDefinitionUpdater(org.apache.jackrabbit.oak.plugins.index.importer.IndexDefinitionUpdater) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 8 with ArrayBasedBlob

use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.

the class IndexTrackerTest method corruptIndex.

private NodeState corruptIndex(String indexPath) {
    NodeBuilder dir = TestUtil.child(builder, PathUtils.concat(indexPath, ":data"));
    for (String name : dir.getChildNodeNames()) {
        if (!"segments.gen".equals(name)) {
            dir.getChildNode(name).setProperty(PropertyStates.createProperty("jcr:data", Collections.singletonList(new ArrayBasedBlob("foo".getBytes())), Type.BINARIES));
        }
    }
    TestUtil.child(builder, PathUtils.concat(indexPath, IndexDefinition.STATUS_NODE)).setProperty("foo", "bar");
    return builder.getNodeState();
}
Also used : ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 9 with ArrayBasedBlob

use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.

the class OakDirectoryTestBase method testOverflow.

// OAK-2388
@Test
public void testOverflow() throws Exception {
    Directory dir = createDir(builder, false, "/foo");
    NodeBuilder file = builder.child(INDEX_DATA_CHILD_NAME).child("test.txt");
    int blobSize = 32768;
    int dataSize = 90844;
    file.setProperty(OakDirectory.PROP_BLOB_SIZE, blobSize);
    List<? super Blob> blobs = new ArrayList<Blob>(dataSize);
    for (int i = 0; i < dataSize; i++) {
        blobs.add(new ArrayBasedBlob(new byte[0]));
    }
    file.setProperty(PropertyStates.createProperty("jcr:data", blobs, Type.BINARIES));
    IndexInput input = dir.openInput("test.txt", IOContext.DEFAULT);
    assertEquals((long) blobSize * (dataSize - 1), input.length());
}
Also used : ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) ArrayList(java.util.ArrayList) IndexInput(org.apache.lucene.store.IndexInput) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Example 10 with ArrayBasedBlob

use of org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob in project jackrabbit-oak by apache.

the class OakDirectoryTestBase method dontReportFilesMarkedUnsafeForActiveDeletion.

// OAK-6950
@Test
public void dontReportFilesMarkedUnsafeForActiveDeletion() throws Exception {
    AtomicInteger blobIdSuffix = new AtomicInteger();
    IndexDefinition def = new IndexDefinition(root, builder.getNodeState(), "/foo");
    BlobFactory factory = in -> {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(in, out);
        byte[] data = out.toByteArray();
        return new ArrayBasedBlob(data) {

            @Override
            public String getContentIdentity() {
                return Long.toString(length() - UNIQUE_KEY_SIZE) + "-id-" + blobIdSuffix.get();
            }
        };
    };
    final AtomicBoolean markingForceActiveDeletionUnsafe = new AtomicBoolean();
    final Set<String> deletedBlobs = Sets.newHashSet();
    OakDirectory dir = getOakDirectoryBuilder(builder, def).setReadOnly(false).with(factory).with(new ActiveDeletedBlobCollectorFactory.BlobDeletionCallback() {

        @Override
        public void deleted(String blobId, Iterable<String> ids) {
            deletedBlobs.add(blobId);
        }

        @Override
        public void commitProgress(IndexProgress indexProgress) {
        }

        @Override
        public boolean isMarkingForActiveDeletionUnsafe() {
            return markingForceActiveDeletionUnsafe.get();
        }
    }).build();
    // file1 created before marking was flagged as unsafe
    blobIdSuffix.set(1);
    writeFile(dir, "file1", fileSize);
    markingForceActiveDeletionUnsafe.set(true);
    // file2 created after marking was flagged as unsafe
    blobIdSuffix.set(1);
    writeFile(dir, "file2", fileSize);
    dir.deleteFile("file1");
    dir.deleteFile("file2");
    dir.close();
    deletedBlobs.forEach(deletedBlob -> {
        assertTrue("Deleted blob id " + deletedBlob + " must belong to file1", deletedBlob.endsWith("-id-1"));
    });
}
Also used : JCR_DATA(org.apache.jackrabbit.JcrConstants.JCR_DATA) Arrays(java.util.Arrays) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) BlobStoreBlob(org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) Random(java.util.Random) Assert.assertThat(org.junit.Assert.assertThat) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Directory(org.apache.lucene.store.Directory) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) UNIQUE_KEY_SIZE(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.UNIQUE_KEY_SIZE) Assert.fail(org.junit.Assert.fail) FileDataStore(org.apache.jackrabbit.core.data.FileDataStore) IOContext(org.apache.lucene.store.IOContext) EmptyNodeState(org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState) PROP_BLOB_SIZE(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_BLOB_SIZE) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Type(org.apache.jackrabbit.oak.api.Type) Set(java.util.Set) ONE_MB(org.apache.commons.io.FileUtils.ONE_MB) FileNotFoundException(java.io.FileNotFoundException) Sets(com.google.common.collect.Sets) SegmentNodeStore(org.apache.jackrabbit.oak.segment.SegmentNodeStore) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) NullInputStream(org.apache.commons.io.input.NullInputStream) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Iterables(com.google.common.collect.Iterables) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) LuceneIndexConstants(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants) SegmentNodeStoreBuilders(org.apache.jackrabbit.oak.segment.SegmentNodeStoreBuilders) FileStore(org.apache.jackrabbit.oak.segment.file.FileStore) ReadOnlyBuilder(org.apache.jackrabbit.oak.spi.state.ReadOnlyBuilder) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) DataStoreBlobStore(org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore) SegmentTestConstants(org.apache.jackrabbit.oak.segment.SegmentTestConstants) PropertyStates(org.apache.jackrabbit.oak.plugins.memory.PropertyStates) IndexOutput(org.apache.lucene.store.IndexOutput) PROP_UNSAFE_FOR_ACTIVE_DELETION(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_UNSAFE_FOR_ACTIVE_DELETION) INDEX_DATA_CHILD_NAME(org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INDEX_DATA_CHILD_NAME) ONE_GB(org.apache.commons.io.FileUtils.ONE_GB) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) IndexInput(org.apache.lucene.store.IndexInput) Assert.assertTrue(org.junit.Assert.assertTrue) FileStoreBuilder(org.apache.jackrabbit.oak.segment.file.FileStoreBuilder) IOException(java.io.IOException) Test(org.junit.Test) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) File(java.io.File) InputStreamDataInput(org.apache.lucene.store.InputStreamDataInput) PROP_UNIQUE_KEY(org.apache.jackrabbit.oak.plugins.index.lucene.directory.OakDirectory.PROP_UNIQUE_KEY) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) MemoryBlobStore(org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore) Blob(org.apache.jackrabbit.oak.api.Blob) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) INITIAL_CONTENT(org.apache.jackrabbit.oak.InitialContent.INITIAL_CONTENT) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Test(org.junit.Test)

Aggregations

ArrayBasedBlob (org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob)27 Test (org.junit.Test)24 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)12 Blob (org.apache.jackrabbit.oak.api.Blob)9 Directory (org.apache.lucene.store.Directory)9 ArrayList (java.util.ArrayList)8 IndexInput (org.apache.lucene.store.IndexInput)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 InputStream (java.io.InputStream)6 NullInputStream (org.apache.commons.io.input.NullInputStream)5 BlobStoreBlob (org.apache.jackrabbit.oak.plugins.blob.BlobStoreBlob)5 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)4 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)3 File (java.io.File)3 IOException (java.io.IOException)3 Random (java.util.Random)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Iterables (com.google.common.collect.Iterables)2