Search in sources :

Example 6 with SchemaContext

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));
}
Also used : Collection(java.util.Collection) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 7 with SchemaContext

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);
}
Also used : BgpTableType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.BgpTableType) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) RIBActivator(org.opendaylight.protocol.bgp.inet.RIBActivator) ArrayList(java.util.ArrayList) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) ModuleInfoBackedContext(org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext) SimpleRIBExtensionProviderContext(org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext) RibId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.RibId) SimpleRIBExtensionProviderContext(org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext) RIBExtensionProviderContext(org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext) ClusterSingletonServiceRegistration(org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration) ClusterSingletonService(org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) BgpTableTypeImpl(org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl)

Example 8 with SchemaContext

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");
}
Also used : EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) Shard(org.opendaylight.controller.cluster.datastore.Shard) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 9 with SchemaContext

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");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) Success(akka.actor.Status.Success) EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) Shard(org.opendaylight.controller.cluster.datastore.Shard) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)9 Test (org.junit.Test)4 Collection (java.util.Collection)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 ActorRef (akka.actor.ActorRef)2 TestActorRef (akka.testkit.TestActorRef)2 TestKit (akka.testkit.javadsl.TestKit)2 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)2 Shard (org.opendaylight.controller.cluster.datastore.Shard)2 ConfigurationImpl (org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)2 EmptyModuleShardConfigProvider (org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider)2 ModuleShardConfiguration (org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)2 CreateShard (org.opendaylight.controller.cluster.datastore.messages.CreateShard)2 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)2 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)2 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)2 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)2 Success (akka.actor.Status.Success)1 Optional (com.google.common.base.Optional)1