Search in sources :

Example 16 with MemoryStore

use of org.apache.jackrabbit.oak.segment.memory.MemoryStore in project jackrabbit-oak by apache.

the class LuceneIndexTest method luceneWithFSDirectory.

@Test
public void luceneWithFSDirectory() throws Exception {
    //Issue is not reproducible with MemoryNodeBuilder and
    //MemoryNodeState as they cannot determine change in childNode without
    //entering
    NodeStore nodeStore = SegmentNodeStoreBuilders.builder(new MemoryStore()).build();
    tracker = new IndexTracker();
    ((Observable) nodeStore).addObserver(new Observer() {

        @Override
        public void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info) {
            tracker.update(root);
        }
    });
    builder = nodeStore.getRoot().builder();
    //Also initialize the NodeType registry required for Lucene index to work
    builder.setChildNode(JCR_SYSTEM, INITIAL_CONTENT.getChildNode(JCR_SYSTEM));
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder idxb = newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo", "foo2"), null);
    idxb.setProperty(PERSISTENCE_NAME, PERSISTENCE_FILE);
    idxb.setProperty(PERSISTENCE_PATH, getIndexDir());
    nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    builder = nodeStore.getRoot().builder();
    builder.setProperty("foo", "bar");
    NodeState indexed = nodeStore.merge(builder, HOOK, CommitInfo.EMPTY);
    assertQuery(tracker, indexed, "foo", "bar");
    builder = nodeStore.getRoot().builder();
    builder.setProperty("foo2", "bar2");
    indexed = nodeStore.merge(builder, HOOK, CommitInfo.EMPTY);
    assertQuery(tracker, indexed, "foo2", "bar2");
}
Also used : MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Observer(org.apache.jackrabbit.oak.spi.commit.Observer) CommitInfo(org.apache.jackrabbit.oak.spi.commit.CommitInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Observable(org.apache.jackrabbit.oak.spi.commit.Observable) Test(org.junit.Test)

Example 17 with MemoryStore

use of org.apache.jackrabbit.oak.segment.memory.MemoryStore in project jackrabbit-oak by apache.

the class RepositorySidegradeTest method createSourceContent.

@SuppressWarnings("unchecked")
protected NodeStore createSourceContent() throws Exception {
    NodeStore source = SegmentNodeStoreBuilders.builder(new MemoryStore()).build();
    Repository repository = new Jcr(new Oak(source)).createRepository();
    Session session = repository.login(CREDENTIALS);
    try {
        JackrabbitWorkspace workspace = (JackrabbitWorkspace) session.getWorkspace();
        NamespaceRegistry registry = workspace.getNamespaceRegistry();
        registry.registerNamespace("test", "http://www.example.org/");
        NodeTypeManager nodeTypeManager = workspace.getNodeTypeManager();
        NodeTypeTemplate template = nodeTypeManager.createNodeTypeTemplate();
        template.setName("test:unstructured");
        template.setDeclaredSuperTypeNames(new String[] { "nt:unstructured" });
        PropertyDefinitionTemplate pDef1 = nodeTypeManager.createPropertyDefinitionTemplate();
        pDef1.setName("defaultString");
        pDef1.setRequiredType(PropertyType.STRING);
        Value stringValue = session.getValueFactory().createValue("stringValue");
        pDef1.setDefaultValues(new Value[] { stringValue });
        template.getPropertyDefinitionTemplates().add(pDef1);
        PropertyDefinitionTemplate pDef2 = nodeTypeManager.createPropertyDefinitionTemplate();
        pDef2.setName("defaultPath");
        pDef2.setRequiredType(PropertyType.PATH);
        Value pathValue = session.getValueFactory().createValue("/jcr:path/nt:value", PropertyType.PATH);
        pDef2.setDefaultValues(new Value[] { pathValue });
        template.getPropertyDefinitionTemplates().add(pDef2);
        nodeTypeManager.registerNodeType(template, false);
        template = nodeTypeManager.createNodeTypeTemplate();
        template.setName("test:referenceable");
        template.setDeclaredSuperTypeNames(new String[] { "nt:unstructured", "mix:referenceable" });
        nodeTypeManager.registerNodeType(template, false);
        Node root = session.getRootNode();
        Node referenceable = root.addNode("referenceable", "test:unstructured");
        referenceable.addMixin(NodeType.MIX_REFERENCEABLE);
        Node versionable = root.addNode("versionable", NT_UNSTRUCTURED);
        versionable.addMixin(MIX_VERSIONABLE);
        Node child = versionable.addNode("child", "test:referenceable");
        child.addNode("child2", NT_UNSTRUCTURED);
        session.save();
        session.getWorkspace().getVersionManager().checkin("/versionable");
        Node properties = root.addNode("properties", "test:unstructured");
        properties.setProperty("boolean", true);
        Binary binary = session.getValueFactory().createBinary(new ByteArrayInputStream(BINARY));
        try {
            properties.setProperty("binary", binary);
        } finally {
            binary.dispose();
        }
        properties.setProperty("date", DATE);
        properties.setProperty("decimal", new BigDecimal(123));
        properties.setProperty("double", Math.PI);
        properties.setProperty("long", 9876543210L);
        properties.setProperty("reference", referenceable);
        properties.setProperty("weak_reference", session.getValueFactory().createValue(referenceable, true));
        properties.setProperty("mv_reference", new Value[] { session.getValueFactory().createValue(versionable, false) });
        properties.setProperty("mv_weak_reference", new Value[] { session.getValueFactory().createValue(versionable, true) });
        properties.setProperty("string", "test");
        properties.setProperty("multiple", "a,b,c".split(","));
        session.save();
        binary = properties.getProperty("binary").getBinary();
        try {
            InputStream stream = binary.getStream();
            try {
                for (byte aBINARY : BINARY) {
                    assertEquals(aBINARY, (byte) stream.read());
                }
                assertEquals(-1, stream.read());
            } finally {
                stream.close();
            }
        } finally {
            binary.dispose();
        }
        return source;
    } finally {
        session.logout();
    }
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Node(javax.jcr.Node) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) BigDecimal(java.math.BigDecimal) MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) Repository(javax.jcr.Repository) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NamespaceRegistry(javax.jcr.NamespaceRegistry) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) ByteArrayInputStream(java.io.ByteArrayInputStream) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) Oak(org.apache.jackrabbit.oak.Oak) Value(javax.jcr.Value) Binary(javax.jcr.Binary) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 18 with MemoryStore

