You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by to...@apache.org on 2018/09/19 06:46:43 UTC
svn commit: r1841291 [3/3] - in /jackrabbit/oak/trunk/oak-search/src:
main/java/org/apache/jackrabbit/oak/plugins/index/search/
main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/binary/
main/java/org/apache/jackrabbit/oak/plugins/index/searc...
Added: jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/update/RefreshOnWritePolicyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/update/RefreshOnWritePolicyTest.java?rev=1841291&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/update/RefreshOnWritePolicyTest.java (added)
+++ jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/update/RefreshOnWritePolicyTest.java Wed Sep 19 06:46:42 2018
@@ -0,0 +1,48 @@
+/*
+ * 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.plugins.index.search.update;
+
+import org.junit.Test;
+
+public class RefreshOnWritePolicyTest {
+ private final RecordingRunnable refreshCallback = new RecordingRunnable();
+
+ @Test
+ public void noRefreshOnRead() throws Exception{
+ RefreshOnWritePolicy policy = new RefreshOnWritePolicy();
+ policy.refreshOnReadIfRequired(refreshCallback);
+ refreshCallback.assertNotInvokedAndReset();
+
+ //Even after update it should not be refreshed
+ policy.updated();
+ policy.refreshOnReadIfRequired(refreshCallback);
+ refreshCallback.assertNotInvokedAndReset();
+ }
+
+ @Test
+ public void refreshOnWrite() throws Exception{
+ RefreshOnWritePolicy policy = new RefreshOnWritePolicy();
+
+ policy.updated();
+ policy.refreshOnWriteIfRequired(refreshCallback);
+ refreshCallback.assertInvokedAndReset();
+ }
+
+}
\ No newline at end of file
Propchange: jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/update/RefreshOnWritePolicyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/update/TimedRefreshPolicyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/update/TimedRefreshPolicyTest.java?rev=1841291&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/update/TimedRefreshPolicyTest.java (added)
+++ jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/update/TimedRefreshPolicyTest.java Wed Sep 19 06:46:42 2018
@@ -0,0 +1,106 @@
+/*
+ * 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.plugins.index.search.update;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.jackrabbit.oak.stats.Clock;
+import org.junit.Test;
+
+public class TimedRefreshPolicyTest {
+ private final Clock clock = new Clock.Virtual();
+ private final RecordingRunnable refreshCallback = new RecordingRunnable();
+
+ @Test
+ public void dirtyAndFirstCheck() throws Exception{
+ clock.waitUntil(System.currentTimeMillis());
+ TimedRefreshPolicy policy = new TimedRefreshPolicy(clock, TimeUnit.SECONDS, 1);
+ policy.refreshOnWriteIfRequired(refreshCallback);
+ refreshCallback.assertNotInvokedAndReset();
+
+ policy.updated();
+
+ policy.refreshOnWriteIfRequired(refreshCallback);
+ refreshCallback.assertInvokedAndReset();
+
+ policy.refreshOnWriteIfRequired(refreshCallback);
+ refreshCallback.assertNotInvokedAndReset();
+ }
+
+ @Test
+ public void dirtyAndNotElapsedTimed() throws Exception{
+ clock.waitUntil(System.currentTimeMillis());
+ TimedRefreshPolicy policy = new TimedRefreshPolicy(clock, TimeUnit.SECONDS, 1);
+
+ policy.updated();
+ policy.refreshOnWriteIfRequired(refreshCallback);
+ refreshCallback.assertInvokedAndReset();
+
+ policy.refreshOnWriteIfRequired(refreshCallback);
+ refreshCallback.assertNotInvokedAndReset();
+
+ policy.updated();
+ //Given time has not elapsed it should still be false
+ policy.refreshOnWriteIfRequired(refreshCallback);
+ refreshCallback.assertNotInvokedAndReset();
+ }
+
+ @Test
+ public void dirtyAndElapsedTime() throws Exception{
+ clock.waitUntil(System.currentTimeMillis());
+ TimedRefreshPolicy policy = new TimedRefreshPolicy(clock, TimeUnit.SECONDS, 1);
+
+ policy.updated();
+ policy.refreshOnWriteIfRequired(refreshCallback);
+ refreshCallback.assertInvokedAndReset();
+
+ policy.refreshOnWriteIfRequired(refreshCallback);
+ refreshCallback.assertNotInvokedAndReset();
+
+ policy.updated();
+ //Given time has not elapsed it should still be false
+ //in both reader and writer mode
+ policy.refreshOnWriteIfRequired(refreshCallback);
+ refreshCallback.assertNotInvokedAndReset();
+
+ policy.refreshOnWriteIfRequired(refreshCallback);
+ refreshCallback.assertNotInvokedAndReset();
+
+ //Let the refresh delta time elapse
+ long refreshDelta = TimeUnit.SECONDS.toMillis(1) + 1;
+ clock.waitUntil(System.currentTimeMillis() + refreshDelta);
+
+ policy.refreshOnWriteIfRequired(refreshCallback);
+ refreshCallback.assertInvokedAndReset();
+
+ policy.refreshOnWriteIfRequired(refreshCallback);
+ refreshCallback.assertNotInvokedAndReset();
+
+ policy.updated();
+ //Do similar check for read
+ clock.waitUntil(clock.getTime() + refreshDelta);
+
+ policy.refreshOnReadIfRequired(refreshCallback);
+ refreshCallback.assertInvokedAndReset();
+
+ policy.refreshOnReadIfRequired(refreshCallback);
+ refreshCallback.assertNotInvokedAndReset();
+ }
+}
\ No newline at end of file
Propchange: jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/update/TimedRefreshPolicyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/util/NodeStateClonerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/util/NodeStateClonerTest.java?rev=1841291&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/util/NodeStateClonerTest.java (added)
+++ jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/util/NodeStateClonerTest.java Wed Sep 19 06:46:42 2018
@@ -0,0 +1,64 @@
+/*
+ * 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.plugins.index.search.util;
+
+import org.apache.jackrabbit.oak.spi.state.EqualsDiff;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
+import org.junit.Test;
+
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class NodeStateClonerTest {
+
+ @Test
+ public void simple() throws Exception{
+ NodeBuilder builder = EMPTY_NODE.builder();
+ builder.child("a").child("b");
+ builder.child("a").setProperty("foo", "bar");
+
+ NodeState state = builder.getNodeState();
+ assertTrue(EqualsDiff.equals(state, NodeStateCloner.cloneVisibleState(state)));
+ }
+
+ @Test
+ public void excludeHidden() throws Exception{
+ NodeBuilder builder = EMPTY_NODE.builder();
+ builder.child("a").child(":b").child("e");
+ builder.child("a").child("c").child(":d");
+ builder.child("a").setProperty("foo", "bar");
+
+ NodeState source = builder.getNodeState();
+ NodeState cloned = NodeStateCloner.cloneVisibleState(source);
+
+ assertFalse(NodeStateUtils.getNode(cloned, "/a/:b").exists());
+ assertFalse(NodeStateUtils.getNode(cloned, "/a/:b/e").exists());
+ assertFalse(NodeStateUtils.getNode(cloned, "/a/c/:d").exists());
+
+ assertTrue(NodeStateUtils.getNode(cloned, "/a/c").exists());
+ assertTrue(NodeStateUtils.getNode(cloned, "/a").hasProperty("foo"));
+
+ assertFalse(EqualsDiff.equals(source, cloned));
+ }
+
+}
\ No newline at end of file
Propchange: jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/util/NodeStateClonerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/util/NodeStateCopyUtilsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/util/NodeStateCopyUtilsTest.java?rev=1841291&r1=1841290&r2=1841291&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/util/NodeStateCopyUtilsTest.java (original)
+++ jackrabbit/oak/trunk/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/search/util/NodeStateCopyUtilsTest.java Wed Sep 19 06:46:42 2018
@@ -47,7 +47,7 @@ import static org.apache.jackrabbit.oak.
import static org.junit.Assert.assertEquals;
public class NodeStateCopyUtilsTest {
- private NodeBuilder builder = EMPTY_NODE.builder();
+ private final NodeBuilder builder = EMPTY_NODE.builder();
private Repository repository;
@After