Search in sources :

Example 1 with DatastoreContextFactory

use of org.opendaylight.controller.cluster.datastore.DatastoreContextFactory 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 2 with DatastoreContextFactory

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

the class ShardManagerTest method newDatastoreContextFactory.

private static DatastoreContextFactory newDatastoreContextFactory(final DatastoreContext datastoreContext) {
    DatastoreContextFactory mockFactory = mock(DatastoreContextFactory.class);
    Mockito.doReturn(datastoreContext).when(mockFactory).getBaseDatastoreContext();
    Mockito.doReturn(datastoreContext).when(mockFactory).getShardDatastoreContext(Mockito.anyString());
    return mockFactory;
}
Also used : DatastoreContextFactory(org.opendaylight.controller.cluster.datastore.DatastoreContextFactory)

Example 3 with DatastoreContextFactory

use of org.opendaylight.controller.cluster.datastore.DatastoreContextFactory 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 4 with DatastoreContextFactory

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

the class ShardManagerTest method testPerShardDatastoreContext.

@Test
public void testPerShardDatastoreContext() throws Exception {
    LOG.info("testPerShardDatastoreContext starting");
    final DatastoreContextFactory mockFactory = newDatastoreContextFactory(datastoreContextBuilder.shardElectionTimeoutFactor(5).build());
    Mockito.doReturn(DatastoreContext.newBuilderFrom(datastoreContextBuilder.build()).shardElectionTimeoutFactor(6).build()).when(mockFactory).getShardDatastoreContext("default");
    Mockito.doReturn(DatastoreContext.newBuilderFrom(datastoreContextBuilder.build()).shardElectionTimeoutFactor(7).build()).when(mockFactory).getShardDatastoreContext("topology");
    final MockConfiguration mockConfig = new MockConfiguration() {

        @Override
        public Collection<String> getMemberShardNames(final MemberName memberName) {
            return Arrays.asList("default", "topology");
        }

        @Override
        public Collection<MemberName> getMembersFromShardName(final String shardName) {
            return members("member-1");
        }
    };
    final ActorRef defaultShardActor = actorFactory.createActor(MessageCollectorActor.props(), actorFactory.generateActorId("default"));
    final ActorRef topologyShardActor = actorFactory.createActor(MessageCollectorActor.props(), actorFactory.generateActorId("topology"));
    final Map<String, Entry<ActorRef, DatastoreContext>> shardInfoMap = Collections.synchronizedMap(new HashMap<String, Entry<ActorRef, DatastoreContext>>());
    shardInfoMap.put("default", new AbstractMap.SimpleEntry<>(defaultShardActor, null));
    shardInfoMap.put("topology", new AbstractMap.SimpleEntry<>(topologyShardActor, null));
    final PrimaryShardInfoFutureCache primaryShardInfoCache = new PrimaryShardInfoFutureCache();
    final CountDownLatch newShardActorLatch = new CountDownLatch(2);
    class LocalShardManager extends ShardManager {

        LocalShardManager(final AbstractShardManagerCreator<?> creator) {
            super(creator);
        }

        @Override
        protected ActorRef newShardActor(final ShardInformation info) {
            Entry<ActorRef, DatastoreContext> entry = shardInfoMap.get(info.getShardName());
            ActorRef ref = null;
            if (entry != null) {
                ref = entry.getKey();
                entry.setValue(info.getDatastoreContext());
            }
            newShardActorLatch.countDown();
            return ref;
        }
    }
    final Creator<ShardManager> creator = new Creator<ShardManager>() {

        private static final long serialVersionUID = 1L;

        @Override
        public ShardManager create() throws Exception {
            return new LocalShardManager(new GenericCreator<>(LocalShardManager.class).datastoreContextFactory(mockFactory).primaryShardInfoCache(primaryShardInfoCache).configuration(mockConfig));
        }
    };
    TestKit kit = new TestKit(getSystem());
    final ActorRef shardManager = actorFactory.createActor(Props.create(new DelegatingShardManagerCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()));
    shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), kit.getRef());
    assertEquals("Shard actors created", true, newShardActorLatch.await(5, TimeUnit.SECONDS));
    assertEquals("getShardElectionTimeoutFactor", 6, shardInfoMap.get("default").getValue().getShardElectionTimeoutFactor());
    assertEquals("getShardElectionTimeoutFactor", 7, shardInfoMap.get("topology").getValue().getShardElectionTimeoutFactor());
    DatastoreContextFactory newMockFactory = newDatastoreContextFactory(datastoreContextBuilder.shardElectionTimeoutFactor(5).build());
    Mockito.doReturn(DatastoreContext.newBuilderFrom(datastoreContextBuilder.build()).shardElectionTimeoutFactor(66).build()).when(newMockFactory).getShardDatastoreContext("default");
    Mockito.doReturn(DatastoreContext.newBuilderFrom(datastoreContextBuilder.build()).shardElectionTimeoutFactor(77).build()).when(newMockFactory).getShardDatastoreContext("topology");
    shardManager.tell(newMockFactory, kit.getRef());
    DatastoreContext newContext = MessageCollectorActor.expectFirstMatching(defaultShardActor, DatastoreContext.class);
    assertEquals("getShardElectionTimeoutFactor", 66, newContext.getShardElectionTimeoutFactor());
    newContext = MessageCollectorActor.expectFirstMatching(topologyShardActor, DatastoreContext.class);
    assertEquals("getShardElectionTimeoutFactor", 77, newContext.getShardElectionTimeoutFactor());
    LOG.info("testPerShardDatastoreContext ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) DatastoreContextFactory(org.opendaylight.controller.cluster.datastore.DatastoreContextFactory) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) AddressFromURIString(akka.actor.AddressFromURIString) Creator(akka.japi.Creator) TestKit(akka.testkit.javadsl.TestKit) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractMap(java.util.AbstractMap) Entry(java.util.Map.Entry) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) PrimaryShardInfoFutureCache(org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

DatastoreContextFactory (org.opendaylight.controller.cluster.datastore.DatastoreContextFactory)4 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)3 TestKit (akka.testkit.javadsl.TestKit)2 Test (org.junit.Test)2 MemberName (org.opendaylight.controller.cluster.access.concepts.MemberName)2 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)2 ActorRef (akka.actor.ActorRef)1 AddressFromURIString (akka.actor.AddressFromURIString)1 Creator (akka.japi.Creator)1 TestActorRef (akka.testkit.TestActorRef)1 AbstractMap (java.util.AbstractMap)1 Entry (java.util.Map.Entry)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)1 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)1 ClusterWrapper (org.opendaylight.controller.cluster.datastore.ClusterWrapper)1 DistributedDataStore (org.opendaylight.controller.cluster.datastore.DistributedDataStore)1 ConfigurationImpl (org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)1 EmptyModuleShardConfigProvider (org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider)1