BUG-5903: do not rely on primary info on failure 27/40627/2
authorRobert Varga <rovarga@cisco.com>
Tue, 21 Jun 2016 16:09:03 +0000 (18:09 +0200)
committerRobert Varga <rovarga@cisco.com>
Tue, 21 Jun 2016 19:58:45 +0000 (21:58 +0200)
This makes sure we check for failure before touching the result,
which is null if a failure occurs.

In order to keep disagnosti information we add a reference
to the message class being broadcast.

Change-Id: I26ab31a45916d11b61b990020bed89ae87233b14
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java

index 2b00d97..6cfc7e1 100644 (file)
@@ -182,7 +182,7 @@ final class TransactionChainProxy extends AbstractTransactionContextFactory<Loca
             public Object apply(Short version) {
                 return new CloseTransactionChain(getHistoryId(), version).toSerializable();
             }
-        });
+        }, CloseTransactionChain.class);
     }
 
     private TransactionProxy allocateWriteTransaction(final TransactionType type) {
index 68ac641..ee0a479 100644 (file)
@@ -398,21 +398,19 @@ public class ActorContext {
 
     /**
      * Send the message to each and every shard
-     *
-     * @param message
      */
-    public void broadcast(final Function<Short, Object> messageSupplier){
+    public void broadcast(final Function<Short, Object> messageSupplier, Class<?> messageClass){
         for(final String shardName : configuration.getAllShardNames()){
 
             Future<PrimaryShardInfo> primaryFuture = findPrimaryShardAsync(shardName);
             primaryFuture.onComplete(new OnComplete<PrimaryShardInfo>() {
                 @Override
                 public void onComplete(Throwable failure, PrimaryShardInfo primaryShardInfo) {
-                    Object message = messageSupplier.apply(primaryShardInfo.getPrimaryShardVersion());
                     if(failure != null) {
                         LOG.warn("broadcast failed to send message {} to shard {}:  {}",
-                                message.getClass().getSimpleName(), shardName, failure);
+                            messageClass.getSimpleName(), shardName, failure);
                     } else {
+                        Object message = messageSupplier.apply(primaryShardInfo.getPrimaryShardVersion());
                         primaryShardInfo.getPrimaryShardActor().tell(message, ActorRef.noSender());
                     }
                 }
index d0af812..72d4771 100644 (file)
@@ -79,7 +79,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest {
     public void testClose() {
         new TransactionChainProxy(mockComponentFactory, historyId).close();
 
-        verify(mockActorContext, times(1)).broadcast(any(Function.class));
+        verify(mockActorContext, times(1)).broadcast(any(Function.class), any(Class.class));
     }
 
     @Test
index 405fe52..3582302 100644 (file)
@@ -503,7 +503,7 @@ public class ActorContextTest extends AbstractActorTest{
                 public Object apply(Short v) {
                     return new TestMessage();
                 }
-            });
+            }, TestMessage.class);
 
             MessageCollectorActor.expectFirstMatching(shardActorRef1, TestMessage.class);
             MessageCollectorActor.expectFirstMatching(shardActorRef2, TestMessage.class);