use of org.apache.jackrabbit.oak.segment.memory.MemoryStore in project jackrabbit-oak by apache.

the class DepthFirstNodeIteratorTest method setup.

@Before
public void setup() throws CommitFailedException, IOException {
    store = SegmentNodeStoreBuilders.builder(new MemoryStore()).build();
    NodeBuilder rootBuilder = this.store.getRoot().builder();
    NodeBuilder countries = rootBuilder.child("countries");
    countries.child("uk").child("cities").child("london").child("districts").child("frognal");
    countries.child("germany");
    countries.child("france").child("cities").child("paris");
    store.merge(rootBuilder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
}
Also used : MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Before(org.junit.Before)

Example 19 with MemoryStore

use of org.apache.jackrabbit.oak.segment.memory.MemoryStore in project jackrabbit-oak by apache.

the class LockBasedSchedulerCheckpointTest method testLongWait.

/**
     * OAK-3587 test simulates a wait less than configured
     * {@code SegmentNodeStore#setCheckpointsLockWaitTime(int)} value so the
     * checkpoint call must return a valid value
     */
@Test
public void testLongWait() throws Exception {
    final int blockTime = 1;
    MemoryStore ms = new MemoryStore();
    System.setProperty("oak.checkpoints.lockWaitTime", "2");
    final LockBasedScheduler scheduler = LockBasedScheduler.builder(ms.getRevisions(), ms.getReader()).build();
    final Semaphore semaphore = new Semaphore(0);
    final Callable<Boolean> block = new Callable<Boolean>() {

        @Override
        public Boolean call() {
            try {
                semaphore.release();
                SECONDS.sleep(blockTime);
            } catch (InterruptedException e) {
            //
            }
            return true;
        }
    };
    Thread background = new Thread() {

        @Override
        public void run() {
            try {
                Commit commit = createBlockingCommit(scheduler, "foo", "bar", block);
                scheduler.schedule(commit);
            } catch (Exception e) {
            //
            }
        }
    };
    background.start();
    semaphore.acquire();
    String cp0 = scheduler.checkpoint(10, Collections.<String, String>emptyMap());
    assertNotNull(retrieveCheckpoint(scheduler, cp0));
}
Also used : MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) Semaphore(java.util.concurrent.Semaphore) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 20 with MemoryStore

use of org.apache.jackrabbit.oak.segment.memory.MemoryStore in project jackrabbit-oak by apache.

the class CopyVersionHistoryTest method performCopy.

protected Session performCopy(VersionCopySetup setup) throws RepositoryException, IOException {
    final RepositoryConfig sourceConfig = RepositoryConfig.create(source);
    final RepositoryContext sourceContext = RepositoryContext.create(sourceConfig);
    final NodeStore targetNodeStore = SegmentNodeStoreBuilders.builder(new MemoryStore()).build();
    try {
        final RepositoryUpgrade upgrade = new RepositoryUpgrade(sourceContext, targetNodeStore);
        setup.setup(upgrade.versionCopyConfiguration);
        upgrade.setEarlyShutdown(true);
        upgrade.copy(null);
    } finally {
        sourceContext.getRepository().shutdown();
    }
    repository = (RepositoryImpl) new Jcr(new Oak(targetNodeStore)).createRepository();
    Session s = repository.login(AbstractRepositoryUpgradeTest.CREDENTIALS);
    sessions.add(s);
    return s;
}
Also used : RepositoryConfig(org.apache.jackrabbit.core.config.RepositoryConfig) MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) RepositoryContext(org.apache.jackrabbit.core.RepositoryContext) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) Oak(org.apache.jackrabbit.oak.Oak) Session(javax.jcr.Session)

Aggregations

MemoryStore (org.apache.jackrabbit.oak.segment.memory.MemoryStore)28 Test (org.junit.Test)15 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)9 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)9 Before (org.junit.Before)7 Oak (org.apache.jackrabbit.oak.Oak)6 Jcr (org.apache.jackrabbit.oak.jcr.Jcr)6 SegmentNodeStore (org.apache.jackrabbit.oak.segment.SegmentNodeStore)4 Session (javax.jcr.Session)3 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Callable (java.util.concurrent.Callable)2 Semaphore (java.util.concurrent.Semaphore)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Node (javax.jcr.Node)2 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)2 InitialContent (org.apache.jackrabbit.oak.InitialContent)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1