Skip to content

Package: ConcurrentClientExecutor$Fixed

ConcurrentClientExecutor$Fixed

nameinstructionbranchcomplexitylinemethod
ConcurrentClientExecutor.Fixed(DeploymentContext, TestClient)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createExecutorService()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Distribution License v. 1.0, which is available at
6: * http://www.eclipse.org/org/documents/edl-v10.php.
7: *
8: * SPDX-License-Identifier: BSD-3-Clause
9: */
10:
11: package com.sun.xml.ws.test.exec;
12:
13: import bsh.Interpreter;
14: import com.sun.xml.ws.test.container.DeploymentContext;
15: import com.sun.xml.ws.test.model.TestClient;
16:
17: import java.util.Vector;
18: import java.util.concurrent.ExecutorService;
19: import java.util.concurrent.Executors;
20: import java.util.concurrent.TimeUnit;
21:
22: /**
23: * Executes {@link TestClient} in concurrent fashion via
24: * {@link Executor}.
25: *
26: * @author Kohsuke Kawaguchi
27: */
28: public abstract class ConcurrentClientExecutor extends ClientExecutor {
29: /**
30: * Degree of concurrency.
31: */
32: public static final int THREAD_COUNT = 20;
33:
34: public static final int REQUESTS = 50000;
35:
36: public ConcurrentClientExecutor(DeploymentContext context, TestClient client) {
37: super(context, client);
38: }
39:
40: /**
41: * Runs the actual test in highly concurrent fashion.
42: */
43: protected void invoke(final Interpreter engine) throws Throwable {
44: ExecutorService service = createExecutorService();
45: // record all errors
46: final Vector<Throwable> errors = new Vector<Throwable>();
47:
48: for(int i=0; i<REQUESTS && errors.isEmpty(); i++) {
49: service.execute(new Runnable() {
50: public void run() {
51: try {
52: ConcurrentClientExecutor.super.invoke(engine);
53: } catch(Throwable e) {
54: errors.add(e);
55: }
56: }
57: });
58: }
59: service.shutdown();
60:
61: while(!service.awaitTermination(1L, TimeUnit.SECONDS))
62: ;
63:
64: // if any error, print first 20 of them
65: if(!errors.isEmpty())
66: System.out.printf("Found %d errors\n",errors.size());
67: for (Throwable error : errors.subList(0,Math.min(errors.size(),20)))
68: error.printStackTrace();
69: if(!errors.isEmpty())
70: throw errors.get(0); // and throw the first failure to make the test fail
71: }
72:
73: /**
74: * Creates the {@link ExecutorService} used for testing.
75: */
76: protected abstract ExecutorService createExecutorService();
77:
78: /**
79: * Fixed thread pool.
80: */
81: public static final class Fixed extends ConcurrentClientExecutor {
82: public Fixed(DeploymentContext context, TestClient client) {
83: super(context, client);
84: }
85:
86: protected ExecutorService createExecutorService() {
87: return Executors.newFixedThreadPool(THREAD_COUNT);
88: }
89: }
90:
91: /**
92: * Fixed thread pool.
93: */
94: public static final class Cached extends ConcurrentClientExecutor {
95: public Cached(DeploymentContext context, TestClient client) {
96: super(context, client);
97: }
98:
99: protected ExecutorService createExecutorService() {
100: return Executors.newCachedThreadPool();
101: }
102: }
103: }