Skip to content

Add benchmark for JUL agent without source information #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2017 École Polytechnique de Montréal
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package org.lttng.ust.agent.benchmarks.jul.handler.lttng;

import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.junit.After;
import org.junit.Before;
import org.lttng.tools.ILttngSession;
import org.lttng.tools.ILttngSession.Domain;
import org.lttng.ust.agent.benchmarks.jul.handler.JulHandlerBenchmarkBase;
import org.lttng.ust.agent.jul.LttngLogHandler;

/**
* Test the LTTng-JUL handler, with it actually sending events to the tracer,
* but without saving the source method and class information
*
* @author Geneviève Bastien
*/
public class LttngJulHandlerTracingEnabledNoSourceBenchmark extends JulHandlerBenchmarkBase {

private ILttngSession session;

/**
* Test setup
*
* @throws IOException
*/
@Before
public void testSetup() throws IOException {
LttngLogHandler hndl = new LttngLogHandler();
hndl.setLogSource(false);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, that's what this public method was for!

Hmm, could it be done through a System.getProperty(), or through a custom constructor?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember that after discussion, we noticed it's common for handler classes to also offer setters for properties like this, so we can stay consistent with that.

handler = hndl;

session = ILttngSession.createSession(null, Domain.JUL);
assertTrue(session.enableAllEvents());
assertTrue(session.start());
}

/**
* Test cleanup
*/
@After
public void testTeardown() {
assertTrue(session.stop());
session.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/*
* Copyright (C) 2017, École Polytechnique de Montréal, Geneviève Bastien <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package org.lttng.ust.agent.integration.events;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.lttng.tools.ILttngSession;
import org.lttng.tools.ILttngSession.Domain;
import org.lttng.ust.agent.jul.LttngLogHandler;
import org.lttng.ust.agent.utils.JulTestUtils;

/**
* Test the {@link LttngLogHandler} log output with source log enabled or not
*
* @author Geneviève Bastien
*/
@RunWith(Parameterized.class)
public class JulHandlerLogSourceIT {

private static final Domain DOMAIN = Domain.JUL;

private static final String LOGGER_NAME = "org.lttng.test";

private ILttngSession session;

private Logger logger;

private final Boolean logSource;
private final String expectedString;

// ------------------------------------------------------------------------
// Test parameter definition
// ------------------------------------------------------------------------

/**
* Get the test parameters, with / without source logging as well as the
* string that should be present in the events as a result of the event
* logging.
*
* @return The test parameters
*/
@Parameters(name = "{index}: logSource={0}")
public static Iterable<Object[]> testCases() {
return Arrays.asList(new Object[][] {
{ Boolean.TRUE, "class_name = \"org.lttng.ust.agent.utils.JulTestUtils\", method_name = \"send10EventsTo\"" },
{ Boolean.FALSE, "class_name = \"\", method_name = \"\"" },
});
}

/**
* Test constructor
*
* @param logSource
* Should source information be logged with the event
* @param expectedString
* A string that should be present in the event
*/
public JulHandlerLogSourceIT(boolean logSource,
String expectedString) {
this.logSource = logSource;
this.expectedString = expectedString;
}

/**
* Class setup
*/
@BeforeClass
public static void julClassSetup() {
JulTestUtils.testClassSetup();
}

/**
* Class cleanup
*/
@AfterClass
public static void julClassCleanup() {
JulTestUtils.testClassCleanup();
}

/**
* Test setup
*
* @throws IOException
* Exceptions thrown by handler
* @throws SecurityException
* Exceptions thrown by handler
*/
@Before
public void setup() throws SecurityException, IOException {
/* Clear the JUL logger configuration */
LogManager.getLogManager().reset();
System.gc();

/* Initialize the logger */
logger = Logger.getLogger(LOGGER_NAME);
logger.setLevel(Level.ALL);

/* Initialize the handler */
LttngLogHandler handler = new LttngLogHandler();
handler.setLogSource(logSource);
logger.addHandler(handler);

/* Create the lttng session */
session = ILttngSession.createSession(null, DOMAIN);
}

/**
* Test cleanup
*/
@After
public void tearDown() {
session.close();
Handler handler = logger.getHandlers()[0];
logger.removeHandler(handler);
handler.close();

logger = null;
}

/**
* Test tracing some events and see if the output contains the expected string
*/
@Test
public void testHandlerOutput() {
assertTrue(session.enableAllEvents());
assertTrue(session.start());

JulTestUtils.send10EventsTo(logger);

assertTrue(session.stop());

List<String> output = session.view();
assertNotNull(output);
assertFalse(output.isEmpty());

assertEquals(10, output.size());
for (String str : output) {
assertTrue("Validating event string : " + str, str.contains(expectedString));
}
}

}