Search in sources :

Example 6 with DatastoreContext

use of org.opendaylight.controller.cluster.datastore.DatastoreContext in project controller by opendaylight.

the class DistributedEntityOwnershipServiceTest method setUp.

@Before
public void setUp() {
    DatastoreContext datastoreContext = DatastoreContext.newBuilder().dataStoreName(dataStoreName).shardInitializationTimeout(10, TimeUnit.SECONDS).build();
    Configuration configuration = new ConfigurationImpl(new EmptyModuleShardConfigProvider()) {

        @Override
        public Collection<MemberName> getUniqueMemberNamesForAllShards() {
            return Sets.newHashSet(MemberName.forName("member-1"));
        }
    };
    DatastoreContextFactory mockContextFactory = mock(DatastoreContextFactory.class);
    Mockito.doReturn(datastoreContext).when(mockContextFactory).getBaseDatastoreContext();
    Mockito.doReturn(datastoreContext).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString());
    dataStore = new DistributedDataStore(getSystem(), new MockClusterWrapper(), configuration, mockContextFactory, null);
    dataStore.onGlobalContextUpdated(SchemaContextHelper.entityOwners());
}
Also used : EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) DistributedDataStore(org.opendaylight.controller.cluster.datastore.DistributedDataStore) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) DatastoreContextFactory(org.opendaylight.controller.cluster.datastore.DatastoreContextFactory) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) MockClusterWrapper(org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) Before(org.junit.Before)

Example 7 with DatastoreContext

use of org.opendaylight.controller.cluster.datastore.DatastoreContext in project controller by opendaylight.

the class ActorContextTest method testFindPrimaryShardAsyncRemotePrimaryFound.

@Test
public void testFindPrimaryShardAsyncRemotePrimaryFound() throws Exception {
    ActorRef shardManager = getSystem().actorOf(MessageCollectorActor.props());
    DatastoreContext dataStoreContext = DatastoreContext.newBuilder().logicalStoreType(LogicalDatastoreType.CONFIGURATION).shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build();
    final String expPrimaryPath = "akka://test-system/find-primary-shard";
    final short expPrimaryVersion = DataStoreVersions.CURRENT_VERSION;
    ActorContext actorContext = new ActorContext(getSystem(), shardManager, mock(ClusterWrapper.class), mock(Configuration.class), dataStoreContext, new PrimaryShardInfoFutureCache()) {

        @Override
        protected Future<Object> doAsk(final ActorRef actorRef, final Object message, final Timeout timeout) {
            return Futures.successful((Object) new RemotePrimaryShardFound(expPrimaryPath, expPrimaryVersion));
        }
    };
    Future<PrimaryShardInfo> foobar = actorContext.findPrimaryShardAsync("foobar");
    PrimaryShardInfo actual = Await.result(foobar, Duration.apply(5000, TimeUnit.MILLISECONDS));
    assertNotNull(actual);
    assertEquals("LocalShardDataTree present", false, actual.getLocalShardDataTree().isPresent());
    assertTrue("Unexpected PrimaryShardActor path " + actual.getPrimaryShardActor().path(), expPrimaryPath.endsWith(actual.getPrimaryShardActor().pathString()));
    assertEquals("getPrimaryShardVersion", expPrimaryVersion, actual.getPrimaryShardVersion());
    Future<PrimaryShardInfo> cached = actorContext.getPrimaryShardInfoCache().getIfPresent("foobar");
    PrimaryShardInfo cachedInfo = Await.result(cached, FiniteDuration.apply(1, TimeUnit.MILLISECONDS));
    assertEquals(cachedInfo, actual);
    actorContext.getPrimaryShardInfoCache().remove("foobar");
    cached = actorContext.getPrimaryShardInfoCache().getIfPresent("foobar");
    assertNull(cached);
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) Timeout(akka.util.Timeout) ClusterWrapper(org.opendaylight.controller.cluster.datastore.ClusterWrapper) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Example 8 with DatastoreContext

use of org.opendaylight.controller.cluster.datastore.DatastoreContext in project controller by opendaylight.

the class ActorContextTest method testFindPrimaryExceptions.

