Inject BindingAwareBroker as it is now provided by OSGi
[controller.git] / opendaylight / md-sal / mdsal-it-base / src / main / java / org / opendaylight / controller / mdsal / it / base / AbstractMdsalTestBase.java
index 34728a99fbbb9c0a942950345caddcc406b9d1c4..ef4ab1ace9a2b2953fe272d0b827c7351e87dd4f 100644 (file)
@@ -1,10 +1,16 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
 package org.opendaylight.controller.mdsal.it.base;
 
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
 import static org.ops4j.pax.exam.CoreOptions.composite;
 
-import java.util.Calendar;
-
 import javax.inject.Inject;
 
 import org.junit.Before;
@@ -16,7 +22,6 @@ import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
 import org.ops4j.pax.exam.util.Filter;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -26,6 +31,8 @@ public abstract class AbstractMdsalTestBase extends AbstractConfigTestBase imple
     private static final int REGISTRATION_TIMEOUT = 70000;
     @Inject @Filter(timeout=60000)
     private BundleContext context;
+    @Inject @Filter(timeout=60000)
+    private BindingAwareBroker broker;
     private ProviderContext session = null;
 
     public ProviderContext getSession() {
@@ -42,19 +49,14 @@ public abstract class AbstractMdsalTestBase extends AbstractConfigTestBase imple
     @Before
     public void setup() throws Exception {
         super.setup();
-        Calendar start = Calendar.getInstance();
-        ServiceReference<BindingAwareBroker> serviceReference = context.getServiceReference(BindingAwareBroker.class);
-        if(serviceReference == null) {
-            throw new RuntimeException("BindingAwareBroker not found");
-        }
-        BindingAwareBroker broker = context.getService(serviceReference);
+        long start = System.nanoTime();
         broker.registerProvider(this);
         for(int i=0;i<REGISTRATION_TIMEOUT;i++) {
             if(session !=null) {
-                Calendar stop = Calendar.getInstance();
-                LOG.info("Registered session {} with the MD-SAL after {} ms",
+                long stop = System.nanoTime();
+                LOG.info("Registered session {} with the MD-SAL after {} ns",
                         session,
-                        stop.getTimeInMillis() - start.getTimeInMillis());
+                        stop - start);
                 return;
             } else {
                 Thread.sleep(1);