Migrate to RpcResultBuilder 06/20606/6
authorRobert Varga <rovarga@cisco.com>
Sat, 16 May 2015 16:59:50 +0000 (18:59 +0200)
committerRobert Varga <rovarga@cisco.com>
Mon, 18 May 2015 01:12:37 +0000 (03:12 +0200)
Removes the use of Rpcs and RpcErrors in favor of RpcResultBuilder.

Change-Id: I9bd5f710321ab70098e79bbab463c7b5447ffa17
Signed-off-by: Robert Varga <rovarga@cisco.com>
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/AbstractRpcListener.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ResponseExpectedRpcListenerTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SimpleRpcListenerTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/TypeKeyMakerFactoryTest.java

index 115f9205ead2a4c6af552624df5e36d42b2321e0..7579cbd63057ed19141aaba0a9e6847a7095fc2b 100644 (file)
@@ -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<T> implements GenericFutureListener<Future<Vo
      * @param cause - details of reason
      * @return
      */
-    static RpcError buildRpcError(final String info, final ErrorSeverity severity, final String message,
-            final Throwable cause) {
-        RpcError error = RpcErrors.getRpcError(APPLICATION_TAG, TAG, info, severity, message,
-                ErrorType.RPC, cause);
-        return error;
+    static RpcError buildRpcError(final String info, final String message, final Throwable cause) {
+        return RpcResultBuilder.newError(ErrorType.RPC, TAG, message, APPLICATION_TAG, info, cause);
     }
 
     AbstractRpcListener(final Object message, final String failureInfo) {
@@ -87,12 +80,8 @@ abstract class AbstractRpcListener<T> implements GenericFutureListener<Future<Vo
     protected abstract void operationSuccessful();
 
     protected final void failedRpc(final Throwable cause) {
-        final RpcError rpcError = buildRpcError(
-                failureInfo, ErrorSeverity.ERROR, "check switch connection", cause);
-        result.set(Rpcs.getRpcResult(
-                false,
-                (T)null,
-                Collections.singletonList(rpcError)));
+        final RpcError rpcError = buildRpcError(failureInfo, "check switch connection", cause);
+        result.set(RpcResultBuilder.<T>failed().withRpcError(rpcError).build());
     }
 
     protected final void successfulRpc(final T value) {
index ec57cb8f738f37a892493adb0e492ee5191ec172..e6d1fff2e4d3746ac0603505234949440c01a726 100644 (file)
@@ -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<RpcResponseKey, ResponseExpectedRpcListener<?>> responseCache  = CacheBuilder.newBuilder()
+    private final Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> 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<RpcResult<?>> 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<RpcResult<?>> result = SettableFuture.create();
-        result.set(Rpcs.getRpcResult(true, barrierInput, Collections.<RpcError>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());
index fff2ea0215ccf1a859cac7a86e0753fc7ccd40d7..7726000532b4d5bfa57af446982ec375c20a16df 100644 (file)
@@ -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<RpcResult<?>> result = SettableFuture.create();
-        result.set(Rpcs.getRpcResult(true, null, Collections.<RpcError>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());
index 0cfb09407df58b85b905de0146480fb207af6bd7..c95541c9c5433e8bc0b85d979f13f133fb345701 100644 (file)
@@ -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);
     }