You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2016/09/26 09:34:21 UTC
[2/2] lucene-solr:branch_6x: SOLR-9486: Fix race in AutoCommitTest
SOLR-9486: Fix race in AutoCommitTest
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0bece6fb
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0bece6fb
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0bece6fb
Branch: refs/heads/branch_6x
Commit: 0bece6fb09e9d44ccf0a20cd614705a4a76d2ac6
Parents: eee7063
Author: Alan Woodward <ro...@apache.org>
Authored: Wed Sep 7 09:14:30 2016 +0100
Committer: Alan Woodward <ro...@apache.org>
Committed: Mon Sep 26 10:34:07 2016 +0100
----------------------------------------------------------------------
.../org/apache/solr/update/AutoCommitTest.java | 29 ++++++++++++++++++++
.../apache/solr/update/HardAutoCommitTest.java | 2 ++
2 files changed, 31 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0bece6fb/solr/core/src/test/org/apache/solr/update/AutoCommitTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/update/AutoCommitTest.java b/solr/core/src/test/org/apache/solr/update/AutoCommitTest.java
index 080a02f..cefc89c 100644
--- a/solr/core/src/test/org/apache/solr/update/AutoCommitTest.java
+++ b/solr/core/src/test/org/apache/solr/update/AutoCommitTest.java
@@ -20,6 +20,7 @@ import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.lucene.util.LuceneTestCase.Slow;
@@ -49,6 +50,8 @@ class NewSearcherListener implements SolrEventListener {
private volatile TriggerOn triggerOnType;
private volatile SolrIndexSearcher newSearcher;
+ private CountDownLatch latch;
+
public NewSearcherListener() {
this(TriggerOn.Both);
}
@@ -63,6 +66,7 @@ class NewSearcherListener implements SolrEventListener {
@Override
public void newSearcher(SolrIndexSearcher newSearcher,
SolrIndexSearcher currentSearcher) {
+ waitForTrigger();
if (triggerOnType == TriggerOn.Soft && lastType == TriggerOn.Soft) {
triggered = true;
} else if (triggerOnType == TriggerOn.Hard && lastType == TriggerOn.Hard) {
@@ -84,6 +88,29 @@ class NewSearcherListener implements SolrEventListener {
lastType = TriggerOn.Soft;
}
+ private void waitForTrigger() {
+ if (latch != null) {
+ try {
+ if (latch.await(30, TimeUnit.SECONDS) == false) {
+ throw new AssertionError("Timed out waiting for search trigger to be released");
+ }
+ } catch (InterruptedException e) {
+ throw new AssertionError("Interrupted waiting for new searcher");
+ }
+ }
+ }
+
+ public void pause() {
+ latch = new CountDownLatch(1);
+ }
+
+ public void unpause() {
+ if (latch != null) {
+ latch.countDown();
+ latch = null;
+ }
+ }
+
public void reset() {
triggered = false;
// log.info("TEST: trigger reset");
@@ -316,6 +343,7 @@ public class AutoCommitTest extends AbstractSolrTestCase {
assertQ("shouldn't find any", req("id:530") ,"//result[@numFound=0]" );
// Delete one document with commitWithin
+ trigger.pause();
req.setContentStreams( toContentStreams(
delI("529", "commitWithin", "1000"), null ) );
trigger.reset();
@@ -323,6 +351,7 @@ public class AutoCommitTest extends AbstractSolrTestCase {
// Now make sure we can find it
assertQ("should find one", req("id:529") ,"//result[@numFound=1]" );
+ trigger.unpause();
// Wait for the commit to happen
assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0bece6fb/solr/core/src/test/org/apache/solr/update/HardAutoCommitTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/update/HardAutoCommitTest.java b/solr/core/src/test/org/apache/solr/update/HardAutoCommitTest.java
index eb2e8aa..3c652b2 100644
--- a/solr/core/src/test/org/apache/solr/update/HardAutoCommitTest.java
+++ b/solr/core/src/test/org/apache/solr/update/HardAutoCommitTest.java
@@ -90,6 +90,7 @@ public class HardAutoCommitTest extends AbstractSolrTestCase {
assertQ("shouldn't find any", req("id:530") ,"//result[@numFound=0]" );
// Delete one document with commitWithin
+ trigger.pause();
req.setContentStreams( AutoCommitTest.toContentStreams(
delI("529", "commitWithin", "1000"), null ) );
trigger.reset();
@@ -97,6 +98,7 @@ public class HardAutoCommitTest extends AbstractSolrTestCase {
// Now make sure we can find it
assertQ("should find one", req("id:529") ,"//result[@numFound=1]" );
+ trigger.unpause();
// Wait for the commit to happen
assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));