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