2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.mdsal.it.base;
11 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
12 import static org.ops4j.pax.exam.CoreOptions.composite;
14 import java.util.Calendar;
16 import javax.inject.Inject;
18 import org.junit.Before;
19 import org.opendaylight.controller.config.it.base.AbstractConfigTestBase;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
21 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
22 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
23 import org.ops4j.pax.exam.Option;
24 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
25 import org.ops4j.pax.exam.util.Filter;
26 import org.osgi.framework.BundleContext;
27 import org.osgi.framework.ServiceReference;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public abstract class AbstractMdsalTestBase extends AbstractConfigTestBase implements BindingAwareProvider {
33 private static final Logger LOG = LoggerFactory.getLogger(AbstractMdsalTestBase.class);
34 private static final int REGISTRATION_TIMEOUT = 70000;
35 @Inject @Filter(timeout=60000)
36 private BundleContext context;
37 private ProviderContext session = null;
39 public ProviderContext getSession() {
44 public void onSessionInitiated(ProviderContext session) {
45 LOG.info("Session Initiated: {}",session);
46 this.session = session;
51 public void setup() throws Exception {
53 Calendar start = Calendar.getInstance();
54 ServiceReference<BindingAwareBroker> serviceReference = context.getServiceReference(BindingAwareBroker.class);
55 if(serviceReference == null) {
56 throw new RuntimeException("BindingAwareBroker not found");
58 BindingAwareBroker broker = context.getService(serviceReference);
59 broker.registerProvider(this);
60 for(int i=0;i<REGISTRATION_TIMEOUT;i++) {
62 Calendar stop = Calendar.getInstance();
63 LOG.info("Registered session {} with the MD-SAL after {} ms",
65 stop.getTimeInMillis() - start.getTimeInMillis());
71 throw new RuntimeException("Session not initiated after " + REGISTRATION_TIMEOUT + " ms");
75 public Option getLoggingOption() {
76 Option option = editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
77 logConfiguration(AbstractMdsalTestBase.class),
78 LogLevel.INFO.name());
79 option = composite(option, super.getLoggingOption());