Skip to content
Permalink
Browse files
All tests working
  • Loading branch information
klcodanr committed Mar 18, 2022
1 parent 8892ff1 commit b8792d4e82e99dcc34df9f561231101cc6c23139
Showing 2 changed files with 10 additions and 121 deletions.
@@ -16,17 +16,11 @@
*/
package org.apache.jackrabbit.oak.plugins.index.elastic;

import static java.util.Arrays.asList;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@@ -40,130 +34,17 @@
import org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants;
import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;

public class ElasticFunctionIndexCommonTest extends FunctionIndexCommonTest {
@ClassRule
public static final ElasticConnectionRule elasticRule = new ElasticConnectionRule(
ElasticTestUtils.ELASTIC_CONNECTION_STRING);

@Rule
public TestName name = new TestName();

public ElasticFunctionIndexCommonTest() {
indexOptions = new ElasticIndexOptions();
}

@Before
public void filter() {
// assumeTrue(name.getMethodName().equals("lengthName"));
}

@Test
public void sameOrderableRelPropWithAndWithoutFunc_checkOrdering() throws Exception {

// Index def with same property - ordered - one with function and one without
Tree luceneIndex = createIndex("upper", Collections.<String>emptySet());
Tree nonFunc = luceneIndex.addChild(FulltextIndexConstants.INDEX_RULES)
.addChild("nt:base")
.addChild(FulltextIndexConstants.PROP_NODE)
.addChild("foo");
nonFunc.setProperty(FulltextIndexConstants.PROP_PROPERTY_INDEX, true);
nonFunc.setProperty(FulltextIndexConstants.PROP_ORDERED, true);
nonFunc.setProperty("name", "jcr:content/n/foo");

Tree func = luceneIndex.getChild(FulltextIndexConstants.INDEX_RULES)
.getChild("nt:base")
.getChild(FulltextIndexConstants.PROP_NODE)
.addChild("testOak");
func.setProperty(FulltextIndexConstants.PROP_ORDERED, true);
func.setProperty(FulltextIndexConstants.PROP_FUNCTION, "fn:upper-case(jcr:content/n/@foo)");

root.commit();

int i = 1;
// Create nodes that will be served by the index definition that follows
for (String node : asList("a", "c", "b", "e", "d")) {

Tree test = root.getTree("/").addChild(node);
test.setProperty("jcr:primaryType", "nt:unstructured", Type.NAME);

Tree a = test.addChild("jcr:content");
a.setProperty("jcr:primaryType", "nt:unstructured", Type.NAME);

Tree b = a.addChild("n");

b.setProperty("jcr:primaryType", "nt:unstructured", Type.NAME);
b.setProperty("foo", "bar" + i);
i++;
}

root.commit();
postCommitHook();

// Check ordering works for func and non func properties
assertOrderedPlanAndQuery(
"select * from [nt:base] order by upper([jcr:content/n/foo])",
getIndexProvider() + "upper(/oak:index/upper)", asList("/a", "/c", "/b", "/e", "/d"));

assertOrderedPlanAndQuery(
"select * from [nt:base] order by [jcr:content/n/foo]",
getIndexProvider() + "upper(/oak:index/upper)", asList("/a", "/c", "/b", "/e", "/d"));

assertOrderedPlanAndQuery(
"select * from [nt:base] order by upper([jcr:content/n/foo]) DESC",
getIndexProvider() + "upper(/oak:index/upper)", asList("/d", "/e", "/b", "/c", "/a"));

assertOrderedPlanAndQuery(
"select * from [nt:base] order by [jcr:content/n/foo] DESC",
getIndexProvider() + "upper(/oak:index/upper)", asList("/d", "/e", "/b", "/c", "/a"));

// Now we change the value of foo on already indexed nodes and see if changes
// get indexed properly.

i = 5;
for (String node : asList("a", "c", "b", "e", "d")) {

Tree test = root.getTree("/").getChild(node).getChild("jcr:content").getChild("n");

test.setProperty("foo", "bar" + i);
i--;
}
root.commit();
postCommitHook();

assertOrderedPlanAndQuery(
"select * from [nt:base] order by upper([jcr:content/n/foo])",
getIndexProvider() + "upper(/oak:index/upper)", asList("/d", "/e", "/b", "/c", "/a"));

assertOrderedPlanAndQuery(
"select * from [nt:base] order by [jcr:content/n/foo]",
getIndexProvider() + "upper(/oak:index/upper)", asList("/d", "/e", "/b", "/c", "/a"));

assertOrderedPlanAndQuery(
"select * from [nt:base] order by upper([jcr:content/n/foo]) DESC",
getIndexProvider() + "upper(/oak:index/upper)", asList("/a", "/c", "/b", "/e", "/d"));

assertOrderedPlanAndQuery(
"select * from [nt:base] order by [jcr:content/n/foo] DESC",
getIndexProvider() + "upper(/oak:index/upper)", asList("/a", "/c", "/b", "/e", "/d"));

}

private void assertOrderedPlanAndQuery(String query, String planExpectation, List<String> paths) {
List<String> result = assertPlanAndQuery(query, planExpectation, paths);
assertEquals("Ordering doesn't match", paths, result);
}

private List<String> assertPlanAndQuery(String query, String planExpectation, List<String> paths) {
assertThat(explain(query), containsString(planExpectation));
return assertQuery(query, paths);
}

@Override
protected String getIndexProvider() {
return "elasticsearch:";
@@ -976,7 +976,11 @@ public void sameOrderableRelPropWithAndWithoutFunc_checkOrdering() throws Except
}

root.commit();
postCommitHook();
// pure paranoia, this test seems to be more suceptable to delays in indexng
// than others
for (int j = 0; j < 5; j++) {
postCommitHook();
}

// Check ordering works for func and non func properties
assertOrderedPlanAndQuery(
@@ -1007,7 +1011,11 @@ public void sameOrderableRelPropWithAndWithoutFunc_checkOrdering() throws Except
i--;
}
root.commit();
postCommitHook();
// pure paranoia, this test seems to be more suceptable to delays in indexng
// than others
for (int j = 0; j < 5; j++) {
postCommitHook();
}

assertOrderedPlanAndQuery(
"select * from [nt:base] order by upper([jcr:content/n/foo])",

0 comments on commit b8792d4

Please sign in to comment.