X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Futils%2FActorContextTest.java;h=1cc89f18af960557ba510814e6fe7c5326fa34ea;hp=4ee89ca76d4866d616b97ba14b1e268fa1aeaa82;hb=163df4f862bcafd625b9d02d367243bbcf43aa04;hpb=0aedb207da64e63900e2dbc85ba2a030ea7800e4 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 4ee89ca76d..1cc89f18af 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 @@ -461,68 +461,44 @@ public class ActorContextTest extends AbstractActorTest{ @Test public void testFindPrimaryShardAsyncPrimaryNotFound() throws Exception { - - TestActorRef shardManager = - TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class)); - - DatastoreContext dataStoreContext = DatastoreContext.newBuilder().dataStoreType("config"). - shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build(); - - ActorContext actorContext = - new ActorContext(getSystem(), shardManager, mock(ClusterWrapper.class), - mock(Configuration.class), dataStoreContext, new PrimaryShardInfoFutureCache()) { - @Override - protected Future doAsk(ActorRef actorRef, Object message, Timeout timeout) { - return Futures.successful((Object) new PrimaryNotFoundException("not found")); - } - }; - - - Future foobar = actorContext.findPrimaryShardAsync("foobar"); - - try { - Await.result(foobar, Duration.apply(100, TimeUnit.MILLISECONDS)); - fail("Expected PrimaryNotFoundException"); - } catch(PrimaryNotFoundException e){ - - } - - Future cached = actorContext.getPrimaryShardInfoCache().getIfPresent("foobar"); - - assertNull(cached); + testFindPrimaryExceptions(new PrimaryNotFoundException("not found")); } @Test public void testFindPrimaryShardAsyncActorNotInitialized() throws Exception { + testFindPrimaryExceptions(new NotInitializedException("not initialized")); + } - TestActorRef shardManager = - TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class)); - - DatastoreContext dataStoreContext = DatastoreContext.newBuilder().dataStoreType("config"). - shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build(); - - ActorContext actorContext = - new ActorContext(getSystem(), shardManager, mock(ClusterWrapper.class), - mock(Configuration.class), dataStoreContext, new PrimaryShardInfoFutureCache()) { - @Override - protected Future doAsk(ActorRef actorRef, Object message, Timeout timeout) { - return Futures.successful((Object) new NotInitializedException("not iniislized")); - } - }; + private void testFindPrimaryExceptions(final Object expectedException) throws Exception { + TestActorRef shardManager = + TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class)); + DatastoreContext dataStoreContext = DatastoreContext.newBuilder().dataStoreType("config"). + shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build(); - Future foobar = actorContext.findPrimaryShardAsync("foobar"); + ActorContext actorContext = + new ActorContext(getSystem(), shardManager, mock(ClusterWrapper.class), + mock(Configuration.class), dataStoreContext, new PrimaryShardInfoFutureCache()) { + @Override + protected Future doAsk(ActorRef actorRef, Object message, Timeout timeout) { + return Futures.successful(expectedException); + } + }; - try { - Await.result(foobar, Duration.apply(100, TimeUnit.MILLISECONDS)); - fail("Expected NotInitializedException"); - } catch(NotInitializedException e){ + Future foobar = actorContext.findPrimaryShardAsync("foobar"); + try { + Await.result(foobar, Duration.apply(100, TimeUnit.MILLISECONDS)); + fail("Expected" + expectedException.getClass().toString()); + } catch(Exception e){ + if(!expectedException.getClass().isInstance(e)) { + fail("Expected Exception of type " + expectedException.getClass().toString()); } + } - Future cached = actorContext.getPrimaryShardInfoCache().getIfPresent("foobar"); + Future cached = actorContext.getPrimaryShardInfoCache().getIfPresent("foobar"); - assertNull(cached); + assertNull(cached); } @Test