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 2b00d970a61ec17a52b89970d87a5476c5dbe8fb..6cfc7e1f05ff78208de740994c7b370487d2d752 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 68ac6412e8ad1346f46686e7d5103be5d0824b76..ee0a4796cac87e8cb79b004a36ad3748f8f52c68 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 d0af812608072fdda4c66057eb632b2581ae4dce..72d47711da6da82afb273df07365bc403ad29d05 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 405fe5221b64255e086db7b37eb1af1679e4da18..3582302072c0c71b737d52df1110215567ba503b 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);