Search in sources :

Example 56 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class TestUtil method registerNodeType.

public static void registerNodeType(NodeBuilder builder, String nodeTypeDefn) {
    //Taken from org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent
    NodeState base = ModifiedNodeState.squeeze(builder.getNodeState());
    NodeStore store = new MemoryNodeStore(base);
    Root root = RootFactory.createSystemRoot(store, new EditorHook(new CompositeEditorProvider(new NamespaceEditorProvider(), new TypeEditorProvider())), null, null, null, null);
    NodeTypeRegistry.register(root, IOUtils.toInputStream(nodeTypeDefn), "test node types");
    NodeState target = store.getRoot();
    target.compareAgainstBaseState(base, new ApplyDiff(builder));
}
Also used : NamespaceEditorProvider(org.apache.jackrabbit.oak.plugins.name.NamespaceEditorProvider) ApplyDiff(org.apache.jackrabbit.oak.spi.state.ApplyDiff) CompositeEditorProvider(org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider) ModifiedNodeState(org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) MemoryNodeStore(org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore) Root(org.apache.jackrabbit.oak.api.Root) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) EditorHook(org.apache.jackrabbit.oak.spi.commit.EditorHook)

Example 57 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class SegmentTarFixtureTest method testReadWrite.

@Test
public void testReadWrite() throws Exception {
    try (NodeStoreFixture fixture = NodeStoreFixtureProvider.create(createSegmentOptions(folder.getRoot()), false)) {
        NodeStore store = fixture.getStore();
        NodeBuilder builder = store.getRoot().builder();
        builder.setChildNode("foo");
        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    }
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 58 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class SegmentTarFixtureTest method testReadOnly.

@Test(expected = UnsupportedOperationException.class)
public void testReadOnly() throws Exception {
    File directory = folder.getRoot();
    createStoreAt(directory);
    try (NodeStoreFixture fixture = NodeStoreFixtureProvider.create(createSegmentOptions(folder.getRoot()), true)) {
        NodeStore s = fixture.getStore();
        NodeBuilder builder = s.getRoot().builder();
        builder.setChildNode("foo");
        s.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    }
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) File(java.io.File) Test(org.junit.Test)

Example 59 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class JsonIndexTest method readWrite.

@Test
public void readWrite() throws Exception {
    JsonIndexCommand index = new JsonIndexCommand();
    try (NodeStoreFixture fixture = memoryFixture()) {
        NodeStore store = fixture.getStore();
        index.session = JsonIndexCommand.openSession(store);
        assertCommand(index, combineLines(""), "{'addNode':'/foo', 'node':{'jcr:primaryType': 'nt:unstructured', 'x': 1, 'y':{}}}", "{'session': 'save'}");
        assertCommand(index, combineLines("/foo", "/jcr:system", "/oak:index", "/rep:security"), "{'xpath':'/jcr:root/* order by @jcr:path'}");
        assertCommand(index, combineLines("/oak:index/counter"), "{'xpath':'/jcr:root//element(*, oak:QueryIndexDefinition)[@type=`counter`] " + "order by @jcr:path'}");
        assertCommand(index, combineLines("[nt:unstructured] as [a] /* property test = 1 " + "where ([a].[x] = 1) and (isdescendantnode([a], [/])) */"), "{'addNode':'/oak:index/test', 'node':{ " + "'jcr:primaryType':'oak:QueryIndexDefinition', " + "'type':'property', " + "'reindex':true, " + "'entryCount': 1, " + "'{Name}declaringNodeTypes': ['nt:unstructured'], " + "'{Name}propertyNames':['x'] " + "}}", "{'session':'save'}", "{'xpath':'explain /jcr:root//element(*, nt:unstructured)[@x=1]'}", "{'xpath':'/jcr:root//element(*, nt:unstructured)[@x=2]'}");
        assertCommand(index, combineLines("50"), "{'addNode':'/foo/test', 'node':{'jcr:primaryType': 'oak:Unstructured', 'child':{}}}", "{'$x':1}", "{'loop':[" + "{'$p': '/foo/test/child/n', '+': '$x'}, " + "{'addNode': '$p', 'node': {'x': '$x', 'jcr:primaryType': 'nt:unstructured'}}, " + "{'session':'save'}, " + "{'$x': '$x', '+':1}, " + "{'$break': true, 'if': '$x', '=': 100}]}", "{'session':'save'}", "{'xpath':'/jcr:root//element(*, nt:unstructured)[@x<50]', 'quiet':true}", "{'$y':0}", "{'for':'$result', 'do': [{'$y': '$y', '+': 1}]}", "{'print': '$y'}");
        assertCommand(index, combineLines("[nt:unstructured] as [a] /* nodeType Filter(query=" + "explain select [jcr:path], [jcr:score], * from [nt:unstructured] as a " + "where [x] = 1 and isdescendantnode(a, '/') /* xpath: " + "/jcr:root//element(*, nt:unstructured)[@x=1] */, path=//*, " + "property=[x=[1]]) where ([a].[x] = 1) and (isdescendantnode([a], [/])) */"), "{'setProperty': '/oak:index/test/type', 'value': 'disabled'}", "{'session':'save'}", "{'xpath':'explain /jcr:root//element(*, nt:unstructured)[@x=1]'}");
        assertCommand(index, combineLines("[nt:unstructured] as [a] /* traverse '*' " + "where [a].[x] = 1 */"), "{'removeNode': '/oak:index/nodetype'}", "{'session':'save'}", "{'sql':'explain select * from [nt:unstructured] as [a] where [x]=1'}");
        assertCommand(index, combineLines("['/foo': {\n" + "  'jcr:primaryType': 'nt:unstructured', '{Long}x': '1', 'y': {}, 'test': {}\n" + "}]"), "{'xpath':'/jcr:root/foo', 'depth':2}");
        index.session.logout();
    }
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) NodeStoreFixture(org.apache.jackrabbit.oak.run.cli.NodeStoreFixture) Test(org.junit.Test)

Example 60 with NodeStore

use of org.apache.jackrabbit.oak.spi.state.NodeStore in project jackrabbit-oak by apache.

the class IndexCommandIT method reindexOutOfBand.

@Test
public void reindexOutOfBand() throws Exception {
    createTestData(true);
    fixture.getAsyncIndexUpdate("async").run();
    String checkpoint = fixture.getNodeStore().checkpoint(TimeUnit.HOURS.toMillis(24));
    //Close the repository so as all changes are flushed
    fixture.close();
    IndexCommand command = new IndexCommand();
    File outDir = temporaryFolder.newFolder();
    File storeDir = fixture.getDir();
    String[] args = { "--index-temp-dir=" + temporaryFolder.newFolder().getAbsolutePath(), "--index-out-dir=" + outDir.getAbsolutePath(), "--index-paths=/oak:index/fooIndex", "--checkpoint=" + checkpoint, "--reindex", // -- indicates that options have ended and rest needs to be treated as non option
    "--", storeDir.getAbsolutePath() };
    command.execute(args);
    RepositoryFixture fixture2 = new RepositoryFixture(storeDir);
    NodeStore store2 = fixture2.getNodeStore();
    PropertyState reindexCount = getNode(store2.getRoot(), "/oak:index/fooIndex").getProperty(IndexConstants.REINDEX_COUNT);
    assertEquals(1, reindexCount.getValue(Type.LONG).longValue());
    File indexes = new File(outDir, OutOfBandIndexer.LOCAL_INDEX_ROOT_DIR);
    assertTrue(indexes.exists());
    IndexRootDirectory idxRoot = new IndexRootDirectory(indexes);
    List<LocalIndexDir> idxDirs = idxRoot.getAllLocalIndexes();
    assertEquals(1, idxDirs.size());
}
Also used : NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) IndexRootDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexRootDirectory) LocalIndexDir(org.apache.jackrabbit.oak.plugins.index.lucene.directory.LocalIndexDir) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Aggregations

NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)141 Test (org.junit.Test)81 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)58 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)52 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)29 Blob (org.apache.jackrabbit.oak.api.Blob)24 Before (org.junit.Before)18 FileInputStream (java.io.FileInputStream)16 Hex.encodeHexString (org.apache.commons.codec.binary.Hex.encodeHexString)16 File (java.io.File)14 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)14 FileStore (org.apache.jackrabbit.oak.segment.file.FileStore)14 ProxyNodeStore (org.apache.jackrabbit.oak.spi.state.ProxyNodeStore)13 Oak (org.apache.jackrabbit.oak.Oak)10 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)10 StandbyClientSync (org.apache.jackrabbit.oak.segment.standby.client.StandbyClientSync)10 StandbyServerSync (org.apache.jackrabbit.oak.segment.standby.server.StandbyServerSync)10 DocumentNodeStore (org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore)9 MemoryStore (org.apache.jackrabbit.oak.segment.memory.MemoryStore)9 MountInfoProvider (org.apache.jackrabbit.oak.spi.mount.MountInfoProvider)9