From 3541dff22eaf6f90def98f4c0c4538cdb1caa66f Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 24 Nov 2022 21:10:46 +0100 Subject: [PATCH] Eliminate RpcServiceInvokers RpcServiceInvokers are a useless indirection, really, as we can get by with a simple map. This is not yet perfect, as we really want to eliminate the lookup map completely. JIRA: MDSAL-86 Change-Id: I6e95bfd979c4862799ea51915c6ca46f69cbe379 Signed-off-by: Robert Varga --- .../BindingDOMRpcProviderServiceAdapter.java | 2 +- .../LegacyDOMRpcImplementationAdapter.java | 26 +++--- .../invoke/AbstractMappedRpcInvoker.java | 60 ------------- .../invoke/LocalNameRpcServiceInvoker.java | 45 ---------- .../invoke/QNameRpcServiceInvoker.java | 28 ------ .../dom/adapter/invoke/RpcMethodInvoker.java | 14 ++- .../dom/adapter/invoke/RpcServiceInvoker.java | 72 --------------- ...LegacyDOMRpcImplementationAdapterTest.java | 35 -------- .../invoke/AbstractMappedRpcInvokerTest.java | 89 ------------------- .../LocalNameRpcServiceInvokerTest.java | 48 ---------- .../invoke/QNameRpcServiceInvokerTest.java | 32 ------- .../adapter/invoke/RpcServiceInvokerTest.java | 36 -------- 12 files changed, 21 insertions(+), 466 deletions(-) delete mode 100644 binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/AbstractMappedRpcInvoker.java delete mode 100644 binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/LocalNameRpcServiceInvoker.java delete mode 100644 binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/QNameRpcServiceInvoker.java delete mode 100644 binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/RpcServiceInvoker.java delete mode 100644 binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/LegacyDOMRpcImplementationAdapterTest.java delete mode 100644 binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/AbstractMappedRpcInvokerTest.java delete mode 100644 binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/LocalNameRpcServiceInvokerTest.java delete mode 100644 binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/QNameRpcServiceInvokerTest.java delete mode 100644 binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/RpcServiceInvokerTest.java diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcProviderServiceAdapter.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcProviderServiceAdapter.java index f381a49292..8b37652982 100644 --- a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcProviderServiceAdapter.java +++ b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMRpcProviderServiceAdapter.java @@ -121,7 +121,7 @@ public class BindingDOMRpcProviderServiceAdapter extends AbstractBindingAdapter< final var rpcs = createQNameToMethod(currentSerializer(), type); return new BindingRpcAdapterRegistration<>(implementation, getDelegate().registerRpcImplementation( - new LegacyDOMRpcImplementationAdapter<>(adapterContext(), type, rpcs, implementation), + new LegacyDOMRpcImplementationAdapter<>(adapterContext(), type, implementation, rpcs), createDomRpcIdentifiers(rpcs.keySet(), rpcContextPaths))); } diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LegacyDOMRpcImplementationAdapter.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LegacyDOMRpcImplementationAdapter.java index 0ecedfdc8f..9446a6ea2e 100644 --- a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LegacyDOMRpcImplementationAdapter.java +++ b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LegacyDOMRpcImplementationAdapter.java @@ -7,15 +7,18 @@ */ package org.opendaylight.mdsal.binding.dom.adapter; +import static com.google.common.base.Verify.verifyNotNull; import static java.util.Objects.requireNonNull; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; import com.google.common.util.concurrent.ListenableFuture; import java.lang.reflect.Method; import java.util.Map; import java.util.concurrent.ExecutionException; -import org.opendaylight.mdsal.binding.dom.adapter.invoke.RpcServiceInvoker; +import org.opendaylight.mdsal.binding.dom.adapter.invoke.RpcMethodInvoker; import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections; import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier; import org.opendaylight.yangtools.yang.binding.RpcService; @@ -26,31 +29,30 @@ import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; @Deprecated(since = "11.0.0", forRemoval = true) final class LegacyDOMRpcImplementationAdapter extends AbstractDOMRpcImplementationAdapter { - private static final Cache, RpcServiceInvoker> SERVICE_INVOKERS = CacheBuilder.newBuilder().weakKeys() - .build(); + private static final Cache, ImmutableMap> CLASS_INVOKERS = + CacheBuilder.newBuilder().weakKeys().build(); - private final RpcServiceInvoker invoker; + private final ImmutableMap invokers; private final T delegate; - LegacyDOMRpcImplementationAdapter(final AdapterContext adapterContext, final Class type, - final Map localNameToMethod, final T delegate) { + LegacyDOMRpcImplementationAdapter(final AdapterContext adapterContext, final Class type, final T delegate, + final Map qnameToMethod) { // FIXME: do not use BindingReflections here super(adapterContext, YangConstants.operationInputQName(BindingReflections.getQNameModule(type)).intern()); + this.delegate = requireNonNull(delegate); try { - invoker = SERVICE_INVOKERS.get(type, () -> RpcServiceInvoker.from(localNameToMethod)); + invokers = CLASS_INVOKERS.get(type, + () -> ImmutableMap.copyOf(Maps.transformValues(qnameToMethod, RpcMethodInvoker::from))); } catch (ExecutionException e) { throw new IllegalArgumentException("Failed to create invokers for type " + type, e); } - - this.delegate = requireNonNull(delegate); } @Override ListenableFuture> invokeRpc(final CurrentAdapterSerializer serializer, final DOMRpcIdentifier rpc, final ContainerNode input) { - final QName rpcType = rpc.getType(); - final var bindingInput = input != null ? deserialize(serializer, rpcType, input) : null; - return invoker.invokeRpc(delegate, rpcType, bindingInput); + final var rpcType = rpc.getType(); + return verifyNotNull(invokers.get(rpcType)).invokeOn(delegate, deserialize(serializer, rpc.getType(), input)); } } diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/AbstractMappedRpcInvoker.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/AbstractMappedRpcInvoker.java deleted file mode 100644 index 00d33582c1..0000000000 --- a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/AbstractMappedRpcInvoker.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.mdsal.binding.dom.adapter.invoke; - -import static com.google.common.base.Preconditions.checkArgument; -import static java.util.Objects.requireNonNull; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; -import com.google.common.util.concurrent.ListenableFuture; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.Map.Entry; -import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.RpcService; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Deprecated(since = "11.0.0", forRemoval = true) -abstract class AbstractMappedRpcInvoker extends RpcServiceInvoker { - private static final Logger LOG = LoggerFactory.getLogger(AbstractMappedRpcInvoker.class); - - @VisibleForTesting - final Map map; - - protected AbstractMappedRpcInvoker(final Map map) { - final Builder b = ImmutableMap.builder(); - - for (Entry e : map.entrySet()) { - if (BindingReflections.isRpcMethod(e.getValue())) { - b.put(e.getKey(), RpcMethodInvoker.from(e.getValue())); - } else { - LOG.debug("Method {} is not an RPC method, ignoring it", e.getValue()); - } - } - - this.map = b.build(); - } - - protected abstract T qnameToKey(QName qname); - - @Override - public final ListenableFuture> invokeRpc(final RpcService impl, final QName rpcName, - final DataObject input) { - requireNonNull(impl, "Implementation must be supplied"); - - RpcMethodInvoker invoker = map.get(qnameToKey(rpcName)); - checkArgument(invoker != null, "Supplied RPC is not valid for implementation %s", impl); - return invoker.invokeOn(impl, input); - } -} diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/LocalNameRpcServiceInvoker.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/LocalNameRpcServiceInvoker.java deleted file mode 100644 index 75bffac192..0000000000 --- a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/LocalNameRpcServiceInvoker.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.mdsal.binding.dom.adapter.invoke; - -import static java.util.Objects.requireNonNull; - -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; - -@Deprecated(since = "11.0.0", forRemoval = true) -final class LocalNameRpcServiceInvoker extends AbstractMappedRpcInvoker { - private final QNameModule module; - - private LocalNameRpcServiceInvoker(final QNameModule module, final Map map) { - super(map); - this.module = requireNonNull(module); - } - - static RpcServiceInvoker instanceFor(final QNameModule module, final Map qnameToMethod) { - final Map map = new HashMap<>(); - for (Entry e : qnameToMethod.entrySet()) { - map.put(e.getKey().getLocalName(), e.getValue()); - } - - return new LocalNameRpcServiceInvoker(module, map); - } - - @Override - protected String qnameToKey(final QName qname) { - if (module.equals(qname.getModule())) { - return qname.getLocalName(); - } else { - return null; - } - } -} diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/QNameRpcServiceInvoker.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/QNameRpcServiceInvoker.java deleted file mode 100644 index 51df73c8de..0000000000 --- a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/QNameRpcServiceInvoker.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.mdsal.binding.dom.adapter.invoke; - -import java.lang.reflect.Method; -import java.util.Map; -import org.opendaylight.yangtools.yang.common.QName; - -@Deprecated(since = "11.0.0", forRemoval = true) -final class QNameRpcServiceInvoker extends AbstractMappedRpcInvoker { - private QNameRpcServiceInvoker(final Map qnameToMethod) { - super(qnameToMethod); - } - - static RpcServiceInvoker instanceFor(final Map qnameToMethod) { - return new QNameRpcServiceInvoker(qnameToMethod); - } - - @Override - protected QName qnameToKey(final QName qname) { - return qname; - } -} diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/RpcMethodInvoker.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/RpcMethodInvoker.java index ffe6077659..2574b96ebc 100644 --- a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/RpcMethodInvoker.java +++ b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/RpcMethodInvoker.java @@ -14,12 +14,13 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.lang.reflect.Method; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.RpcService; import org.opendaylight.yangtools.yang.common.RpcResult; @Deprecated(since = "11.0.0", forRemoval = true) -final class RpcMethodInvoker { +public final class RpcMethodInvoker { private static final MethodType INVOCATION_SIGNATURE = MethodType.methodType(ListenableFuture.class, RpcService.class, DataObject.class); @@ -30,21 +31,18 @@ final class RpcMethodInvoker { this.handle = handle.asType(INVOCATION_SIGNATURE); } - static RpcMethodInvoker from(final Method method) { - final MethodHandle methodHandle; + public static @NonNull RpcMethodInvoker from(final Method method) { try { - methodHandle = MethodHandles.publicLookup().unreflect(method); + return new RpcMethodInvoker(MethodHandles.publicLookup().unreflect(method)); } catch (IllegalAccessException e) { throw new IllegalStateException("Lookup on public method failed.", e); } - - return new RpcMethodInvoker(methodHandle); } @SuppressWarnings("checkstyle:illegalCatch") - ListenableFuture> invokeOn(final RpcService impl, final DataObject input) { + public @NonNull ListenableFuture> invokeOn(final RpcService impl, final DataObject input) { try { - return (ListenableFuture>) handle.invokeExact(impl,input); + return (ListenableFuture>) handle.invokeExact(impl, input); } catch (Throwable e) { Throwables.throwIfUnchecked(e); throw new IllegalStateException(e); diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/RpcServiceInvoker.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/RpcServiceInvoker.java deleted file mode 100644 index 3b84e930db..0000000000 --- a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/RpcServiceInvoker.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.mdsal.binding.dom.adapter.invoke; - -import static com.google.common.base.Preconditions.checkArgument; - -import com.google.common.util.concurrent.ListenableFuture; -import java.lang.reflect.Method; -import java.util.Map; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.RpcService; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Provides single method invocation of RPCs on supplied instance. - * - *

- * RPC Service invoker provides common invocation interface for any subtype of {@link RpcService} via - * {@link #invokeRpc(RpcService, QName, DataObject)} method. - */ -@Deprecated(since = "11.0.0", forRemoval = true) -public abstract class RpcServiceInvoker { - private static final Logger LOG = LoggerFactory.getLogger(RpcServiceInvoker.class); - - /** - * Creates an RPCServiceInvoker for specified QName-<Method mapping. - * - * @param qnameToMethod translation mapping, must not be null nor empty. - * @return An {@link RpcServiceInvoker} instance. - */ - public static RpcServiceInvoker from(final Map qnameToMethod) { - checkArgument(!qnameToMethod.isEmpty()); - QNameModule module = null; - - for (QName qname : qnameToMethod.keySet()) { - if (module != null) { - if (!module.equals(qname.getModule())) { - LOG.debug("QNames from different modules {} and {}, falling back to QName map", module, - qname.getModule()); - return QNameRpcServiceInvoker.instanceFor(qnameToMethod); - } - } else { - module = qname.getModule(); - } - } - - // All module are equal, which means we can use localName only - return LocalNameRpcServiceInvoker.instanceFor(module, qnameToMethod); - } - - /** - * Invokes supplied RPC on provided implementation of RPC Service. - * - * @param impl Imlementation on which RPC should be invoked. - * @param rpcName Name of RPC to be invoked. - * @param input Input data for RPC. - * @return Future which will complete once rpc procesing is finished. - */ - public abstract ListenableFuture> invokeRpc(@NonNull RpcService impl, @NonNull QName rpcName, - @Nullable DataObject input); -} diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/LegacyDOMRpcImplementationAdapterTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/LegacyDOMRpcImplementationAdapterTest.java deleted file mode 100644 index 6bc42bf048..0000000000 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/LegacyDOMRpcImplementationAdapterTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.mdsal.binding.dom.adapter; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; - -import java.util.Map; -import org.junit.Test; -import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService; -import org.opendaylight.yangtools.yang.common.QName; - -@Deprecated(since = "11.0.0", forRemoval = true) -public class LegacyDOMRpcImplementationAdapterTest { - @Test - public void basicTest() throws Exception { - final var codecServices = mock(BindingDOMCodecServices.class); - final var testMethod = getClass().getDeclaredMethod("testMethod"); - final var rpcType = QName.create("tst", "test"); - final var adapter = new LegacyDOMRpcImplementationAdapter<>(new ConstantAdapterContext(codecServices), - OpendaylightTestRpcServiceService.class, Map.of(rpcType, testMethod), - mock(OpendaylightTestRpcServiceService.class)); - assertNotNull(adapter); - } - - private void testMethod() { - //NOOP - } -} \ No newline at end of file diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/AbstractMappedRpcInvokerTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/AbstractMappedRpcInvokerTest.java deleted file mode 100644 index 99ae45bff7..0000000000 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/AbstractMappedRpcInvokerTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.mdsal.binding.dom.adapter.invoke; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; - -import com.google.common.collect.ImmutableMap; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.Optional; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.jdt.annotation.Nullable; -import org.junit.Test; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.RpcService; -import org.opendaylight.yangtools.yang.common.QName; - -@Deprecated(since = "11.0.0", forRemoval = true) -public class AbstractMappedRpcInvokerTest { - @Test - public void invokeRpcTest() throws Exception { - final Method methodWithInput = - TestRpcService.class.getDeclaredMethod("methodWithInput", RpcService.class, DataObject.class); - - methodWithInput.setAccessible(true); - - final RpcService rpcService = new TestRpcService(); - - final TestRpcInvokerImpl testRpcInvoker = - new TestRpcInvokerImpl(ImmutableMap.of( - "(test)tstWithInput", methodWithInput)); - - assertTrue(testRpcInvoker.map.get("(test)tstWithInput") instanceof RpcMethodInvoker); - - final DataObject dataObject = mock(DataObject.class); - final Crate crateWithInput = - (Crate) testRpcInvoker.invokeRpc(rpcService, QName.create("test", "tstWithInput"), dataObject).get(); - assertEquals(TestRpcService.methodWithInput(rpcService, dataObject).get().getRpcService(), - crateWithInput.getRpcService()); - assertTrue(crateWithInput.getDataObject().isPresent()); - assertEquals(dataObject, crateWithInput.getDataObject().get()); - } - - private static class TestRpcInvokerImpl extends AbstractMappedRpcInvoker { - TestRpcInvokerImpl(final Map map) { - super(map); - } - - @Override - protected String qnameToKey(final QName qname) { - return qname.toString(); - } - } - - static class Crate { - private final RpcService rpcService; - private final ThreadLocal> dataObject; - - Crate(final @NonNull RpcService rpcService, final @Nullable DataObject dataObject) { - this.rpcService = rpcService; - this.dataObject = - ThreadLocal.withInitial(() -> dataObject == null ? Optional.empty() : Optional.of(dataObject)); - } - - RpcService getRpcService() { - return rpcService; - } - - Optional getDataObject() { - return dataObject.get(); - } - } - - static class TestRpcService implements RpcService { - static ListenableFuture methodWithInput(final RpcService testArgument, final DataObject testArgument2) { - return Futures.immediateFuture(new Crate(testArgument, testArgument2)); - } - } -} - diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/LocalNameRpcServiceInvokerTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/LocalNameRpcServiceInvokerTest.java deleted file mode 100644 index 7b63d1f8c2..0000000000 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/LocalNameRpcServiceInvokerTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.mdsal.binding.dom.adapter.invoke; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; - -import com.google.common.collect.ImmutableMap; -import org.junit.BeforeClass; -import org.junit.Test; -import org.opendaylight.yangtools.yang.binding.RpcService; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.common.Revision; -import org.opendaylight.yangtools.yang.common.XMLNamespace; - -@Deprecated(since = "11.0.0", forRemoval = true) -public class LocalNameRpcServiceInvokerTest { - - private static RpcServiceInvoker rpcServiceInvoker; - private static final QNameModule Q_NAME_MODULE = QNameModule.create(XMLNamespace.of("testURI"), - Revision.of("2017-10-26")); - private static final RpcService RPC_SERVICE = mock(RpcService.class); - - @BeforeClass - public static void setUp() throws Exception { - rpcServiceInvoker = LocalNameRpcServiceInvoker.instanceFor( - Q_NAME_MODULE, ImmutableMap.of(QName.create(Q_NAME_MODULE, "test"), - Object.class.getDeclaredMethod("hashCode"))); - - assertNotNull(rpcServiceInvoker); - } - - @Test(expected = IllegalArgumentException.class) - public void qnameToKeyTest() throws Exception { - rpcServiceInvoker.invokeRpc(RPC_SERVICE, QName.create(Q_NAME_MODULE, "test"), null); - } - - @Test(expected = IllegalArgumentException.class) - public void qnameToKeyWithNullTest() throws Exception { - rpcServiceInvoker.invokeRpc(RPC_SERVICE, QName.create("", "test"), null); - } -} diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/QNameRpcServiceInvokerTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/QNameRpcServiceInvokerTest.java deleted file mode 100644 index 61dce76e86..0000000000 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/QNameRpcServiceInvokerTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.mdsal.binding.dom.adapter.invoke; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; - -import com.google.common.collect.ImmutableMap; -import org.junit.Test; -import org.opendaylight.yangtools.yang.binding.RpcService; -import org.opendaylight.yangtools.yang.common.QName; - -@Deprecated(since = "11.0.0", forRemoval = true) -public class QNameRpcServiceInvokerTest { - @Test - public void instanceForTest() throws Exception { - assertNotNull(QNameRpcServiceInvoker.instanceFor(ImmutableMap.of())); - } - - @Test(expected = IllegalArgumentException.class) - public void qnameToKeyTest() throws Exception { - final RpcService rpcService = mock(RpcService.class); - QNameRpcServiceInvoker.instanceFor(ImmutableMap.of()).invokeRpc(rpcService, QName.create("", "test"), null); - fail("Expected exception: constructed with empty map"); - } -} \ No newline at end of file diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/RpcServiceInvokerTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/RpcServiceInvokerTest.java deleted file mode 100644 index 4eab89ee25..0000000000 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/RpcServiceInvokerTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.mdsal.binding.dom.adapter.invoke; - -import static org.junit.Assert.assertNotNull; - -import java.lang.reflect.Method; -import java.util.Map; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.common.Revision; -import org.opendaylight.yangtools.yang.common.XMLNamespace; - -@Deprecated(since = "11.0.0", forRemoval = true) -public class RpcServiceInvokerTest { - @Test - public void fromTest() throws Exception { - final Method method = this.getClass().getDeclaredMethod("testMethod"); - method.setAccessible(true); - assertNotNull(RpcServiceInvoker.from(Map.of( - QName.create(QNameModule.create(XMLNamespace.of("testURI"), Revision.of("2017-10-26")),"test"), method, - QName.create(QNameModule.create(XMLNamespace.of("testURI2"), Revision.of("2017-10-26")),"test"), method))); - assertNotNull(RpcServiceInvoker.from(Map.of( - QName.create(QNameModule.create(XMLNamespace.of("testURI"), Revision.of("2017-10-26")), "test"), method))); - } - - private void testMethod() { - // NOOP - } -} -- 2.36.6