Fix Cache Removal listener

- Removal lister will be called even if the entry was manually
  invalidated. Timeout handler should check for the cause.

Note: In both of the cases fixed in this patch, Future should silently ignore
  setException, external behavior-wise no change by this patch.

Change-Id: Id46f23c9ff8dfa607874cfd94807000f03a95b31
diff --git a/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleFlowRuleStore.java b/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleFlowRuleStore.java
index 9cfb258..a8e15a2 100644
--- a/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleFlowRuleStore.java
+++ b/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleFlowRuleStore.java
@@ -312,9 +312,11 @@
         @Override
         public void onRemoval(RemovalNotification<Integer, SettableFuture<CompletedBatchOperation>> notification) {
             // wrapping in ExecutionException to support Future.get
-            notification.getValue()
-                .setException(new ExecutionException("Timed out",
+            if (notification.wasEvicted()) {
+                notification.getValue()
+                    .setException(new ExecutionException("Timed out",
                                                      new TimeoutException()));
+            }
         }
     }
 }
diff --git a/utils/netty/src/main/java/org/onlab/netty/NettyMessagingService.java b/utils/netty/src/main/java/org/onlab/netty/NettyMessagingService.java
index ae646b6..b611fad 100644
--- a/utils/netty/src/main/java/org/onlab/netty/NettyMessagingService.java
+++ b/utils/netty/src/main/java/org/onlab/netty/NettyMessagingService.java
@@ -72,7 +72,9 @@
             .removalListener(new RemovalListener<Long, SettableFuture<byte[]>>() {
                 @Override
                 public void onRemoval(RemovalNotification<Long, SettableFuture<byte[]>> entry) {
-                    entry.getValue().setException(new TimeoutException("Timedout waiting for reply"));
+                    if (entry.wasEvicted()) {
+                        entry.getValue().setException(new TimeoutException("Timedout waiting for reply"));
+                    }
                 }
             })
             .build();