📄 runleveltest.java
字号:
log.info(tmp.toXml()); PluginConfig[] help = holder.getAllPluginConfig("avalon"); assertEquals(me + " get all plugins for avalon", 2, help.length); String xml = new String(); xml += "<xmlBlaster>\n" + " <!-- A typical plugin which is loaded by client request -->\n" + " <plugin id='dispatchPriority'\n" + " className='org.xmlBlaster.util.dispatch.plugins.prio.PriorizedDispatchPlugin'\n" + " jar='/tmp/my.jar'>\n" + " <attribute id='config'>\n" + " <![CDATA[\n" + " <msgDispatch defaultStatus='64k' defaultAction='send'>\n" + " <onStatus oid='_bandwidth.status' content='64k' defaultAction='destroy'>\n" + " <action do='send' ifPriority='7-9'/>\n" + " <action do='queue' ifPriority='2-6'/>\n" + " </onStatus>\n" + " <onStatus oid='_bandwidth.status' content='2M'>\n" + " <action do='send' ifPriority='0-9'/>\n" + " </onStatus>\n" + " </msgDispatch>\n" + " ]]>\n" + " </attribute>\n" + " </plugin>\n" + "\n" + " <plugin id='queueCACHE' className='org.xmlBlaster.util.queue.cache.CacheQueueInterceptorPlugin'>\n" + " <attribute id='transientQueue'>queueRAM</attribute>\n" + " <attribute id='persistentQueue'>queueJDBC</attribute>\n" + " </plugin>\n" + " \n" + " <plugin id='queueRAM' className='org.xmlBlaster.util.queue.ram.RamQueuePlugin'/>\n" + "\n" + " <plugin id='storage:CACHE' className='org.xmlBlaster.engine.msgstore.cache.PersistenceCachePlugin'>\n" + " <attribute id='transientQueue'>storage:RAM</attribute>\n" + " <attribute id='persistentQueue'>storage:JDBC</attribute>\n" + " </plugin>\n" + " \n" + " <plugin id='storage:RAM' className='org.xmlBlaster.engine.msgstore.ram.MapPlugin'/>\n" + " \n" + " <!-- and here the declarations which are specific to the given nodes -->\n" + " <node id='heron'>\n" + " <plugin id='protocol:SOCKET:admin' \n" + " className='org.xmlBlaster.protocol.socket.SocketDriver'>\n" + " <attribute id='port'>69000</attribute>\n" + " </plugin>\n" + " \n" + " <!-- /node/heron/plugin/protocol:SOCKET:users/attribute/port=6901 -->\n" + " <!-- /node/heron/plugin/protocol:SOCKET:users/action/LOAD/onStartupRunlevel=3 -->\n" + " <!-- /node/heron/plugin/protocol:SOCKET:users/action/LOAD/sequence=5 -->\n" + " <plugin id='protocol:SOCKET:users' className='org.xmlBlaster.protocol.socket.SocketDriver'>\n" + " <attribute id='port'>6901</attribute>\n" + " <action do='LOAD' onStartupRunlevel='3' sequence='5' onFail='resource.configuration.pluginFailed'/>\n" + " <action do='STOP' onShutdownRunlevel='2' sequence='4'/>\n" + " </plugin>\n" + " \n" + " <plugin id='queueJDBC' className='org.xmlBlaster.util.queue.jdbc.JDBCQueueCommonTablePlugin'>\n" + " <attribute id='url'>jdbc:oracle:thin:@localhost:1521:noty</attribute>\n" + " <attribute id='user'>joe</attribute>\n" + " <attribute id='password'>secret</attribute>\n" + " <attribute id='connectionBusyTimeout'>90000</attribute>\n" + " <attribute id='maxWaitingThreads'>300</attribute>\n" + " </plugin>\n" + " \n" + " <plugin id='storage:JDBC' className='org.xmlBlaster.engine.msgstore.cache.PersistenceCachePlugin'>\n" + " <attribute id='url'>jdbc:oracle:thin:@localhost:1521:noty</attribute>\n" + " <attribute id='user'>joe</attribute>\n" + " <attribute id='password'>secret</attribute>\n" + " <attribute id='connectionBusyTimeout'>90000</attribute>\n" + " <attribute id='maxWaitingThreads'>300</attribute>\n" + " </plugin>\n" + " </node> <!-- heron -->\n" + " \n" + " <node id='avalon'>\n" + " ...\n" + " <plugin id='queueJDBC' className='org.xmlBlaster.util.queue.jdbc.JDBCQueueCommonTablePlugin'>\n" + " <attribute id='url'>jdbc:oracle:thin:@localhost:1521:noty</attribute>\n" + " <attribute id='user'>joe</attribute>\n" + " <attribute id='password'>secret</attribute>\n" + " <attribute id='connectionBusyTimeout'>90000</attribute>\n" + " <attribute id='maxWaitingThreads'>300</attribute>\n" + " <attribute id='tableNamePrefix'>AVALON_</attribute>\n" + " </plugin>\n" + " ...\n" + " </node>\n" + "</xmlBlaster>\n"; PluginHolderSaxFactory factory = new PluginHolderSaxFactory(this.glob); PluginHolder pluginHolder = null; for (int i=0; i < 2; i++) { log.info("looping through the loop. sweep '" + i + "'"); pluginHolder = factory.readObject(xml); PluginConfig[] plugins = pluginHolder.getAllPluginConfig("avalon"); assertEquals(me + " number of plugins for 'avalon' in plugin holder", 6, plugins.length); PluginConfig pluginConfig = null; pluginConfig = pluginHolder.getPluginConfig("avalon","dispatchPriority"); if (pluginConfig == null) assertTrue(me + " getting plugin 'dispatchPriority' for avalon gives null", false); String id = pluginConfig.getId(); assertEquals(me + " id for avalon/dispatchPriority", "dispatchPriority", id); String className = pluginConfig.getClassName(); assertEquals(me + " className for avalon/dispatchPriority", "org.xmlBlaster.util.dispatch.plugins.prio.PriorizedDispatchPlugin", className); pluginConfig = pluginHolder.getPluginConfig("avalon","queueCACHE"); pluginConfig = pluginHolder.getPluginConfig("avalon","queueRAM"); pluginConfig = pluginHolder.getPluginConfig("avalon","queueJDBC"); pluginConfig = pluginHolder.getPluginConfig("avalon","storage:CACHE"); pluginConfig = pluginHolder.getPluginConfig("avalon","storage:RAM"); //should not exist pluginConfig = pluginHolder.getPluginConfig("avalon","storage:JDBC"); //should be the individual of heron (not from xmlBlaster) pluginConfig = pluginHolder.getPluginConfig("heron","queueJDBC"); xml = pluginHolder.toXml(); log.info(xml); } } catch (XmlBlasterException e) { fail(me + " failed: " + e.toString()); } log.info("successfully ended"); } public void testPluginConfigComparator() { String me = ME + "-testPluginConfigConparator"; log.info("start"); PluginConfigComparator upComparator = new PluginConfigComparator(this.glob, true); PluginConfigComparator downComparator = new PluginConfigComparator(this.glob, false); PluginConfig config1 = new PluginConfig(this.glob, "test:PLUGIN1", true, "org.universe.Plugin1"); RunLevelAction action = new RunLevelAction(this.glob, "LOAD", 3, -1, null, 5); config1.addAction(action); action = new RunLevelAction(this.glob, "STOP", -1, 2, null, 4); config1.addAction(action); PluginConfig config2 = new PluginConfig(this.glob, "test:PLUGIN2", true, "org.universe.Plugin2"); action = new RunLevelAction(this.glob, "LOAD", 3, -1, null, 5); config2.addAction(action); action = new RunLevelAction(this.glob, "STOP", -1, 2, null, 4); config2.addAction(action); int cmp = upComparator.compare(config1, config2); assertTrue(me + " number of actions", cmp < 0); cmp = downComparator.compare(config1, config2); assertTrue(me + " number of actions", cmp > 0); PluginConfig config3 = new PluginConfig(this.glob, "test:PLUGIN3", true, "org.universe.Plugin3"); action = new RunLevelAction(this.glob, "LOAD", 2, -1, null, 3); config3.addAction(action); action = new RunLevelAction(this.glob, "STOP", -1, 1, null, 3); config3.addAction(action); cmp = upComparator.compare(config1, config3); assertTrue(me + " number of actions", cmp > 0); cmp = downComparator.compare(config1, config3); assertTrue(me + " number of actions", cmp < 0); PluginConfig config4 = new PluginConfig(this.glob, "test:PLUGIN4", true, "org.universe.Plugin4"); action = new RunLevelAction(this.glob, "LOAD", 2, -1, null, 4); config4.addAction(action); action = new RunLevelAction(this.glob, "STOP", -1, 1, null, 4); config4.addAction(action); cmp = upComparator.compare(config3, config4); assertTrue(me + " number of actions", cmp < 0); cmp = downComparator.compare(config3, config4); assertTrue(me + " number of actions", cmp < 0); try { cmp = upComparator.compare(config3, (PluginConfig)null); assertTrue(me + " number of actions", true); } catch (ClassCastException ex) { log.info("exception is OK and expected in this context"); } try { cmp = upComparator.compare(config3, (PluginConfig)null); assertTrue(me + " number of actions", true); } catch (ClassCastException ex) { log.info("exception is OK and expected in this context"); } try { cmp = upComparator.compare((PluginConfig)null, config4); assertTrue(me + " number of actions", true); } catch (ClassCastException ex) { log.info("exception is OK and expected in this context"); } try { cmp = downComparator.compare((PluginConfig)null, config4); assertTrue(me + " number of actions", true); } catch (ClassCastException ex) { log.info("exception is OK and expected in this context"); } log.info("successfully ended"); } /** * <pre> * java org.xmlBlaster.test.classtest.RunLevelTest * </pre> */ public static void main(String args[]) { RunLevelTest testSub = new RunLevelTest("RunLevelTest", args); testSub.setUp(); testSub.testAction(); testSub.tearDown(); testSub.setUp(); testSub.testPluginConfig(); testSub.tearDown(); testSub.setUp(); testSub.testPluginConfigParser(); testSub.tearDown(); testSub.setUp(); testSub.testPluginHolder(); testSub.tearDown(); testSub.setUp(); testSub.testPluginConfigComparator(); testSub.tearDown(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -