use of org.apache.qpid.server.SystemLauncher in project qpid-broker-j by apache.
the class InternalBrokerHolder method start.
public void start(final Map<String, Object> systemConfig) throws Exception {
if (Thread.getDefaultUncaughtExceptionHandler() == null) {
Thread.setDefaultUncaughtExceptionHandler(UNCAUGHT_EXCEPTION_HANDLER);
}
LOGGER.info("Starting internal broker (same JVM)");
_systemLauncher = new SystemLauncher(new LogbackLoggingSystemLauncherListener(), new SystemLauncherListener.DefaultSystemLauncherListener() {
@Override
public void onShutdown(final int exitCode) {
_systemLauncher = null;
}
@Override
public void exceptionOnShutdown(final Exception e) {
if (e instanceof IllegalStateException || e instanceof IllegalStateTransitionException) {
System.out.println("IllegalStateException occurred on broker shutdown in test " + getClassQualifiedTestName());
}
}
});
_systemLauncher.startup(systemConfig);
}
use of org.apache.qpid.server.SystemLauncher in project beam by apache.
the class RabbitMqIOTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
port = NetworkTestHelper.getAvailableLocalPort();
defaultPort = System.getProperty("qpid.amqp_port");
System.setProperty("qpid.amqp_port", "" + port);
System.setProperty("derby.stream.error.field", "MyApp.DEV_NULL");
// see https://stackoverflow.com/a/49234754/796064 for qpid setup
launcher = new SystemLauncher();
Map<String, Object> attributes = new HashMap<>();
URL initialConfig = RabbitMqIOTest.class.getResource("rabbitmq-io-test-config.json");
attributes.put("type", "Memory");
attributes.put("initialConfigurationLocation", initialConfig.toExternalForm());
attributes.put(SystemConfig.DEFAULT_QPID_WORK_DIR, temporaryFolder.newFolder().toString());
launcher.startup(attributes);
}
use of org.apache.qpid.server.SystemLauncher in project qpid-broker-j by apache.
the class SNITest method doBrokerStartup.
private void doBrokerStartup(boolean useMatching, String defaultAlias, final boolean ignoreInvalidSni) throws Exception {
final File initialConfiguration = createInitialContext();
_brokerWork = TestFileUtils.createTestDirectory("qpid-work", true);
Map<String, String> context = new HashMap<>();
context.put("qpid.work_dir", _brokerWork.toString());
Map<String, Object> attributes = new HashMap<>();
attributes.put(SystemConfig.INITIAL_CONFIGURATION_LOCATION, initialConfiguration.getAbsolutePath());
attributes.put(SystemConfig.TYPE, JsonSystemConfigImpl.SYSTEM_CONFIG_TYPE);
attributes.put(SystemConfig.CONTEXT, context);
_systemLauncher = new SystemLauncher(new DefaultSystemLauncherListener() {
@Override
public void onContainerResolve(final SystemConfig<?> systemConfig) {
_broker = systemConfig.getContainer(Broker.class);
}
});
_systemLauncher.startup(attributes);
final Map<String, Object> authProviderAttr = new HashMap<>();
authProviderAttr.put(AuthenticationProvider.NAME, "myAuthProvider");
authProviderAttr.put(AuthenticationProvider.TYPE, AnonymousAuthenticationManager.PROVIDER_TYPE);
final AuthenticationProvider authProvider = _broker.createChild(AuthenticationProvider.class, authProviderAttr);
Map<String, Object> keyStoreAttr = new HashMap<>();
keyStoreAttr.put(FileKeyStore.NAME, "myKeyStore");
keyStoreAttr.put(FileKeyStore.STORE_URL, _keyStoreFile.toURI().toURL().toString());
keyStoreAttr.put(FileKeyStore.PASSWORD, TLS_RESOURCE.getSecret());
keyStoreAttr.put(FileKeyStore.USE_HOST_NAME_MATCHING, useMatching);
keyStoreAttr.put(FileKeyStore.CERTIFICATE_ALIAS, defaultAlias);
final KeyStore keyStore = _broker.createChild(KeyStore.class, keyStoreAttr);
Map<String, Object> portAttr = new HashMap<>();
portAttr.put(Port.NAME, "myPort");
portAttr.put(Port.TYPE, "AMQP");
portAttr.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL));
portAttr.put(Port.PORT, 0);
portAttr.put(Port.AUTHENTICATION_PROVIDER, authProvider);
portAttr.put(Port.KEY_STORE, keyStore);
portAttr.put(Port.CONTEXT, Collections.singletonMap(AmqpPort.PORT_IGNORE_INVALID_SNI, String.valueOf(ignoreInvalidSni)));
final Port<?> port = _broker.createChild(Port.class, portAttr);
_boundPort = port.getBoundPort();
}
use of org.apache.qpid.server.SystemLauncher in project qpid-broker-j by apache.
the class EmbeddedBrokerPerClassAdminImpl method beforeTestClass.
@Override
public void beforeTestClass(final Class testClass) {
_preservedProperties = new HashMap<>();
try {
String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date(System.currentTimeMillis()));
_currentWorkDirectory = Files.createTempDirectory(String.format("qpid-work-%s-%s-", timestamp, testClass.getSimpleName())).toString();
ConfigItem[] configItems = (ConfigItem[]) testClass.getAnnotationsByType(ConfigItem.class);
Arrays.stream(configItems).filter(ConfigItem::jvm).forEach(i -> {
_preservedProperties.put(i.name(), System.getProperty(i.name()));
System.setProperty(i.name(), i.value());
});
Map<String, String> context = new HashMap<>();
context.put("qpid.work_dir", _currentWorkDirectory);
context.put("qpid.port.protocol_handshake_timeout", "1000000");
context.putAll(Arrays.stream(configItems).filter(i -> !i.jvm()).collect(Collectors.toMap(ConfigItem::name, ConfigItem::value, (name, value) -> value)));
Map<String, Object> systemConfigAttributes = new HashMap<>();
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 BrokerAdminException("Failed to start broker for test class", e);
}
}
use of org.apache.qpid.server.SystemLauncher in project qpid-broker-j by apache.
the class AESGCMKeyFileEncrypterTest method createBrokerAndAuthenticationProviderWithEncrypterPassword.
private void createBrokerAndAuthenticationProviderWithEncrypterPassword(final Object encryptionType, final Path workDir, final Map<String, String> brokerContext) throws Exception {
_workDir = workDir;
final Map<String, String> context = new HashMap<>();
context.put("qpid.work_dir", workDir.toFile().getAbsolutePath());
_configurationLocation = Files.createTempFile(_workDir, "config", ".json");
final Map<String, Object> config = new HashMap<>();
config.put(ConfiguredObject.NAME, getTestName());
config.put(Broker.MODEL_VERSION, BrokerModel.MODEL_VERSION);
config.put(Broker.CONFIDENTIAL_CONFIGURATION_ENCRYPTION_PROVIDER, encryptionType);
config.put(Broker.CONTEXT, brokerContext);
new ObjectMapper().writeValue(_configurationLocation.toFile(), config);
final Map<String, Object> attributes = new HashMap<>();
attributes.put("storePath", _configurationLocation.toFile().getAbsolutePath());
attributes.put("preferenceStoreAttributes", "{\"type\": \"Noop\"}");
attributes.put(SystemConfig.TYPE, JsonSystemConfigImpl.SYSTEM_CONFIG_TYPE);
attributes.put(SystemConfig.STARTUP_LOGGED_TO_SYSTEM_OUT, Boolean.FALSE);
attributes.put(SystemConfig.CONTEXT, context);
final SettableFuture<SystemConfig<?>> configFuture = SettableFuture.create();
_systemLauncher = new SystemLauncher(new SystemLauncherListener.DefaultSystemLauncherListener() {
@Override
public void onContainerResolve(final SystemConfig<?> systemConfig) {
configFuture.set(systemConfig);
}
});
_systemLauncher.startup(attributes);
final SystemConfig<?> systemConfig = configFuture.get(BROKER_START_TIMEOUT, TimeUnit.SECONDS);
_broker = (Broker<?>) systemConfig.getContainer();
final Map<String, Object> authProviderAttributes = new HashMap<>();
authProviderAttributes.put(ConfiguredObject.NAME, "testAuthProvider");
authProviderAttributes.put(ConfiguredObject.TYPE, "Plain");
final AuthenticationProvider<?> authProvider = _broker.createChild(AuthenticationProvider.class, authProviderAttributes);
final Map<String, Object> userAttrs = new HashMap<>();
userAttrs.put(User.TYPE, "managed");
userAttrs.put(User.NAME, "guest");
userAttrs.put(User.PASSWORD, SECRET);
authProvider.createChild(User.class, userAttrs);
}
Aggregations