From 70b924258e6c87219c38bcfefb3781ee3d2e2d02 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 21 Jun 2016 18:09:03 +0200 Subject: [PATCH] BUG-5903: do not rely on primary info on failure 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 --- .../cluster/datastore/TransactionChainProxy.java | 2 +- .../controller/cluster/datastore/utils/ActorContext.java | 8 +++----- .../cluster/datastore/TransactionChainProxyTest.java | 2 +- .../cluster/datastore/utils/ActorContextTest.java | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java index 2b00d970a6..6cfc7e1f05 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java @@ -182,7 +182,7 @@ final class TransactionChainProxy extends AbstractTransactionContextFactory messageSupplier){ + public void broadcast(final Function messageSupplier, Class messageClass){ for(final String shardName : configuration.getAllShardNames()){ Future primaryFuture = findPrimaryShardAsync(shardName); primaryFuture.onComplete(new OnComplete() { @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()); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java index d0af812608..72d47711da 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java @@ -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 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java index 405fe5221b..3582302072 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java @@ -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); -- 2.36.6