Search in sources :

Example 1 with BindingAwareConsumer

use of org.opendaylight.controller.sal.binding.api.BindingAwareConsumer in project controller by opendaylight.

the class NotificationIT method notificationTest.

/**
 * test of delivering of notification
 * @throws Exception
 */
@Test
public void notificationTest() throws Exception {
    LOG.info("The registration of the Provider 1.");
    AbstractTestProvider provider1 = new AbstractTestProvider() {

        @Override
        public void onSessionInitiated(ProviderContext session) {
            notifyProviderService = session.getSALService(NotificationProviderService.class);
        }
    };
    // registerProvider method calls onSessionInitiated method above
    broker.registerProvider(provider1);
    assertNotNull(notifyProviderService);
    LOG.info("The registration of the Consumer 1. It retrieves Notification Service " + "from MD-SAL and registers OpendaylightTestNotificationListener as notification listener");
    BindingAwareConsumer consumer1 = session -> {
        NotificationService notificationService = session.getSALService(NotificationService.class);
        assertNotNull(notificationService);
        listener1Reg = notificationService.registerNotificationListener(listener1);
    };
    // registerConsumer method calls onSessionInitialized method above
    broker.registerConsumer(consumer1);
    assertNotNull(listener1Reg);
    LOG.info("The notification of type FlowAdded with cookie ID 0 is created. The " + "delay 100ms to make sure that the notification was delivered to " + "listener.");
    notifyProviderService.publish(noDustNotification("rainy day", 42));
    Thread.sleep(100);
    /**
     * Check that one notification was delivered and has correct cookie.
     */
    assertEquals(1, listener1.notificationBag.size());
    assertEquals("rainy day", listener1.notificationBag.get(0).getReason());
    assertEquals(42, listener1.notificationBag.get(0).getDaysTillNewDust().intValue());
    LOG.info("The registration of the Consumer 2. SalFlowListener is registered " + "registered as notification listener.");
    BindingAwareProvider provider = session -> listener2Reg = session.getSALService(NotificationProviderService.class).registerNotificationListener(listener2);
    // registerConsumer method calls onSessionInitialized method above
    broker.registerProvider(provider);
    LOG.info("3 notifications are published");
    notifyProviderService.publish(noDustNotification("rainy day", 5));
    notifyProviderService.publish(noDustNotification("rainy day", 10));
    notifyProviderService.publish(noDustNotification("tax collector", 2));
    /**
     * The delay 100ms to make sure that the notifications were delivered to
     * listeners.
     */
    Thread.sleep(100);
    /**
     * Check that 3 notification was delivered to both listeners (first one
     * received 4 in total, second 3 in total).
     */
    assertEquals(4, listener1.notificationBag.size());
    assertEquals(3, listener2.notificationBag.size());
    /**
     * The second listener is closed (unregistered)
     */
    listener2Reg.close();
    LOG.info("The notification 5 is published");
    notifyProviderService.publish(noDustNotification("entomologist hunt", 10));
    /**
     * The delay 100ms to make sure that the notification was delivered to
     * listener.
     */
    Thread.sleep(100);
    /**
     * Check that first consumer received 5 notifications in total, second
     * consumer received only three. Last notification was never received by
     * second consumer because its listener was unregistered.
     */
    assertEquals(5, listener1.notificationBag.size());
    assertEquals(3, listener2.notificationBag.size());
}
Also used : Logger(org.slf4j.Logger) NotificationService(org.opendaylight.controller.sal.binding.api.NotificationService) OutOfPixieDustNotificationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OutOfPixieDustNotificationBuilder) Assert.assertNotNull(org.junit.Assert.assertNotNull) LoggerFactory(org.slf4j.LoggerFactory) Test(org.junit.Test) ProviderContext(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext) NotificationProviderService(org.opendaylight.controller.sal.binding.api.NotificationProviderService) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) ArrayList(java.util.ArrayList) BindingAwareConsumer(org.opendaylight.controller.sal.binding.api.BindingAwareConsumer) OpendaylightTestNotificationListener(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OpendaylightTestNotificationListener) List(java.util.List) BindingAwareProvider(org.opendaylight.controller.sal.binding.api.BindingAwareProvider) OutOfPixieDustNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OutOfPixieDustNotification) NotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener) Assert.assertEquals(org.junit.Assert.assertEquals) ProviderContext(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext) BindingAwareProvider(org.opendaylight.controller.sal.binding.api.BindingAwareProvider) NotificationProviderService(org.opendaylight.controller.sal.binding.api.NotificationProviderService) NotificationService(org.opendaylight.controller.sal.binding.api.NotificationService) BindingAwareConsumer(org.opendaylight.controller.sal.binding.api.BindingAwareConsumer) Test(org.junit.Test)

