[JENKINS-52101] protect against possible IllegalArgumentException (#1758)
* [JENKINS-52101] protect against possible IllegalArgumentException Signed-off-by: olivier lamy <olamy@apache.org> * add unit test Signed-off-by: olivier lamy <olamy@apache.org> * cleanup imports Signed-off-by: olivier lamy <olamy@apache.org>
This commit is contained in:
parent
1124704057
commit
518eb57462
|
@ -92,12 +92,7 @@ public class RunSearch extends OmniSearch<BlueRun> {
|
|||
RunList<? extends Run> runList = p.getBuilds();
|
||||
|
||||
for (Run r : runList) {
|
||||
BlueRun run = BlueRunFactory.getRun(r, new Reachable() {
|
||||
@Override
|
||||
public Link getLink() {
|
||||
return parent;
|
||||
}
|
||||
});
|
||||
BlueRun run = BlueRunFactory.getRun(r, () -> parent);
|
||||
if (run != null) {
|
||||
runs.add(run);
|
||||
}
|
||||
|
@ -133,7 +128,9 @@ public class RunSearch extends OmniSearch<BlueRun> {
|
|||
return runs;
|
||||
}
|
||||
|
||||
private static final int COLLECT_THREADS = Integer.getInteger( "blueocean.collectRuns.threads", 0 );
|
||||
public static final String COLLECT_THREADS_KEY = "blueocean.collectRuns.threads";
|
||||
|
||||
private static final int COLLECT_THREADS = Integer.getInteger( COLLECT_THREADS_KEY, 0 );
|
||||
|
||||
private static List<BlueRun> collectRuns(Iterator<? extends Run> runIterator, final Link parent, int start, int limit){
|
||||
if (COLLECT_THREADS > 1) {
|
||||
|
@ -184,11 +181,14 @@ public class RunSearch extends OmniSearch<BlueRun> {
|
|||
}
|
||||
int n = callables.size();
|
||||
LOGGER.debug( "before submit size:{}", n );
|
||||
if(n<1){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
ExecutorService
|
||||
executorService = new ThreadPoolExecutor( n < COLLECT_THREADS? n : COLLECT_THREADS,
|
||||
n < COLLECT_THREADS? n : COLLECT_THREADS,
|
||||
60L, TimeUnit.MILLISECONDS,
|
||||
new ArrayBlockingQueue<>( limit ));
|
||||
new ArrayBlockingQueue<>( n ));
|
||||
ExecutorCompletionService<BlueRun> ecs = new ExecutorCompletionService( executorService );
|
||||
for(Callable<BlueRun> callable : callables) {
|
||||
ecs.submit( callable );
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package io.jenkins.blueocean.service.embedded.rest;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Resources;
|
||||
import io.jenkins.blueocean.rest.model.BlueRun;
|
||||
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
|
||||
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.jvnet.hudson.test.Issue;
|
||||
import org.jvnet.hudson.test.JenkinsRule;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class RunMultiThreadLoadTest
|
||||
{
|
||||
@Rule
|
||||
public JenkinsRule j = new JenkinsRule();
|
||||
|
||||
@BeforeClass
|
||||
public static void activate_multi_threaded() {
|
||||
System.setProperty( RunSearch.COLLECT_THREADS_KEY, "2" );
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void desactivate_multi_threaded() {
|
||||
System.setProperty( RunSearch.COLLECT_THREADS_KEY, "0" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void load_runs_multi_threaded() throws Exception {
|
||||
|
||||
URL resource = Resources.getResource( getClass(), "RunMultiThreadLoadTest.jenkinsfile");
|
||||
String jenkinsFile = Resources.toString( resource, Charsets.UTF_8);
|
||||
WorkflowJob p = j.createProject( WorkflowJob.class, "project1");
|
||||
p.setDefinition(new CpsFlowDefinition( jenkinsFile, false));
|
||||
p.save();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
j.waitForCompletion(p.scheduleBuild2(0).waitForStart());
|
||||
}
|
||||
Iterable<BlueRun> blueRuns = RunSearch.findRuns( p, null, 0, 20 );
|
||||
List<BlueRun> runs = StreamSupport.stream( blueRuns.spliterator(), false )
|
||||
.collect(Collectors.toList());
|
||||
Assert.assertFalse( runs.isEmpty() );
|
||||
Assert.assertEquals( 10, runs.size() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@Issue( "JENKINS-52101" )
|
||||
public void load_runs_multi_threaded_no_runs() throws Exception {
|
||||
|
||||
URL resource = Resources.getResource( getClass(), "RunMultiThreadLoadTest.jenkinsfile");
|
||||
String jenkinsFile = Resources.toString( resource, Charsets.UTF_8);
|
||||
WorkflowJob p = j.createProject( WorkflowJob.class, "project2");
|
||||
p.setDefinition(new CpsFlowDefinition( jenkinsFile, false));
|
||||
p.save();
|
||||
|
||||
Iterable<BlueRun> blueRuns = RunSearch.findRuns( p, null, 0, 0 );
|
||||
List<BlueRun> runs = StreamSupport.stream( blueRuns.spliterator(), false )
|
||||
.collect(Collectors.toList());
|
||||
Assert.assertTrue( runs.isEmpty() );
|
||||
Assert.assertEquals( 0, runs.size() );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
node {
|
||||
echo "Multi thread load"
|
||||
def test = "<testsuite tests=\"3\">\n" +
|
||||
" <testcase classname=\"foo1\" name=\"ASuccessfulTest\"/>\n" +
|
||||
" <testcase classname=\"foo2\" name=\"AnotherSuccessfulTest\"/>\n" +
|
||||
" <testcase classname=\"foo3\" name=\"AFailingTest\">\n" +
|
||||
" <failure type=\"NotEnoughFoo\"> details about failure </failure>\n" +
|
||||
" </testcase>\n" +
|
||||
"</testsuite>";
|
||||
writeFile file:'result.xml', text: test
|
||||
junit 'result.xml'
|
||||
}
|
Loading…
Reference in New Issue