use of org.opendaylight.controller.sal.binding.api.BindingAwareProvider 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());
}
use of org.opendaylight.controller.sal.binding.api.BindingAwareProvider 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);
}
Aggregations