felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1679808 - in /felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest: ./ .settings/ src/ src/org/ src/org/apache/ src/org/apache/felix/ src/org/apache/felix/framework/ src/org/apache/felix/framework/concurrency...
Date Sat, 16 May 2015 21:48:06 GMT
Author: pderop
Date: Sat May 16 21:48:06 2015
New Revision: 1679808

URL: http://svn.apache.org/r1679808
Log:
added a new simpler scenario test.

Added:
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.classpath
  (with props)
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.gitignore
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.project
  (with props)
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.settings/
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.settings/org.eclipse.jdt.core.prefs
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/bnd.bnd
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/.gitignore
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Activator.java
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Component.java
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Helper.java
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Loader.java
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/test/
    felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/test/.gitignore

Added: felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.classpath
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.classpath?rev=1679808&view=auto
==============================================================================
Binary file - no diff available.

Propchange: felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.classpath
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.gitignore
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.gitignore?rev=1679808&view=auto
==============================================================================
--- felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.gitignore
(added)
+++ felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.gitignore
Sat May 16 21:48:06 2015
@@ -0,0 +1,3 @@
+/bin/
+/bin_test/
+/generated/

Added: felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.project
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.project?rev=1679808&view=auto
==============================================================================
Binary file - no diff available.

Propchange: felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.project
------------------------------------------------------------------------------
    svn:mime-type = application/xml

Added: felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.settings/org.eclipse.jdt.core.prefs?rev=1679808&view=auto
==============================================================================
--- felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.settings/org.eclipse.jdt.core.prefs
(added)
+++ felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/.settings/org.eclipse.jdt.core.prefs
Sat May 16 21:48:06 2015
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8

Added: felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/bnd.bnd
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/bnd.bnd?rev=1679808&view=auto
==============================================================================
--- felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/bnd.bnd
(added)
+++ felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/bnd.bnd
Sat May 16 21:48:06 2015
@@ -0,0 +1,29 @@
+Bundle-Version: 0.0.0.${tstamp}
+-buildpath:  \
+	osgi.cmpn;version=4.2,\
+	osgi.core;version=4.2
+Private-Package:  \
+	org.apache.felix.framework.concurrencytest
+Bundle-Activator: org.apache.felix.framework.concurrencytest.Activator
+
+-runbundles:  \
+	org.apache.felix.log;version=1.0.1,\
+	org.apache.felix.gogo.command;version=0.12.0,\
+	org.apache.felix.gogo.shell;version=0.10.0,\
+	org.apache.felix.gogo.runtime;version=0.10.0,\
+	org.apache.felix.framework.concurrencytest;version=latest
+	
+-runproperties: org.osgi.framework.bootdelegation='sun.*,'
+-runee: JavaSE/compact1-1.8
+javac.source:          1.8
+javac.target:          1.8
+-runvm: -server -Xmx1024m -Xms1024m -Dthreads=10
+
+# Works with Equinox
+#-runfw: org.eclipse.osgi;version='[3.10.1.v20140909-1633,3.10.1.v20140909-1633]'
+
+# Works with last released framework
+#-runfw: org.apache.felix.main;version='[5.0.0, 5.0.0]'
+
+# Fails with latest Felix framework, in trunk (that includes the FELIX-4866 patch)
+-runfw: org.apache.felix.main;version=latest

Added: felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/.gitignore
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/.gitignore?rev=1679808&view=auto
==============================================================================
    (empty)

Added: felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Activator.java?rev=1679808&view=auto
==============================================================================
--- felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Activator.java
(added)
+++ felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Activator.java
Sat May 16 21:48:06 2015
@@ -0,0 +1,20 @@
+package org.apache.felix.framework.concurrencytest;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+	Loader m_loader;
+
+	@Override
+	public void start(BundleContext context) throws Exception {
+		System.out.println("Starting load test.");
+		m_loader = new Loader(context);
+		m_loader.start();		
+	}
+
+	@Override
+	public void stop(BundleContext context) throws Exception {
+		m_loader.stop();		
+	}
+}

Added: felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Component.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Component.java?rev=1679808&view=auto
==============================================================================
--- felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Component.java
(added)
+++ felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Component.java
Sat May 16 21:48:06 2015
@@ -0,0 +1,87 @@
+package org.apache.felix.framework.concurrencytest;
+
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+/**
+ * A simple component, that is optionally registered in the osgi registry.
+ */
+public class Component implements ServiceTrackerCustomizer {
+	private final BundleContext m_ctx;
+	private final int m_id;
+	private volatile int m_dependsOnId;
+	private volatile ServiceTracker m_tracker;
+	private volatile boolean m_satisfied;
+	private volatile ServiceRegistration m_registration;
+
+	public Component(BundleContext ctx, int id) {
+		m_ctx = ctx;
+		m_id = id;
+	}
+	
+	public void dependsOn(int componentId) {
+		m_dependsOnId = componentId;
+	}
+	
+	public void start() {
+		// if we depends on another component, wait for it before starting up.
+		if (m_dependsOnId != -1) {
+			Filter filter;
+			try {
+				filter = m_ctx.createFilter("(&(objectClass=" + Component.class.getName() + ")(id="
+ m_dependsOnId + "))");
+			} catch (InvalidSyntaxException e) {
+				e.printStackTrace();
+				return;
+			}
+			m_tracker = new ServiceTracker(m_ctx, filter, this);
+			m_tracker.open();
+		} else {
+			m_satisfied = true;
+		}
+		Hashtable<String, Object> properties = new Hashtable<String, Object>();
+		properties.put("id", String.valueOf(m_id));
+		m_registration = m_ctx.registerService(Component.class.getName(), this, properties);
+	}
+	
+	public boolean isSatisfied() {
+		return m_satisfied;
+	}
+	
+	public void stop() {
+		m_tracker.close();
+		m_registration.unregister();
+	}
+
+	@Override
+	public Object addingService(ServiceReference reference) {
+		Object service = m_ctx.getService(reference);	
+		String id = (String) reference.getProperty("id");
+		if (String.valueOf(m_dependsOnId).equals(id)) {
+			m_satisfied = true;	
+		} else {
+			System.err.println("Component#" + m_id + " received wrong dependency #" + id);
+		}
+		
+		return service;
+	}
+
+	@Override
+	public void modifiedService(ServiceReference reference, Object service) {
+	}
+
+	@Override
+	public void removedService(ServiceReference reference, Object service) {
+		try {
+			m_ctx.ungetService(reference);
+		} catch (IllegalStateException e) {
+			e.printStackTrace();
+		}
+	}
+}

