From: Robert Varga Date: Sat, 16 May 2015 16:59:50 +0000 (+0200) Subject: Migrate to RpcResultBuilder X-Git-Tag: release/lithium~23 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=8e5473613cc8f6b0d9558edd170b93e238b87d57;p=openflowjava.git Migrate to RpcResultBuilder Removes the use of Rpcs and RpcErrors in favor of RpcResultBuilder. Change-Id: I9bd5f710321ab70098e79bbab463c7b5447ffa17 Signed-off-by: Robert Varga --- diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/AbstractRpcListener.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/AbstractRpcListener.java index 115f9205..7579cbd6 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/AbstractRpcListener.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/AbstractRpcListener.java @@ -12,11 +12,7 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; -import java.util.Collections; -import org.opendaylight.controller.sal.common.util.RpcErrors; -import org.opendaylight.controller.sal.common.util.Rpcs; import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity; import org.opendaylight.yangtools.yang.common.RpcError.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; @@ -44,11 +40,8 @@ abstract class AbstractRpcListener implements GenericFutureListener implements GenericFutureListenerfailed().withRpcError(rpcError).build()); } protected final void successfulRpc(final T value) { diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ResponseExpectedRpcListenerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ResponseExpectedRpcListenerTest.java index ec57cb8f..e6d1fff2 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ResponseExpectedRpcListenerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ResponseExpectedRpcListenerTest.java @@ -9,31 +9,23 @@ package org.opendaylight.openflowjava.protocol.impl.core.connection; import static org.junit.Assert.fail; - -import java.util.Collections; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.RemovalListener; +import com.google.common.cache.RemovalNotification; +import com.google.common.util.concurrent.SettableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; - import org.junit.Assert; import org.junit.Test; -import org.opendaylight.controller.sal.common.util.Rpcs; -import org.opendaylight.openflowjava.protocol.impl.core.connection.AbstractRpcListener; -import org.opendaylight.openflowjava.protocol.impl.core.connection.ResponseExpectedRpcListener; -import org.opendaylight.openflowjava.protocol.impl.core.connection.RpcResponseKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity; import org.opendaylight.yangtools.yang.common.RpcResult; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.RemovalListener; -import com.google.common.cache.RemovalNotification; -import com.google.common.util.concurrent.SettableFuture; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; /** * @author michal.polkorab @@ -50,7 +42,7 @@ public class ResponseExpectedRpcListenerTest { } }; private static final int RPC_RESPONSE_EXPIRATION = 1; - private Cache> responseCache = CacheBuilder.newBuilder() + private final Cache> responseCache = CacheBuilder.newBuilder() .concurrencyLevel(1) .expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES) .removalListener(REMOVAL_LISTENER).build(); @@ -82,9 +74,9 @@ public class ResponseExpectedRpcListenerTest { new ResponseExpectedRpcListener<>("MESSAGE", "Failed to send message", responseCache, key); listener.discard(); RpcError rpcError = AbstractRpcListener.buildRpcError("Failed to send message", - ErrorSeverity.ERROR, "check switch connection", new TimeoutException("Request timed out")); + "check switch connection", new TimeoutException("Request timed out")); SettableFuture> result = SettableFuture.create(); - result.set(Rpcs.getRpcResult(false, null, Collections.singletonList(rpcError))); + result.set(RpcResultBuilder.failed().withRpcError(rpcError).build()); try { Assert.assertEquals("Wrong result", result.get().getErrors().iterator().next().getMessage(), listener.getResult().get().getErrors().iterator().next().getMessage()); @@ -107,7 +99,7 @@ public class ResponseExpectedRpcListenerTest { BarrierInput barrierInput = barrierBuilder.build(); listener.completed(barrierInput); SettableFuture> result = SettableFuture.create(); - result.set(Rpcs.getRpcResult(true, barrierInput, Collections.emptyList())); + result.set(RpcResultBuilder.success(barrierInput).build()); try { Assert.assertEquals("Wrong result", result.get().getErrors(), listener.getResult().get().getErrors()); Assert.assertEquals("Wrong result", result.get().getResult(), listener.getResult().get().getResult()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SimpleRpcListenerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SimpleRpcListenerTest.java index fff2ea02..77260005 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SimpleRpcListenerTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SimpleRpcListenerTest.java @@ -12,22 +12,16 @@ import static org.junit.Assert.fail; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.google.common.util.concurrent.SettableFuture; import io.netty.util.concurrent.Future; - -import java.util.Collections; import java.util.concurrent.ExecutionException; - import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.sal.common.util.Rpcs; -import org.opendaylight.openflowjava.protocol.impl.core.connection.SimpleRpcListener; -import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; - -import com.google.common.util.concurrent.SettableFuture; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; /** * @author michal.polkorab @@ -63,7 +57,7 @@ public class SimpleRpcListenerTest { SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message"); listener.operationSuccessful(); SettableFuture> result = SettableFuture.create(); - result.set(Rpcs.getRpcResult(true, null, Collections.emptyList())); + result.set(RpcResultBuilder.success((Void)null).build()); try { Assert.assertEquals("Wrong result", result.get().getErrors(), listener.getResult().get().getErrors()); Assert.assertEquals("Wrong result", result.get().getResult(), listener.getResult().get().getResult()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/TypeKeyMakerFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/TypeKeyMakerFactoryTest.java index 0cfb0940..c95541c9 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/TypeKeyMakerFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/TypeKeyMakerFactoryTest.java @@ -77,7 +77,7 @@ public class TypeKeyMakerFactoryTest { MessageTypeKey key = keyMaker.make(action); Assert.assertNotNull("Null key", key); - Assert.assertEquals("Wrong key", new ActionSerializerKey(EncodeConstants.OF13_VERSION_ID, + Assert.assertEquals("Wrong key", new ActionSerializerKey<>(EncodeConstants.OF13_VERSION_ID, CopyTtlInCase.class, 42L), key); } @@ -114,7 +114,7 @@ public class TypeKeyMakerFactoryTest { MessageTypeKey key = keyMaker.make(instruction); Assert.assertNotNull("Null key", key); - Assert.assertEquals("Wrong key", new InstructionSerializerKey(EncodeConstants.OF13_VERSION_ID, + Assert.assertEquals("Wrong key", new InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID, ClearActionsCase.class, 42L), key); }