From 6d51170e94038f9db0740022066ba4301f82691b Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 15 Jan 2024 08:13:08 +0100 Subject: [PATCH] Migrate ntfbenchmark The model is using only a single notification, do not use generated Listener. Change-Id: I3f9f4074994fd0ad133f21de1b44cdfd277f4858 Signed-off-by: Robert Varga --- .../impl/NtfbenchTestListener.java | 7 +++--- .../impl/NtfbenchWTCListener.java | 5 ++-- .../impl/NtfbenchmarkProvider.java | 23 +++++++++---------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchTestListener.java b/benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchTestListener.java index d126b2774a..b57d37b99b 100644 --- a/benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchTestListener.java +++ b/benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchTestListener.java @@ -9,11 +9,10 @@ package ntfbenchmark.impl; import com.google.common.util.concurrent.Futures; import java.util.concurrent.Future; +import org.opendaylight.mdsal.binding.api.NotificationService.Listener; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbench.payload.rev150709.Ntfbench; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbench.payload.rev150709.NtfbenchPayloadListener; - -public class NtfbenchTestListener implements NtfbenchPayloadListener { +public class NtfbenchTestListener implements Listener { private final int expectedSize; private int received = 0; @@ -22,7 +21,7 @@ public class NtfbenchTestListener implements NtfbenchPayloadListener { } @Override - public void onNtfbench(final Ntfbench notification) { + public void onNotification(final Ntfbench notification) { if (expectedSize == notification.getPayload().size()) { received++; } diff --git a/benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchWTCListener.java b/benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchWTCListener.java index 1b16329d52..8cce7448bc 100644 --- a/benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchWTCListener.java +++ b/benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchWTCListener.java @@ -20,9 +20,8 @@ public class NtfbenchWTCListener extends NtfbenchTestListener { } @Override - public void onNtfbench(final Ntfbench notification) { - // TODO Auto-generated method stub - super.onNtfbench(notification); + public void onNotification(final Ntfbench notification) { + super.onNotification(notification); if (expectedCount == getReceived()) { allDone.set(null); } diff --git a/benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchmarkProvider.java b/benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchmarkProvider.java index 4456f47c70..dacf2529d9 100644 --- a/benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchmarkProvider.java +++ b/benchmark/ntfbenchmark/src/main/java/ntfbenchmark/impl/NtfbenchmarkProvider.java @@ -13,7 +13,6 @@ import static java.util.Objects.requireNonNull; import com.google.common.collect.ImmutableClassToInstanceMap; import com.google.common.util.concurrent.ListenableFuture; import java.util.ArrayList; -import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -24,6 +23,7 @@ import javax.inject.Singleton; import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.mdsal.binding.api.NotificationService; import org.opendaylight.mdsal.binding.api.RpcProviderService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbench.payload.rev150709.Ntfbench; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTest; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTestInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.StartTestInput.ProducerType; @@ -32,7 +32,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbench import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.TestStatus; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.TestStatusInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ntfbenchmark.rev150105.TestStatusOutput; -import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.Rpc; import org.opendaylight.yangtools.yang.common.RpcResult; @@ -85,13 +84,14 @@ public final class NtfbenchmarkProvider implements AutoCloseable { final int iterations = input.getIterations().intValue(); final int payloadSize = input.getIterations().intValue(); - final List producers = new ArrayList<>(producerCount); - final List> listeners = new ArrayList<>(listenerCount); + final var producers = new ArrayList(producerCount); for (int i = 0; i < producerCount; i++) { producers.add(new NtfbenchBlockingProducer(publishService, iterations, payloadSize)); } int expectedCntPerListener = producerCount * iterations; + final var listeners = new ArrayList(listenerCount); + final var registrations = new ArrayList(listenerCount); for (int i = 0; i < listenerCount; i++) { final NtfbenchTestListener listener; if (input.getProducerType() == ProducerType.BLOCKING) { @@ -99,7 +99,8 @@ public final class NtfbenchmarkProvider implements AutoCloseable { } else { listener = new NtfbenchTestListener(payloadSize); } - listeners.add(listenService.registerNotificationListener(listener)); + listeners.add(listener); + registrations.add(listenService.registerListener(Ntfbench.class, listener)); } try { @@ -115,8 +116,8 @@ public final class NtfbenchmarkProvider implements AutoCloseable { executor.shutdown(); try { executor.awaitTermination(TEST_TIMEOUT, TimeUnit.MINUTES); - for (ListenerRegistration listenerRegistration : listeners) { - listenerRegistration.getInstance().getAllDone().get(); + for (var listener : listeners) { + listener.getAllDone().get(); } } catch (final InterruptedException | ExecutionException e) { LOG.error("Out of time: test did not finish within the {} min deadline ", TEST_TIMEOUT, e); @@ -129,8 +130,8 @@ public final class NtfbenchmarkProvider implements AutoCloseable { long allProducersOk = 0; long allProducersError = 0; - for (final ListenerRegistration listenerRegistration : listeners) { - allListeners += listenerRegistration.getInstance().getReceived(); + for (var listener : listeners) { + allListeners += listener.getReceived(); } final long listenerElapsedTime = producerEndTime - startTime; @@ -154,9 +155,7 @@ public final class NtfbenchmarkProvider implements AutoCloseable { .build(); return RpcResultBuilder.success(output).buildFuture(); } finally { - for (final ListenerRegistration listenerRegistration : listeners) { - listenerRegistration.close(); - } + registrations.forEach(Registration::close); } } -- 2.36.6