Example 2 with BindingAwareConsumer

use of org.opendaylight.controller.sal.binding.api.BindingAwareConsumer in project openflowplugin by opendaylight.

the class SalIntegrationTest method handshakeAndNodeUpdate.

/**
 * test basic integration with OFLib running the handshake
 *
 * @throws Exception
 */
@Test
public void handshakeAndNodeUpdate() throws Exception {
    final TestInventoryListener listener = new TestInventoryListener();
    BindingAwareConsumer openflowConsumer = new BindingAwareConsumer() {

        @Override
        public void onSessionInitialized(ConsumerContext session) {
            session.getSALService(NotificationService.class).registerNotificationListener(listener);
        }
    };
    ConsumerContext consumerReg = broker.registerConsumer(openflowConsumer, ctx);
    assertNotNull(consumerReg);
    LOG.debug("handshake integration test");
    LOG.debug("openflowPluginProvider: " + openflowPluginProvider);
    switchSim.setSecuredClient(false);
    ScenarioHandler scenario = new ScenarioHandler(ScenarioFactory.createHandshakeScenarioVBM(ScenarioFactory.VERSION_BITMAP_13, (short) 0, ScenarioFactory.VERSION_BITMAP_10_13, true));
    switchSim.setScenarioHandler(scenario);
    scenarioPool.execute(switchSim);
    finalCheck = new Runnable() {

        @Override
        public void run() {
            // FIXME: Enable the test -- It's requires EntityOnwershipService hook to the test
            // assertEquals(1, listener.nodeUpdated.size());
            assertEquals(0, listener.nodeUpdated.size());
        // assertNotNull(listener.nodeUpdated.get(0));
        }
    };
}
Also used : ConsumerContext(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext) ScenarioHandler(org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler) NotificationService(org.opendaylight.controller.sal.binding.api.NotificationService) BindingAwareConsumer(org.opendaylight.controller.sal.binding.api.BindingAwareConsumer) Test(org.junit.Test)

Example 3 with BindingAwareConsumer

use of org.opendaylight.controller.sal.binding.api.BindingAwareConsumer in project controller by opendaylight.

the class RoutedServiceIT method testServiceRegistration.

