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));
}
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);
}
}
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);
}
}
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();
}
}
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());
}
Aggregations