Introduce NetconfTimer
[netconf.git] / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / netconf / test / tool / client / stress / StressClient.java
index 9b1c30d244f83840a7773b37f6a34f2ee1c0f1be..ed2b31a742babf2b547565001b5c4fc30e66a620 100644 (file)
@@ -30,6 +30,7 @@ import org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder;
 import org.opendaylight.netconf.client.mdsal.NetconfDeviceCommunicator;
 import org.opendaylight.netconf.client.mdsal.api.NetconfSessionPreferences;
 import org.opendaylight.netconf.client.mdsal.api.RemoteDevice;
+import org.opendaylight.netconf.common.impl.DefaultNetconfTimer;
 import org.opendaylight.netconf.test.tool.TestToolUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.CommitInput;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.EditConfigInput;
@@ -165,29 +166,30 @@ public final class StressClient {
             }
         }
 
-        final var netconfClientFactory = new NetconfClientFactoryImpl();
+        try (var timer = new DefaultNetconfTimer()) {
+            try (var netconfClientFactory = new NetconfClientFactoryImpl(timer)) {
 
-        final var callables = new ArrayList<StressClientCallable>(threadAmount);
-        for (var messages : allPreparedMessages) {
-            callables.add(new StressClientCallable(params, netconfClientFactory, getBaseConfiguration(), messages));
-        }
-
-        final var executorService = Executors.newFixedThreadPool(threadAmount);
+                final var callables = new ArrayList<StressClientCallable>(threadAmount);
+                for (var messages : allPreparedMessages) {
+                    callables.add(new StressClientCallable(params, netconfClientFactory, getBaseConfiguration(),
+                        messages));
+                }
 
-        LOG.info("Starting stress test");
-        final var sw = Stopwatch.createStarted();
-        final var futures = executorService.invokeAll(callables);
-        for (var future : futures) {
-            future.get(4L, TimeUnit.MINUTES);
-        }
-        executorService.shutdownNow();
-        sw.stop();
+                final var executorService = Executors.newFixedThreadPool(threadAmount);
 
-        LOG.info("FINISHED. Execution time: {}", sw);
-        LOG.info("Requests per second: {}", params.editCount * 1000.0 / sw.elapsed(TimeUnit.MILLISECONDS));
+                LOG.info("Starting stress test");
+                final var sw = Stopwatch.createStarted();
+                final var futures = executorService.invokeAll(callables);
+                for (var future : futures) {
+                    future.get(4L, TimeUnit.MINUTES);
+                }
+                executorService.shutdownNow();
+                sw.stop();
 
-        // Cleanup
-        netconfClientFactory.close();
+                LOG.info("FINISHED. Execution time: {}", sw);
+                LOG.info("Requests per second: {}", params.editCount * 1000.0 / sw.elapsed(TimeUnit.MILLISECONDS));
+            }
+        }
     }
 
     static NetconfMessage prepareMessage(final int id, final String editContentString) {