Search in sources :

Example 1 with SystemLauncherListener

use of org.apache.qpid.server.SystemLauncherListener in project qpid-broker-j by apache.

the class EmbeddedBrokerPerClassAdminImpl method beforeTestClass.

@Override
public void beforeTestClass(final Class testClass) {
    setClassQualifiedTestName(testClass.getName());
    LOGGER.info("========================= starting broker for test class : " + testClass.getSimpleName());
    try {
        String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date(System.currentTimeMillis()));
        _currentWorkDirectory = Files.createTempDirectory(String.format("qpid-work-%s-%s-", timestamp, testClass.getSimpleName())).toString();
        Map<String, String> context = new HashMap<>();
        context.put("qpid.work_dir", _currentWorkDirectory);
        context.put("qpid.port.protocol_handshake_timeout", "1000000");
        context.putAll(Arrays.stream((ConfigItem[]) testClass.getAnnotationsByType(ConfigItem.class)).collect(Collectors.toMap(ConfigItem::name, ConfigItem::value, (name, value) -> value)));
        Map<String, Object> systemConfigAttributes = new HashMap<>();
        // systemConfigAttributes.put(SystemConfig.INITIAL_CONFIGURATION_LOCATION, "classpath:config-protocol-tests.json");
        systemConfigAttributes.put(ConfiguredObject.CONTEXT, context);
        systemConfigAttributes.put(ConfiguredObject.TYPE, System.getProperty("broker.config-store-type", "JSON"));
        systemConfigAttributes.put(SystemConfig.STARTUP_LOGGED_TO_SYSTEM_OUT, Boolean.FALSE);
        if (Thread.getDefaultUncaughtExceptionHandler() == null) {
            Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
        }
        LOGGER.info("Starting internal broker (same JVM)");
        List<SystemLauncherListener> systemLauncherListeners = new ArrayList<>();
        systemLauncherListeners.add(new LogbackLoggingSystemLauncherListener());
        systemLauncherListeners.add(new ShutdownLoggingSystemLauncherListener());
        systemLauncherListeners.add(new PortExtractingLauncherListener());
        _systemLauncher = new SystemLauncher(systemLauncherListeners.toArray(new SystemLauncherListener[systemLauncherListeners.size()]));
        _systemLauncher.startup(systemConfigAttributes);
    } catch (Exception e) {
        throw new RuntimeException("Failed to start broker for test class", e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException) IllegalStateTransitionException(org.apache.qpid.server.model.IllegalStateTransitionException) NotFoundException(org.apache.qpid.server.model.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) SystemLauncherListener(org.apache.qpid.server.SystemLauncherListener) LogbackLoggingSystemLauncherListener(org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener) SystemLauncher(org.apache.qpid.server.SystemLauncher) LogbackLoggingSystemLauncherListener(org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 SystemLauncher (org.apache.qpid.server.SystemLauncher)1 SystemLauncherListener (org.apache.qpid.server.SystemLauncherListener)1 LogbackLoggingSystemLauncherListener (org.apache.qpid.server.logging.logback.LogbackLoggingSystemLauncherListener)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 IllegalStateTransitionException (org.apache.qpid.server.model.IllegalStateTransitionException)1 NotFoundException (org.apache.qpid.server.model.NotFoundException)1