List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext destroy
@Deprecated public void destroy()
From source file:com.bt.aloha.batchtest.PerformanceBatchTest.java
private static int[] getInitParams() { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "batchTestApplicationContext.xml"); PerformanceBatchTest t = (PerformanceBatchTest) applicationContext.getBean("performanceBatchTestBean"); PerformanceMeasurmentDao dao = (PerformanceMeasurmentDao) applicationContext .getBean("performanceMeasurementDaoBean"); long runId = dao.generateId(); int jainPoolStart = t.getInitialJainPoolSize(); int jainPoolMax = t.getMaxJainPoolSize(); int jainPoolInc = t.getJainPoolSizeIncrement(); int sssPoolStart = t.getInitialSssPoolSize(); int sssPoolMax = t.getMaxSssPoolSize(); int sssPoolInc = t.getSssPoolSizeIncrement(); int start = t.getNumberOfInitialConcurrentStarts(); int max = t.getNumberOfMaxConcurrentStarts(); int inc = t.getNumberOfConcurrentStartsIncrements(); applicationContext.destroy(); return new int[] { (int) runId, jainPoolStart, jainPoolMax, jainPoolInc, sssPoolStart, sssPoolMax, sssPoolInc, start, max, inc }; }
From source file:com.nokia.dempsy.mpcluster.TestAllMpClusterImpls.java
private <T, N> void runAllCombinations(Checker<T, N> checker) throws Throwable { for (String clusterManager : clusterManagers) { ClassPathXmlApplicationContext actx = new ClassPathXmlApplicationContext(clusterManager); actx.registerShutdownHook();//from w ww .ja v a2 s . c om @SuppressWarnings("unchecked") MpClusterSessionFactory<T, N> factory = (MpClusterSessionFactory<T, N>) actx .getBean("clusterSessionFactory"); if (checker != null) checker.check("pass for:" + clusterManager, factory); actx.stop(); actx.destroy(); } }
From source file:com.bt.aloha.fitnesse.FixtureApplicationContexts.java
public ClassPathXmlApplicationContext startCustomApplicationContext( ClassPathXmlApplicationContext applicationContext, String resourceName, boolean destroyFirst, int restartAfter) { if (applicationContext == null) { String distroyMessage = (destroyFirst ? "(ignoring 'distroyFirst' flag)" : ""); log.debug(String.format("creating new application context from '%s' %s", resourceName, distroyMessage)); return new ClassPathXmlApplicationContext(resourceName); }//from w w w . j av a 2 s . c o m if (destroyFirst) { log.debug(String.format("distroying and re-creating new application context from '%s'", resourceName)); cancelTerminationTimers(applicationContext); applicationContext.destroy(); try { Thread.sleep(restartAfter); } catch (InterruptedException e) { log.warn("Unable to sleep while jvm is down, interrupted"); } ClassPathXmlApplicationContext result = new ClassPathXmlApplicationContext(resourceName); log.debug("returning"); return result; } log.debug(String.format("using an already created application context from '%s'", resourceName)); return applicationContext; }
From source file:com.nokia.dempsy.TestDempsy.java
@Test public void testAdaptorThrowsRuntimeOnSetDispatcher() throws Throwable { TestAdaptor.throwExceptionOnSetDispatcher = true; ClassPathXmlApplicationContext actx = null; boolean gotException = false; try {/*from w ww . j a va 2 s. c o m*/ actx = new ClassPathXmlApplicationContext("testDempsy/Dempsy.xml", "testDempsy/Transport-PassthroughActx.xml", "testDempsy/ClusterManager-LocalVmActx.xml", "testDempsy/SimpleMultistageApplicationActx.xml"); actx.registerShutdownHook(); } catch (Throwable th) { assertEquals("Forced RuntimeException", th.getCause().getLocalizedMessage()); gotException = true; } finally { TestAdaptor.throwExceptionOnSetDispatcher = false; if (actx != null) { actx.stop(); actx.destroy(); } } assertTrue(gotException); }
From source file:org.bpmscript.integration.internal.memory.BpmScriptTestSupport.java
/** * @see org.bpmscript.test.ITestSupport#execute(org.bpmscript.test.ITestCallback) *//*from w w w.j a va 2s . c o m*/ public void execute(final ITestCallback<ApplicationContext> callback) throws Exception { final CountDownLatch latch = new CountDownLatch(total); final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(spring); try { final BpmScriptEngine engine = (BpmScriptEngine) context.getBean("engine"); final IVersionedDefinitionManager processManager = (IVersionedDefinitionManager) context .getBean("versionedDefinitionManager"); processManager.createDefinition("id", new JavascriptProcessDefinition("test", StreamService.DEFAULT_INSTANCE.getResourceAsString(script))); engine.setInstanceListener(new LoggingInstanceListener() { @Override public void instanceCompleted(String pid, ICompletedResult result) { super.instanceCompleted(pid, result); latch.countDown(); } }); IBenchmarkPrinter.STDOUT.print(new Benchmark().execute(total, new IBenchmarkCallback() { public void execute(int count) throws Exception { callback.execute(context); } }, new IWaitForCallback() { public void call() throws Exception { latch.await(); } }, false)); } finally { context.destroy(); } }
From source file:com.nokia.dempsy.TestDempsy.java
public void runAllCombinations(String applicationContext, Checker checker) throws Throwable { int runCount = 0; for (String clusterManager : clusterManagers) { for (String[] alternatingTransports : transports) { // select one of the alternatingTransports String transport = alternatingTransports[runCount % alternatingTransports.length]; // alternate the dempsy configs String dempsyConfig = dempsyConfigs[runCount % dempsyConfigs.length]; if (!badCombos.contains(new ClusterId(clusterManager, transport))) { try { logger.debug("*****************************************************************"); logger.debug(" test: " + (checker == null ? "none" : checker) + " using " + dempsyConfig + "," + clusterManager + "," + transport); logger.debug("*****************************************************************"); DefaultRoutingStrategy.resetOutboundsChecking(); String[] ctx = new String[4]; ctx[0] = dempsyConfig; ctx[1] = clusterManager; ctx[2] = transport;/*from w w w.j a va 2 s.c o m*/ ctx[3] = "testDempsy/" + applicationContext; logger.debug("Starting up the appliction context ..."); ClassPathXmlApplicationContext actx = new ClassPathXmlApplicationContext(ctx); actx.registerShutdownHook(); Dempsy dempsy = (Dempsy) actx.getBean("dempsy"); assertTrue(TestUtils.waitForClustersToBeInitialized(baseTimeoutMillis, 20, dempsy)); WaitForShutdown waitingForShutdown = new WaitForShutdown(dempsy); Thread waitingForShutdownThread = new Thread(waitingForShutdown, "Waiting For Shutdown"); waitingForShutdownThread.start(); Thread.yield(); logger.debug("Running test ..."); if (checker != null) checker.check(actx); logger.debug("Done with test, stopping the application context ..."); actx.stop(); actx.destroy(); assertTrue(waitingForShutdown.waitForShutdownDoneLatch.await(baseTimeoutMillis, TimeUnit.MILLISECONDS)); assertTrue(waitingForShutdown.shutdown); logger.debug("Finished this pass."); } catch (AssertionError re) { logger.error("***************** FAILED ON: " + clusterManager + ", " + transport); throw re; } runCount++; } } } }
From source file:com.nokia.dempsy.TestDempsy.java
@Test public void testIndividualClusterStart() throws Throwable { ClassPathXmlApplicationContext actx = new ClassPathXmlApplicationContext( "testDempsy/Dempsy-IndividualClusterStart.xml", "testDempsy/Transport-PassthroughActx.xml", "testDempsy/ClusterManager-LocalVmActx.xml", "testDempsy/SimpleMultistageApplicationActx.xml"); actx.registerShutdownHook();/*from w w w . j a v a2s. co m*/ Dempsy dempsy = (Dempsy) actx.getBean("dempsy"); assertNotNull(dempsy); Dempsy.Application.Cluster cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster0")); assertNull(cluster); cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster1")); assertNull(cluster); cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster2")); assertNotNull(cluster); assertEquals(1, cluster.getNodes().size()); cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster3")); assertNull(cluster); cluster = dempsy.getCluster(new ClusterId("test-app", "test-cluster4")); assertNull(cluster); actx.stop(); actx.destroy(); }
From source file:org.bpmscript.process.hibernate.SpringHibernateInstanceManagerTest.java
public void testInstanceManagerSeparateThread() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "/org/bpmscript/endtoend/spring.xml"); try {//ww w . j av a 2 s . co m final IInstanceManager instanceManager = (IInstanceManager) context.getBean("instanceManager"); final String pid1 = instanceManager.createInstance("parentVersion", "definitionId", "test", IJavascriptProcessDefinition.DEFINITION_TYPE_JAVASCRIPT, "one"); IInstance instance = instanceManager.getInstance(pid1); assertNotNull(instance); instanceManager.createInstance("parentVersion", "definitionId", "test", IJavascriptProcessDefinition.DEFINITION_TYPE_JAVASCRIPT, "two"); ExecutorService executorService = Executors.newFixedThreadPool(2); final AtomicReference<Queue<String>> results = new AtomicReference<Queue<String>>( new LinkedList<String>()); Future<Object> future1 = executorService.submit(new Callable<Object>() { public Object call() throws Exception { return instanceManager.doWithInstance(pid1, new IInstanceCallback() { public IExecutorResult execute(IInstance instance) throws Exception { log.info("locking one"); Thread.sleep(2000); results.get().add("one"); return new IgnoredResult("", "", ""); } }); } }); Thread.sleep(100); assertNotNull(future1.get()); } finally { context.destroy(); } }
From source file:org.bpmscript.endtoend.LoanBrokerTest.java
License:asdf
public void testLoanBroker() throws Exception { final int total = 10; final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "/org/bpmscript/endtoend/spring.xml"); try {/* w w w . jav a 2 s. co m*/ final IMessageSender bus = (IMessageSender) context.getBean("bus"); final BpmScriptEngine engine = (BpmScriptEngine) context.getBean("engine"); final IVersionedDefinitionManager processManager = (IVersionedDefinitionManager) context .getBean("versionedDefinitionManager"); String source = StreamService.DEFAULT_INSTANCE .getResourceAsString("/org/bpmscript/endtoend/loanbroker.js"); String id = engine.validate(new JavascriptProcessDefinition("loanBroker", source)); processManager.createDefinition(id, new JavascriptProcessDefinition("loanBroker", source)); IBenchmarkPrinter.STDOUT.print(new Benchmark().execute(total, new IBenchmarkCallback() { public void execute(int count) throws Exception { InvocationMessage message = new InvocationMessage(); message.setArgs(null, "loanBroker", "requestBestRate", new Object[] { new LoanRequest("asdf", 1, 1000) }); message.setReplyTo("recording"); bus.send("bpmscript-first", message); } }, new IWaitForCallback() { public void call() throws Exception { RecordingAdapter recorder = (RecordingAdapter) context.getBean("recording"); BlockingQueue<IInternalMessage> internalMessages = recorder.getMessages(); for (int i = 0; i < total; i++) { Object result = internalMessages.poll(2, TimeUnit.SECONDS); assertNotNull(result); } } }, false)); } finally { context.destroy(); } log.info("done"); }
From source file:org.bpmscript.endtoend.JavaLoanBrokerTest.java
License:asdf
public void testLoanBroker() throws Exception { final int total = 10; final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "/org/bpmscript/endtoend/spring.xml"); try {// w w w . ja va2 s. c o m final IMessageSender bus = (IMessageSender) context.getBean("bus"); final IVersionedDefinitionManager processManager = (IVersionedDefinitionManager) context .getBean("versionedDefinitionManager"); processManager.createDefinition("id", new JavaProcessDefinition("loanBroker", LoanBrokerProcess.class.getName())); IBenchmarkPrinter.STDOUT.print(new Benchmark().execute(total, new IBenchmarkCallback() { public void execute(int count) throws Exception { InvocationMessage message = new InvocationMessage(); message.setArgs(null, "loanBroker", "requestBestRate", new Object[] { new LoanRequest("asdf", 1, 1000) }); message.setReplyTo("recording"); bus.send("bpmscript-first", message); log.debug("sent message"); } }, new IWaitForCallback() { public void call() throws Exception { RecordingAdapter recorder = (RecordingAdapter) context.getBean("recording"); BlockingQueue<IInternalMessage> internalMessages = recorder.getMessages(); for (int i = 0; i < total; i++) { Object result = internalMessages.poll(total, TimeUnit.SECONDS); assertNotNull(result); if (result instanceof ExceptionMessage) { ExceptionMessage exceptionMessage = (ExceptionMessage) result; log.error(exceptionMessage.getThrowable(), exceptionMessage.getThrowable()); fail(exceptionMessage.getThrowable().getMessage()); } } } }, false)); } finally { context.destroy(); } log.info("done"); }