karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [2/2] karaf git commit: Simplify MavenResolverTests
Date Thu, 18 May 2017 09:25:24 GMT
Simplify MavenResolverTests


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/646c91b7
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/646c91b7
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/646c91b7

Branch: refs/heads/master
Commit: 646c91b7555e59f983d0c3cde1d3234da1d425bf
Parents: e3b275b
Author: Christian Schneider <chris@die-schneider.net>
Authored: Thu May 18 11:25:16 2017 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Thu May 18 11:25:16 2017 +0200

----------------------------------------------------------------------
 .../KarafMinimalMonitoredTestSupport.java       | 58 ++++++++++----------
 .../karaf/itests/monitoring/Activator.java      | 15 ++---
 .../itests/monitoring/RegisteredService.java    | 34 ------------
 .../karaf/itests/monitoring/ServiceMonitor.java | 15 ++---
 4 files changed, 43 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/646c91b7/itests/src/test/java/org/apache/karaf/itests/mavenresolver/KarafMinimalMonitoredTestSupport.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/mavenresolver/KarafMinimalMonitoredTestSupport.java
b/itests/src/test/java/org/apache/karaf/itests/mavenresolver/KarafMinimalMonitoredTestSupport.java
index d5c7d66..eb6d45f 100644
--- a/itests/src/test/java/org/apache/karaf/itests/mavenresolver/KarafMinimalMonitoredTestSupport.java
+++ b/itests/src/test/java/org/apache/karaf/itests/mavenresolver/KarafMinimalMonitoredTestSupport.java
@@ -16,43 +16,57 @@
  */
 package org.apache.karaf.itests.mavenresolver;
 
+import static org.apache.karaf.itests.KarafTestSupport.MAX_RMI_REG_PORT;
+import static org.apache.karaf.itests.KarafTestSupport.MAX_RMI_SERVER_PORT;
+import static org.apache.karaf.itests.KarafTestSupport.MIN_RMI_REG_PORT;
+import static org.apache.karaf.itests.KarafTestSupport.MIN_RMI_SERVER_PORT;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureSecurity;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
+import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
+import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
+import static org.osgi.framework.Constants.OBJECTCLASS;
+
 import java.io.File;
 import java.io.InputStream;
 import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.function.Function;
 
 import javax.inject.Inject;
 
 import org.apache.karaf.itests.KarafTestSupport;
 import org.apache.karaf.itests.monitoring.Activator;
-import org.apache.karaf.itests.monitoring.RegisteredService;
 import org.apache.karaf.itests.monitoring.ServiceMonitor;
 import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.ProbeBuilder;
+import org.ops4j.pax.exam.TestProbeBuilder;
 import org.ops4j.pax.exam.karaf.options.LogLevelOption;
 import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
 import org.ops4j.store.Handle;
 import org.ops4j.store.Store;
 import org.ops4j.store.intern.TemporaryStore;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceEvent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.karaf.itests.KarafTestSupport.*;
-import static org.ops4j.pax.exam.CoreOptions.composite;
-import static org.ops4j.pax.exam.CoreOptions.maven;
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.*;
-import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
-
 // don't extend, because we don't want @Rule Retry
 public abstract class KarafMinimalMonitoredTestSupport {
 
     public static Logger LOG = LoggerFactory.getLogger(KarafMinimalMonitoredTestSupport.class);
 
     @Inject
-    protected BundleContext bundleContext;
+    protected ServiceMonitor serviceMonitor;
+    
+    @ProbeBuilder
+    public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
+        probe.setHeader(Constants.IMPORT_PACKAGE, ServiceMonitor.class.getPackage().getName());
+        return probe;
+    }
 
     public Option[] baseConfig() throws Exception {
         MavenArtifactUrlReference karafUrl = maven()
@@ -70,38 +84,26 @@ public abstract class KarafMinimalMonitoredTestSupport {
                 karafDistributionConfiguration().frameworkUrl(karafUrl).name("Apache Karaf").unpackDirectory(new
File("target/exam")),
                 // enable JMX RBAC security, thanks to the KarafMBeanServerBuilder
                 configureSecurity().disableKarafMBeanServerBuilder(),
-                keepRuntimeFolder(),
                 logLevel(LogLevelOption.LogLevel.INFO),
                 editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort",
rmiRegistryPort),
                 editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort",
rmiServerPort),
                 editConfigurationFilePut("etc/startup.properties", "file:../../" + new File(url.toURI()).getName(),
"1"),
-//                new TimeoutOption(3600000),
-//                KarafDistributionOption.debugConfiguration("8889", true),
                 composite(editConfigurationFilePut("etc/org.apache.karaf.features.cfg", new
File("target/test-classes/etc/org.apache.karaf.features.cfg")))
         };
     }
 
     private InputStream createMonitorBundle() {
         return bundle()
-                .set(Constants.BUNDLE_SYMBOLICNAME, "monitor")
                 .set(Constants.BUNDLE_ACTIVATOR, Activator.class.getName())
-                .set(Constants.IMPORT_PACKAGE, "org.osgi.framework")
-                .set(Constants.EXPORT_PACKAGE, Activator.class.getPackage().getName())
-                .set(Constants.BUNDLE_VERSION, "1.0.0")
-                .set(Constants.BUNDLE_MANIFESTVERSION, "2")
+                .set(Constants.EXPORT_PACKAGE, ServiceMonitor.class.getPackage().getName())
                 .add(Activator.class)
-                .add(RegisteredService.class)
                 .add(ServiceMonitor.class)
-                .build();
+                .build(withBnd());
     }
 
