-
Notifications
You must be signed in to change notification settings - Fork 3.7k
testclient: add regression test for LoadSimulationController executor… #25156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
2559450
3cc3d5a
d753bb9
ef0a582
6dfa3e8
abbb9c4
941ad2c
ed06782
bb1eda7
09f33d1
e97df9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * 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.pulsar.testclient; | ||
|
|
||
| import java.lang.reflect.Field; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ExecutorService; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
|
|
||
| public class LoadSimulationControllerTest { | ||
|
|
||
| @Test | ||
| public void shouldLeakThreadsWhenExecutorIsNotShutdown() throws Exception { | ||
| LoadSimulationController controller = new LoadSimulationController(); | ||
| Field threadPoolField = LoadSimulationController.class.getDeclaredField("threadPool"); | ||
| threadPoolField.setAccessible(true); | ||
| ExecutorService threadPool = (ExecutorService) threadPoolField.get(controller); | ||
|
|
||
| threadPool.submit(() -> { | ||
| try { | ||
| Thread.sleep(50); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| }); | ||
|
|
||
| Thread.sleep(100); | ||
|
|
||
| controller.close(); | ||
|
|
||
| long poolThreadCount = 0; | ||
| for (int i = 0; i < 20; i++) { | ||
| Map<Thread, StackTraceElement[]> threads = Thread.getAllStackTraces(); | ||
| poolThreadCount = threads.keySet().stream() | ||
| .filter(Thread::isAlive) | ||
| .filter(t -> !t.isDaemon()) | ||
| .filter(t -> t.getName().startsWith("pool-")) | ||
| .count(); | ||
| if (poolThreadCount == 0) { | ||
| break; | ||
| } | ||
| Thread.sleep(25); | ||
| } | ||
|
|
||
| assertTrue(poolThreadCount == 0, | ||
| String.format("Found %d alive non-daemon pool- threads after close", poolThreadCount)); | ||
ChimdumebiNebolisa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.