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);
}
}
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());
}
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);
}
};
}
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));
}
Aggregations