public void testSendTransactedRollback() throws Exception { final int countDownInitialCount = 2; final CountDownLatch countDown = new CountDownLatch(countDownInitialCount); // This exception strategy will be invoked when a message is redelivered // after a rollback // setup the component and start Mule UMODescriptor descriptor = getDescriptor("testComponent", FunctionalTestComponent.class.getName()); EventCallback callback = new EventCallback() { public void eventReceived(UMOEventContext context, Object Component) throws Exception { callbackCalled = true; currentTx = context.getCurrentTransaction(); assertNotNull(currentTx); assertTrue(currentTx.isBegun()); System.out.println("@@@@ Rolling back transaction @@@@"); currentTx.setRollbackOnly(); countDown.countDown(); } }; initialiseComponent(descriptor, UMOTransactionConfig.ACTION_ALWAYS_BEGIN, callback); UMOManager manager = MuleManager.getInstance(); addResultListener(getOutDest().getAddress(), countDown); UMOConnector umoCnn = manager.lookupConnector(CONNECTOR_NAME); // Set the test Exception strategy umoCnn.setExceptionListener(new RollbackExceptionListener(countDown)); // Start the server manager.start(); // Send a test message firstso that it is there when the component is // started send(DEFAULT_MESSAGE, false, Session.AUTO_ACKNOWLEDGE); afterInitialise(); countDown.tryLock(LOCK_WAIT, TimeUnit.MILLISECONDS); assertTrue( "Only " + (countDownInitialCount - countDown.getCount()) + " of " + countDownInitialCount + " checkpoints hit", countDown.tryLock()); // Sleep a while to allow transaction to be rolled back afterInitialise(); assertNull(currentMsg); assertTrue(callbackCalled); assertTrue(currentTx.isRolledBack()); // Make sure the message isn't on the queue assertNull(receive(getInDest().getAddress(), 2000)); }
public UMOManager configure(ReaderResource[] configResources, Properties startupProperties) throws ConfigurationException { try { manager.start(); } catch (UMOException e) { throw new ConfigurationException(e); } return manager; }
protected void initMule() { try { // endpointsCache.clear(); // See if there has been a discriptor explicitly configured if (applicationContext.containsBean(EVENT_MULTICASTER_DESCRIPTOR_NAME)) { descriptor = (UMODescriptor) applicationContext.getBean(EVENT_MULTICASTER_DESCRIPTOR_NAME); } // If the mule manager has been initialised in the contain // there is not need to do anything here if (applicationContext.containsBean("muleManager")) { // Register the multicaster descriptor registerMulticasterDescriptor(); return; } UMOManager manager = MuleManager.getInstance(); Map map = applicationContext.getBeansOfType(MuleConfiguration.class); if (map != null && map.size() > 0) { MuleManager.setConfiguration((MuleConfiguration) map.values().iterator().next()); } if (!manager.isStarted()) { MuleManager.getConfiguration().setSynchronous(!asynchronous); // register any endpointUri mappings registerEndpointMappings(); } // tell mule to load component definitions from spring SpringContainerContext containerContext = new SpringContainerContext(); containerContext.setBeanFactory(applicationContext); manager.setContainerContext(null); manager.setContainerContext(containerContext); // see if there are any UMOConnectors to register registerConnectors(); // Next see if there are any UMOTransformers to register registerTransformers(); registerGlobalEndpoints(); // Register the multicaster descriptor registerMulticasterDescriptor(); if (!manager.isStarted()) { manager.start(); } } catch (UMOException e) { throw new MuleRuntimeException(SpringMessages.failedToReinitMule(), e); } }
protected void setUp() throws Exception { super.setUp(); if (MuleManager.isInstanciated()) { MuleManager.getInstance().dispose(); } UMOManager manager = MuleManager.getInstance(); MuleManager.getConfiguration().setSynchronous(true); MuleManager.getConfiguration() .getPoolingProfile() .setInitialisationPolicy(PoolingProfile.POOL_INITIALISE_ONE_COMPONENT); manager.setModel(new SedaModel()); MuleDescriptor descriptor = createInDescriptor("httpIn", EchoComponent.class.getName()); manager.getModel().registerComponent(descriptor); manager.start(); }
/** * Configures a started manager. This method will throw InitialisationException if the current * manager is already started * * @param synchronous whether to start the manager in synchronous mode * @param serverUrl the url used to receive client requests, or null if the server listening * components should not be set up * @return the configured manager * @throws UMOException if the manager is already started or it fails to start */ public UMOManager createStartedManager(boolean synchronous, String serverUrl, String modeltype) throws UMOException { if (manager.isStarted()) { throw new InitialisationException(new Message(Messages.MANAGER_ALREADY_STARTED), this); } if (serverUrl == null) { serverUrl = ""; } MuleManager.getConfiguration().setServerUrl(serverUrl); MuleManager.getConfiguration().setSynchronous(synchronous); if (!MODEL_NOT_SET.equals(modeltype)) { model = ModelFactory.createModel(modeltype); } else { model = ModelFactory.createModel("seda"); } manager.registerModel(model); manager.start(); return manager; }
public void testTransactedRedeliveryToDLDestination() throws Exception { // there are 2 check points for each message delivered, so // the message will be delivered twice before this countdown will release final int countDownInitialCount = 4; final CountDownLatch countDown = new CountDownLatch(countDownInitialCount); // setup the component and start Mule UMODescriptor descriptor = getDescriptor("testComponent", FunctionalTestComponent.class.getName()); EventCallback callback = new EventCallback() { public void eventReceived(UMOEventContext context, Object Component) throws Exception { callbackCalled = true; currentTx = context.getCurrentTransaction(); assertNotNull(currentTx); assertTrue(currentTx.isBegun()); System.out.println("@@@@ Rolling back transaction @@@@"); currentTx.setRollbackOnly(); countDown.countDown(); } }; initialiseComponent(descriptor, UMOTransactionConfig.ACTION_ALWAYS_BEGIN, callback); UMOManager manager = MuleManager.getInstance(); addResultListener(getDLDest().getAddress(), countDown); JmsConnector umoCnn = (JmsConnector) manager.lookupConnector(CONNECTOR_NAME); // After redelivery retry the message and then fail umoCnn.setMaxRedelivery(1); // Set the test Exception strategy umoCnn.setExceptionListener(new RollbackExceptionListener(countDown, getDLDest())); // Start the server manager.start(); // Send a test message firstso that it is there when the component is // started send(DEFAULT_MESSAGE, false, Session.AUTO_ACKNOWLEDGE); afterInitialise(); countDown.tryLock(LOCK_WAIT, TimeUnit.MILLISECONDS); assertTrue( "Only " + (countDownInitialCount - countDown.getCount()) + " of " + countDownInitialCount + " checkpoints hit", countDown.tryLock()); assertNotNull(currentMsg); System.out.println(currentMsg); String dest = currentMsg.getStringProperty(MuleProperties.MULE_ENDPOINT_PROPERTY); assertNotNull(dest); assertEquals(getDLDest().getUri().toString(), dest); assertTrue(callbackCalled); // Make sure the message isn't on the queue assertNull(receive(getInDest().getAddress(), 2000)); }