use of org.opendaylight.yangtools.yang.model.api.SchemaContext in project controller by opendaylight.
the class NormalizedNodeAggregatorTest method testAggregate.
@Test
public void testAggregate() throws InterruptedException, ExecutionException, ReadFailedException, DataValidationFailedException {
SchemaContext schemaContext = SchemaContextHelper.full();
NormalizedNode<?, ?> expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
NormalizedNode<?, ?> expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME);
Optional<NormalizedNode<?, ?>> optional = NormalizedNodeAggregator.aggregate(YangInstanceIdentifier.EMPTY, ImmutableList.of(Optional.<NormalizedNode<?, ?>>of(getRootNode(expectedNode1, schemaContext)), Optional.<NormalizedNode<?, ?>>of(getRootNode(expectedNode2, schemaContext))), schemaContext, LogicalDatastoreType.CONFIGURATION);
NormalizedNode<?, ?> normalizedNode = optional.get();
assertTrue("Expect value to be a Collection", normalizedNode.getValue() instanceof Collection);
@SuppressWarnings("unchecked") Collection<NormalizedNode<?, ?>> collection = (Collection<NormalizedNode<?, ?>>) normalizedNode.getValue();
for (NormalizedNode<?, ?> node : collection) {
assertTrue("Expected " + node + " to be a ContainerNode", node instanceof ContainerNode);
}
assertTrue("Child with QName = " + TestModel.TEST_QNAME + " not found", findChildWithQName(collection, TestModel.TEST_QNAME) != null);
assertEquals(expectedNode1, findChildWithQName(collection, TestModel.TEST_QNAME));
assertTrue("Child with QName = " + CarsModel.BASE_QNAME + " not found", findChildWithQName(collection, CarsModel.BASE_QNAME) != null);
assertEquals(expectedNode2, findChildWithQName(collection, CarsModel.BASE_QNAME));
}
use of org.opendaylight.yangtools.yang.model.api.SchemaContext in project bgpcep by opendaylight.
the class AbstractRIBTestSetup method mockRib.
public void mockRib() throws Exception {
final RIBExtensionProviderContext context = new SimpleRIBExtensionProviderContext();
final ModuleInfoBackedContext strategy = createClassLoadingStrategy();
final SchemaContext schemaContext = strategy.tryToCreateSchemaContext().get();
this.codecFactory = createCodecFactory(strategy, schemaContext);
final List<BgpTableType> localTables = new ArrayList<>();
localTables.add(new BgpTableTypeImpl(AFI, SAFI));
this.a1 = new RIBActivator();
this.a1.startRIBExtensionProvider(context);
final CodecsRegistryImpl codecsRegistry = CodecsRegistryImpl.create(this.codecFactory, GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy());
mockedMethods();
doReturn(mock(ClusterSingletonServiceRegistration.class)).when(this.clusterSingletonServiceProvider).registerClusterSingletonService(any(ClusterSingletonService.class));
this.rib = new RIBImpl(new RibId("test"), new AsNumber(5L), RIB_ID, context, this.dispatcher, codecsRegistry, this.dom, getDataBroker(), this.policies, this.peerTracker, localTables, Collections.singletonMap(new TablesKey(AFI, SAFI), BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker)));
this.rib.onGlobalContextUpdated(schemaContext);
this.ribSupport = getRib().getRibSupportContext().getRIBSupport(KEY);
}
use of org.opendaylight.yangtools.yang.model.api.SchemaContext in project controller by opendaylight.
the class ShardManagerTest method testOnCreateShardWithNoInitialSchemaContext.
@Test
public void testOnCreateShardWithNoInitialSchemaContext() {
LOG.info("testOnCreateShardWithNoInitialSchemaContext starting");
new TestKit(getSystem()) {
{
ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
Shard.Builder shardBuilder = Shard.builder();
ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module", "foo", null, members("member-1"));
shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
expectMsgClass(duration("5 seconds"), Success.class);
SchemaContext schemaContext = TestModel.createTestContext();
shardManager.tell(new UpdateSchemaContext(schemaContext), ActorRef.noSender());
shardManager.tell(new FindLocalShard("foo", true), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
assertSame("schemaContext", schemaContext, shardBuilder.getSchemaContext());
assertNotNull("schemaContext is null", shardBuilder.getDatastoreContext());
}
};
LOG.info("testOnCreateShardWithNoInitialSchemaContext ending");
}
use of org.opendaylight.yangtools.yang.model.api.SchemaContext in project controller by opendaylight.
the class ShardManagerTest method testOnCreateShard.
@Test
public void testOnCreateShard() {
LOG.info("testOnCreateShard starting");
new TestKit(getSystem()) {
{
datastoreContextBuilder.shardInitializationTimeout(1, TimeUnit.MINUTES).persistent(true);
ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
SchemaContext schemaContext = TestModel.createTestContext();
shardManager.tell(new UpdateSchemaContext(schemaContext), ActorRef.noSender());
DatastoreContext datastoreContext = DatastoreContext.newBuilder().shardElectionTimeoutFactor(100).persistent(false).build();
Shard.Builder shardBuilder = Shard.builder();
ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module", "foo", null, members("member-1", "member-5", "member-6"));
shardManager.tell(new CreateShard(config, shardBuilder, datastoreContext), getRef());
expectMsgClass(duration("5 seconds"), Success.class);
shardManager.tell(new FindLocalShard("foo", true), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
assertEquals("isRecoveryApplicable", false, shardBuilder.getDatastoreContext().isPersistent());
assertTrue("Epxected ShardPeerAddressResolver", shardBuilder.getDatastoreContext().getShardRaftConfig().getPeerAddressResolver() instanceof ShardPeerAddressResolver);
assertEquals("peerMembers", Sets.newHashSet(ShardIdentifier.create("foo", MemberName.forName("member-5"), shardMrgIDSuffix).toString(), ShardIdentifier.create("foo", MemberName.forName("member-6"), shardMrgIDSuffix).toString()), shardBuilder.getPeerAddresses().keySet());
assertEquals("ShardIdentifier", ShardIdentifier.create("foo", MEMBER_1, shardMrgIDSuffix), shardBuilder.getId());
assertSame("schemaContext", schemaContext, shardBuilder.getSchemaContext());
// Send CreateShard with same name - should return Success with
// a message.
shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
Success success = expectMsgClass(duration("5 seconds"), Success.class);
assertNotNull("Success status is null", success.status());
}
};
LOG.info("testOnCreateShard ending");
}
Aggregations