private void assertFeedbackChannelsNotPresent(FeedbackHandler handler, String... names) throws IOException { for (String name : names) { assertNull(handler.getChannel(name), "Expected channel '" + name + "' NOT to be present!"); } } }
private Set<String> getFeedbackChannelNames() { try { return getFeedbackHandler().getChannelNames(); } catch (IOException e) { // Probably a serious problem due to local IO related to feedback. No cause to abort the sync so we just log // it as an error. logError("Exception while looking up feedback channel names."); } return Collections.emptySet(); }
private void assertFeedbackChannelsPresent(FeedbackHandler handler, String... names) throws IOException { for (String name : names) { assertNotNull(handler.getChannel(name), "Expected channel '" + name + "' to be present!"); } }
private void assertFeedbackChannelNames(FeedbackHandler handler, String... names) throws IOException { Set<String> availableNames = handler.getChannelNames(); assertNotNull(availableNames); assertEquals(availableNames.size(), names.length); for (String name : names) { assertTrue(availableNames.contains(name), "Expected channel '" + name + "' to be present!"); } }
private FeedbackChannel getFeedbackChannel(String name) { try { return getFeedbackHandler().getChannel(name); } catch (IOException e) { // Probably a serious problem due to local IO related to feedback. No cause to abort the sync so we just log // it as an error. logError("Exception while looking up feedback channel %s", e, name); } return null; }
private void writeAuditEvent(int eventType, Map<String, String> payload) { try { FeedbackChannel channel = getFeedbackHandler().getChannel(EVENTLOGGER_FEEDBACKCHANNEL); boolean isExcluded; synchronized(m_excludeEventList) { isExcluded = m_excludeEventList.contains(eventType); } if (channel != null && !isExcluded) { channel.write(eventType, payload); } } catch (IOException e) { logWarning("Failed to write feedback event!", e); } } }
@SuppressWarnings("deprecation") @Test public void testWriteEvent() throws Exception { FrameworkEvent event = new FrameworkEvent(32, new Object()); m_eventLogger.frameworkEvent(event); FeedbackHandler feedbackHandler = m_agentContext.getHandler(FeedbackHandler.class); TestFeedbackChannel channel = (TestFeedbackChannel) feedbackHandler.getChannel("auditlog"); assertEquals(channel.getLastTtype(), 1001); }
@SuppressWarnings("deprecation") @Test public void testExcludeEvent() throws Exception { ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, AgentConstants.CONFIG_LOGGING_EXCLUDE_EVENTS, "1001,1002"); FrameworkEvent event = new FrameworkEvent(32, new Object()); FeedbackHandler feedbackHandler = m_agentContext.getHandler(FeedbackHandler.class); TestFeedbackChannel channel = (TestFeedbackChannel) feedbackHandler.getChannel("auditlog"); // make sure the configuration is written to the channel assertEquals(channel.getLastTtype(), 2000); m_eventLogger.frameworkEvent(event); // make sure nothing is written to the channel assertEquals(channel.getLastTtype(), 2000); } }
@BeforeMethod(alwaysRun = true) public void reset() throws Exception { // create a new eventlogger for every test m_eventLogger = new EventLoggerImpl(mockBundleContext()); m_eventLogger.init(m_agentContext); m_eventsHandler.addListener(m_eventLogger); m_eventLogger.start(m_agentContext); // reset the previously logged data in our mock feedbackchannel. No need to create a new one here FeedbackHandler feedbackHandler = m_agentContext.getHandler(FeedbackHandler.class); TestFeedbackChannel channel = (TestFeedbackChannel) feedbackHandler.getChannel("auditlog"); channel.reset(); }