* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.test.tool;
import ch.qos.logback.classic.Level;
import com.google.common.base.Stopwatch;
+import com.google.common.collect.Lists;
+import com.google.common.math.IntMath;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import java.util.ArrayList;
+import java.math.RoundingMode;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
import org.opendaylight.netconf.test.tool.config.Configuration;
import org.opendaylight.netconf.test.tool.config.ConfigurationBuilder;
import org.slf4j.Logger;
private static final Logger LOG = LoggerFactory.getLogger(Main.class);
private Main() {
-
+ // hidden on purpose
}
@SuppressWarnings("checkstyle:IllegalCatch")
}
//if ODL controller ip is not set NETCONF devices will be started, but not registered at the controller
if (params.controllerIp != null) {
- final ArrayList<ArrayList<Execution.DestToPayload>> allThreadsPayloads = params
- .getThreadsPayloads(openDevices);
- final ArrayList<Execution> executions = new ArrayList<>();
- for (ArrayList<Execution.DestToPayload> payloads : allThreadsPayloads) {
- executions.add(new Execution(params, payloads));
- }
+ final List<Execution> executionThreads = divideDevicesForThreads(openDevices, params);
final ExecutorService executorService = Executors.newFixedThreadPool(params.threadAmount);
final Stopwatch time = Stopwatch.createStarted();
- List<Future<Void>> futures = executorService.invokeAll(executions, params.timeOut, TimeUnit.SECONDS);
+ final List<Future<Void>> futures = executorService.invokeAll(executionThreads,
+ params.timeOut, TimeUnit.SECONDS);
int threadNum = 0;
- for (Future<Void> future : futures) {
+ for (final Future<Void> future : futures) {
threadNum++;
if (future.isCancelled()) {
- LOG.info("{}. thread timed out.",threadNum);
+ LOG.info("{}. thread timed out.", threadNum);
} else {
try {
future.get();
}
}
time.stop();
- LOG.info("Time spent with configuration of devices: {}.",time);
+ LOG.info("Time spent with configuration of devices: {}.", time);
}
- } catch (RuntimeException | InterruptedException e) {
+ } catch (final RuntimeException | InterruptedException e) {
LOG.error("Unhandled exception", e);
netconfDeviceSimulator.close();
System.exit(1);
}
}
}
+
+ private static List<Execution> divideDevicesForThreads(final List<Integer> openDevices,
+ final TesttoolParameters params) {
+ final int devicesPerThread = IntMath.divide(openDevices.size(), params.threadAmount, RoundingMode.UP);
+ return Lists.partition(openDevices, devicesPerThread).stream()
+ .map(t -> new Execution(t, params))
+ .collect(Collectors.toList());
+ }
}