Search in sources :

Example 1 with Logger

use of org.apache.felix.dm.Logger in project felix by apache.

the class ConfigurationDependencyImplTest method createConfigurationDependency.

private ConfigurationDependencyImpl createConfigurationDependency(Object service) {
    BundleContext bc = mock(BundleContext.class);
    Logger mockLogger = mock(Logger.class);
    ComponentContext component = mock(ComponentContext.class);
    when(component.getExecutor()).thenReturn(Executors.newSingleThreadExecutor());
    when(component.getLogger()).thenReturn(mockLogger);
    ConfigurationDependencyImpl result = new ConfigurationDependencyImpl(bc, mockLogger);
    result.setCallback(service, "updated").setPid("does.not.matter");
    result.setComponentContext(component);
    result.start();
    return result;
}
Also used : ComponentContext(org.apache.felix.dm.context.ComponentContext) Logger(org.apache.felix.dm.Logger) BundleContext(org.osgi.framework.BundleContext)

Example 2 with Logger

use of org.apache.felix.dm.Logger in project felix by apache.

the class SerialExecutorTest method testSerialExecutor.

@Test
public void testSerialExecutor() {
    info("Testing serial executor");
    int cores = Math.max(10, Runtime.getRuntime().availableProcessors());
    ExecutorService threadPool = null;
    try {
        threadPool = Executors.newFixedThreadPool(cores);
        final SerialExecutor serial = new SerialExecutor(new Logger(null));
        long timeStamp = System.currentTimeMillis();
        for (int i = 0; i < TESTS; i++) {
            final CountDownLatch latch = new CountDownLatch(cores * 2);
            final SerialTask task = new SerialTask(serial, latch);
            for (int j = 0; j < cores; j++) {
                threadPool.execute(new Runnable() {

                    public void run() {
                        serial.execute(task);
                    }
                });
            }
            Assert.assertTrue("Test " + i + " did not terminate timely", latch.await(20000, TimeUnit.MILLISECONDS));
        }
        long now = System.currentTimeMillis();
        System.out.println("Performed " + TESTS + " tests in " + (now - timeStamp) + " ms.");
        timeStamp = now;
    } catch (Throwable t) {
        t.printStackTrace();
        Assert.fail("Test failed: " + t.getMessage());
    } finally {
        if (threadPool != null) {
            shutdown(threadPool);
        }
    }
}
Also used : SerialExecutor(org.apache.felix.dm.impl.SerialExecutor) ExecutorService(java.util.concurrent.ExecutorService) Logger(org.apache.felix.dm.Logger) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

Logger (org.apache.felix.dm.Logger)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 ComponentContext (org.apache.felix.dm.context.ComponentContext)1 SerialExecutor (org.apache.felix.dm.impl.SerialExecutor)1 Test (org.junit.Test)1 BundleContext (org.osgi.framework.BundleContext)1