@Test
public void testServiceRegistration() {
    assertNotNull(broker);
    final BindingAwareProvider provider1 = new AbstractTestProvider() {

        @Override
        public void onSessionInitiated(final ProviderContext session) {
            assertNotNull(session);
            firstReg = session.addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService1);
        }
    };
    LOG.info("Register provider 1 with first implementation of routeSimpleService - service1");
    broker.registerProvider(provider1);
    assertNotNull("Registration should not be null", firstReg);
    assertSame(odlRoutedService1, firstReg.getInstance());
    final BindingAwareProvider provider2 = new AbstractTestProvider() {

        @Override
        public void onSessionInitiated(final ProviderContext session) {
            assertNotNull(session);
            secondReg = session.addRoutedRpcImplementation(OpendaylightTestRoutedRpcService.class, odlRoutedService2);
        }
    };
    LOG.info("Register provider 2 with second implementation of routeSimpleService - service2");
    broker.registerProvider(provider2);
    assertNotNull("Registration should not be null", firstReg);
    assertSame(odlRoutedService2, secondReg.getInstance());
    assertNotSame(secondReg, firstReg);
    final BindingAwareConsumer consumer = session -> consumerService = session.getRpcService(OpendaylightTestRoutedRpcService.class);
    LOG.info("Register routeService consumer");
    broker.registerConsumer(consumer);
    assertNotNull("MD-SAL instance of test Service should be returned", consumerService);
    assertNotSame("Provider instance and consumer instance should not be same.", odlRoutedService1, consumerService);
    final InstanceIdentifier<UnorderedList> nodeOnePath = createNodeRef("foo:node:1");
    LOG.info("Provider 1 registers path of node 1");
    firstReg.registerPath(TestContext.class, nodeOnePath);
    /**
     * Consumer creates addFlow message for node one and sends it to the
     * MD-SAL
     */
    final RoutedSimpleRouteInput simpleRouteFirstFoo = createSimpleRouteInput(nodeOnePath);
    consumerService.routedSimpleRoute(simpleRouteFirstFoo);
    /**
     * Verifies that implementation of the first provider received the same
     * message from MD-SAL.
     */
    verify(odlRoutedService1).routedSimpleRoute(simpleRouteFirstFoo);
    /**
     * Verifies that second instance was not invoked with first message
     */
    verify(odlRoutedService2, times(0)).routedSimpleRoute(simpleRouteFirstFoo);
    LOG.info("Provider 2 registers path of node 2");
    final InstanceIdentifier<UnorderedList> nodeTwo = createNodeRef("foo:node:2");
    secondReg.registerPath(TestContext.class, nodeTwo);
    /**
     * Consumer sends message to nodeTwo for three times. Should be
     * processed by second instance.
     */
    final RoutedSimpleRouteInput simpleRouteSecondFoo = createSimpleRouteInput(nodeTwo);
    consumerService.routedSimpleRoute(simpleRouteSecondFoo);
    consumerService.routedSimpleRoute(simpleRouteSecondFoo);
    consumerService.routedSimpleRoute(simpleRouteSecondFoo);
    /**
     * Verifies that second instance was invoked 3 times with second message
     * and first instance wasn't invoked.
     */
    verify(odlRoutedService2, times(3)).routedSimpleRoute(simpleRouteSecondFoo);
    verify(odlRoutedService1, times(0)).routedSimpleRoute(simpleRouteSecondFoo);
    LOG.info("Unregistration of the path for the node one in the first provider");
    firstReg.unregisterPath(TestContext.class, nodeOnePath);
    LOG.info("Provider 2 registers path of node 1");
    secondReg.registerPath(TestContext.class, nodeOnePath);
    /**
     * A consumer sends third message to node 1
     */
    final RoutedSimpleRouteInput simpleRouteThirdFoo = createSimpleRouteInput(nodeOnePath);
    consumerService.routedSimpleRoute(simpleRouteThirdFoo);
    /**
     * Verifies that provider 1 wasn't invoked and provider 2 was invoked 1
     * time.
     * TODO: fix unregister path
     */
    // verify(odlRoutedService1, times(0)).routedSimpleRoute(simpleRouteThirdFoo);
    verify(odlRoutedService2).routedSimpleRoute(simpleRouteThirdFoo);
}
Also used : OpendaylightTestRoutedRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.OpendaylightTestRoutedRpcService) UnorderedListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListKey) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Assert.assertNotSame(org.junit.Assert.assertNotSame) LoggerFactory(org.slf4j.LoggerFactory) ProviderContext(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext) Lists(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.Lists) Assert.assertSame(org.junit.Assert.assertSame) Before(org.junit.Before) UnorderedList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) OpendaylightTestRoutedRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.OpendaylightTestRoutedRpcService) RoutedSimpleRouteInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInputBuilder) RoutedRpcRegistration(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) UnorderedContainer(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.UnorderedContainer) Mockito.verify(org.mockito.Mockito.verify) BindingAwareConsumer(org.opendaylight.controller.sal.binding.api.BindingAwareConsumer) Mockito(org.mockito.Mockito) Futures(com.google.common.util.concurrent.Futures) BindingAwareProvider(org.opendaylight.controller.sal.binding.api.BindingAwareProvider) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) TestContext(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.TestContext) RoutedSimpleRouteInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput) Mockito.mock(org.mockito.Mockito.mock) ProviderContext(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext) BindingAwareProvider(org.opendaylight.controller.sal.binding.api.BindingAwareProvider) UnorderedList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList) RoutedSimpleRouteInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.RoutedSimpleRouteInput) BindingAwareConsumer(org.opendaylight.controller.sal.binding.api.BindingAwareConsumer) Test(org.junit.Test)

