List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean
@Override public Object getBean(String name) throws BeansException
From source file:com.nokia.dempsy.mpcluster.zookeeper.TestFullApp.java
@Test public void testStartStop() throws Throwable { ClassPathXmlApplicationContext actx = null; Dempsy dempsy = null;/*w ww. j a va 2 s .com*/ try { logger.debug("Starting up the appliction context ..."); actx = new ClassPathXmlApplicationContext(ctx); actx.registerShutdownHook(); dempsy = (Dempsy) actx.getBean("dempsy"); dempsy.start(); final FullApplication app = (FullApplication) actx.getBean("app"); // this checks that the throughput works. assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>() { @Override public boolean conditionMet(Object o) { return app.finalMessageCount.get() > 100; } })); } finally { if (dempsy != null) dempsy.stop(); if (actx != null) actx.close(); if (dempsy != null) assertTrue(dempsy.waitToBeStopped(baseTimeoutMillis)); } }
From source file:com.nokia.dempsy.mpcluster.zookeeper.TestFullApp.java
@Test public void testFailover() throws Throwable { // now start each cluster ctx[0] = "fullApp/Dempsy-FullUp.xml"; Map<ClusterId, DempsyHolder> dempsys = new HashMap<ClusterId, DempsyHolder>(); DempsyHolder spare = new DempsyHolder(); try {/*from w w w. j a v a2 s . co m*/ ApplicationDefinition ad = new FullApplication().getTopology(); ad.initialize(); List<ClusterDefinition> clusters = ad.getClusterDefinitions(); for (int i = clusters.size() - 1; i >= 0; i--) { ClusterDefinition cluster = clusters.get(i); CheckCluster.toCheckAgainst = cluster.getClusterId(); DempsyHolder cur = new DempsyHolder(); cur.clusterid = cluster.getClusterId(); cur.actx = new ClassPathXmlApplicationContext(ctx); cur.actx.registerShutdownHook(); cur.dempsy = (Dempsy) cur.actx.getBean("dempsy"); cur.dempsy.start(); dempsys.put(cluster.getClusterId(), cur); } // get the last FullApplication in the processing chain. ClassPathXmlApplicationContext actx = dempsys .get(new ClusterId(FullApplication.class.getSimpleName(), MyRankMp.class.getSimpleName())).actx; final FullApplication app = (FullApplication) actx.getBean("app"); // this checks that the throughput works. assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>() { @Override public boolean conditionMet(Object o) { return app.finalMessageCount.get() > 100; } })); // now start another MyMp cluster. spare = new DempsyHolder(); spare.clusterid = new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName()); CheckCluster.toCheckAgainst = spare.clusterid; spare.actx = new ClassPathXmlApplicationContext(ctx); spare.dempsy = (Dempsy) spare.actx.getBean("dempsy"); spare.dempsy.start(); Dempsy.Application.Cluster cluster = spare.dempsy.getCluster(spare.clusterid); Dempsy.Application.Cluster.Node node = cluster.getNodes().get(0); final StatsCollector collector = node.getStatsCollector(); // we are going to create another node of the MyMp via a test hack cluster = spare.dempsy .getCluster(new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName())); node = cluster.getNodes().get(0); final MyMp spareprototype = (MyMp) node.getMpContainer().getPrototype(); // TODO, see if we really need that check, and if so, implement // an alternate way to get it, since with the stats collector rework // we no longer use an independent MetricsRegistry per StatsCollector // instance. assertEquals(0, collector.getDispatchedMessageCount()); assertEquals(0, spareprototype.myMpReceived.get()); // now bring down the original DempsyHolder original = dempsys.get(spare.clusterid); final MyMp originalprototype = (MyMp) original.dempsy.getCluster(spare.clusterid).getNodes().get(0) .getMpContainer().getPrototype(); final long originalNumMessages = originalprototype.myMpReceived.get(); // makes sure the message count is still advancing assertTrue(poll(baseTimeoutMillis, app, new Condition<Object>() { @Override public boolean conditionMet(Object o) { return originalprototype.myMpReceived.get() > originalNumMessages; } })); // check one more time assertEquals(0, spareprototype.myMpReceived.get()); // now stop the original ... the spare should pick up. original.dempsy.stop(); // there's a race condition between the stop returning and the last message // being processed. // we need to check that a certain amount of time passes during which no more messages have been received. final long numMillisecondsWithoutAMessage = 500; // if we haven't seen a message in 1/2 second then we // will assume that the messages have stopped. // now we wait until at least numMillisecondsWithoutAMessage goes by without the myMpReceived // being incremented. This must happen within the baseTimeoutMillis or this check is // considered failed. poll(baseTimeoutMillis + numMillisecondsWithoutAMessage, originalprototype, new Condition<Object>() { long startCheckingTime = System.currentTimeMillis(); long lastMessage = originalprototype.myMpReceived.get(); @Override public boolean conditionMet(Object o) { if (originalprototype.myMpReceived.get() != lastMessage) { startCheckingTime = System.currentTimeMillis(); lastMessage = originalprototype.myMpReceived.get(); return false; } else return (System.currentTimeMillis() - startCheckingTime) > numMillisecondsWithoutAMessage; } }); // now check to see if the new one picked up. assertTrue(poll(baseTimeoutMillis, app, new Condition<Object>() { @Override public boolean conditionMet(Object o) { return spareprototype.myMpReceived.get() > 10; } })); } finally { ctx[0] = dempsyConfig; for (DempsyHolder cur : dempsys.values()) { cur.dempsy.stop(); cur.actx.close(); } if (spare.dempsy != null) spare.dempsy.stop(); if (spare.actx != null) spare.actx.close(); } }
From source file:gr.seab.r2rml.test.ComplianceTests.java
@Test public void testAll() { log.info("test all"); LinkedHashMap<String, String[]> tests = new LinkedHashMap<String, String[]>(); tests.put("D000-1table1column0rows", new String[] { "r2rml.ttl" }); tests.put("D001-1table1column1row", new String[] { "r2rmla.ttl", "r2rmlb.ttl" }); tests.put("D002-1table2columns1row", new String[] { "r2rmla.ttl", "r2rmlb.ttl", "r2rmlc.ttl", "r2rmld.ttl", "r2rmle.ttl", "r2rmlf.ttl", "r2rmlg.ttl", "r2rmlh.ttl", "r2rmli.ttl", "r2rmlj.ttl" }); tests.put("D003-1table3columns1row", new String[] { "r2rmla.ttl", "r2rmlb.ttl", "r2rmlc.ttl" }); tests.put("D004-1table2columns1row", new String[] { "r2rmla.ttl", "r2rmlb.ttl" }); tests.put("D005-1table3columns3rows2duplicates", new String[] { "r2rmla.ttl", "r2rmlb.ttl" }); tests.put("D006-1table1primarykey1column1row", new String[] { "r2rmla.ttl" }); tests.put("D007-1table1primarykey2columns1row", new String[] { "r2rmla.ttl", "r2rmlb.ttl", "r2rmlc.ttl", "r2rmld.ttl", "r2rmle.ttl", "r2rmlf.ttl", "r2rmlg.ttl", "r2rmlh.ttl" }); tests.put("D008-1table1compositeprimarykey3columns1row", new String[] { "r2rmla.ttl", "r2rmlb.ttl", "r2rmlc.ttl" }); tests.put("D009-2tables1primarykey1foreignkey", new String[] { "r2rmla.ttl", "r2rmlb.ttl", "r2rmlc.ttl", "r2rmld.ttl" }); tests.put("D010-1table1primarykey3colums3rows", new String[] { "r2rmla.ttl", "r2rmlb.ttl", "r2rmlc.ttl" }); tests.put("D011-M2MRelations", new String[] { "r2rmla.ttl", "r2rmlb.ttl" }); tests.put("D012-2tables2duplicates0nulls", new String[] { "r2rmla.ttl", "r2rmlb.ttl", "r2rmlc.ttl", "r2rmld.ttl", "r2rmle.ttl" }); tests.put("D013-1table1primarykey3columns2rows1nullvalue", new String[] { "r2rmla.ttl" }); tests.put("D014-3tables1primarykey1foreignkey", new String[] { "r2rmla.ttl", "r2rmlb.ttl", "r2rmlc.ttl", "r2rmld.ttl" }); tests.put("D015-1table3columns1composityeprimarykey3rows2languages", new String[] { "r2rmla.ttl", "r2rmlb.ttl" }); tests.put("D016-1table1primarykey10columns3rowsSQLdatatypes", new String[] { "r2rmla.ttl", "r2rmlb.ttl", "r2rmlc.ttl", "r2rmld.ttl", "r2rmle.ttl" }); tests.put("D017-I18NnoSpecialChars", new String[] {}); tests.put("D018-1table1primarykey2columns3rows", new String[] { "r2rmla.ttl" }); tests.put("D019-1table1primarykey3columns3rows", new String[] { "r2rmla.ttl", "r2rmlb.ttl" }); tests.put("D020-1table1column5rows", new String[] { "r2rmla.ttl", "r2rmlb.ttl" }); tests.put("D021-2tables2primarykeys1foreignkeyReferencesAllNulls", new String[] {}); tests.put("D022-2tables1primarykey1foreignkeyReferencesNoPrimaryKey", new String[] {}); tests.put("D023-2tables2primarykeys2foreignkeysReferencesToNon-primarykeys", new String[] {}); tests.put("D024-2tables2primarykeys1foreignkeyToARowWithSomeNulls", new String[] {}); tests.put("D025-3tables3primarykeys3foreignkeys", new String[] {}); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("test-context.xml"); int counter = 0; for (String key : tests.keySet()) { if (counter > 2 && counter < 26) { String folder = "src/test/resources/postgres/" + key + "/"; initialiseSourceDatabase(folder + "create.sql"); for (String mappingFile : tests.get(key)) { //Override property file Parser parser = (Parser) context.getBean("parser"); Properties p = parser.getProperties(); mappingFile = folder + mappingFile; if (new File(mappingFile).exists()) { p.setProperty("mapping.file", mappingFile); } else { log.error("File " + mappingFile + " does not exist."); }/* www . ja v a 2s.c o m*/ p.setProperty("jena.destinationFileName", mappingFile.substring(0, mappingFile.indexOf(".") + 1) + "nq"); parser.setProperties(p); MappingDocument mappingDocument = parser.parse(); Generator generator = (Generator) context.getBean("generator"); generator.setProperties(parser.getProperties()); generator.setResultModel(parser.getResultModel()); log.info("--- generating " + p.getProperty("jena.destinationFileName") + " from " + mappingFile + " ---"); generator.createTriples(mappingDocument); } } counter++; } context.close(); }
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 a 2 s. 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:com.nokia.dempsy.mpcluster.zookeeper.TestFullApp.java
@Test public void testStartForceMpDisconnectStop() throws Throwable { ClassPathXmlApplicationContext actx = null; Dempsy dempsy = null;/*from w ww .ja va 2 s. co m*/ try { logger.debug("Starting up the appliction context ..."); actx = new ClassPathXmlApplicationContext(ctx); actx.registerShutdownHook(); final FullApplication app = (FullApplication) actx.getBean("app"); dempsy = (Dempsy) actx.getBean("dempsy"); // Override the cluster session factory to keep track of the sessions asked for. // This is so that I can grab the ZookeeperSession that's being instantiated by // the MyMp cluster. zookeeperCluster = null; dempsy.setClusterSessionFactory(new ZookeeperSessionFactory<ClusterInformation, SlotInformation>( System.getProperty("zk_connect"), 5000) { int sessionCount = 0; @Override public synchronized MpClusterSession<ClusterInformation, SlotInformation> createSession() throws MpClusterException { sessionCount++; MpClusterSession<ClusterInformation, SlotInformation> ret = super.createSession(); if (sessionCount == 2) zookeeperCluster = (ZookeeperSession<ClusterInformation, SlotInformation>) ret; return ret; } }); dempsy.start(); Dempsy.Application.Cluster cluster = dempsy.getCluster( new ClusterId(FullApplication.class.getSimpleName(), MyAdaptor.class.getSimpleName())); Dempsy.Application.Cluster.Node node = cluster.getNodes().get(0); final StatsCollector collector = node.getStatsCollector(); // this checks that the throughput works. assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>() { @Override public boolean conditionMet(Object o) { return app.finalMessageCount.get() > 10; } })); assertNotNull(zookeeperCluster); assertEquals(0, collector.getDiscardedMessageCount()); assertEquals(0, collector.getMessageFailedCount()); // ok ... so now we have stuff going all the way through. let's kick // the middle Mp's zookeeper cluster and see what happens. ZooKeeper origZk = zookeeperCluster.zkref.get(); long sessionid = origZk.getSessionId(); ZooKeeper killer = new ZooKeeper(System.getProperty("zk_connect"), 5000, new Watcher() { @Override public void process(WatchedEvent arg0) { } }, sessionid, null); killer.close(); // tricks the server into expiring the other session // // we should be getting failures now ... // // but it's possible that it can reconnect prior to actually seeing an error so if this // // fails frequently we need to remove this test. // assertTrue(poll(baseTimeoutMillis, app, new Condition() // { // @Override // public boolean conditionMet(Object o) // { // return collector.getMessageFailedCount() > 1; // } // })); //... and then recover. // get the MyMp prototype cluster = dempsy .getCluster(new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName())); node = cluster.getNodes().get(0); final MyMp prototype = (MyMp) node.getMpContainer().getPrototype(); // so let's see where we are final long interimMessageCount = prototype.myMpReceived.get(); // and now we should eventually get more as the session recovers. assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>() { @Override public boolean conditionMet(Object o) { return prototype.myMpReceived.get() > interimMessageCount + 100; } })); } finally { if (dempsy != null) dempsy.stop(); if (actx != null) actx.close(); if (dempsy != null) assertTrue(dempsy.waitToBeStopped(baseTimeoutMillis)); } }
From source file:com.nokia.dempsy.mpcluster.zookeeper.TestFullApp.java
@Test public void testStartForceMpDisconnectWithStandby() throws Throwable { ClassPathXmlApplicationContext actx = null; Dempsy dempsy = null;/*w w w . jav a 2s . com*/ try { logger.debug("Starting up the appliction context ..."); actx = new ClassPathXmlApplicationContext(ctx); actx.registerShutdownHook(); final FullApplication app = (FullApplication) actx.getBean("app"); dempsy = (Dempsy) actx.getBean("dempsy"); // Override the cluster session factory to keep track of the sessions asked for. // This is so that I can grab the ZookeeperSession that's being instantiated by // the MyMp cluster. zookeeperCluster = null; dempsy.setClusterSessionFactory(new ZookeeperSessionFactory<ClusterInformation, SlotInformation>( System.getProperty("zk_connect"), 5000) { int sessionCount = 0; @Override public synchronized MpClusterSession<ClusterInformation, SlotInformation> createSession() throws MpClusterException { sessionCount++; MpClusterSession<ClusterInformation, SlotInformation> ret = super.createSession(); if (sessionCount == 2) zookeeperCluster = (ZookeeperSession<ClusterInformation, SlotInformation>) ret; return ret; } }); dempsy.start(); Dempsy.Application.Cluster cluster = dempsy.getCluster( new ClusterId(FullApplication.class.getSimpleName(), MyAdaptor.class.getSimpleName())); Dempsy.Application.Cluster.Node node = cluster.getNodes().get(0); final StatsCollector collector = node.getStatsCollector(); // we are going to create another node of the MyMp via a test hack cluster = dempsy .getCluster(new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName())); Dempsy.Application.Cluster.Node mpnode = cluster.getNodes().get(0); cluster.instantiateAndStartAnotherNodeForTesting(); // the code for start instantiates a new node // this checks that the throughput works. assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>() { @Override public boolean conditionMet(Object o) { return app.finalMessageCount.get() > 10; } })); assertNotNull(zookeeperCluster); assertEquals(0, collector.getDiscardedMessageCount()); assertEquals(0, collector.getMessageFailedCount()); // ok ... so now we have stuff going all the way through. let's kick // the middle Mp's zookeeper cluster and see what happens. ZooKeeper origZk = zookeeperCluster.zkref.get(); origZk.close(); // this should kill it. // but just to be sure actually stop the node. mpnode.stop(); // // we should be getting failures now ... // // but it's possible that it can reconnect prior to actually seeing an error so if this // // fails frequently we need to remove this test. // assertTrue(poll(baseTimeoutMillis, app, new Condition() // { // @Override // public boolean conditionMet(Object o) // { // return collector.getMessageFailedCount() > 1; // } // })); //... and then recover. // get the MyMp prototype cluster = dempsy .getCluster(new ClusterId(FullApplication.class.getSimpleName(), MyMp.class.getSimpleName())); node = cluster.getNodes().get(1); // notice, we're getting the SECOND node. final MyMp prototype = (MyMp) node.getMpContainer().getPrototype(); // so let's see where we are final long interimMessageCount = prototype.myMpReceived.get(); // and now we should eventually get more as the session recovers. assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>() { @Override public boolean conditionMet(Object o) { return prototype.myMpReceived.get() > interimMessageCount + 100; } })); } finally { if (dempsy != null) dempsy.stop(); if (actx != null) actx.close(); if (dempsy != null) assertTrue(dempsy.waitToBeStopped(baseTimeoutMillis)); } }
From source file:org.drools.server.CxfSoapClientServerTest.java
@org.junit.Test public void test1() throws Exception { ClassPathXmlApplicationContext springContext = new ClassPathXmlApplicationContext( "classpath:beans-test.xml"); SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(); SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody(); QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1"); body.addBodyElement(payloadName);//from www. ja v a 2s. c o m String cmd = ""; cmd += "<batch-execution lookup=\"ksession1\">\n"; cmd += " <insert out-identifier=\"message\">\n"; cmd += " <org.drools.server.Message>\n"; cmd += " <text>Helllo World</text>\n"; cmd += " </org.drools.server.Message>\n"; cmd += " </insert>\n"; cmd += "</batch-execution>\n"; body.addTextNode(cmd); CamelServerApp test = new CamelServerApp(); String response = test.execute(soapMessage, (CamelContext) springContext.getBean("camel-client-ctx")); assertTrue(response.contains("execution-results")); assertTrue(response.contains("echo")); springContext.stop(); }
From source file:org.openspaces.itest.persistency.cassandra.archive.CassandaraArchiveOperationHandlerTest.java
private void xmlTest(String relativeXmlName) { final boolean refreshNow = false; final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { relativeXmlName }, refreshNow); PropertyPlaceholderConfigurer propertyConfigurer = new PropertyPlaceholderConfigurer(); Properties properties = new Properties(); properties.put("cassandra.keyspace", server.getKeySpaceName()); properties.put("cassandra.hosts", server.getHost()); properties.put("cassandra.port", "" + server.getPort()); properties.put("cassandra.write-consistency", "ALL"); propertyConfigurer.setProperties(properties); context.addBeanFactoryPostProcessor(propertyConfigurer); context.refresh();//ww w . j a va 2 s.co m try { final CassandraArchiveOperationHandler archiveHandler = context .getBean(CassandraArchiveOperationHandler.class); Assert.assertEquals(CassandraConsistencyLevel.ALL, archiveHandler.getWriteConsistency()); final GigaSpace gigaSpace = context.getBean(org.openspaces.core.GigaSpace.class); test(archiveHandler, gigaSpace); } finally { context.close(); } }
From source file:com.digitalgeneralists.assurance.ui.components.ComparisonResultPanel.java
private void displayAttributesDialog(FileReference file) { ClassPathXmlApplicationContext springContext = null; try {//w w w.jav a 2 s.c om if (this.getParent() != null) { JFrame parent = (JFrame) SwingUtilities.getWindowAncestor(this.getParent()); springContext = new ClassPathXmlApplicationContext("/META-INF/spring/app-context.xml"); IDialogFactory dialogFactory = (IDialogFactory) springContext.getBean("DialogFactory"); JDialog scanDefinitionDialog = dialogFactory.createFileAttributesDialogInstance(parent, ModalityType.APPLICATION_MODAL, file); scanDefinitionDialog.setPreferredSize(new Dimension(400, 600)); scanDefinitionDialog.setVisible(true); dialogFactory = null; } } finally { if (springContext != null) { springContext.close(); springContext = null; } } }