-    @SuppressWarnings({
-     "unchecked", "rawtypes"
-    })
     protected long numberOfServiceEventsFor(String serviceName) {
-        ServiceReference<List> sr = bundleContext.getBundle(0L).getBundleContext().getServiceReference(List.class);
-        List<String> services = new ArrayList<>(bundleContext.getService(sr));
-        return services.stream().filter(v -> v.equals(serviceName)).count();
+        Function<ServiceEvent, String> getObjectClass = event -> ((String[])event.getServiceReference().getProperty(OBJECTCLASS))[0];
+        return serviceMonitor.getEvents().stream().map(getObjectClass).filter(v -> v.equals(serviceName)).count();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/646c91b7/itests/src/test/java/org/apache/karaf/itests/monitoring/Activator.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/monitoring/Activator.java b/itests/src/test/java/org/apache/karaf/itests/monitoring/Activator.java
index 8edfc8c..8ffe9ff 100644
--- a/itests/src/test/java/org/apache/karaf/itests/monitoring/Activator.java
+++ b/itests/src/test/java/org/apache/karaf/itests/monitoring/Activator.java
@@ -16,28 +16,23 @@
  */
 package org.apache.karaf.itests.monitoring;
 
-import java.util.List;
-
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
 
 public class Activator implements BundleActivator {
 
-    private ServiceRegistration<List> registration;
-    private ServiceMonitor service;
+    private ServiceMonitor serviceMonitor;
 
     @Override
     public void start(BundleContext context) throws Exception {
-        service = new ServiceMonitor();
-        registration = context.registerService(List.class, service.getServices(), null);
-        context.addServiceListener(service::addServiceEvent);
+        serviceMonitor = new ServiceMonitor();
+        context.registerService(ServiceMonitor.class, serviceMonitor, null);
+        context.addServiceListener(serviceMonitor);
     }
 
     @Override
     public void stop(BundleContext context) throws Exception {
-        context.removeServiceListener(service::addServiceEvent);
-        registration.unregister();
+        context.removeServiceListener(serviceMonitor);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/646c91b7/itests/src/test/java/org/apache/karaf/itests/monitoring/RegisteredService.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/monitoring/RegisteredService.java
b/itests/src/test/java/org/apache/karaf/itests/monitoring/RegisteredService.java
deleted file mode 100644
index 51f51b5..0000000
--- a/itests/src/test/java/org/apache/karaf/itests/monitoring/RegisteredService.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.karaf.itests.monitoring;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceEvent;
-
-public class RegisteredService {
-
-    private String[] objectClass;
-    private int type;
-    private Object service;
-
-    public RegisteredService(BundleContext context, ServiceEvent event) {
-        objectClass = (String[])event.getServiceReference().getProperty("objectClass");
-        type = event.getType();
-        service = context.getService(event.getServiceReference());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/646c91b7/itests/src/test/java/org/apache/karaf/itests/monitoring/ServiceMonitor.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/monitoring/ServiceMonitor.java b/itests/src/test/java/org/apache/karaf/itests/monitoring/ServiceMonitor.java
index 1999e83..c47414d 100644
--- a/itests/src/test/java/org/apache/karaf/itests/monitoring/ServiceMonitor.java
+++ b/itests/src/test/java/org/apache/karaf/itests/monitoring/ServiceMonitor.java
@@ -20,17 +20,18 @@ import java.util.LinkedList;
 import java.util.List;
 
 import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
 
-public class ServiceMonitor {
+public class ServiceMonitor implements ServiceListener {
 
-    private List<String> services = new LinkedList<>();
+    private List<ServiceEvent> events = new LinkedList<>();
 
-    public void addServiceEvent(ServiceEvent event) {
-        services.add(((String[])event.getServiceReference().getProperty("objectClass"))[0]);
+    @Override
+    public void serviceChanged(ServiceEvent event) {
+        events.add(event);
     }
 
-    public List<String> getServices() {
-        return services;
+    public List<ServiceEvent> getEvents() {
+        return events;
     }
-
 }


Mime
View raw message