forked from apache/solr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SOLR-15635: don't repeat close hooks if SRI cleared twice due to usin…
…g MDCThreadPool (apache#376) * SOLR-15635: don't repeat close hooks if SRI cleared twice * user impact: fromCore is closed by {!join} if used under `/export` * Use reference counting to close on last close. Also: * trace logging * protected -> private Co-authored-by: David Smiley <[email protected]> Co-authored-by: Mikhail Khludnev <[email protected]>
- Loading branch information
1 parent
f088857
commit dbdd2d4
Showing
4 changed files
with
149 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
solr/core/src/test/org/apache/solr/request/TestSolrRequestInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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.solr.request; | ||
|
||
import java.util.concurrent.ArrayBlockingQueue; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.apache.solr.SolrTestCaseJ4; | ||
import org.apache.solr.common.util.ExecutorUtil; | ||
import org.apache.solr.response.SolrQueryResponse; | ||
import org.junit.BeforeClass; | ||
|
||
public class TestSolrRequestInfo extends SolrTestCaseJ4 { | ||
|
||
@BeforeClass | ||
public static void beforeClass() throws Exception { | ||
initCore("solrconfig.xml","schema11.xml"); | ||
} | ||
|
||
public void testCloseHookTwice(){ | ||
final SolrRequestInfo info = new SolrRequestInfo( | ||
new LocalSolrQueryRequest(h.getCore(), params()), | ||
new SolrQueryResponse()); | ||
AtomicInteger counter = new AtomicInteger(); | ||
info.addCloseHook(counter::incrementAndGet); | ||
SolrRequestInfo.setRequestInfo(info); | ||
SolrRequestInfo.setRequestInfo(info); | ||
SolrRequestInfo.clearRequestInfo(); | ||
assertNotNull(SolrRequestInfo.getRequestInfo()); | ||
SolrRequestInfo.clearRequestInfo(); | ||
assertEquals("hook should be closed only once", 1, counter.get()); | ||
assertNull(SolrRequestInfo.getRequestInfo()); | ||
} | ||
|
||
public void testThreadPool() throws InterruptedException { | ||
final SolrRequestInfo info = new SolrRequestInfo( | ||
new LocalSolrQueryRequest(h.getCore(), params()), | ||
new SolrQueryResponse()); | ||
AtomicInteger counter = new AtomicInteger(); | ||
|
||
SolrRequestInfo.setRequestInfo(info); | ||
ExecutorUtil.MDCAwareThreadPoolExecutor pool = new ExecutorUtil.MDCAwareThreadPoolExecutor(1, 1, 1, | ||
TimeUnit.SECONDS, new ArrayBlockingQueue<>(1)); | ||
AtomicBoolean run = new AtomicBoolean(false); | ||
pool.execute(() -> { | ||
final SolrRequestInfo poolInfo = SolrRequestInfo.getRequestInfo(); | ||
assertSame(info, poolInfo); | ||
info.addCloseHook(counter::incrementAndGet); | ||
run.set(true); | ||
}); | ||
if (random().nextBoolean()) { | ||
pool.shutdown(); | ||
} else { | ||
pool.shutdownNow(); | ||
} | ||
SolrRequestInfo.clearRequestInfo(); | ||
SolrRequestInfo.reset(); | ||
|
||
pool.awaitTermination(1, TimeUnit.MINUTES); | ||
assertTrue(run.get()); | ||
assertEquals("hook should be closed only once", 1, counter.get()); | ||
assertNull(SolrRequestInfo.getRequestInfo()); | ||
} | ||
} |