@Test public void testStartFails() { appender.topicBindingName = null; appender.start(); assertFalse(appender.isStarted()); }
@Test public void testStartUserPass() { appender.setUserName("test"); appender.setPassword("test"); appender.start(); assertTrue(appender.isStarted()); try { assertEquals(appender.topicBindingName, appender.topicPublisher.getTopic().getTopicName()); } catch (Exception e) { fail(); } }
@Test public void testStartMinimalInfo() { // let's leave only what's in the setup() // method, minus the providerURL appender.setProviderURL(null); appender.start(); assertTrue(appender.isStarted()); try { assertEquals(appender.topicBindingName, appender.topicPublisher.getTopic().getTopicName()); } catch (Exception e) { fail(); } }
@Test public void testAppendOk() { appender.start(); ILoggingEvent le = createLoggingEvent(); appender.append(le); MockTopicPublisher tp = (MockTopicPublisher) appender.topicPublisher; assertEquals(1, tp.getMessageList().size()); ObjectMessage message = (ObjectMessage) tp.getMessageList().get(0); try { Serializable witness = pst.transform(le); assertEquals(witness, message.getObject()); } catch (Exception e) { fail(); } }
@Test public void testBuildEnvPropertiesWithNullCredentials() { appender.setInitialContextFactoryName("icfn"); appender.setProviderURL("url"); appender.setURLPkgPrefixes("pkgPref"); appender.setSecurityPrincipalName("user"); appender.setSecurityCredentials(null); Properties props = appender.buildEnvProperties(); assertEquals(4, props.size()); assertEquals( appender.getInitialContextFactoryName(), props.getProperty(Context.INITIAL_CONTEXT_FACTORY)); assertEquals(appender.getProviderURL(), props.getProperty(Context.PROVIDER_URL)); assertEquals(appender.getURLPkgPrefixes(), props.getProperty(Context.URL_PKG_PREFIXES)); assertEquals( appender.getSecurityPrincipalName(), props.getProperty(Context.SECURITY_PRINCIPAL)); assertEquals(null, props.getProperty(Context.SECURITY_CREDENTIALS)); assertEquals(1, context.getStatusManager().getCount()); }
@Before public void setUp() throws Exception { context = new ContextBase(); appender = new JMSTopicAppender(); appender.setContext(context); appender.setName("jmsTopic"); appender.tcfBindingName = "topicCnxFactory"; appender.topicBindingName = "testTopic"; appender.setProviderURL("url"); appender.setInitialContextFactoryName(MockInitialContextFactory.class.getName()); MockInitialContext mic = MockInitialContextFactory.getContext(); mic.map.put(appender.tcfBindingName, new MockTopicConnectionFactory()); mic.map.put(appender.topicBindingName, new MockTopic(appender.topicBindingName)); }
public static void main(String[] args) { Logger logger = (Logger) LoggerFactory.getLogger(JMSTopicAppenderTestApp.class); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); lc.reset(); JMSTopicAppender appender = new JMSTopicAppender(); appender.setContext(lc); appender.setName("jmsTopic"); appender.setInitialContextFactoryName("org.apache.activemq.jndi.ActiveMQInitialContextFactory"); // appender.setPassword(""); appender.setProviderURL("tcp://localhost:61616"); // appender.setSecurityCredentials(""); // appender.setSecurityPrincipalName(""); appender.setTopicBindingName("MyTopic"); appender.setTopicConnectionFactoryBindingName("ConnectionFactory"); // appender.setURLPkgPrefixes(""); // appender.setUserName(""); appender.start(); logger.addAppender(appender); // JIT for (int i = 0; i < 10000; i++) { logger.debug("** Hello world. n=" + i); } long before = System.nanoTime(); for (int i = 0; i < 10000; i++) { logger.debug("** Hello world. n=" + i); } long after = System.nanoTime(); System.out.println("Time per logs for 10'000 logs: " + (after - before) / 10000); StatusPrinter.print(lc.getStatusManager()); }
@Test public void testAppendFailure() { appender.start(); // make sure the append method does not work appender.topicPublisher = null; ILoggingEvent le = createLoggingEvent(); for (int i = 1; i <= 3; i++) { appender.append(le); assertEquals(i, context.getStatusManager().getCount()); assertTrue(appender.isStarted()); } appender.append(le); assertEquals(4, context.getStatusManager().getCount()); assertFalse(appender.isStarted()); }