/** * Makes sure that a "hollow" TestServer (either local or remote, depending on the nature of the * test), exists and it's ready to be started. */ public static synchronized Server create() throws Exception { return new LocalTestServer(); }
@Override public void deployConnectionFactory(final String objectName, final int consumerWindowSize, final String... jndiBindings) throws Exception { deployConnectionFactory(null, JMSFactoryType.CF, objectName, consumerWindowSize, -1, -1, -1, false, false, -1, false, jndiBindings); }
@Override public synchronized void stopServerPeer() throws Exception { System.setProperty(Constants.SERVER_INDEX_PROPERTY_NAME, "" + getServerID()); getActiveMQServer().stop(); // also unbind everything unbindAll(); }
@Override public synchronized void startServerPeer() throws Exception { System.setProperty(Constants.SERVER_INDEX_PROPERTY_NAME, "" + getServerID()); getActiveMQServer().start(); }
@Override public synchronized void start(final HashMap<String, Object> configuration, final boolean clearJournal) throws Exception { if (isStarted()) { return; } if (clearJournal) { // Delete the Journal environment File dir = new File("target/data"); boolean deleted = LocalTestServer.deleteDirectory(dir); JmsTestLogger.LOGGER.info("Deleted dir: " + dir.getAbsolutePath() + " deleted: " + deleted); } javax.management.MBeanServer beanServer = java.lang.management.ManagementFactory.getPlatformMBeanServer(); FileConfiguration fileConfiguration = new FileConfiguration(); ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration()); securityManager.getConfiguration().addUser("guest", "guest"); securityManager.getConfiguration().setDefaultUser("guest"); securityManager.getConfiguration().addRole("guest", "guest"); ActiveMQServerImpl activeMQServer = new ActiveMQServerImpl(fileConfiguration, beanServer, securityManager); jmsServerManager = new JMSServerManagerImpl(activeMQServer); System.setProperty(Constants.SERVER_INDEX_PROPERTY_NAME, "" + getServerID()); jmsServerManager.setRegistry(new JndiBindingRegistry(getInitialContext())); FileDeploymentManager deploymentManager = new FileDeploymentManager(); deploymentManager.addDeployable(fileConfiguration).readConfiguration(); jmsServerManager.start(); started = true; }
/** * Only for in-VM use! */ @Override public ActiveMQServer getServerPeer() { return getActiveMQServer(); }
@Override public void deployConnectionFactory(final String clientId, final JMSFactoryType type, final String objectName, final int prefetchSize, final int defaultTempQueueFullSize, final int defaultTempQueuePageSize, final int defaultTempQueueDownCacheSize, final boolean supportsFailover, final boolean supportsLoadBalancing, final int dupsOkBatchSize, final boolean blockOnAcknowledge, final String... jndiBindings) throws Exception { List<TransportConfiguration> connectorConfigs = new ArrayList<>(); connectorConfigs.add(new TransportConfiguration(NettyConnectorFactory.class.getName())); ArrayList<String> connectors = new ArrayList<>(); connectors.add("netty"); getJMSServerManager().createConnectionFactory(objectName, false, type, connectors, clientId, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_COMPRESS_LARGE_MESSAGES, prefetchSize, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, blockOnAcknowledge, true, true, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, dupsOkBatchSize, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_MAX_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS, ActiveMQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION, null, jndiBindings); }
@Override public void createQueue(final String name, final String jndiName) throws Exception { getJMSServerManager().createQueue(true, name, null, true, "/queue/" + (jndiName != null ? jndiName : name)); }
@Override public synchronized void kill() throws Exception { stop(); }
@Override public void ping() throws Exception { if (!isStarted()) { throw new RuntimeException("ok"); } }
private static boolean deleteDirectory(final File directory) { if (directory.isDirectory()) { String[] files = directory.list(); for (int j = 0; j < files.length; j++) { if (!LocalTestServer.deleteDirectory(new File(directory, files[j]))) { return false; } } } return directory.delete(); }
@Override public InitialContext getInitialContext() throws Exception { Properties props = new Properties(); props.setProperty("java.naming.factory.initial", "org.apache.activemq.artemis.jms.tests.tools.container.InVMInitialContextFactory"); props.setProperty(Constants.SERVER_INDEX_PROPERTY_NAME, "" + getServerID()); return new InitialContext(props); }
private void unbindAll() throws Exception { Collection<List<String>> bindings = allBindings.values(); for (List<String> binding : bindings) { for (String s : binding) { getInitialContext().unbind(s); } } }
@Override public synchronized boolean stop() throws Exception { jmsServerManager.stop(); started = false; unbindAll(); jmsServerManager = null; return true; }
@Override public void configureSecurityForDestination(final String destName, final boolean isQueue, final Set<Role> roles) throws Exception { if (roles != null) { getActiveMQServer().getSecurityRepository().addMatch(destName, roles); } else { getActiveMQServer().getSecurityRepository().removeMatch(destName); } }
@Override public void destroyQueue(final String name, final String jndiName) throws Exception { getJMSServerManager().destroyQueue(name); }
@Override public void setSecurityConfig(final Set<Role> defConfig) throws Exception { getActiveMQServer().getSecurityRepository().removeMatch("#"); getActiveMQServer().getSecurityRepository().addMatch("#", defConfig); }
@Override public void createTopic(final String name, final String jndiName) throws Exception { getJMSServerManager().createTopic(true, name, "/topic/" + (jndiName != null ? jndiName : name)); }
@Override public void deployConnectionFactory(final String clientId, final String objectName, final String... jndiBindings) throws Exception { deployConnectionFactory(clientId, JMSFactoryType.CF, objectName, -1, -1, -1, -1, false, false, -1, false, jndiBindings); }
@Override public Set<Role> getSecurityConfig() throws Exception { return getActiveMQServer().getSecurityRepository().getMatch("*"); }