1 package org.opendaylight.controller.mdsal.it.base;
3 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
4 import static org.ops4j.pax.exam.CoreOptions.composite;
6 import java.util.Calendar;
8 import javax.inject.Inject;
10 import org.junit.Before;
11 import org.opendaylight.controller.config.it.base.AbstractConfigTestBase;
12 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
15 import org.ops4j.pax.exam.Option;
16 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
17 import org.ops4j.pax.exam.util.Filter;
18 import org.osgi.framework.BundleContext;
19 import org.osgi.framework.ServiceReference;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public abstract class AbstractMdsalTestBase extends AbstractConfigTestBase implements BindingAwareProvider {
25 private static final Logger LOG = LoggerFactory.getLogger(AbstractMdsalTestBase.class);
26 private static final int REGISTRATION_TIMEOUT = 70000;
27 @Inject @Filter(timeout=60000)
28 private BundleContext context;
29 private ProviderContext session = null;
31 public ProviderContext getSession() {
36 public void onSessionInitiated(ProviderContext session) {
37 LOG.info("Session Initiated: {}",session);
38 this.session = session;
43 public void setup() throws Exception {
45 Calendar start = Calendar.getInstance();
46 ServiceReference<BindingAwareBroker> serviceReference = context.getServiceReference(BindingAwareBroker.class);
47 if(serviceReference == null) {
48 throw new RuntimeException("BindingAwareBroker not found");
50 BindingAwareBroker broker = context.getService(serviceReference);
51 broker.registerProvider(this);
52 for(int i=0;i<REGISTRATION_TIMEOUT;i++) {
54 Calendar stop = Calendar.getInstance();
55 LOG.info("Registered session {} with the MD-SAL after {} ms",
57 stop.getTimeInMillis() - start.getTimeInMillis());
63 throw new RuntimeException("Session not initiated after " + REGISTRATION_TIMEOUT + " ms");
67 public Option getLoggingOption() {
68 Option option = editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
69 logConfiguration(AbstractMdsalTestBase.class),
70 LogLevel.INFO.name());
71 option = composite(option, super.getLoggingOption());