Added: felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Helper.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Helper.java?rev=1679808&view=auto
==============================================================================
--- felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Helper.java
(added)
+++ felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Helper.java
Sat May 16 21:48:06 2015
@@ -0,0 +1,69 @@
+/*
+ * 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.felix.framework.concurrencytest;
+
+import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Supplier;
+
+/**
+ * Helper class containing misc functions, and constants.
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class Helper {
+    /**
+     * Activate this flag for debugging.
+     */
+    private final static boolean DEBUG = false;
+
+    /** 
+     * Generator used to create unique identifiers.
+     */
+    private final static AtomicLong m_idGenerator = new AtomicLong();
+
+    /**
+     * Threadpool which can be optionally used by parallel scenarios.
+     */
+    private final static int CORES = Runtime.getRuntime().availableProcessors();
+    private final static ForkJoinPool TPOOL = new ForkJoinPool(Integer.getInteger("threads",
CORES));
+    
+    /**
+     * Get the threadpool, possibly needed by some scenario supporting parallel mode
+     */
+    public static ForkJoinPool getThreadPool() {
+        return TPOOL;
+    }
+    
+    /**
+     * Display some debug messages.
+     */
+    public static void debug(Supplier<String> message) {
+        if (DEBUG) {
+            System.out.println(message.get());
+        }
+    }
+
+    /**
+     * Generates a unique id.
+     */
+    public static String generateId() {
+        return String.valueOf(m_idGenerator.incrementAndGet());
+    }
+}

Added: felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Loader.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Loader.java?rev=1679808&view=auto
==============================================================================
--- felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Loader.java
(added)
+++ felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/src/org/apache/felix/framework/concurrencytest/Loader.java
Sat May 16 21:48:06 2015
@@ -0,0 +1,85 @@
+package org.apache.felix.framework.concurrencytest;
+
+import static java.util.stream.Collectors.toList;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+
+import org.osgi.framework.BundleContext;
+import static java.lang.System.err;
+import static java.lang.System.out;
+
+public class Loader implements Runnable {
+	final BundleContext m_ctx;
+	private Thread m_thread;
+	final static int COMPONENTS = 10;
+	final static int ITERATIONS = 10000;
+
+	Loader(BundleContext ctx) {
+		m_ctx = ctx;
+	}
+
+	public void start() {
+		m_thread = new Thread(this);
+		m_thread.start();		
+	}
+	
+	public void stop() {
+		m_thread.interrupt();		
+	}
+
+	public void run() {
+		try { Thread.sleep(200); } catch (InterruptedException e) {}
+		
+		// Creates all components. Each nth components will depends on the
+		// nth+1 component. The last component has not any dependencies.
+		String anim= "|/-\\";
+	        	        
+		for (int i = 0; i < ITERATIONS; i ++) {
+			out.print("\rLoading ...  " + anim.charAt((int) i % anim.length()));
+			try {
+				createComponentsConcurrently();
+			} catch (Throwable error) {
+				err.println("Test failed");
+				error.printStackTrace(err);
+				break;
+			}
+		}       
+		
+		out.println("\nTest successful.");
+	}
+
+	private void createComponentsConcurrently() throws Exception {
+		// Create components.
+		List<Component> components = IntStream.range(0, COMPONENTS).mapToObj(i -> createComponents(i)).collect(toList());
+        			
+		// Start all components asynchronously.
+        components.stream().forEach(component -> Helper.getThreadPool().execute(() ->
component.start()));
+
+		// Make sure all worker threads have finished to register components.
+		if (! Helper.getThreadPool().awaitQuiescence(3, TimeUnit.SECONDS)) {
+			System.err.println("ThreadPool did not complete timely.");
+			return;
+		}
+		
+		// Count the number of satisfied components.
+		long satisfied = components.stream().filter(Component::isSatisfied).count();			
+		
+		// Stop all components
+        components.stream().forEach(Component::stop);
+        
+        // Report an error if we don't have expected satisfied components.
+		if (satisfied != COMPONENTS) {
+			throw new Exception("found unsatisfied component: " + (COMPONENTS - satisfied));			
+		}
+	}
+
+	private Component createComponents(int i) {
+		Component component = new Component(m_ctx, i);
+		if (i < (COMPONENTS - 1)) {
+			component.dependsOn(i + 1);
+		}
+		return component;
+	}
+}

Added: felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/test/.gitignore
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/bndtools-FELIX-4866/org.apache.felix.framework.concurrencytest/test/.gitignore?rev=1679808&view=auto
==============================================================================
    (empty)



Mime
View raw message