Example 4 with BindingAwareConsumer

use of org.opendaylight.controller.sal.binding.api.BindingAwareConsumer in project controller by opendaylight.

the class DataServiceIT method test.

/**
 * Ignored this, because classes here are constructed from
 * very different class loader as MD-SAL is run into,
 * this is code is run from different classloader.
 *
 * @throws Exception
 */
@Test
public void test() throws Exception {
    BindingAwareConsumer consumer = session -> dataBroker = session.getSALService(DataBroker.class);
    broker.registerConsumer(consumer);
    assertNotNull(dataBroker);
    final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
    assertNotNull(transaction);
    InstanceIdentifier<UnorderedList> node1 = createNodeRef("0");
    Optional<UnorderedList> node = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, node1).checkedGet(5, TimeUnit.SECONDS);
    assertFalse(node.isPresent());
    UnorderedList nodeData1 = createNode("0");
    transaction.put(LogicalDatastoreType.OPERATIONAL, node1, nodeData1);
    transaction.submit().checkedGet(5, TimeUnit.SECONDS);
    Optional<UnorderedList> readedData = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, node1).checkedGet(5, TimeUnit.SECONDS);
    assertTrue(readedData.isPresent());
    assertEquals(nodeData1.getKey(), readedData.get().getKey());
    final WriteTransaction transaction2 = dataBroker.newWriteOnlyTransaction();
    assertNotNull(transaction2);
    transaction2.delete(LogicalDatastoreType.OPERATIONAL, node1);
    transaction2.submit().checkedGet(5, TimeUnit.SECONDS);
    Optional<UnorderedList> readedData2 = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, node1).checkedGet(5, TimeUnit.SECONDS);
    assertFalse(readedData2.isPresent());
}
Also used : UnorderedListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListKey) UnorderedList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList) Assert.assertNotNull(org.junit.Assert.assertNotNull) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UnorderedContainer(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.UnorderedContainer) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Lists(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.Lists) TimeUnit(java.util.concurrent.TimeUnit) BindingAwareConsumer(org.opendaylight.controller.sal.binding.api.BindingAwareConsumer) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(com.google.common.base.Optional) UnorderedListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListBuilder) Assert.assertEquals(org.junit.Assert.assertEquals) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) UnorderedList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList) BindingAwareConsumer(org.opendaylight.controller.sal.binding.api.BindingAwareConsumer) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 BindingAwareConsumer (org.opendaylight.controller.sal.binding.api.BindingAwareConsumer)4 Assert.assertNotNull (org.junit.Assert.assertNotNull)3 Assert.assertEquals (org.junit.Assert.assertEquals)2 ProviderContext (org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext)2 BindingAwareProvider (org.opendaylight.controller.sal.binding.api.BindingAwareProvider)2 NotificationService (org.opendaylight.controller.sal.binding.api.NotificationService)2 Lists (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.Lists)2 UnorderedContainer (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.UnorderedContainer)2 UnorderedList (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList)2 UnorderedListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedListKey)2 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Optional (com.google.common.base.Optional)1 Futures (com.google.common.util.concurrent.Futures)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Assert.assertFalse (org.junit.Assert.assertFalse)1