Search in sources :

Example 1 with MockClusterWrapper

use of org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper in project controller by opendaylight.

the class ThreePhaseCommitCohortProxyTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    actorContext = new ActorContext(getSystem(), actorFactory.createActor(Props.create(DoNothingActor.class)), new MockClusterWrapper(), new MockConfiguration(), DatastoreContext.newBuilder().build(), new PrimaryShardInfoFutureCache()) {

        @Override
        public Timer getOperationTimer(final String operationName) {
            return commitTimer;
        }

        @Override
        public double getTxCreationLimit() {
            return 10.0;
        }
    };
    doReturn(commitTimerContext).when(commitTimer).time();
    doReturn(commitSnapshot).when(commitTimer).getSnapshot();
    for (int i = 1; i < 11; i++) {
        // Keep on increasing the amount of time it takes to complete transaction for each tenth of a
        // percentile. Essentially this would be 1ms for the 10th percentile, 2ms for 20th percentile and so on.
        doReturn(TimeUnit.MILLISECONDS.toNanos(i) * 1D).when(commitSnapshot).getValue(i * 0.1);
    }
}
Also used : Timer(com.codahale.metrics.Timer) DoNothingActor(org.opendaylight.controller.cluster.raft.utils.DoNothingActor) MockClusterWrapper(org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper) PrimaryShardInfoFutureCache(org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) Before(org.junit.Before)

Example 2 with MockClusterWrapper

use of org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper 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 3 with MockClusterWrapper

use of org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper in project controller by opendaylight.

the class ShardManagerTest method testServerChangeWhenAlreadyInProgress.

public void testServerChangeWhenAlreadyInProgress(final String shardName, final Object firstServerChange, final Class<?> firstForwardedServerChangeClass, final Object secondServerChange) throws Exception {
    new TestKit(getSystem()) {

        {
            TestKit mockShardLeaderKit = new TestKit(getSystem());
            final TestKit secondRequestKit = new TestKit(getSystem());
            MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put(shardName, Arrays.asList("member-2")).build());
            final TestActorRef<TestShardManager> shardManager = TestActorRef.create(getSystem(), newTestShardMgrBuilder().configuration(mockConfig).shardActor(mockShardActor).cluster(new MockClusterWrapper()).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardMgrID);
            shardManager.underlyingActor().setMessageInterceptor(newFindPrimaryInterceptor(mockShardLeaderKit.getRef()));
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(firstServerChange, getRef());
            mockShardLeaderKit.expectMsgClass(firstForwardedServerChangeClass);
            shardManager.tell(secondServerChange, secondRequestKit.getRef());
            secondRequestKit.expectMsgClass(duration("5 seconds"), Failure.class);
        }
    };
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) MockClusterWrapper(org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) TestKit(akka.testkit.javadsl.TestKit) AddressFromURIString(akka.actor.AddressFromURIString)

Example 4 with MockClusterWrapper

use of org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper in project controller by opendaylight.

the class DataChangeListenerProxyTest method testOnDataChanged.

@Test
public void testOnDataChanged() throws Exception {
    final ActorRef actorRef = getSystem().actorOf(MessageCollectorActor.props());
    DataChangeListenerProxy dataChangeListenerProxy = new DataChangeListenerProxy(getSystem().actorSelection(actorRef.path()));
    dataChangeListenerProxy.onDataChanged(new MockDataChangedEvent());
    // Check if it was received by the remote actor
    ActorContext testContext = new ActorContext(getSystem(), getSystem().actorOf(Props.create(DoNothingActor.class)), new MockClusterWrapper(), new MockConfiguration());
    Object messages = testContext.executeOperation(actorRef, MessageCollectorActor.GET_ALL_MESSAGES);
    Assert.assertNotNull(messages);
    Assert.assertTrue(messages instanceof List);
    List<?> listMessages = (List<?>) messages;
    Assert.assertEquals(1, listMessages.size());
    Assert.assertTrue(listMessages.get(0).getClass().equals(DataChanged.class));
}
Also used : DataChanged(org.opendaylight.controller.cluster.datastore.messages.DataChanged) ActorRef(akka.actor.ActorRef) MockClusterWrapper(org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) List(java.util.List) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) Test(org.junit.Test)

Aggregations

MockClusterWrapper (org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper)4 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)3 Before (org.junit.Before)2 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)2 ActorRef (akka.actor.ActorRef)1 AddressFromURIString (akka.actor.AddressFromURIString)1 TestKit (akka.testkit.javadsl.TestKit)1 Timer (com.codahale.metrics.Timer)1 List (java.util.List)1 Test (org.junit.Test)1 MemberName (org.opendaylight.controller.cluster.access.concepts.MemberName)1 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)1 DatastoreContextFactory (org.opendaylight.controller.cluster.datastore.DatastoreContextFactory)1 DistributedDataStore (org.opendaylight.controller.cluster.datastore.DistributedDataStore)1 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)1 ConfigurationImpl (org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)1 EmptyModuleShardConfigProvider (org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider)1 DataChanged (org.opendaylight.controller.cluster.datastore.messages.DataChanged)1 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)1 PrimaryShardInfoFutureCache (org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache)1