mreutegg commented on a change in pull request #453: URL: https://github.com/apache/jackrabbit-oak/pull/453#discussion_r780950882
########## File path: oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/RecoveryWithIncorrectClockTest.java ########## @@ -0,0 +1,97 @@ +/* + * 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.document; + +import java.util.concurrent.TimeUnit; + +import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore; +import org.apache.jackrabbit.oak.stats.Clock; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.lessThan; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class RecoveryWithIncorrectClockTest { + + @Rule + public DocumentMKBuilderProvider builderProvider = new DocumentMKBuilderProvider(); + + private final DocumentStore store = new MemoryDocumentStore(); + private final FailingDocumentStore s1 = new FailingDocumentStore(store); + + private final Clock clock = new Clock.Virtual(); + + private DocumentNodeStore ns1; + + private DocumentNodeStore ns2; + + @Before + public void before() throws Exception { + clock.waitUntil(System.currentTimeMillis()); + Revision.setClock(clock); + ClusterNodeInfo.setClock(clock); + ns1 = createDocumentNodeStore(1, s1); + ns2 = createDocumentNodeStore(2, store); + } + + @AfterClass + public static void after() { + Revision.resetClockToDefault(); + ClusterNodeInfo.resetClockToDefault(); + } + + @Test + public void recover() throws Exception { + // prevent ns1 from writing anything. This will also prevent any + // further updates to clusterNodes entry 1 + s1.fail().after(0).eternally(); + + long now = clock.getTime(); + // simulate a sudden jump of time to the system clock + clock.waitUntil(now + TimeUnit.HOURS.toMillis(1)); + long ahead = clock.getTime(); + // ns2 now sees an expired lease for clusterId 1 + LastRevRecoveryAgent agent = ns2.getLastRevRecoveryAgent(); + try { + assertTrue(agent.isRecoveryNeeded()); + agent.performRecoveryIfNeeded(); + } catch (DocumentStoreException e) { + // this is expected. any of the above LastRevRecoveryAgent calls + // can and should fail because the lease for ns2 expired + } + + ClusterNodeInfoDocument infoDoc = store.find(Collection.CLUSTER_NODES, "" + 1); Review comment: Yes, you are right. Don't know what I was thinking here. Probably copied the line and adjusted. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