@SuppressWarnings("checkstyle:IllegalCatch")
private static void testFindPrimaryExceptions(final Object expectedException) throws Exception {
    ActorRef shardManager = getSystem().actorOf(MessageCollectorActor.props());
    DatastoreContext dataStoreContext = DatastoreContext.newBuilder().logicalStoreType(LogicalDatastoreType.CONFIGURATION).shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build();
    ActorContext actorContext = new ActorContext(getSystem(), shardManager, mock(ClusterWrapper.class), mock(Configuration.class), dataStoreContext, new PrimaryShardInfoFutureCache()) {

        @Override
        protected Future<Object> doAsk(final ActorRef actorRef, final Object message, final Timeout timeout) {
            return Futures.successful(expectedException);
        }
    };
    Future<PrimaryShardInfo> 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<PrimaryShardInfo> cached = actorContext.getPrimaryShardInfoCache().getIfPresent("foobar");
    assertNull(cached);
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) Timeout(akka.util.Timeout) ClusterWrapper(org.opendaylight.controller.cluster.datastore.ClusterWrapper) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) PrimaryNotFoundException(org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)

Example 9 with DatastoreContext

use of org.opendaylight.controller.cluster.datastore.DatastoreContext in project controller by opendaylight.

the class ActorContextTest method testSetDatastoreContext.

@Test
public void testSetDatastoreContext() {
    new TestKit(getSystem()) {

        {
            ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class), DatastoreContext.newBuilder().operationTimeoutInSeconds(5).shardTransactionCommitTimeoutInSeconds(7).build(), new PrimaryShardInfoFutureCache());
            assertEquals("getOperationDuration", 5, actorContext.getOperationDuration().toSeconds());
            assertEquals("getTransactionCommitOperationTimeout", 7, actorContext.getTransactionCommitOperationTimeout().duration().toSeconds());
            DatastoreContext newContext = DatastoreContext.newBuilder().operationTimeoutInSeconds(6).shardTransactionCommitTimeoutInSeconds(8).build();
            DatastoreContextFactory mockContextFactory = mock(DatastoreContextFactory.class);
            Mockito.doReturn(newContext).when(mockContextFactory).getBaseDatastoreContext();
            actorContext.setDatastoreContext(mockContextFactory);
            expectMsgClass(duration("5 seconds"), DatastoreContextFactory.class);
            Assert.assertSame("getDatastoreContext", newContext, actorContext.getDatastoreContext());
            assertEquals("getOperationDuration", 6, actorContext.getOperationDuration().toSeconds());
            assertEquals("getTransactionCommitOperationTimeout", 8, actorContext.getTransactionCommitOperationTimeout().duration().toSeconds());
        }
    };
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) DatastoreContextFactory(org.opendaylight.controller.cluster.datastore.DatastoreContextFactory) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) ClusterWrapper(org.opendaylight.controller.cluster.datastore.ClusterWrapper) TestKit(akka.testkit.javadsl.TestKit) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Example 10 with DatastoreContext

use of org.opendaylight.controller.cluster.datastore.DatastoreContext in project controller by opendaylight.

the class CDSShardAccessImplTest method setUp.

@Before
public void setUp() {
    context = mock(ActorContext.class);
    final DatastoreContext datastoreContext = DatastoreContext.newBuilder().build();
    doReturn(Optional.of(getSystem().deadLetters())).when(context).findLocalShard(any());
    doReturn(datastoreContext).when(context).getDatastoreContext();
    doReturn(getSystem()).when(context).getActorSystem();
    shardAccess = new CDSShardAccessImpl(TEST_ID, context);
}
Also used : DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) Before(org.junit.Before)

Aggregations

DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)15 Timeout (akka.util.Timeout)6 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)6 ActorRef (akka.actor.ActorRef)5 TestActorRef (akka.testkit.TestActorRef)5 Test (org.junit.Test)5 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)5 ClusterWrapper (org.opendaylight.controller.cluster.datastore.ClusterWrapper)4 DeleteSnapshotsFailure (akka.persistence.DeleteSnapshotsFailure)3 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)3 TestKit (akka.testkit.javadsl.TestKit)3 Dispatchers (org.opendaylight.controller.cluster.common.actor.Dispatchers)3 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)3 DatastoreContextFactory (org.opendaylight.controller.cluster.datastore.DatastoreContextFactory)3 PrimaryShardInfo (org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)3 Before (org.junit.Before)2 MemberName (org.opendaylight.controller.cluster.access.concepts.MemberName)2 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)2 Builder (org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder)2 ConfigurationImpl (org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)2