use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.
the class AtomicCounterEditorTest method increment.
@Test
public void increment() throws CommitFailedException {
NodeBuilder builder;
Editor editor;
builder = EMPTY_NODE.builder();
editor = new AtomicCounterEditor(builder, null, null, null, null);
editor.propertyAdded(INCREMENT_BY_1);
assertNoCounters(builder.getProperties());
builder = EMPTY_NODE.builder();
builder = setMixin(builder);
editor = new AtomicCounterEditor(builder, null, null, null, null);
editor.propertyAdded(INCREMENT_BY_1);
assertNull("the oak:increment should never be set", builder.getProperty(PROP_INCREMENT));
assertTotalCountersValue(builder.getProperties(), 1);
}
use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.
the class AtomicCounterEditorTest method consolidate.
@Test
public void consolidate() throws CommitFailedException {
NodeBuilder builder;
Editor editor;
builder = EMPTY_NODE.builder();
builder = setMixin(builder);
editor = new AtomicCounterEditor(builder, null, null, null, null);
editor.propertyAdded(INCREMENT_BY_1);
assertTotalCountersValue(builder.getProperties(), 1);
editor.propertyAdded(INCREMENT_BY_1);
assertTotalCountersValue(builder.getProperties(), 2);
AtomicCounterEditor.consolidateCount(builder);
assertCounterNodeState(builder, ImmutableSet.of(PREFIX_PROP_COUNTER, PREFIX_PROP_REVISION), 2);
}
use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.
the class IndexUpdate method childNodeAdded.
@Override
@Nonnull
public Editor childNodeAdded(String name, NodeState after) throws CommitFailedException {
List<Editor> children = newArrayListWithCapacity(1 + editors.size());
children.add(new IndexUpdate(this, name));
for (Editor editor : editors) {
Editor child = editor.childNodeAdded(name, after);
if (child != null) {
children.add(child);
}
}
return compose(children);
}
use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.
the class IndexUpdate method collectIndexEditors.
private void collectIndexEditors(NodeBuilder definitions, NodeState before) throws CommitFailedException {
for (String name : definitions.getChildNodeNames()) {
NodeBuilder definition = definitions.getChildNode(name);
if (isIncluded(rootState.async, definition)) {
String type = definition.getString(TYPE_PROPERTY_NAME);
if (type == null) {
// probably not an index def
continue;
}
boolean shouldReindex = shouldReindex(definition, before, name);
String indexPath = getIndexPath(getPath(), name);
if (definition.hasProperty(IndexConstants.CORRUPT_PROPERTY_NAME) && !shouldReindex) {
String corruptSince = definition.getProperty(IndexConstants.CORRUPT_PROPERTY_NAME).getValue(Type.DATE);
rootState.corruptIndexHandler.skippingCorruptIndex(rootState.async, indexPath, ISO8601.parse(corruptSince));
continue;
}
Editor editor = rootState.provider.getIndexEditor(type, definition, rootState.root, rootState.newCallback(indexPath, shouldReindex, getEstimatedCount(definition)));
if (editor == null) {
rootState.missingProvider.onMissingIndex(type, definition, indexPath);
} else if (shouldReindex) {
if (definition.getBoolean(REINDEX_ASYNC_PROPERTY_NAME) && definition.getString(ASYNC_PROPERTY_NAME) == null) {
// switch index to an async update mode
definition.setProperty(ASYNC_PROPERTY_NAME, ASYNC_REINDEX_VALUE);
} else {
definition.setProperty(REINDEX_PROPERTY_NAME, false);
incrementReIndexCount(definition);
// beforehand, we'll remove all child nodes
for (String rm : definition.getChildNodeNames()) {
if (NodeStateUtils.isHidden(rm)) {
definition.getChildNode(rm).remove();
}
}
clearCorruptFlag(definition, indexPath);
reindex.put(concat(getPath(), INDEX_DEFINITIONS_NAME, name), editor);
}
} else {
editors.add(editor);
}
}
}
}
use of org.apache.jackrabbit.oak.spi.commit.Editor in project jackrabbit-oak by apache.
the class IndexUpdateTest method testMissingProviderFailsCommit.
/**
* OAK-3505 Provide an optionally stricter policy for missing synchronous
* index editor providers
*/
@Test
public void testMissingProviderFailsCommit() throws Exception {
final IndexUpdateCallback noop = new IndexUpdateCallback() {
@Override
public void indexUpdate() {
}
};
final MissingIndexProviderStrategy mips = new MissingIndexProviderStrategy();
mips.setFailOnMissingIndexProvider(true);
EditorHook hook = new EditorHook(new EditorProvider() {
@Override
public Editor getRootEditor(NodeState before, NodeState after, NodeBuilder builder, CommitInfo info) throws CommitFailedException {
return new IndexUpdate(emptyProvider(), null, after, builder, noop).withMissingProviderStrategy(mips);
}
});
NodeState before = builder.getNodeState();
createIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "rootIndex", true, false, ImmutableSet.of("foo"), null);
builder.child(INDEX_DEFINITIONS_NAME).child("azerty");
builder.child("testRoot").setProperty("foo", "abc");
NodeState after = builder.getNodeState();
try {
hook.processCommit(before, after, CommitInfo.EMPTY);
fail("commit should fail on missing index provider");
} catch (CommitFailedException ex) {
// expected
}
}
Aggregations