@Test public void testIsolatedClusters() throws Exception { HornetQServer server1 = createServer1(); HornetQServer server2 = createServer2(); server1.start(); server2.start(); waitForTopology(server1, "cc1", 2, 5000); waitForTopology(server1, "cc2", 2, 5000); waitForTopology(server2, "cc1", 2, 5000); waitForTopology(server2, "cc2", 2, 5000); String node1 = server1.getNodeID().toString(); String node2 = server2.getNodeID().toString(); checkTopology( server1, "cc1", node1, node2, createInVMTransportConnectorConfig(1, "srv1"), createInVMTransportConnectorConfig(3, "srv1")); checkTopology( server2, "cc1", node1, node2, createInVMTransportConnectorConfig(1, "srv1"), createInVMTransportConnectorConfig(3, "srv1")); checkTopology( server1, "cc2", node1, node2, createInVMTransportConnectorConfig(2, "srv1"), createInVMTransportConnectorConfig(4, "srv1")); checkTopology( server2, "cc2", node1, node2, createInVMTransportConnectorConfig(2, "srv1"), createInVMTransportConnectorConfig(4, "srv1")); Thread.sleep(500); }
@Override @Before public void setUp() throws Exception { super.setUp(); configuration = createDefaultConfig(); configuration.setSecurityEnabled(false); server = createServer(true, configuration); // start the server server.start(); qs = new AddressSettings(); qs.setLastValueQueue(true); server.getAddressSettingsRepository().addMatch(address.toString(), qs); // then we create a client as normal locator = HornetQClient.createServerLocatorWithoutHA( new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY)); locator.setBlockOnAcknowledge(true); locator.setAckBatchSize(0); ClientSessionFactory sessionFactory = createSessionFactory(locator); clientSession = sessionFactory.createSession(false, true, true); clientSessionXa = sessionFactory.createSession(true, false, false); clientSession.createQueue(address, qName1, null, true); }
@Test public void testGetNumberOfBytesPerPage() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); session.createQueue(address, address, true); AddressControl addressControl = createManagementControl(address); Assert.assertEquals( HornetQDefaultConfiguration.getDefaultJournalFileSize(), addressControl.getNumberOfBytesPerPage()); session.close(); server.stop(); AddressSettings addressSettings = new AddressSettings(); addressSettings.setPageSizeBytes(1024); server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings); server.start(); ServerLocator locator2 = HornetQClient.createServerLocatorWithoutHA( new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY)); addServerLocator(locator2); ClientSessionFactory sf2 = createSessionFactory(locator2); session = sf2.createSession(false, true, false); session.createQueue(address, address, true); Assert.assertEquals(1024, addressControl.getNumberOfBytesPerPage()); }
/** * This would force a journal duplication on bindings even with the scenario that generated fixed, * the server shouldn't hold of from starting * * @throws Exception */ @Test public void testForceDuplicationOnBindings() throws Exception { queue = server.createQueue(QUEUE, QUEUE, null, true, false); ClientSessionFactory factory = locator.createSessionFactory(); ClientSession session = factory.createSession(false, false, false); ClientProducer producer = session.createProducer(QUEUE); producer.send(session.createMessage(true)); session.commit(); long queueID = server.getStorageManager().generateUniqueID(); long txID = server.getStorageManager().generateUniqueID(); // Forcing a situation where the server would unexpectedly create a duplicated queue. The server // should still start normally LocalQueueBinding newBinding = new LocalQueueBinding( QUEUE, new QueueImpl(queueID, QUEUE, QUEUE, null, true, false, null, null, null, null, null), server.getNodeID()); server.getStorageManager().addQueueBinding(txID, newBinding); server.getStorageManager().commitBindings(txID); server.stop(); // a duplicate binding would impede the server from starting server.start(); waitForServer(server); server.stop(); }
@Override protected void setUp() throws Exception { super.setUp(); server = createServer(false); server.start(); locator = createInVMNonHALocator(); }
@Override protected void setUp() throws Exception { super.setUp(); server = createServer(false); server.start(); }
@Override public void setUp() throws Exception { super.setUp(); server = createServer(true); server.start(); locator = createInVMNonHALocator(); sf = createSessionFactory(locator); }
public void test2HornetQServersManagedFrom1MBeanServer() throws Exception { Configuration config_0 = createDefaultConfig(); config_0.setJMXManagementEnabled(true); String jmxDomain_1 = HornetQDefaultConfiguration.DEFAULT_JMX_DOMAIN + ".1"; Configuration config_1 = createBasicConfig(); Map<String, Object> params = new HashMap<String, Object>(); params.put(TransportConstants.SERVER_ID_PROP_NAME, 1); config_1 .getAcceptorConfigurations() .add(new TransportConfiguration(InVMAcceptorFactory.class.getName(), params)); config_1.setJMXDomain(jmxDomain_1); config_1.setJMXManagementEnabled(true); HornetQServer server_0 = HornetQServers.newHornetQServer(config_0, mbeanServer, false); HornetQServer server_1 = HornetQServers.newHornetQServer(config_1, mbeanServer, false); ObjectNameBuilder builder_0 = ObjectNameBuilder.DEFAULT; ObjectNameBuilder builder_1 = ObjectNameBuilder.create(jmxDomain_1); checkNoResource(builder_0.getHornetQServerObjectName()); checkNoResource(builder_1.getHornetQServerObjectName()); server_0.start(); checkResource(builder_0.getHornetQServerObjectName()); checkNoResource(builder_1.getHornetQServerObjectName()); server_1.start(); checkResource(builder_0.getHornetQServerObjectName()); checkResource(builder_1.getHornetQServerObjectName()); server_0.stop(); checkNoResource(builder_0.getHornetQServerObjectName()); checkResource(builder_1.getHornetQServerObjectName()); server_1.stop(); checkNoResource(builder_0.getHornetQServerObjectName()); checkNoResource(builder_1.getHornetQServerObjectName()); }
@Test public void testLargeMessageCompression2() throws Exception { final int messageSize = (int) (3.5 * HornetQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE); HornetQServer server = createServer(true, isNetty()); server.start(); ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = addClientSession(sf.createSession(false, false, false)); session.createTemporaryQueue(ADDRESS, ADDRESS); ClientProducer producer = session.createProducer(ADDRESS); Message clientFile = createLargeClientMessageStreaming(session, messageSize, true); producer.send(clientFile); session.commit(); session.start(); ClientConsumer consumer = session.createConsumer(ADDRESS); ClientMessage msg1 = consumer.receive(1000); Assert.assertNotNull(msg1); String testDir = getTestDir(); File testFile = new File(testDir, "async_large_message"); FileOutputStream output = new FileOutputStream(testFile); msg1.setOutputStream(output); msg1.waitOutputStreamCompletion(0); msg1.acknowledge(); output.close(); session.commit(); consumer.close(); session.close(); // verify FileInputStream input = new FileInputStream(testFile); for (int i = 0; i < messageSize; i++) { byte b = (byte) input.read(); assertEquals("position = " + i, getSamplebyte(i), b); } input.close(); testFile.delete(); validateNoFilesOnLargeDir(); }
private void setupServer(boolean backup, String... interceptors) throws Exception { final TransportConfiguration liveConnector = TransportConfigurationUtils.getInVMConnector(true); final TransportConfiguration backupConnector = TransportConfigurationUtils.getInVMConnector(false); final TransportConfiguration backupAcceptor = TransportConfigurationUtils.getInVMAcceptor(false); Configuration backupConfig = createDefaultConfig(); Configuration liveConfig = createDefaultConfig(); backupConfig.setBackup(backup); final String suffix = "_backup"; backupConfig.setBindingsDirectory(backupConfig.getBindingsDirectory() + suffix); backupConfig.setJournalDirectory(backupConfig.getJournalDirectory() + suffix); backupConfig.setPagingDirectory(backupConfig.getPagingDirectory() + suffix); backupConfig.setLargeMessagesDirectory(backupConfig.getLargeMessagesDirectory() + suffix); if (interceptors.length > 0) { List<String> interceptorsList = Arrays.asList(interceptors); backupConfig.setIncomingInterceptorClassNames(interceptorsList); } ReplicatedBackupUtils.configureReplicationPair( backupConfig, backupConnector, backupAcceptor, liveConfig, liveConnector); if (backup) { liveServer = createServer(liveConfig); liveServer.start(); waitForComponent(liveServer); } backupServer = createServer(backupConfig); locator = createInVMNonHALocator(); backupServer.start(); if (backup) { ServiceTestBase.waitForRemoteBackup(null, 5, true, backupServer); } int count = 0; waitForReplication(count); }
@BeforeClass public static void setup() throws Exception { Configuration configuration = new ConfigurationImpl(); configuration.setPersistenceEnabled(false); configuration.setSecurityEnabled(false); configuration .getAcceptorConfigurations() .add(new TransportConfiguration(InVMAcceptorFactory.class.getName())); server = HornetQServers.newHornetQServer(configuration); server.start(); }
@Override protected void setUp() throws Exception { locator = createInVMNonHALocator(); super.setUp(); service = createServer(false); service.start(); locator.setProducerMaxRate(99); locator.setBlockOnNonDurableSend(true); locator.setBlockOnNonDurableSend(true); cf = createSessionFactory(locator); clientSession = (ClientSessionInternal) addClientSession(cf.createSession(false, true, true)); }
@Override public void setUp() throws Exception { super.setUp(); Configuration config = createDefaultConfig(); HashMap<String, AddressSettings> settings = new HashMap<String, AddressSettings>(); messagingService = createServer(true, config, 10024, 200024, settings); messagingService.start(); pagedServerQueue = (QueueImpl) messagingService.createQueue(ADDRESS, ADDRESS, null, true, false); }
/** @throws Exception */ protected void initServer() throws Exception { configuration = createDefaultConfig(); configuration.setSecurityEnabled(false); configuration.setJournalMinFiles(2); server = createServer(true, configuration); server.start(); AddressSettings qs = server.getAddressSettingsRepository().getMatch("*"); AddressSettings newSets = new AddressSettings(); newSets.setRedeliveryDelay(DelayedMessageTest.DELAY); newSets.merge(qs); server.getAddressSettingsRepository().addMatch(qName, newSets); locator = createInVMNonHALocator(); }
protected void startServer() throws Exception { Configuration config = createDefaultConfig(); config.setJournalFileSize(HornetQDefaultConfiguration.DEFAULT_JOURNAL_FILE_SIZE); config.setJournalCompactMinFiles(HornetQDefaultConfiguration.DEFAULT_JOURNAL_COMPACT_MIN_FILES); config.setJournalCompactPercentage( HornetQDefaultConfiguration.DEFAULT_JOURNAL_COMPACT_PERCENTAGE); config.setJournalMinFiles(2); server = super.createServer(true, config); server.start(); locator = createInVMNonHALocator(); factory = createSessionFactory(locator); }
public void testConnection( final String acceptorHost, final String connectorHost, final boolean mustConnect) throws Exception { System.out.println( "acceptor=" + acceptorHost + ", connector=" + connectorHost + ", mustConnect=" + mustConnect); Map<String, Object> params = new HashMap<String, Object>(); params.put(getHostPropertyKey(), acceptorHost); TransportConfiguration acceptorConfig = new TransportConfiguration(getAcceptorFactoryClassName(), params); Set<TransportConfiguration> transportConfigs = new HashSet<TransportConfiguration>(); transportConfigs.add(acceptorConfig); Configuration config = createDefaultConfig(true); config.setAcceptorConfigurations(transportConfigs); HornetQServer messagingService = createServer(false, config); messagingService.start(); params = new HashMap<String, Object>(); params.put(getHostPropertyKey(), connectorHost); TransportConfiguration connectorConfig = new TransportConfiguration(getConnectorFactoryClassName(), params); try { ClientSessionFactory sf = HornetQClient.createClientSessionFactory(connectorConfig); if (mustConnect) { ClientSession session = sf.createSession(false, true, true); session.close(); System.out.println("connection OK"); } else { try { sf.createSession(false, true, true); Assert.fail( "session creation must fail because connector must not be able to connect to the server bound to another network interface"); } catch (Exception e) { } } } finally { if (messagingService != null) { messagingService.stop(); } } }
@Override protected void setUp() throws Exception { super.setUp(); ConfigurationImpl config = createBasicConfig(); config.setSecurityEnabled(false); Map<String, Object> params = new HashMap<String, Object>(); params.put(TransportConstants.SSL_ENABLED_PROP_NAME, true); config .getAcceptorConfigurations() .add(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY, params)); server = createServer(false, config); server.start(); waitForServer(server); tc = new TransportConfiguration(NETTY_CONNECTOR_FACTORY); }
@Override @Before public void setUp() throws Exception { super.setUp(); Configuration config = createDefaultConfig() .addAcceptorConfiguration(new TransportConfiguration(INVM_ACCEPTOR_FACTORY)) .setSecurityEnabled(false); server = createServer(false, config); server.start(); ServerLocator locator = createInVMNonHALocator(); sf = createSessionFactory(locator); }
protected void startServer() throws Exception { Configuration config = createDefaultConfig(); config.setJournalFileSize(HornetQDefaultConfiguration.getDefaultJournalFileSize()); config.setJournalCompactMinFiles( HornetQDefaultConfiguration.getDefaultJournalCompactMinFiles()); config.setJournalCompactPercentage( HornetQDefaultConfiguration.getDefaultJournalCompactPercentage()); config.setJournalMinFiles(2); server = super.createServer(true, config); server.start(); locator = createInVMNonHALocator(); factory = createSessionFactory(locator); }
public static ServerManager initializeServer() throws Exception { FileConfiguration configuration = null; SecurityManager security = null; // configuration start configuration = new FileConfiguration(); configuration.setSecurityEnabled(true); configuration.setPersistenceEnabled(true); configuration.setJournalType(JournalType.NIO); configuration.setClusterUser("clusterAdmin"); configuration.setClusterPassword("H0rnN4tGoo"); configuration.setConfigurationUrl("hornetq-configuration.xml"); // load user set properties from file Properties properties = loadProperties(); // set acceptor based on config file Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("protocol", "stomp"); parameters.put("host", properties.getProperty("server.address")); parameters.put("port", properties.getProperty("server.port")); parameters.put("use-nio", "true"); TransportConfiguration tpConf = new TransportConfiguration( NettyAcceptorFactory.class.getName(), parameters, "stomp-acceptor"); configuration.getAcceptorConfigurations().add(tpConf); configuration.start(); // Initialize dbconnection dbConnect = new DbConnect( properties.getProperty("database.address"), properties.getProperty("database.name"), properties.getProperty("database.username"), properties.getProperty("database.password")); // Create securitymanager security = new SecurityManager(dbConnect); // we create the HornetQ server using this config HornetQServer hornetqServer = HornetQServers.newHornetQServer(configuration, null, security); hornetqServer.start(); ServerManager serverManager = new ServerManagerImpl(hornetqServer, dbConnect, properties); return serverManager; }
/** @throws Exception */ protected void startServer() throws Exception { Configuration conf = createDefaultConfig(false); conf.getConnectorConfigurations() .put("invm", new TransportConfiguration(INVM_CONNECTOR_FACTORY)); conf.setSecurityEnabled(false); conf.setJMXManagementEnabled(true); conf.getAcceptorConfigurations().add(new TransportConfiguration(INVM_ACCEPTOR_FACTORY)); server = HornetQServers.newHornetQServer(conf, mbeanServer, true); server.start(); serverManager = new JMSServerManagerImpl(server); serverManager.start(); ctx = new InVMNamingContext(); serverManager.setContext(ctx); serverManager.activated(); }
public void testCreateConsumerWithFilter() throws Exception { HornetQServer service = createServer(false); try { service.start(); ClientSessionFactory cf = createInVMFactory(); cf.setProducerMaxRate(99); cf.setBlockOnNonDurableSend(true); cf.setBlockOnNonDurableSend(true); ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true); clientSession.createQueue(queueName, queueName, false); ClientConsumer consumer = clientSession.createConsumer(queueName, "foo=bar"); Assert.assertNotNull(consumer); clientSession.close(); } finally { service.stop(); } }
@Test public void testLargeMessageCompression() throws Exception { final int messageSize = (int) (3.5 * HornetQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE); HornetQServer server = createServer(true, isNetty()); server.start(); ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = addClientSession(sf.createSession(false, false, false)); session.createTemporaryQueue(ADDRESS, ADDRESS); ClientProducer producer = session.createProducer(ADDRESS); Message clientFile = createLargeClientMessageStreaming(session, messageSize, true); producer.send(clientFile); session.commit(); session.start(); ClientConsumer consumer = session.createConsumer(ADDRESS); ClientMessage msg1 = consumer.receive(1000); Assert.assertNotNull(msg1); for (int i = 0; i < messageSize; i++) { byte b = msg1.getBodyBuffer().readByte(); assertEquals("position = " + i, getSamplebyte(i), b); } msg1.acknowledge(); session.commit(); consumer.close(); session.close(); validateNoFilesOnLargeDir(); }
@Override @Before public void setUp() throws Exception { super.setUp(); Configuration config = createDefaultConfig(false); config.setMessageExpiryScanPeriod(10); HornetQSecurityManager securityManager = new HornetQSecurityManagerImpl(); config.setPersistenceEnabled(true); server = new MyHornetQServer(config, ManagementFactory.getPlatformMBeanServer(), securityManager); server.start(); locator = createInVMNonHALocator(); }
@Override protected void setUp() throws Exception { super.setUp(); Map<String, Object> params = new HashMap<String, Object>(); // params.put(RandomUtil.randomString(), RandomUtil.randomBoolean()); connectorConfig = new TransportConfiguration( InVMConnectorFactory.class.getName(), params, RandomUtil.randomString()); conf = createDefaultConfig(false); conf.setSecurityEnabled(false); conf.setJMXManagementEnabled(true); conf.getAcceptorConfigurations().clear(); conf.getAcceptorConfigurations() .add(new TransportConfiguration(InVMAcceptorFactory.class.getName())); server = HornetQServers.newHornetQServer(conf, mbeanServer, true); conf.getConnectorConfigurations().put(connectorConfig.getName(), connectorConfig); server.start(); }
public void testCreateConsumerNoQ() throws Exception { HornetQServer service = createServer(false); try { service.start(); ClientSessionFactory cf = createInVMFactory(); cf.setProducerMaxRate(99); cf.setBlockOnNonDurableSend(true); cf.setBlockOnNonDurableSend(true); ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true); try { clientSession.createConsumer(queueName); Assert.fail("should throw exception"); } catch (HornetQException e) { Assert.assertEquals(e.getCode(), HornetQException.QUEUE_DOES_NOT_EXIST); } clientSession.close(); } finally { service.stop(); } }
@Override @Before public void setUp() throws Exception { super.setUp(); Configuration conf = createBasicConfig(); conf.setSecurityEnabled(false); conf.setJMXManagementEnabled(true); conf.getAcceptorConfigurations() .add(new TransportConfiguration(InVMAcceptorFactory.class.getName())); server = createServer(false, conf, mbeanServer); server.start(); locator = createInVMNonHALocator(); locator.setBlockOnNonDurableSend(true); locator.setBlockOnNonDurableSend(true); sf = createSessionFactory(locator); session = sf.createSession(false, true, false); session.start(); addClientSession(session); }
@Override protected void setUp() throws Exception { super.setUp(); Configuration conf = new ConfigurationImpl(); conf.setSecurityEnabled(false); conf.setJMXManagementEnabled(true); conf.getAcceptorConfigurations() .add(new TransportConfiguration(NettyAcceptorFactory.class.getName())); server = HornetQServers.newHornetQServer(conf, false); server.start(); serverManager = new JMSServerManagerImpl(server); initialContext = new InVMContext(); serverManager.setContext(initialContext); serverManager.start(); serverManager.activated(); serverManager.createTopic(topicName, topicName); registerConnectionFactory(); }
public void testCreateConsumerWithInvalidFilter() throws Exception { HornetQServer service = createServer(false); try { service.start(); ClientSessionFactory cf = createInVMFactory(); cf.setProducerMaxRate(99); cf.setBlockOnNonDurableSend(true); cf.setBlockOnNonDurableSend(true); ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true); clientSession.createQueue(queueName, queueName, false); try { clientSession.createConsumer(queueName, "foobar"); Assert.fail("should throw exception"); } catch (HornetQException e) { Assert.assertEquals(e.getCode(), HornetQException.INVALID_FILTER_EXPRESSION); } clientSession.close(); } finally { service.stop(); } }
/** * This will simulate what would happen with topic creationg where a single record is supposed to * be created on the journal * * @throws Exception */ @Test public void testDuplicateDestinationsOnTopic() throws Exception { for (int i = 0; i < 5; i++) { if (server.locateQueue(SimpleString.toSimpleString("jms.topic.tt")) == null) { server.createQueue( SimpleString.toSimpleString("jms.topic.tt"), SimpleString.toSimpleString("jms.topic.tt"), SimpleString.toSimpleString(HornetQServerImpl.GENERIC_IGNORED_FILTER), true, false); } server.stop(); SequentialFileFactory messagesFF = new NIOSequentialFileFactory(getBindingsDir(), null); JournalImpl messagesJournal = new JournalImpl(1024 * 1024, 2, 0, 0, messagesFF, "hornetq-bindings", "bindings", 1); messagesJournal.start(); LinkedList<RecordInfo> infos = new LinkedList<RecordInfo>(); messagesJournal.load(infos, null, null); int bindings = 0; for (RecordInfo info : infos) { if (info.getUserRecordType() == JournalRecordIds.QUEUE_BINDING_RECORD) { bindings++; } } assertEquals(1, bindings); System.out.println("Bindings: " + bindings); messagesJournal.stop(); if (i < 4) server.start(); } }