Skip to content
Permalink
Browse files
Adding missing files
  • Loading branch information
klcodanr committed Mar 10, 2022
1 parent 8a44639 commit f220ce4e7e5f71ae9defd64f71f26ac9f8633e04
Show file tree
Hide file tree
Showing 3 changed files with 289 additions and 0 deletions.
@@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.jackrabbit.oak.index.merge;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import groovy.json.StringEscapeUtils;

/**
* Test merging conflict detection
*/
@RunWith(Parameterized.class)
public class IndexDefMergerConflictsTest extends ParameterizedMergingTestBase {

@Parameters(name = "{0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
testCase("product and custom properties must equal if not in ancestor",
"conflict-new-properties.json")
});
}

private final String expectedMessage;

public IndexDefMergerConflictsTest(String name, String testCaseFile)
throws IOException {
super(name, testCaseFile);
this.expectedMessage = StringEscapeUtils.unescapeJavaScript(testCase.getProperties().get("expected"));
}

@Test
public void verifyExpectedConflict() {
UnsupportedOperationException exception = assertThrows(
"Expected exception not thrown for test case:" + super.testCaseName,
UnsupportedOperationException.class,
() -> IndexDefMergerUtils.merge(buildIndexes, runIndexes));
assertEquals("Unexpected exception message validating: " + super.testCaseName, "" + expectedMessage,
"\"" + exception.getMessage() + "\"");
}

}
@@ -0,0 +1,54 @@
package org.apache.jackrabbit.oak.index.merge;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Optional;

import org.apache.commons.io.IOUtils;
import org.apache.jackrabbit.oak.commons.json.JsonObject;

public class ParameterizedMergingTestBase {

protected final String testCaseFile;
protected final String testCaseName;
protected final JsonObject buildIndexes;
protected final JsonObject runIndexes;
protected final JsonObject testCase;

public static Object[] testCase(String name, String testCaseFile) {
return new Object[] {
name,
testCaseFile
};
}

public ParameterizedMergingTestBase(String name, String testCaseFile)
throws IOException {
this.testCaseName = name;
this.testCaseFile = testCaseFile;
this.testCase = readTestCaseFile(testCaseFile);
this.buildIndexes = getTestCaseChild("build");
this.runIndexes = getTestCaseChild("run");
}

private JsonObject readTestCaseFile(String testCaseFileName) {
return Optional.ofNullable(IndexDefMergerConflictsTest.class.getResourceAsStream(testCaseFileName))
.map(in -> {
try {
return IOUtils.toString(in, StandardCharsets.UTF_8.toString());
} catch (IOException e) {
throw new IllegalArgumentException(
"Unexpected IOException reading test case file: " + testCaseFileName, e);
}
})
.map(s -> JsonObject.fromJson(s, true))
.orElseThrow(() -> new IllegalArgumentException("Unable to read test case file: " + testCaseFileName));
}

protected JsonObject getTestCaseChild(String fieldName) {
return Optional.ofNullable(testCase.getChildren().get(fieldName))
.orElseThrow(() -> new IllegalArgumentException(
"Unable to run test: " + testCaseName + ", Expected field " + fieldName + " not set"));
}

}
@@ -0,0 +1,168 @@
{
"build": {
"/oak:index/lucene-2": {
"jcr:primaryType": "nam:oak:QueryIndexDefinition",
":version": 2,
"includePropertyTypes": ["String", "Binary"],
"type": "lucene",
"async": "async",
"reindex": false,
"reindexCount": 1,
"indexRules": {
"jcr:primaryType": "nam:nt:unstructured",
"nt:base": {
"jcr:primaryType": "nam:nt:unstructured",
"includePropertyTypes": ["String", "Binary"],
"properties": {
"jcr:primaryType": "nam:nt:unstructured",
"sling:alias": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "sling:alias",
"index": false
},
"jcr:lastmodifiedby": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "str:jcr:lastmodifiedby",
"index": false
},
"sling:resourcetype": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "sling:resourcetype",
"index": false
},
"jcr:createdby": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "str:jcr:createdby",
"index": false
},
"sling:vanitypath": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "sling:vanitypath",
"index": false
},
"prop0": {
"jcr:primaryType": "nam:nt:unstructured",
"nodeScopeIndex": true,
"propertyIndex": false,
"analyzed": true,
"useInExcerpt": true,
"isRegexp": true,
"name": "^[^\\/]*$"
}
}
}
}
}
},

"run": {
"/oak:index/lucene-1": {
"jcr:primaryType": "nam:oak:QueryIndexDefinition",
":version": 2,
"includePropertyTypes": ["String", "Binary"],
"type": "lucene",
"async": "async",
"reindex": false,
"reindexCount": 1,
"indexRules": {
"jcr:primaryType": "nam:nt:unstructured",
"nt:base": {
"jcr:primaryType": "nam:nt:unstructured",
"includePropertyTypes": ["String", "Binary"],
"properties": {
"jcr:primaryType": "nam:nt:unstructured",
"sling:alias": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "sling:alias",
"index": false
},
"jcr:lastmodifiedby": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "str:jcr:lastmodifiedby",
"index": false
},
"sling:resourcetype": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "sling:resourcetype",
"index": false
},
"jcr:createdby": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "str:jcr:createdby",
"index": false
},
"prop0": {
"jcr:primaryType": "nam:nt:unstructured",
"nodeScopeIndex": true,
"propertyIndex": false,
"analyzed": true,
"useInExcerpt": true,
"isRegexp": true,
"name": "^[^\\/]*$"
}
}
}
}
},
"/oak:index/lucene-1-custom-1": {
"jcr:primaryType": "nam:oak:QueryIndexDefinition",
":version": 2,
"includePropertyTypes": ["String", "Binary"],
"type": "lucene",
"async": "async",
"reindex": false,
"reindexCount": 1,
"indexRules": {
"jcr:primaryType": "nam:nt:unstructured",
"nt:base": {
"jcr:primaryType": "nam:nt:unstructured",
"includePropertyTypes": ["String", "Binary"],
"properties": {
"jcr:primaryType": "nam:nt:unstructured",
"sling:alias": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "sling:alias",
"index": false
},
"jcr:lastmodifiedby": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "str:jcr:lastmodifiedby",
"index": false
},
"sling:resourcetype": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "sling:resourcetype",
"index": false
},
"jcr:createdby": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "str:jcr:createdby",
"index": false
},
"myco:myProperty": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "myco:myProperty",
"index": false
},
"sling:vanitypath": {
"jcr:primaryType": "nam:nt:unstructured",
"name": "sling:vanitypath2",
"index": false
},
"prop0": {
"jcr:primaryType": "nam:nt:unstructured",
"nodeScopeIndex": true,
"propertyIndex": false,
"analyzed": true,
"useInExcerpt": true,
"isRegexp": true,
"name": "^[^\\/]*$"
}
}
}
}
}
},

"expected": "Index: /oak:index/lucene-2: Conflicts detected: [Could not merge value; path=/indexRules/nt:base/properties/sling:vanitypath property=name; ancestor=null; custom=\"sling:vanitypath2\"; product=\"sling:vanitypath\"]"
}

0 comments on commit f220ce4

Please sign in to comment.