protected void waitForServerStart(ActiveMQServer server) throws Exception { if (!server.waitForActivation(5000L, TimeUnit.MILLISECONDS)) throw new IllegalStateException("Timed out waiting for server starting = " + server); } }
protected void waitForServerRestart(final int node) throws Exception { long waitTimeout = ActiveMQTestBase.WAIT_TIMEOUT; if (!isSharedStore()) { //it should be greater than //QuorumManager.WAIT_TIME_AFTER_FIRST_LIVE_STOPPING_MSG (60 sec) waitTimeout = 1000 * (SharedNothingBackupQuorum.WAIT_TIME_AFTER_FIRST_LIVE_STOPPING_MSG + 5); } if (!servers[node].waitForActivation(waitTimeout, TimeUnit.MILLISECONDS)) { String msg = "Timed out waiting for server starting = " + node; log.error(msg); throw new IllegalStateException(msg); } }
public void startBroker() throws Exception { configureBroker(); server.start(); server.waitForActivation(10, TimeUnit.SECONDS); }
@Test public void testFailoverTransportReconnect() throws Exception { Connection exConn = null; try { String urlString = "failover:(tcp://" + OWHOST + ":" + OWPORT + ")"; ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory(urlString); Queue queue = new ActiveMQQueue(durableQueueName); exConn = exFact.createConnection(); exConn.start(); Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer messageProducer = session.createProducer(queue); messageProducer.send(session.createTextMessage("Test")); MessageConsumer consumer = session.createConsumer(queue); assertNotNull(consumer.receive(5000)); server.stop(); Thread.sleep(3000); server.start(); server.waitForActivation(10, TimeUnit.SECONDS); messageProducer.send(session.createTextMessage("Test2")); assertNotNull(consumer.receive(5000)); } finally { if (exConn != null) { exConn.close(); } } }
@Test public void testCanRestartWithSuppliedThreadPool() throws Exception { server.stop(); server.start(); server.waitForActivation(100, TimeUnit.MILLISECONDS); testSuppliedThreadPoolsAreCorrectlySet(); }
@Before public void setup() throws Exception { serviceRegistry = new ServiceRegistryImpl(); serviceRegistry.setExecutorService(Executors.newFixedThreadPool(1, ActiveMQThreadFactory.defaultThreadFactory())); serviceRegistry.setIOExecutorService(Executors.newFixedThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory())); serviceRegistry.setScheduledExecutorService(Executors.newScheduledThreadPool(1, ActiveMQThreadFactory.defaultThreadFactory())); server = new ActiveMQServerImpl(null, null, null, null, serviceRegistry); server.start(); server.waitForActivation(100, TimeUnit.MILLISECONDS); }
assertTrue(server0.waitForActivation(5, TimeUnit.SECONDS)); server1.start(); assertFalse(server1.waitForActivation(1, TimeUnit.SECONDS)); assertTrue(server1.waitForActivation(5, TimeUnit.SECONDS)); assertFalse(server0.waitForActivation(1, TimeUnit.SECONDS)); assertTrue(server0.waitForActivation(5, TimeUnit.SECONDS)); assertFalse(server1.waitForActivation(1, TimeUnit.SECONDS));
protected void waitForServerToStart(ActiveMQServer server, boolean activation) throws InterruptedException { if (server == null) return; final long wait = 5000; long timetowait = System.currentTimeMillis() + wait; while (!server.isStarted() && System.currentTimeMillis() < timetowait) { Thread.sleep(50); } if (!server.isStarted()) { log.info(threadDump("Server didn't start")); fail("server didn't start: " + server); } if (activation) { if (!server.getHAPolicy().isBackup()) { if (!server.waitForActivation(wait, TimeUnit.MILLISECONDS)) fail("Server didn't initialize: " + server); } } }
@Before public void setup() throws Exception { server = createServer(true); server.start(); server.waitForActivation(10, TimeUnit.SECONDS); ServerLocator sl = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(INVM_CONNECTOR_FACTORY)); sessionFactory = sl.createSessionFactory(); addSessionFactory(sessionFactory); }
protected void finishSyncAndFailover() throws Exception { syncDelay.deliverUpToDateMsg(); waitForRemoteBackup(sessionFactory, BACKUP_WAIT_TIME, true, backupServer.getServer()); assertFalse("should not be initialized", backupServer.getServer().isActive()); crash(session); assertTrue("backup initialized", backupServer.getServer().waitForActivation(5, TimeUnit.SECONDS)); assertNodeIdWasSaved(); }
@Before public void setup() throws Exception { server = createServer(true); server.start(); server.waitForActivation(10, TimeUnit.SECONDS); ServerLocator sl = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(INVM_CONNECTOR_FACTORY)); sessionFactory = sl.createSessionFactory(); addSessionFactory(sessionFactory); addressInfo = new AddressInfo(baseAddress); addressInfo.addRoutingType(RoutingType.MULTICAST); server.addOrUpdateAddressInfo(addressInfo); }
@Before public void setup() throws Exception { server = createServer(true); server.start(); server.waitForActivation(10, TimeUnit.SECONDS); ServerLocator sl = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(INVM_CONNECTOR_FACTORY)); sessionFactory = sl.createSessionFactory(); addSessionFactory(sessionFactory); addressInfo = new AddressInfo(baseAddress); addressInfo.addRoutingType(RoutingType.ANYCAST); server.addOrUpdateAddressInfo(addressInfo); }
private void startBackupCrashLive() throws Exception { assertFalse("backup is started?", backupServer.isStarted()); liveServer.removeInterceptor(syncDelay); backupServer.start(); waitForBackup(sessionFactory, BACKUP_WAIT_TIME); failoverWaiter.reset(); crash(session); backupServer.getServer().waitForActivation(5, TimeUnit.SECONDS); //for some system the retryAttempts and retryInterval may be too small //so that during failover all attempts have failed before the backup //server is fully activated. assertTrue("Session didn't failover, the maxRetryAttempts and retryInterval may be too small", failoverWaiter.waitFailoverComplete()); }
@Override @Before public void setUp() throws Exception { super.setUp(); server = createServer(true, true); server.start(); server.waitForActivation(10, TimeUnit.SECONDS); Configuration serverConfig = server.getConfiguration(); serverConfig.getAddressesSettings().put("#", new AddressSettings().setAutoCreateQueues(false) .setAutoCreateAddresses(false) .setDeadLetterAddress(new SimpleString("ActiveMQ.DLQ"))); serverConfig.setSecurityEnabled(false); coreQueue = new SimpleString(queueName); server.createQueue(coreQueue, RoutingType.ANYCAST, coreQueue, null, false, false); }
@Override @Before public void setUp() throws Exception { super.setUp(); server = createServer(true, true); server.start(); server.waitForActivation(10, TimeUnit.SECONDS); Configuration serverConfig = server.getConfiguration(); serverConfig.getAddressesSettings().put("#", new AddressSettings().setAutoCreateQueues(false) .setAutoCreateAddresses(false) .setDeadLetterAddress(new SimpleString("ActiveMQ.DLQ"))); serverConfig.setSecurityEnabled(false); coreQueue = new SimpleString(queueName); server.createQueue(coreQueue, RoutingType.ANYCAST, coreQueue, null, false, false); }
/** * @throws Exception */ @Test public void testDeleteLargeMessagesDuringSync() throws Exception { setNumberOfMessages(200); File backupLMdir = new File(backupServer.getServer().getConfiguration().getLargeMessagesDirectory()); File liveLMDir = new File(liveServer.getServer().getConfiguration().getLargeMessagesDirectory()); assertEquals("Should not have any large messages... previous test failed to clean up?", 0, getAllMessageFileIds(backupLMdir).size()); createProducerSendSomeMessages(); backupServer.start(); waitForComponent(backupServer.getServer(), 5); receiveMsgsInRange(0, getNumberOfMessages() / 2); startBackupFinishSyncing(); Thread.sleep(500); liveServer.getServer().stop(); backupServer.getServer().waitForActivation(10, TimeUnit.SECONDS); backupServer.stop(); Set<Long> backupLM = getAllMessageFileIds(backupLMdir); Set<Long> liveLM = getAllMessageFileIds(liveLMDir); assertEquals("live and backup should have the same files ", liveLM, backupLM); assertEquals("we really ought to delete these after delivery: " + backupLM, getNumberOfMessages() / 2, backupLM.size()); assertEquals("we really ought to delete these after delivery", getNumberOfMessages() / 2, getAllMessageFileIds(backupLMdir).size()); }
@Override @Before public void setUp() throws Exception { super.setUp(); server = createServer(true, true); server.start(); server.waitForActivation(10, TimeUnit.SECONDS); Configuration serverConfig = server.getConfiguration(); serverConfig.getAddressesSettings().put("#", new AddressSettings().setAutoCreateQueues(false).setAutoCreateAddresses(false).setDeadLetterAddress(new SimpleString("ActiveMQ.DLQ"))); serverConfig.setSecurityEnabled(false); coreQueue = new SimpleString(queueName); server.createQueue(coreQueue, RoutingType.ANYCAST, coreQueue, null, false, false); qpidfactory = new JmsConnectionFactory("amqp://localhost:61616"); }
@Test(timeout = 60 * 1000) public void testBrokerRestartAfterSubHashWithConfigurationQueues() throws Exception { // Add some pre configured queues CoreQueueConfiguration coreQueueConfiguration = new CoreQueueConfiguration(); coreQueueConfiguration.setName("DLQ"); coreQueueConfiguration.setRoutingType(RoutingType.ANYCAST); coreQueueConfiguration.setAddress("DLA"); CoreAddressConfiguration coreAddressConfiguration = new CoreAddressConfiguration(); coreAddressConfiguration.setName("DLA"); coreAddressConfiguration.addRoutingType(RoutingType.ANYCAST); coreAddressConfiguration.addQueueConfiguration(coreQueueConfiguration); getServer().getConfiguration().getAddressConfigurations().add(coreAddressConfiguration); getServer().stop(); getServer().start(); getServer().waitForActivation(10, TimeUnit.SECONDS); for (int i = 0; i < 2; i++) { MQTT mqtt = createMQTTConnection("myClient", false); BlockingConnection connection = mqtt.blockingConnection(); connection.connect(); connection.subscribe(new Topic[]{new Topic("#", QoS.AT_MOST_ONCE)}); connection.disconnect(); getServer().stop(); getServer().start(); getServer().waitForActivation(10, TimeUnit.SECONDS); } }
@Test public void testRestartWithTXPrepareDeletedQueue() throws Exception { ClientSession clientSession2 = sessionFactory.createSession(false, true, true); ClientProducer clientProducer = clientSession2.createProducer(atestq); ClientMessage m1 = createTextMessage(clientSession2, "m1"); clientProducer.send(m1); Xid xid = newXID(); clientSession.start(xid, XAResource.TMNOFLAGS); clientSession.start(); ClientConsumer clientConsumer = clientSession.createConsumer(atestq); ClientMessage message = clientConsumer.receive(5000); message.acknowledge(); clientSession.end(xid, XAResource.TMSUCCESS); clientSession.prepare(xid); clientSession.getSessionFactory().getConnection().destroy(); messagingService.destroyQueue(atestq); messagingService.stop(); messagingService.start(); messagingService.waitForActivation(10, TimeUnit.SECONDS); assertTrue(messagingService.isStarted()); }
@Test public void testInjectedTransformer() throws Exception { final SimpleString ADDRESS = new SimpleString("myAddress"); final String DIVERT = "myDivert"; ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl(); Transformer transformer = new Transformer() { @Override public Message transform(Message message) { return null; } }; serviceRegistry.addDivertTransformer(DIVERT, transformer); ActiveMQServer server = addServer(new ActiveMQServerImpl(null, null, null, null, serviceRegistry)); server.start(); server.waitForActivation(100, TimeUnit.MILLISECONDS); server.createQueue(ADDRESS, RoutingType.MULTICAST, SimpleString.toSimpleString("myQueue"), null, false, false); server.deployDivert(new DivertConfiguration().setName(DIVERT).setAddress(ADDRESS.toString()).setForwardingAddress(ADDRESS.toString())); Collection<Binding> bindings = server.getPostOffice().getBindingsForAddress(ADDRESS).getBindings(); Divert divert = null; for (Binding binding : bindings) { if (binding instanceof DivertBinding) { divert = ((DivertBinding) binding).getDivert(); } } assertNotNull(divert); assertEquals(transformer, divert.getTransformer()); } }