From 0d5cc257609d0e0ec81149a7823abd44c77d3e87 Mon Sep 17 00:00:00 2001 From: Alexander Straube Date: Mon, 5 Jun 2023 18:35:01 +0200 Subject: [PATCH 1/7] Removed easymock --- pom.xml | 8 +--- .../reports/PerformanceReportTest.java | 46 +++++++++---------- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/pom.xml b/pom.xml index 71daca72..9d985432 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.jenkins-ci.plugins plugin - 4.54 + 4.66 @@ -95,12 +95,6 @@ plexus-utils 4.0.0 - - org.easymock - easymockclassextension - 3.2 - test - com.google.code.gson gson diff --git a/src/test/java/hudson/plugins/performance/reports/PerformanceReportTest.java b/src/test/java/hudson/plugins/performance/reports/PerformanceReportTest.java index 67a84eaf..fbd84f6b 100644 --- a/src/test/java/hudson/plugins/performance/reports/PerformanceReportTest.java +++ b/src/test/java/hudson/plugins/performance/reports/PerformanceReportTest.java @@ -1,14 +1,9 @@ package hudson.plugins.performance.reports; -import hudson.plugins.performance.actions.PerformanceBuildAction; -import hudson.plugins.performance.data.HttpSample; -import hudson.plugins.performance.data.TaurusFinalStats; -import hudson.plugins.performance.parsers.JMeterParser; -import hudson.plugins.performance.parsers.JUnitParser; -import hudson.util.StreamTaskListener; -import org.easymock.classextension.EasyMock; -import org.junit.Before; -import org.junit.Test; +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.File; import java.io.IOException; @@ -19,10 +14,16 @@ import java.util.List; import java.util.Map; -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 org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import hudson.plugins.performance.actions.PerformanceBuildAction; +import hudson.plugins.performance.data.HttpSample; +import hudson.plugins.performance.data.TaurusFinalStats; +import hudson.plugins.performance.parsers.JMeterParser; +import hudson.plugins.performance.parsers.JUnitParser; +import hudson.util.StreamTaskListener; public class PerformanceReportTest { public static final String DEFAULT_PERCENTILES = "0,50,90,100"; @@ -31,22 +32,19 @@ public class PerformanceReportTest { @Before public void setUp() throws Exception { - PerformanceBuildAction buildAction = EasyMock - .createMock(PerformanceBuildAction.class); + PerformanceBuildAction buildAction = Mockito.mock(PerformanceBuildAction.class); performanceReport = new PerformanceReport(DEFAULT_PERCENTILES); performanceReport.setBuildAction(buildAction); } @Test public void testAddSample() throws Exception { - PrintStream printStream = EasyMock.createMock(PrintStream.class); - EasyMock.expect( + PrintStream printStream = Mockito.mock(PrintStream.class); + Mockito.when( performanceReport.getBuildAction().getHudsonConsoleWriter()) - .andReturn(printStream); + .thenReturn(printStream); printStream .println("label cannot be empty, please ensure your jmx file specifies name properly for each http sample: skipping sample"); - EasyMock.replay(printStream); - EasyMock.replay(performanceReport.getBuildAction()); HttpSample sample1 = new HttpSample(); sample1.setDate(new Date()); @@ -72,14 +70,12 @@ public void testAddSample() throws Exception { @Test public void testAddTaurusSample() throws Exception { - PrintStream printStream = EasyMock.createMock(PrintStream.class); - EasyMock.expect( + PrintStream printStream = Mockito.mock(PrintStream.class); + Mockito.when( performanceReport.getBuildAction().getHudsonConsoleWriter()) - .andReturn(printStream); + .thenReturn(printStream); printStream .println("label cannot be empty, please ensure your jmx file specifies name properly for each http sample: skipping sample"); - EasyMock.replay(printStream); - EasyMock.replay(performanceReport.getBuildAction()); TaurusFinalStats sample = new TaurusFinalStats(); performanceReport.addSample(sample, true); From 94d754f41d0b35f198c048f168b1d98b8df0670f Mon Sep 17 00:00:00 2001 From: Alexander Straube Date: Mon, 5 Jun 2023 19:48:21 +0200 Subject: [PATCH 2/7] Replace PowerMock by Mockito --- pom.xml | 13 +--- .../reports/ConstraintReportTest.java | 61 +++++++++---------- 2 files changed, 31 insertions(+), 43 deletions(-) diff --git a/pom.xml b/pom.xml index 9d985432..4c682461 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,6 @@ 2 false - 2.0.9 @@ -101,15 +100,9 @@ 2.10.1 - org.powermock - powermock-module-junit4 - ${powermock.version} - test - - - org.powermock - powermock-api-mockito2 - ${powermock.version} + org.mockito + mockito-inline + 5.2.0 test diff --git a/src/test/java/hudson/plugins/performance/reports/ConstraintReportTest.java b/src/test/java/hudson/plugins/performance/reports/ConstraintReportTest.java index f8cdc87f..d4bc61de 100644 --- a/src/test/java/hudson/plugins/performance/reports/ConstraintReportTest.java +++ b/src/test/java/hudson/plugins/performance/reports/ConstraintReportTest.java @@ -1,8 +1,8 @@ package hudson.plugins.performance.reports; -import hudson.FilePath; -import hudson.model.AbstractBuild; -import hudson.model.Result; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; import java.io.File; import java.io.IOException; @@ -11,28 +11,27 @@ import java.util.Calendar; import java.util.Date; -import hudson.plugins.performance.constraints.AbsoluteConstraint; -import hudson.plugins.performance.constraints.ConstraintEvaluation; -import hudson.plugins.performance.constraints.RelativeConstraint; -import jenkins.model.Jenkins; -import hudson.plugins.performance.constraints.AbstractConstraint.Escalation; -import hudson.plugins.performance.constraints.AbstractConstraint.Metric; -import hudson.plugins.performance.constraints.AbstractConstraint.Operator; - +import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; +import hudson.FilePath; +import hudson.model.AbstractBuild; +import hudson.model.Result; +import hudson.plugins.performance.constraints.AbsoluteConstraint; +import hudson.plugins.performance.constraints.AbstractConstraint.Escalation; +import hudson.plugins.performance.constraints.AbstractConstraint.Metric; +import hudson.plugins.performance.constraints.AbstractConstraint.Operator; +import hudson.plugins.performance.constraints.ConstraintEvaluation; +import hudson.plugins.performance.constraints.RelativeConstraint; +import jenkins.model.Jenkins; -@RunWith(PowerMockRunner.class) -@PrepareForTest({Jenkins.class, FilePath.class, AbstractBuild.class, Calendar.class}) +@RunWith(MockitoJUnitRunner.class) public class ConstraintReportTest { @Mock @@ -67,9 +66,6 @@ public class ConstraintReportTest { @Mock Date date; - @Mock - Jenkins jenkins; - @Mock Calendar calendar; @@ -112,6 +108,8 @@ public class ConstraintReportTest { "Measured value for Average: 9 \n " + "Escalation Level: Warning"; + final MockedStatic staticJenkins = Mockito.mockStatic(Jenkins.class); + @Before public void setUp() throws IOException, InterruptedException { when(ce0.getAbstractConstraint()).thenReturn(rc0); @@ -150,34 +148,32 @@ public void setUp() throws IOException, InterruptedException { when(ac5.getRelatedPerfReport()).thenReturn("Result.xml"); when(rc0.getOperator()).thenReturn(Operator.NOT_GREATER); - when(rc1.getOperator()).thenReturn(Operator.NOT_LESS); when(rc2.getOperator()).thenReturn(Operator.NOT_GREATER); - when(ac3.getOperator()).thenReturn(Operator.NOT_GREATER); when(ac4.getOperator()).thenReturn(Operator.NOT_LESS); - when(ac5.getOperator()).thenReturn(Operator.NOT_EQUAL); when(rc0.getMeteredValue()).thenReturn(Metric.AVERAGE); - when(rc1.getMeteredValue()).thenReturn(Metric.AVERAGE); when(rc2.getMeteredValue()).thenReturn(Metric.MAXIMUM); - when(ac3.getMeteredValue()).thenReturn(Metric.AVERAGE); when(ac4.getMeteredValue()).thenReturn(Metric.AVERAGE); - when(ac5.getMeteredValue()).thenReturn(Metric.AVERAGE); when(globBuild.getNumber()).thenReturn(42); when(globBuild.getTimestamp()).thenReturn(calendar); - filePath = PowerMockito.mock(FilePath.class); + filePath = Mockito.mock(FilePath.class); when(globBuild.getWorkspace()).thenReturn(filePath); when(filePath.toURI()).thenReturn(uri); when(uri.getPath()).thenReturn("test-jenkins-filepath/"); - PowerMockito.mockStatic(Jenkins.class); - when(Jenkins.get()).thenReturn(jenkins); + final Jenkins jenkins = Mockito.mock(Jenkins.class); + staticJenkins.when(Jenkins::get).thenReturn(jenkins); when(jenkins.getRootUrl()).thenReturn("test-jenkins-rooturl"); } - @Ignore("Fails with java.lang.NoSuchMethodError: 'org.mockito.stubbing.Answer org.mockito.Answers.get()'") + @After + public void tearDown() { + staticJenkins.closeOnDemand(); + } + @Test public void happyPathWithoutConstraintLog() throws IOException, InterruptedException { @@ -206,7 +202,6 @@ public void happyPathWithoutConstraintLog() throws IOException, InterruptedExcep assertEquals(42, result.getBuildNumber()); } - @Ignore("Fails with java.lang.NoSuchMethodError: 'org.mockito.stubbing.Answer org.mockito.Answers.get()'") @Test public void happyPathWithConstraintLog() throws IOException, InterruptedException { ceList = new ArrayList(); From 69b1e10644b0b0cca55bda26c35e954db134f77d Mon Sep 17 00:00:00 2001 From: Alexander Straube Date: Mon, 5 Jun 2023 21:57:08 +0200 Subject: [PATCH 3/7] Fix broken test setup --- .../java/hudson/plugins/performance/BaselineComparisonTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/hudson/plugins/performance/BaselineComparisonTest.java b/src/test/java/hudson/plugins/performance/BaselineComparisonTest.java index 2c7e2a51..80bd56c2 100644 --- a/src/test/java/hudson/plugins/performance/BaselineComparisonTest.java +++ b/src/test/java/hudson/plugins/performance/BaselineComparisonTest.java @@ -47,6 +47,7 @@ public class BaselineComparisonTest extends AbstractGraphGenerationTest { public void setup() { when(build.getPreviousBuild()).thenReturn(prevBuild); when(prevBuild.getPreviousBuild()).thenReturn(buildWithNumber3); + when(prevBuild.getPreviousCompletedBuild()).thenReturn(buildWithNumber3); when(build.getNumber()).thenReturn(5); when(prevBuild.getNumber()).thenReturn(4); when(buildWithNumber3.getNumber()).thenReturn(3); From b8ce3b8717a7e8253c9a09420994a4fe8a60fc81 Mon Sep 17 00:00:00 2001 From: Alexander Straube Date: Mon, 5 Jun 2023 23:01:03 +0200 Subject: [PATCH 4/7] Replaced most of deprecated api usages --- .../performance/PerformancePublisher.java | 2 +- .../performance/PerformancePipelineTest.java | 74 ++--- .../performance/PerformancePublisherTest.java | 279 ++++++++++-------- .../build/PerformanceTestBuildTest.java | 188 ++++++------ .../constraints/ConstraintCheckerTest.java | 18 +- .../constraints/ConstraintFactoryTest.java | 49 +-- .../parsers/AbstractParserTest.java | 8 +- .../performance/parsers/IagoParserTest.java | 67 +++-- .../parsers/WrkSummarizerParserTest.java | 3 +- .../reports/ConstraintReportTest.java | 4 - .../reports/PerformanceReportTest.java | 5 +- .../reports/ThroughputReportTest.java | 3 +- .../workflow/WorkflowActionsFactoryTest.java | 79 +++-- 13 files changed, 416 insertions(+), 363 deletions(-) diff --git a/src/main/java/hudson/plugins/performance/PerformancePublisher.java b/src/main/java/hudson/plugins/performance/PerformancePublisher.java index 625e96b3..6e9ef6e9 100644 --- a/src/main/java/hudson/plugins/performance/PerformancePublisher.java +++ b/src/main/java/hudson/plugins/performance/PerformancePublisher.java @@ -80,7 +80,7 @@ public class PerformancePublisher extends Recorder implements SimpleBuildStep { - public static final double THRESHOLD_TOLERANCE = 0.00000001; + public static final double THRESHOLD_TOLERANCE = 0.0000000000000000000000000000000000000000000000000000000000000000000000000000001; private static final double DEFAULT_THRESHOLD = -1; private int errorFailedThreshold = -1; diff --git a/src/test/java/hudson/plugins/performance/PerformancePipelineTest.java b/src/test/java/hudson/plugins/performance/PerformancePipelineTest.java index 1d665c68..b0549927 100644 --- a/src/test/java/hudson/plugins/performance/PerformancePipelineTest.java +++ b/src/test/java/hudson/plugins/performance/PerformancePipelineTest.java @@ -1,7 +1,8 @@ package hudson.plugins.performance; -import hudson.model.Result; -import hudson.slaves.DumbSlave; +import java.net.URL; +import java.nio.charset.StandardCharsets; + import org.apache.commons.io.IOUtils; import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; import org.jenkinsci.plugins.workflow.job.WorkflowJob; @@ -9,14 +10,14 @@ import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.junit.runners.model.Statement; import org.jvnet.hudson.test.BuildWatcher; import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.RestartableJenkinsRule; -import java.net.URL; +import hudson.model.Result; +import hudson.slaves.DumbSlave; -public class PerformancePipelineTest { +public class PerformancePipelineTest { @ClassRule public static BuildWatcher buildWatcher = new BuildWatcher(); @@ -26,26 +27,25 @@ public class PerformancePipelineTest { @Test public void bztSmokeTests() throws Exception { final String path = getClass().getResource("/performanceTest.yml").getPath(); - - story.addStep(new Statement() { - public void evaluate() throws Throwable { - DumbSlave s = story.j.createOnlineSlave(); - s.setLabelString("test performance test "); - WorkflowJob p = story.j.createProject(WorkflowJob.class, "demo job"); - p.getRootDir().mkdirs(); - String bztParams = path + ' ' + "-o modules.jmeter.plugins=[] -o services=[] " + - "-o \\'reporting.-1={module: \"junit-xml\", filename: \"report.xml\"}\\' " + - "-o \\'execution.0.scenario.requests.1={url: \"http://blazedemo.com/\": assert: [\"yo mamma\"]}\\'"; - p.setDefinition(new CpsFlowDefinition( - "node('" + story.j.jenkins.getSelfLabel().getName() + "'){ bzt(params: '" + bztParams + "', useSystemSitePackages: false, printDebugOutput: true, bztVersion: '1.16.19') }", true)); - WorkflowRun r = p.scheduleBuild2(0).waitForStart(); - story.j.assertBuildStatusSuccess(story.j.waitForCompletion(r)); - story.j.assertLogContains("Writing JUnit XML report into: report.xml", r); - story.j.assertLogContains("File aggregate-results.xml reported", r); - story.j.assertLogContains("of errors [SUCCESS].", r); - if (JenkinsRule.getLog(r).contains("Performance test: Installing bzt into 'taurus-venv'")) { - story.j.assertLogContains("Taurus CLI Tool v1.16.19", r); - } + story.then(step -> { + DumbSlave s = story.j.createOnlineSlave(); + s.setLabelString("test performance test "); + WorkflowJob p = story.j.createProject(WorkflowJob.class, "demo job"); + p.getRootDir().mkdirs(); + String bztParams = path + ' ' + "-o modules.jmeter.plugins=[] -o services=[] " + + "-o \\'reporting.-1={module: \"junit-xml\", filename: \"report.xml\"}\\' " + + "-o \\'execution.0.scenario.requests.1={url: \"http://blazedemo.com/\": assert: [\"yo mamma\"]}\\'"; + p.setDefinition(new CpsFlowDefinition( + "node('" + story.j.jenkins.getSelfLabel().getName() + "'){ bzt(params: '" + bztParams + + "', useSystemSitePackages: false, printDebugOutput: true, bztVersion: '1.16.19') }", + true)); + WorkflowRun r = p.scheduleBuild2(0).waitForStart(); + story.j.assertBuildStatusSuccess(story.j.waitForCompletion(r)); + story.j.assertLogContains("Writing JUnit XML report into: report.xml", r); + story.j.assertLogContains("File aggregate-results.xml reported", r); + story.j.assertLogContains("of errors [SUCCESS].", r); + if (JenkinsRule.getLog(r).contains("Performance test: Installing bzt into 'taurus-venv'")) { + story.j.assertLogContains("Taurus CLI Tool v1.16.19", r); } }); } @@ -56,22 +56,22 @@ public void perfReportSmokeTests() throws Exception { URL url = getClass().getResource("/TaurusXMLReport.xml"); if (url != null) { - fileContents = IOUtils.toString(url); + fileContents = IOUtils.toString(url, StandardCharsets.UTF_8); } final String report = fileContents; - story.addStep(new Statement() { - public void evaluate() throws Throwable { - DumbSlave s = story.j.createOnlineSlave(); - s.setLabelString("test performance report DSL function"); - WorkflowJob p = story.j.createProject(WorkflowJob.class, "demo"); - p.setDefinition(new CpsFlowDefinition( - "node{ writeFile file: 'test.xml', text: '''" + report + "'''; perfReport errorFailedThreshold: 0, errorUnstableThreshold: 0, sourceDataFiles: 'test.xml' }", true)); - WorkflowRun r = p.scheduleBuild2(0).waitForStart(); - story.j.assertBuildStatus(Result.FAILURE, story.j.waitForCompletion(r)); - story.j.assertLogContains("File test.xml reported 1.625% of errors [FAILURE]. Build status is: FAILURE", r); - } + story.then(step -> { + DumbSlave s = story.j.createOnlineSlave(); + s.setLabelString("test performance report DSL function"); + WorkflowJob p = story.j.createProject(WorkflowJob.class, "demo"); + p.setDefinition(new CpsFlowDefinition( + "node{ writeFile file: 'test.xml', text: '''" + report + + "'''; perfReport errorFailedThreshold: 0, errorUnstableThreshold: 0, sourceDataFiles: 'test.xml' }", + true)); + WorkflowRun r = p.scheduleBuild2(0).waitForStart(); + story.j.assertBuildStatus(Result.FAILURE, story.j.waitForCompletion(r)); + story.j.assertLogContains("File test.xml reported 1.625% of errors [FAILURE]. Build status is: FAILURE", r); }); } diff --git a/src/test/java/hudson/plugins/performance/PerformancePublisherTest.java b/src/test/java/hudson/plugins/performance/PerformancePublisherTest.java index 49bece43..9e93911d 100644 --- a/src/test/java/hudson/plugins/performance/PerformancePublisherTest.java +++ b/src/test/java/hudson/plugins/performance/PerformancePublisherTest.java @@ -1,5 +1,34 @@ package hudson.plugins.performance; +import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.Issue; +import org.jvnet.hudson.test.JenkinsRule; +import org.jvnet.hudson.test.JenkinsRule.WebClient; +import org.jvnet.hudson.test.TestBuilder; + +import edu.umd.cs.findbugs.annotations.NonNull; import hudson.EnvVars; import hudson.FilePath; import hudson.Launcher; @@ -23,37 +52,22 @@ import hudson.plugins.performance.reports.UriReport; import hudson.util.StreamTaskListener; import jenkins.util.BuildListenerAdapter; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.jvnet.hudson.test.Bug; -import org.jvnet.hudson.test.HudsonTestCase; -import org.jvnet.hudson.test.TestBuilder; - -import edu.umd.cs.findbugs.annotations.NonNull; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.PrintStream; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; /** * @author Kohsuke Kawaguchi */ -public class PerformancePublisherTest extends HudsonTestCase { +public class PerformancePublisherTest { + + @Rule + public final JenkinsRule jenkinsRule = new JenkinsRule(); @Test public void testBuild() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = jenkinsRule.createFreeStyleProject(); p.getBuildersList().add(new TestBuilder() { @Override public boolean perform(AbstractBuild build, - Launcher launcher, BuildListener listener) + Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("test.jtl").copyFrom( getClass().getResource("/JMeterResults.jtl")); @@ -61,15 +75,16 @@ public boolean perform(AbstractBuild build, } }); p.getPublishersList().add( - new PerformancePublisher("", 0, 0, "", 0, 0, 0, 0, 0, false, "", false, false, false, false,false, null)); + new PerformancePublisher("", 0, 0, "", 0, 0, 0, 0, 0, false, "", false, false, false, false, false, + null)); - FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0).get()); + FreeStyleBuild b = jenkinsRule.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); PerformanceBuildAction a = b.getAction(PerformanceBuildAction.class); try { //assertNotNull(a); // poke a few random pages to verify rendering - WebClient wc = createWebClient(); + WebClient wc = jenkinsRule.createWebClient(); wc.getPage(b, "performance"); wc.getPage(b, "performance/uriReport/test.jtl:Home.endperformanceparameter/"); } catch (Exception e) { @@ -79,11 +94,11 @@ public boolean perform(AbstractBuild build, @Test public void testStandardResultsXML() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = jenkinsRule.createFreeStyleProject(); p.getBuildersList().add(new TestBuilder() { @Override public boolean perform(AbstractBuild build, - Launcher launcher, BuildListener listener) + Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("test.jtl").copyFrom(getClass().getResource("/JMeterResults.jtl")); return true; @@ -93,14 +108,16 @@ public boolean perform(AbstractBuild build, List parsers = new ArrayList(); parsers.add(new JMeterParser("test.jtl", PerformanceReportTest.DEFAULT_PERCENTILES)); - PerformancePublisher publisher = new PerformancePublisher("", 0, 0, "", 0, 0, 0, 0, 0, false, "", false, false, false, false,false, parsers); + PerformancePublisher publisher = new PerformancePublisher("", 0, 0, "", 0, 0, 0, 0, 0, false, "", false, false, + false, false, false, parsers); publisher.setModeEvaluation(false); p.getPublishersList().add(publisher); - FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0).get()); + FreeStyleBuild b = jenkinsRule.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); b.getAction(PerformanceBuildAction.class); - String standardExportFilename = b.getRootDir().getAbsolutePath() + File.separator + "archive" + File.separator + "standardResults.xml"; + String standardExportFilename = b.getRootDir().getAbsolutePath() + File.separator + "archive" + File.separator + + "standardResults.xml"; String content = new String(Files.readAllBytes(Paths.get(standardExportFilename))); Assert.assertEquals("\n" + "\n" + @@ -131,11 +148,11 @@ public boolean perform(AbstractBuild build, @Test public void testBuildWithParameters() throws Exception { - FreeStyleProject p = createFreeStyleProject("JobTest"); + FreeStyleProject p = jenkinsRule.createFreeStyleProject("JobTest"); p.getBuildersList().add(new TestBuilder() { @Override public boolean perform(AbstractBuild build, - Launcher launcher, BuildListener listener) + Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("JobTest/test.jtl").copyFrom( getClass().getResource("/JMeterResults.jtl")); @@ -143,15 +160,16 @@ public boolean perform(AbstractBuild build, } }); p.getPublishersList().add( - new PerformancePublisher("", 0, 0, "", 0, 0, 0, 0, 0, false, "", false, false, false, false,false, null)); + new PerformancePublisher("", 0, 0, "", 0, 0, 0, 0, 0, false, "", false, false, false, false, false, + null)); - FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0).get()); + FreeStyleBuild b = jenkinsRule.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); PerformanceBuildAction a = b.getAction(PerformanceBuildAction.class); try { //assertNotNull(a); // poke a few random pages to verify rendering - WebClient wc = createWebClient(); + WebClient wc = jenkinsRule.createWebClient(); wc.getPage(b, "performance"); wc.getPage(b, "performance/uriReport/test.jtl:Home.endperformanceparameter/"); } catch (Exception e) { @@ -162,11 +180,11 @@ public boolean perform(AbstractBuild build, @Test public void testBuildUnstableResponseThreshold() throws Exception { - FreeStyleProject p = createFreeStyleProject("TestJob"); + FreeStyleProject p = jenkinsRule.createFreeStyleProject("TestJob"); p.getBuildersList().add(new TestBuilder() { @Override public boolean perform(AbstractBuild build, - Launcher launcher, BuildListener listener) + Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("test.jtl").copyFrom( getClass().getResource("/JMeterResults.jtl")); @@ -174,16 +192,16 @@ public boolean perform(AbstractBuild build, } }); p.getPublishersList().add( - new PerformancePublisher("test.jtl", 0, 0, "test.jtl:100", 0, 0, 0, 0, 0, false, "", false, false, false, false,false, null)); + new PerformancePublisher("test.jtl", 0, 0, "test.jtl:100", 0, 0, 0, 0, 0, false, "", false, false, + false, false, false, null)); - FreeStyleBuild b = assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get()); + FreeStyleBuild b = jenkinsRule.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get()); PerformanceBuildAction a = b.getAction(PerformanceBuildAction.class); try { - //assertNotNull(a); - + assertNotNull(a); // poke a few random pages to verify rendering - WebClient wc = createWebClient(); + WebClient wc = jenkinsRule.createWebClient(); wc.getPage(b, "performance"); wc.getPage(b, "performance/uriReport/test.jtl:Home.endperformanceparameter/"); } catch (Exception e) { @@ -193,11 +211,11 @@ public boolean perform(AbstractBuild build, @Test public void testBuildStableResponseThreshold() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = jenkinsRule.createFreeStyleProject(); p.getBuildersList().add(new TestBuilder() { @Override public boolean perform(AbstractBuild build, - Launcher launcher, BuildListener listener) + Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("test.jtl").copyFrom( getClass().getResource("/JMeterResults.jtl")); @@ -205,16 +223,17 @@ public boolean perform(AbstractBuild build, } }); p.getPublishersList().add( - new PerformancePublisher("", 0, 0, "test.jtl:5000", 0, 0, 0, 0, 0, false, "", false, false, false, false,false, null)); + new PerformancePublisher("", 0, 0, "test.jtl:5000", 0, 0, 0, 0, 0, false, "", false, false, false, + false, false, null)); - FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0).get()); + FreeStyleBuild b = jenkinsRule.assertBuildStatusSuccess(p.scheduleBuild2(0).get()); PerformanceBuildAction a = b.getAction(PerformanceBuildAction.class); try { //assertNotNull(a); // poke a few random pages to verify rendering - WebClient wc = createWebClient(); + WebClient wc = jenkinsRule.createWebClient(); wc.getPage(b, "performance"); wc.getPage(b, "performance/uriReport/test.jtl:Home.endperformanceparameter/"); } catch (Exception e) { @@ -222,23 +241,24 @@ public boolean perform(AbstractBuild build, } } - @Bug(22011) - //TODO - Fix this test case, it was not compiling with forking over - //and now its not passing due to second build being successful, - //not failing due to threshold problems Ignore flag not being - //used, have to look at dependency tree, most likely pre 4.x - //junit dependency + @Issue("JENKINS-22011") + // TODO - Fix this test case, it was not compiling with forking over + // and now its not passing due to second build being successful, + // not failing due to threshold problems Ignore flag not being + // used, have to look at dependency tree, most likely pre 4.x + // junit dependency @Ignore public void buildUnstableAverageResponseTimeRelativeThreshold() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = jenkinsRule.createFreeStyleProject(); p.getPublishersList().add( - new PerformancePublisher("", 0, 0, null, 100.0d, 0, 50.0d, 0, 0, false, "ART", true, false, true, false,false, null)); + new PerformancePublisher("", 0, 0, null, 100.0d, 0, 50.0d, 0, 0, false, "ART", true, false, true, false, + false, null)); // first build p.getBuildersList().add(new TestBuilder() { @Override public boolean perform(AbstractBuild build, - Launcher launcher, BuildListener listener) + Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("test1.xml").copyFrom( getClass().getResource("/TEST-JUnitResults-relative-thrashould.xml")); @@ -246,14 +266,13 @@ public boolean perform(AbstractBuild build, } }); - assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()); - + jenkinsRule.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()); // second build with high time p.getBuildersList().add(new TestBuilder() { @Override public boolean perform(AbstractBuild build, - Launcher launcher, BuildListener listener) + Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("test2.xml").copyFrom( getClass().getResource("/TEST-JUnitResults-relative-thrashould-2.xml")); @@ -261,18 +280,19 @@ public boolean perform(AbstractBuild build, } }); - assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get()); + jenkinsRule.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get()); } @Test public void testEmptyReportParsersList() throws Exception { PerformancePublisher publisher = new PerformancePublisher("", 0, 0, "", 0.0, 0.0, 0.0, 0.0, 0, true, "MRT", - true, true, true, true,false, null); - RunExt run = new RunExt( createFreeStyleProject()); + true, true, true, true, false, null); + RunExt run = new RunExt(jenkinsRule.createFreeStyleProject()); run.onStartBuilding(); try { - publisher.perform(run, new FilePath(new File(".")), createLocalLauncher(), createTaskListener()); + publisher.perform(run, new FilePath(new File(".")), jenkinsRule.createLocalLauncher(), + jenkinsRule.createTaskListener()); } catch (NullPointerException ex) { fail("Plugin must work with empty parser list" + ex.getMessage()); } @@ -293,8 +313,9 @@ protected void onStartBuilding() { @Test public void testOptionMethods() throws Exception { final double DELTA = 0.001; - PerformancePublisher publisher = new PerformancePublisher("reportFile.xml", 15, 16, "reportFile.xml:100", 9.0, 8.0, 7.0, 6.0, 3, true, "MRT", - true, true, true, true,false, null); + PerformancePublisher publisher = new PerformancePublisher("reportFile.xml", 15, 16, "reportFile.xml:100", 9.0, + 8.0, 7.0, 6.0, 3, true, "MRT", + true, true, true, true, false, null); assertEquals("reportFile.xml", publisher.getSourceDataFiles()); assertEquals(15, publisher.getErrorFailedThreshold()); assertEquals(16, publisher.getErrorUnstableThreshold()); @@ -356,14 +377,17 @@ public void testOptionMethods() throws Exception { publisher.setConstraints(allConstraints); assertEquals(allConstraints, publisher.getConstraints()); - publisher = new PerformancePublisher("reportFile.xml", 15, 16, "reportFile.xml:100", 9.0, 8.0, 7.0, 6.0, 3, true, "MRT", - true, true, true, true,false, null); + publisher = new PerformancePublisher("reportFile.xml", 15, 16, "reportFile.xml:100", 9.0, 8.0, 7.0, 6.0, 3, + true, "MRT", + true, true, true, true, false, null); assertTrue(publisher.isMRT()); - publisher = new PerformancePublisher("reportFile.xml", 15, 16, "reportFile.xml:100", 9.0, 8.0, 7.0, 6.0, 3, true, "ART", - true, true, true, true,false, null); + publisher = new PerformancePublisher("reportFile.xml", 15, 16, "reportFile.xml:100", 9.0, 8.0, 7.0, 6.0, 3, + true, "ART", + true, true, true, true, false, null); assertTrue(publisher.isART()); - publisher = new PerformancePublisher("reportFile.xml", 15, 16, "reportFile.xml:100", 9.0, 8.0, 7.0, 6.0, 3, true, "PRT", - true, true, true, true,false, null); + publisher = new PerformancePublisher("reportFile.xml", 15, 16, "reportFile.xml:100", 9.0, 8.0, 7.0, 6.0, 3, + true, "PRT", + true, true, true, true, false, null); assertTrue(publisher.isPRT()); publisher.setFilename("testfilename"); @@ -379,12 +403,12 @@ public void testErrorThresholdUnstable() throws Exception { PerformancePublisher publisherUnstable = new PerformancePublisher("JMeterPublisher.csv", -1, - 1, // errorUnstableThreshold + 1, // errorUnstableThreshold "", 0.0, 0.0, 0.0, 0.0, 1, true, "MRT", false, // modeOfThreshold (false = Error Threshold) - true, true, true,false, null); + true, true, true, false, null); - FreeStyleProject project = createFreeStyleProject(); + FreeStyleProject project = jenkinsRule.createFreeStyleProject(); PerformanceTestBuildTest.FreeStyleBuildExt buildExt = new PerformanceTestBuildTest.FreeStyleBuildExt(project); buildExt.setWorkspace(new FilePath(Files.createTempDirectory(null).toFile())); @@ -395,23 +419,26 @@ public void testErrorThresholdUnstable() throws Exception { getClass().getResource("/JMeterPublisher.csv")); ByteArrayOutputStream stream = new ByteArrayOutputStream(); - publisherUnstable.perform(buildExt, buildExt.getWorkspace(), createLocalLauncher(), new BuildListenerAdapter(new StreamTaskListener(stream))); + publisherUnstable.perform(buildExt, buildExt.getWorkspace(), jenkinsRule.createLocalLauncher(), + new BuildListenerAdapter(new StreamTaskListener(stream, StandardCharsets.UTF_8))); String log = new String(stream.toByteArray()); - assertEquals(log, Result.UNSTABLE, buildExt.getResult()); - assertTrue(log, log.contains("Performance: File JMeterPublisher.csv reported 33.333% of errors [UNSTABLE]. Build status is: UNSTABLE")); + assertEquals(Result.UNSTABLE, buildExt.getResult(), log); + assertTrue(log.contains( + "Performance: File JMeterPublisher.csv reported 33.333% of errors [UNSTABLE]. Build status is: UNSTABLE"), + log); } @Test public void testErrorThresholdFailed() throws Exception { PerformancePublisher publisherFailed = new PerformancePublisher("JMeterPublisher.csv", - 2, //errorFailedThreshold + 2, // errorFailedThreshold -1, "", 0.0, 0.0, 0.0, 0.0, 1, true, "MRT", false, // modeOfThreshold (false = Error Threshold) - true, true, true,false, null); + true, true, true, false, null); - FreeStyleProject project = createFreeStyleProject(); + FreeStyleProject project = jenkinsRule.createFreeStyleProject(); PerformanceTestBuildTest.FreeStyleBuildExt buildExt = new PerformanceTestBuildTest.FreeStyleBuildExt(project); buildExt.setWorkspace(new FilePath(Files.createTempDirectory(null).toFile())); @@ -422,11 +449,14 @@ public void testErrorThresholdFailed() throws Exception { getClass().getResource("/JMeterPublisher.csv")); ByteArrayOutputStream stream = new ByteArrayOutputStream(); - publisherFailed.perform(buildExt, buildExt.getWorkspace(), createLocalLauncher(), new BuildListenerAdapter(new StreamTaskListener(stream))); + publisherFailed.perform(buildExt, buildExt.getWorkspace(), jenkinsRule.createLocalLauncher(), + new BuildListenerAdapter(new StreamTaskListener(stream, StandardCharsets.UTF_8))); String log = new String(stream.toByteArray()); - assertEquals(log, Result.FAILURE, buildExt.getResult()); - assertTrue(log, log.contains("Performance: File JMeterPublisher.csv reported 33.333% of errors [FAILURE]. Build status is: FAILURE")); + assertEquals(Result.FAILURE, buildExt.getResult(), log); + assertTrue(log.contains( + "Performance: File JMeterPublisher.csv reported 33.333% of errors [FAILURE]. Build status is: FAILURE"), + log); } @Test @@ -435,9 +465,9 @@ public void testErrorThresholdAverageResponseTime() throws Exception { PerformancePublisher publisherART = new PerformancePublisher("JMeterPublisher.csv", -1, -1, "JMeterPublisher.csv:1000", 0.0, 0.0, 0.0, 0.0, 1, true, "MRT", false, // modeOfThreshold (false = Error Threshold) - true, true, true,false, null); + true, true, true, false, null); - FreeStyleProject project = createFreeStyleProject(); + FreeStyleProject project = jenkinsRule.createFreeStyleProject(); PerformanceTestBuildTest.FreeStyleBuildExt buildExt = new PerformanceTestBuildTest.FreeStyleBuildExt(project); buildExt.setWorkspace(new FilePath(Files.createTempDirectory(null).toFile())); @@ -448,21 +478,23 @@ public void testErrorThresholdAverageResponseTime() throws Exception { getClass().getResource("/JMeterPublisher.csv")); ByteArrayOutputStream stream = new ByteArrayOutputStream(); - publisherART.perform(buildExt, buildExt.getWorkspace(), createLocalLauncher(), new BuildListenerAdapter(new StreamTaskListener(stream))); + publisherART.perform(buildExt, buildExt.getWorkspace(), jenkinsRule.createLocalLauncher(), + new BuildListenerAdapter(new StreamTaskListener(stream, StandardCharsets.UTF_8))); String log = new String(stream.toByteArray()); - assertEquals(log, Result.UNSTABLE, buildExt.getResult()); - assertTrue(log, log.contains("UNSTABLE: JMeterPublisher.csv has exceeded the threshold of [1000] with the time of [1433]")); - + assertEquals(Result.UNSTABLE, buildExt.getResult(), log); + assertTrue(log.contains( + "UNSTABLE: JMeterPublisher.csv has exceeded the threshold of [1000] with the time of [1433]"), log); // For Number Format Exception publisherART.setErrorUnstableResponseTimeThreshold("JMeterPublisher.csv:1!00"); stream = new ByteArrayOutputStream(); - publisherART.perform(buildExt, buildExt.getWorkspace(), createLocalLauncher(), new BuildListenerAdapter(new StreamTaskListener(stream))); + publisherART.perform(buildExt, buildExt.getWorkspace(), jenkinsRule.createLocalLauncher(), + new BuildListenerAdapter(new StreamTaskListener(stream, StandardCharsets.UTF_8))); log = new String(stream.toByteArray()); - assertEquals(log, Result.FAILURE, buildExt.getResult()); - assertTrue(log, log.contains("ERROR: Threshold set to a non-number [1!00]")); + assertEquals(Result.FAILURE, buildExt.getResult(), log); + assertTrue(log.contains("ERROR: Threshold set to a non-number [1!00]"), log); } @Test @@ -471,7 +503,8 @@ public void testMigration() throws Exception { parsers.add(new JMeterCsvParser("test1", PerformanceReportTest.DEFAULT_PERCENTILES)); parsers.add(new JMeterParser("test2", PerformanceReportTest.DEFAULT_PERCENTILES)); - PerformancePublisher publisher = new PerformancePublisher("", -1, -1, "", 0.0, 0.0, 0.0, 0.0, 1, true, "MRT", false, true, true, true,false, parsers); + PerformancePublisher publisher = new PerformancePublisher("", -1, -1, "", 0.0, 0.0, 0.0, 0.0, 1, true, "MRT", + false, true, true, true, false, parsers); assertEquals("test1;test2", publisher.getSourceDataFiles()); assertNull(publisher.getParsers()); @@ -488,20 +521,20 @@ public void testMigration() throws Exception { @Test public void testRelativeThresholdUnstableNegative() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = jenkinsRule.createFreeStyleProject(); PerformancePublisher publisher = new PerformancePublisher("JMeterCsvResults.csv", -1, -1, "", -0.1, -0.1, -0.1, 5.0, // relativeUnstableThresholdNegative 1, true, "MRT", true, // modeOfThreshold (true = Relative Threshold) - true, true, true,false, null); + true, true, true, false, null); p.getPublishersList().add(publisher); // first build p.getBuildersList().add(new TestBuilder() { @Override public boolean perform(AbstractBuild build, - Launcher launcher, BuildListener listener) + Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("JMeterCsvResults.csv").copyFrom( getClass().getResource("/JMeterCsvResults.csv")); @@ -512,30 +545,30 @@ public boolean perform(AbstractBuild build, } }); - assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()); + jenkinsRule.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()); publisher.setSourceDataFiles("JMeterPublisher.csv"); - assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get()); + jenkinsRule.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get()); } @Test public void testRelativeThresholdUnstablePositive() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = jenkinsRule.createFreeStyleProject(); PerformancePublisher publisher = new PerformancePublisher("JMeterPublisher.csv", -1, -1, "", -0.1, -0.1, 9.0, // relativeUnstableThresholdPositive -0.1, // relativeUnstableThresholdNegative 1, true, "ART", true, // modeOfThreshold (true = Relative Threshold) - true, true, true,false, null); + true, true, true, false, null); p.getPublishersList().add(publisher); // first build p.getBuildersList().add(new TestBuilder() { @Override public boolean perform(AbstractBuild build, - Launcher launcher, BuildListener listener) + Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("JMeterCsvResults.csv").copyFrom( getClass().getResource("/JMeterCsvResults.csv")); @@ -546,30 +579,30 @@ public boolean perform(AbstractBuild build, } }); - assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()); + jenkinsRule.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()); publisher.setSourceDataFiles("JMeterCsvResults.csv"); - assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get()); + jenkinsRule.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get()); } @Test public void testRelativeThresholdFailedNegative() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = jenkinsRule.createFreeStyleProject(); PerformancePublisher publisher = new PerformancePublisher("JMeterCsvResults.csv", -1, -1, "", -0.1, 5.1, // relativeFailedThresholdNegative -0.1, -0.1, 1, true, "PRT", true, // modeOfThreshold (true = Relative Threshold) true, false, // false - means compare with Build Number - true,false, null); + true, false, null); p.getPublishersList().add(publisher); // first build p.getBuildersList().add(new TestBuilder() { @Override public boolean perform(AbstractBuild build, - Launcher launcher, BuildListener listener) + Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("JMeterCsvResults.csv").copyFrom( getClass().getResource("/JMeterCsvResults.csv")); @@ -580,30 +613,30 @@ public boolean perform(AbstractBuild build, } }); - assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()); + jenkinsRule.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()); publisher.setSourceDataFiles("JMeterPublisher.csv"); - assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get()); + jenkinsRule.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get()); } @Test public void testRelativeThresholdFailedPositive() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = jenkinsRule.createFreeStyleProject(); PerformancePublisher publisher = new PerformancePublisher("JMeterPublisher.csv", -1, -1, "", 5.1, // relativeFailedThresholdPositive -0.1, -0.1, -0.1, 1, true, "PRT", true, // modeOfThreshold (true = Relative Threshold) true, false, // false - means compare with Build Number - true,false, null); + true, false, null); p.getPublishersList().add(publisher); // first build p.getBuildersList().add(new TestBuilder() { @Override public boolean perform(AbstractBuild build, - Launcher launcher, BuildListener listener) + Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child("JMeterCsvResults.csv").copyFrom( getClass().getResource("/JMeterCsvResults.csv")); @@ -614,28 +647,31 @@ public boolean perform(AbstractBuild build, } }); - assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()); + jenkinsRule.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()); publisher.setSourceDataFiles("JMeterCsvResults.csv"); - assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get()); + jenkinsRule.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get()); } public void testRelativeThresholds() throws Exception { - FreeStyleProject freeStyleProject = createFreeStyleProject(); + FreeStyleProject freeStyleProject = jenkinsRule.createFreeStyleProject(); final RunExt prevBuild = new RunExt(freeStyleProject); prevBuild.onStartBuilding(); PerformancePublisher publisher = new PerformancePublisher("") { @Override - protected List getParsers(Run build, FilePath workspace, PrintStream logger, EnvVars env) throws IOException, InterruptedException { + protected List getParsers(Run build, FilePath workspace, PrintStream logger, + EnvVars env) throws IOException, InterruptedException { List parsers = new ArrayList<>(); parsers.add(new JMeterCsvParser("", "")); return parsers; } @Override - public Collection prepareEvaluation(Run run, FilePath workspace, TaskListener listener, List parsers) throws IOException, InterruptedException { + public Collection prepareEvaluation(Run run, FilePath workspace, + TaskListener listener, List parsers) + throws IOException, InterruptedException { List reports = new ArrayList<>(); reports.add(new PerformanceReport()); reports.add(new PerformanceReport()); @@ -643,7 +679,9 @@ public Collection prepareEvaluation(Run run, FilePath w } @Override - protected List getBuildUriReports(Run build, FilePath workspace, TaskListener listener, List parsers, boolean locatePerformanceReports) throws IOException, InterruptedException { + protected List getBuildUriReports(Run build, FilePath workspace, TaskListener listener, + List parsers, boolean locatePerformanceReports) + throws IOException, InterruptedException { List uriReports = new ArrayList<>(); if (locatePerformanceReports) { UriReport report = new UriReport(new PerformanceReport(), "aaaaa", "bbbbb"); @@ -672,19 +710,22 @@ protected List getBuildUriReports(Run build, FilePath workspace RunExt run1 = new RunExt(freeStyleProject); run1.onStartBuilding(); - publisher.perform(run1, new FilePath(new File(".")), createLocalLauncher(), createTaskListener()); + publisher.perform(run1, new FilePath(new File(".")), jenkinsRule.createLocalLauncher(), + jenkinsRule.createTaskListener()); assertEquals(Result.SUCCESS, run1.getResult()); publisher.setRelativeUnstableThresholdNegative(10); RunExt run2 = new RunExt(freeStyleProject); run2.onStartBuilding(); - publisher.perform(run2, new FilePath(new File(".")), createLocalLauncher(), createTaskListener()); + publisher.perform(run2, new FilePath(new File(".")), jenkinsRule.createLocalLauncher(), + jenkinsRule.createTaskListener()); assertEquals(Result.UNSTABLE, run2.getResult()); publisher.setRelativeFailedThresholdNegative(10); RunExt run3 = new RunExt(freeStyleProject); run3.onStartBuilding(); - publisher.perform(run3, new FilePath(new File(".")), createLocalLauncher(), createTaskListener()); + publisher.perform(run3, new FilePath(new File(".")), jenkinsRule.createLocalLauncher(), + jenkinsRule.createTaskListener()); assertEquals(Result.FAILURE, run3.getResult()); } } \ No newline at end of file diff --git a/src/test/java/hudson/plugins/performance/build/PerformanceTestBuildTest.java b/src/test/java/hudson/plugins/performance/build/PerformanceTestBuildTest.java index e1481e76..310a7ca7 100644 --- a/src/test/java/hudson/plugins/performance/build/PerformanceTestBuildTest.java +++ b/src/test/java/hudson/plugins/performance/build/PerformanceTestBuildTest.java @@ -1,9 +1,14 @@ package hudson.plugins.performance.build; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Arrays; import java.util.Iterator; @@ -13,8 +18,9 @@ import edu.umd.cs.findbugs.annotations.NonNull; import org.jenkinsci.plugins.workflow.job.WorkflowJob; +import org.junit.Rule; import org.junit.Test; -import org.jvnet.hudson.test.HudsonTestCase; +import org.jvnet.hudson.test.JenkinsRule; import hudson.EnvVars; import hudson.FilePath; @@ -30,14 +36,16 @@ import hudson.util.StreamTaskListener; import jenkins.util.BuildListenerAdapter; +public class PerformanceTestBuildTest { -public class PerformanceTestBuildTest extends HudsonTestCase { + @Rule + public final JenkinsRule jenkinsRule = new JenkinsRule(); @Test public void testFlow() throws Exception { String path = getClass().getResource("/performanceTest.yml").getPath(); - FreeStyleProject project = createFreeStyleProject(); + FreeStyleProject project = jenkinsRule.createFreeStyleProject(); FreeStyleBuildExt buildExt = new FreeStyleBuildExt(project); FilePath workspace = new FilePath(Files.createTempDirectory(null).toFile()); @@ -46,7 +54,9 @@ public void testFlow() throws Exception { buildExt.getRootDir().mkdirs(); - PerformanceTestBuild buildTest = new PerformanceTestBuild(new File(path).getAbsolutePath() + ' ' + "-o modules.jmeter.plugins=[] -o services=[] -o modules.jmeter.version=3.1 -o modules.jmeter.path=" + workspace.getRemote()); + PerformanceTestBuild buildTest = new PerformanceTestBuild(new File(path).getAbsolutePath() + ' ' + + "-o modules.jmeter.plugins=[] -o services=[] -o modules.jmeter.version=3.1 -o modules.jmeter.path=" + + workspace.getRemote()); buildTest.setGeneratePerformanceTrend(true); buildTest.setPrintDebugOutput(true); buildTest.setUseSystemSitePackages(false); @@ -54,10 +64,10 @@ public void testFlow() throws Exception { assertEquals(PerformanceProjectAction.class, buildTest.getProjectAction((AbstractProject) project).getClass()); - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - StreamTaskListener taskListener = new StreamTaskListener(stream); - buildTest.perform(buildExt, buildExt.getWorkspace(), createLocalLauncher(), new BuildListenerAdapter(taskListener)); + StreamTaskListener taskListener = new StreamTaskListener(stream, StandardCharsets.UTF_8); + buildTest.perform(buildExt, buildExt.getWorkspace(), jenkinsRule.createLocalLauncher(), + new BuildListenerAdapter(taskListener)); Iterator iterator = project.getPublishersList().iterator(); StringBuilder builder = new StringBuilder("\n\nList publishers:\n"); @@ -67,7 +77,7 @@ public void testFlow() throws Exception { String jobLog = new String(stream.toByteArray()) + builder.toString(); - assertEquals(jobLog, Result.SUCCESS, buildExt.getResult()); + assertEquals(Result.SUCCESS, buildExt.getResult(), jobLog); } @Test @@ -75,7 +85,7 @@ public void testInstallFromGit() throws Exception { String path = getClass().getResource("/performanceTest.yml").getPath(); String gitRepo = "git+https://github.com/Blazemeter/taurus.git"; - FreeStyleProject project = createFreeStyleProject(); + FreeStyleProject project = jenkinsRule.createFreeStyleProject(); FreeStyleBuildExt buildExt = new FreeStyleBuildExt(project); FilePath workspace = new FilePath(Files.createTempDirectory(null).toFile()); @@ -93,8 +103,9 @@ public void testInstallFromGit() throws Exception { buildTest.setBztVersion(gitRepo); ByteArrayOutputStream stream = new ByteArrayOutputStream(); - StreamTaskListener taskListener = new StreamTaskListener(stream); - buildTest.perform(buildExt, buildExt.getWorkspace(), createLocalLauncher(), new BuildListenerAdapter(taskListener)); + StreamTaskListener taskListener = new StreamTaskListener(stream, StandardCharsets.UTF_8); + buildTest.perform(buildExt, buildExt.getWorkspace(), jenkinsRule.createLocalLauncher(), + new BuildListenerAdapter(taskListener)); Iterator iterator = project.getPublishersList().iterator(); StringBuilder builder = new StringBuilder("\n\nList publishers:\n"); @@ -104,9 +115,11 @@ public void testInstallFromGit() throws Exception { String jobLog = new String(stream.toByteArray()) + builder.toString(); - assertEquals(jobLog, Result.SUCCESS, buildExt.getResult()); - assertEquals(jobLog, 5, buildTest.commands.size()); - assertTrue(jobLog, Arrays.toString(buildTest.commands.get(buildTest.commands.size() - 3)).contains("install, " + gitRepo)); + assertEquals(Result.SUCCESS, buildExt.getResult(), jobLog); + assertEquals(5, buildTest.commands.size(), jobLog); + assertTrue( + Arrays.toString(buildTest.commands.get(buildTest.commands.size() - 3)).contains("install, " + gitRepo), + jobLog); } @Test @@ -114,7 +127,7 @@ public void testInstallFromURL() throws Exception { String path = getClass().getResource("/performanceTest.yml").getPath(); String url = "http://gettaurus.org/snapshots/bzt-1.9.5.1622.tar.gz"; - FreeStyleProject project = createFreeStyleProject(); + FreeStyleProject project = jenkinsRule.createFreeStyleProject(); FreeStyleBuildExt buildExt = new FreeStyleBuildExt(project); FilePath workspace = new FilePath(Files.createTempDirectory(null).toFile()); @@ -132,8 +145,9 @@ public void testInstallFromURL() throws Exception { buildTest.setBztVersion(url); ByteArrayOutputStream stream = new ByteArrayOutputStream(); - StreamTaskListener taskListener = new StreamTaskListener(stream); - buildTest.perform(buildExt, buildExt.getWorkspace(), createLocalLauncher(), new BuildListenerAdapter(taskListener)); + StreamTaskListener taskListener = new StreamTaskListener(stream, StandardCharsets.UTF_8); + buildTest.perform(buildExt, buildExt.getWorkspace(), jenkinsRule.createLocalLauncher(), + new BuildListenerAdapter(taskListener)); Iterator iterator = project.getPublishersList().iterator(); StringBuilder builder = new StringBuilder("\n\nList publishers:\n"); @@ -143,16 +157,17 @@ public void testInstallFromURL() throws Exception { String jobLog = new String(stream.toByteArray()) + builder.toString(); - assertEquals(jobLog, Result.SUCCESS, buildExt.getResult()); - assertEquals(jobLog, 5, buildTest.commands.size()); - assertTrue(jobLog, Arrays.toString(buildTest.commands.get(buildTest.commands.size() - 3)).contains("install, " + url)); + assertEquals(Result.SUCCESS, buildExt.getResult(), jobLog); + assertEquals(5, buildTest.commands.size(), jobLog); + assertTrue(Arrays.toString(buildTest.commands.get(buildTest.commands.size() - 3)).contains("install, " + url), + jobLog); } @Test public void testInstallFromPath() throws Exception { String path = getClass().getResource("/performanceTest.yml").getPath(); - FreeStyleProject project = createFreeStyleProject(); + FreeStyleProject project = jenkinsRule.createFreeStyleProject(); FreeStyleBuildExt buildExt = new FreeStyleBuildExt(project); FilePath workspace = new FilePath(Files.createTempDirectory(null).toFile()); @@ -170,8 +185,9 @@ public void testInstallFromPath() throws Exception { buildTest.setBztVersion(path); ByteArrayOutputStream stream = new ByteArrayOutputStream(); - StreamTaskListener taskListener = new StreamTaskListener(stream); - buildTest.perform(buildExt, buildExt.getWorkspace(), createLocalLauncher(), new BuildListenerAdapter(taskListener)); + StreamTaskListener taskListener = new StreamTaskListener(stream, StandardCharsets.UTF_8); + buildTest.perform(buildExt, buildExt.getWorkspace(), jenkinsRule.createLocalLauncher(), + new BuildListenerAdapter(taskListener)); Iterator iterator = project.getPublishersList().iterator(); StringBuilder builder = new StringBuilder("\n\nList publishers:\n"); @@ -181,9 +197,10 @@ public void testInstallFromPath() throws Exception { String jobLog = new String(stream.toByteArray()) + builder.toString(); - assertEquals(jobLog, Result.SUCCESS, buildExt.getResult()); - assertEquals(jobLog, 5, buildTest.commands.size()); - assertTrue(jobLog, Arrays.toString(buildTest.commands.get(buildTest.commands.size() - 3)).contains("install, " + path)); + assertEquals(Result.SUCCESS, buildExt.getResult(), jobLog); + assertEquals(5, buildTest.commands.size(), jobLog); + assertTrue(Arrays.toString(buildTest.commands.get(buildTest.commands.size() - 3)).contains("install, " + path), + jobLog); } public static class PerformanceTestBuildExt extends PerformanceTestBuild { @@ -194,7 +211,8 @@ public PerformanceTestBuildExt(String params) { public List commands = new LinkedList<>(); @Override - public int runCmd(String[] commands, FilePath workspace, OutputStream logger, Launcher launcher, EnvVars envVars) throws InterruptedException, IOException { + public int runCmd(String[] commands, FilePath workspace, OutputStream logger, Launcher launcher, + EnvVars envVars) throws InterruptedException, IOException { if (launcher instanceof Launcher.DummyLauncher) { super.runCmd(commands, workspace, logger, launcher, envVars); } @@ -203,7 +221,6 @@ public int runCmd(String[] commands, FilePath workspace, OutputStream logger, La } } - public static class FreeStyleBuildExt extends FreeStyleBuild { public FreeStyleBuildExt(FreeStyleProject project) throws IOException { @@ -267,12 +284,11 @@ public void testGetters() throws Exception { assertEquals("$VARIABLE_PATH/virtualenv", testBuild.getVirtualEnvCommand()); } - @Test public void testGenerateReportInPipe() throws Exception { String path = getClass().getResource("/performanceTest.yml").getPath(); - WorkflowJob p = jenkins.createProject(WorkflowJob.class, "p"); + WorkflowJob p = jenkinsRule.createProject(WorkflowJob.class, "p"); FilePath workspace = new FilePath(Files.createTempDirectory(null).toFile()); p.createExecutable(); Run run = p.getFirstBuild(); @@ -281,7 +297,6 @@ public void testGenerateReportInPipe() throws Exception { FilePath report = new FilePath(new File(workspace.getRemote(), "aggregate-results.xml")); report.copyFrom(getClass().getResource("/aggregate-results.xml")); - PerformanceTestBuildExt buildTest = new PerformanceTestBuildExt(args); buildTest.setGeneratePerformanceTrend(true); buildTest.setPrintDebugOutput(true); @@ -289,36 +304,37 @@ public void testGenerateReportInPipe() throws Exception { buildTest.setUseBztExitCode(false); ByteArrayOutputStream stream = new ByteArrayOutputStream(); - StreamTaskListener taskListener = new StreamTaskListener(stream); - buildTest.perform(run, workspace, createLocalLauncher(), new BuildListenerAdapter(taskListener)); - + StreamTaskListener taskListener = new StreamTaskListener(stream, StandardCharsets.UTF_8); + buildTest.perform(run, workspace, jenkinsRule.createLocalLauncher(), new BuildListenerAdapter(taskListener)); String jobLog = new String(stream.toByteArray()); File reportFile = new File(run.getRootDir(), "performance-reports/Taurus/aggregate-results.xml"); - assertTrue("Report file " + reportFile.getAbsolutePath() + " expected to exist", reportFile.exists()); - assertTrue("Job log expected to contains 'Performance: Recording Taurus reports', jobLog:" + jobLog, - jobLog.contains("Performance: Recording Taurus reports")); - assertTrue("Job log expected to contains 'aggregate-results.xml', jobLog:" + jobLog, jobLog.contains("aggregate-results.xml'")); - assertTrue("Job log expected to contains 'Performance: Parsing report file ...', jobLog:" + jobLog, - jobLog.contains("Performance: Parsing report file '" + reportFile.getAbsolutePath() + "' with filterRegex '" - + PerformanceReport.INCLUDE_ALL + "'.")); + assertTrue(reportFile.exists(), "Report file " + reportFile.getAbsolutePath() + " expected to exist"); + assertTrue(jobLog.contains("Performance: Recording Taurus reports"), + "Job log expected to contains 'Performance: Recording Taurus reports', jobLog:" + jobLog); + assertTrue(jobLog.contains("aggregate-results.xml'"), + "Job log expected to contains 'aggregate-results.xml', jobLog:" + jobLog); + assertTrue(jobLog.contains( + "Performance: Parsing report file '" + reportFile.getAbsolutePath() + "' with filterRegex '" + + PerformanceReport.INCLUDE_ALL + "'."), + "Job log expected to contains 'Performance: Parsing report file ...', jobLog:" + jobLog); } - @Test public void testFailCriteria() throws Exception { String path = getClass().getResource("/performanceTestWithFailCriteria.yml").getPath(); - WorkflowJob p = jenkins.createProject(WorkflowJob.class, "p"); + WorkflowJob p = jenkinsRule.createProject(WorkflowJob.class, "p"); FilePath workspace = new FilePath(Files.createTempDirectory(null).toFile()); p.createExecutable(); Run run = p.getFirstBuild(); - String args = new File(path).getAbsolutePath() + ' ' + "-o modules.jmeter.plugins=[] -o services=[]" ; + String args = new File(path).getAbsolutePath() + ' ' + "-o modules.jmeter.plugins=[] -o services=[]"; PerformanceTestBuild buildTest = new PerformanceTestBuildExt(args) { @Override - public int runCmd(String[] commands, FilePath workspace, OutputStream logger, Launcher launcher, EnvVars envVars) throws InterruptedException, IOException { + public int runCmd(String[] commands, FilePath workspace, OutputStream logger, Launcher launcher, + EnvVars envVars) throws InterruptedException, IOException { for (String cmd : commands) { if (cmd.contains("performanceTestWithFailCriteria.yml")) { logger.write("Done performing with code: 3".getBytes()); @@ -334,12 +350,12 @@ public int runCmd(String[] commands, FilePath workspace, OutputStream logger, La buildTest.setUseBztExitCode(true); ByteArrayOutputStream stream = new ByteArrayOutputStream(); - StreamTaskListener taskListener = new StreamTaskListener(stream); - buildTest.perform(run, workspace, createLocalLauncher(), new BuildListenerAdapter(taskListener)); + StreamTaskListener taskListener = new StreamTaskListener(stream, StandardCharsets.UTF_8); + buildTest.perform(run, workspace, jenkinsRule.createLocalLauncher(), new BuildListenerAdapter(taskListener)); String jobLog = new String(stream.toByteArray()); - assertEquals(jobLog, Result.UNSTABLE, run.getResult()); - assertTrue(jobLog, jobLog.contains("Done performing with code: 3")); + assertEquals(Result.UNSTABLE, run.getResult(), jobLog); + assertTrue(jobLog.contains("Done performing with code: 3"), jobLog); } @Test @@ -363,13 +379,13 @@ public void testResutsChecker() throws Exception { @Test public void testPWD() throws Exception { - WorkflowJob p = jenkins.createProject(WorkflowJob.class, "p"); + WorkflowJob p = jenkinsRule.createProject(WorkflowJob.class, "p"); File buildWorkspace = Files.createTempDirectory(null).toFile(); FilePath workspace = new FilePath(buildWorkspace); p.createExecutable(); Run run = p.getFirstBuild(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); - StreamTaskListener taskListener = new StreamTaskListener(stream); + StreamTaskListener taskListener = new StreamTaskListener(stream, StandardCharsets.UTF_8); PerformanceTestBuildExt testBuild = new PerformanceTestBuildExt(""); testBuild.setUseSystemSitePackages(false); @@ -378,29 +394,27 @@ public void testPWD() throws Exception { // test absolute path String absoluteWorkspace = "/tmp/o/work/bzt"; testBuild.setWorkspace(absoluteWorkspace); - testBuild.perform(run, workspace, createLocalLauncher(), new BuildListenerAdapter(taskListener)); + testBuild.perform(run, workspace, jenkinsRule.createLocalLauncher(), new BuildListenerAdapter(taskListener)); String jobLog = new String(stream.toByteArray()); - assertTrue(jobLog, new File(absoluteWorkspace).isDirectory()); - assertTrue(jobLog, new File(absoluteWorkspace).exists()); - assertTrue(jobLog, new File(absoluteWorkspace, "jenkins-report.yml").exists()); + assertTrue(new File(absoluteWorkspace).isDirectory(), jobLog); + assertTrue(new File(absoluteWorkspace).exists(), jobLog); + assertTrue(new File(absoluteWorkspace, "jenkins-report.yml").exists(), jobLog); // test relative path String relativeWorkspace = "oooooh/relative/path"; testBuild.setWorkspace(relativeWorkspace); - testBuild.perform(run, workspace, createLocalLauncher(), new BuildListenerAdapter(taskListener)); + testBuild.perform(run, workspace, jenkinsRule.createLocalLauncher(), new BuildListenerAdapter(taskListener)); jobLog = new String(stream.toByteArray()); - assertTrue(jobLog, new File(buildWorkspace, relativeWorkspace).isDirectory()); - assertTrue(jobLog, new File(buildWorkspace, relativeWorkspace).exists()); - assertTrue(jobLog, new File(buildWorkspace, relativeWorkspace + "/jenkins-report.yml").exists()); - - + assertTrue(new File(buildWorkspace, relativeWorkspace).isDirectory(), jobLog); + assertTrue(new File(buildWorkspace, relativeWorkspace).exists(), jobLog); + assertTrue(new File(buildWorkspace, relativeWorkspace + "/jenkins-report.yml").exists(), jobLog); // test Permission denied String rootPath = "/rootWorkspace/"; testBuild.setWorkspace(rootPath); - testBuild.perform(run, workspace, createLocalLauncher(), new BuildListenerAdapter(taskListener)); + testBuild.perform(run, workspace, jenkinsRule.createLocalLauncher(), new BuildListenerAdapter(taskListener)); jobLog = new String(stream.toByteArray()); - assertTrue(jobLog, jobLog.contains("Cannot create working directory because of error: /rootWorkspace")); + assertTrue(jobLog.contains("Cannot create working directory because of error: /rootWorkspace"), jobLog); } private void resetVirtualEnvCommands() { @@ -408,12 +422,13 @@ private void resetVirtualEnvCommands() { PerformanceTestBuild.CREATE_LOCAL_PYTHON_COMMAND_WITH_SYSTEM_PACKAGES_OPTION[0] = PerformanceTestBuild.VIRTUALENV_COMMAND; PerformanceTestBuild.CREATE_LOCAL_PYTHON_COMMAND[0] = PerformanceTestBuild.VIRTUALENV_COMMAND; } + @Test public void testDefaultVirtualEnvCommand() throws Exception { resetVirtualEnvCommands(); String path = getClass().getResource("/performanceTest.yml").getPath(); - FreeStyleProject project = createFreeStyleProject(); + FreeStyleProject project = jenkinsRule.createFreeStyleProject(); FreeStyleBuildExt buildExt = new FreeStyleBuildExt(project); FilePath workspace = new FilePath(Files.createTempDirectory(null).toFile()); @@ -430,8 +445,9 @@ public void testDefaultVirtualEnvCommand() throws Exception { buildTest.setAlwaysUseVirtualenv(true); ByteArrayOutputStream stream = new ByteArrayOutputStream(); - StreamTaskListener taskListener = new StreamTaskListener(stream); - buildTest.perform(buildExt, buildExt.getWorkspace(), new Launcher.DummyLauncher(taskListener), new BuildListenerAdapter(taskListener)); + StreamTaskListener taskListener = new StreamTaskListener(stream, StandardCharsets.UTF_8); + buildTest.perform(buildExt, buildExt.getWorkspace(), new Launcher.DummyLauncher(taskListener), + new BuildListenerAdapter(taskListener)); Iterator iterator = project.getPublishersList().iterator(); StringBuilder builder = new StringBuilder("\n\nList publishers:\n"); @@ -441,10 +457,10 @@ public void testDefaultVirtualEnvCommand() throws Exception { String jobLog = new String(stream.toByteArray()) + builder.toString(); - assertEquals(jobLog, Result.SUCCESS, buildExt.getResult()); - assertEquals(jobLog, 5, buildTest.commands.size()); - assertTrue("Command should have been 'virtualenv', but instead it was: '" + buildTest.commands.get(0)[0] + "'", - buildTest.commands.get(0)[0].equals("virtualenv")); + assertEquals(Result.SUCCESS, buildExt.getResult(), jobLog); + assertEquals(5, buildTest.commands.size(), jobLog); + assertTrue(buildTest.commands.get(0)[0].equals("virtualenv"), + "Command should have been 'virtualenv', but instead it was: '" + buildTest.commands.get(0)[0] + "'"); resetVirtualEnvCommands(); } @@ -453,7 +469,7 @@ public void testHardcodedVirtualEnvCommand() throws Exception { resetVirtualEnvCommands(); String path = getClass().getResource("/performanceTest.yml").getPath(); - FreeStyleProject project = createFreeStyleProject(); + FreeStyleProject project = jenkinsRule.createFreeStyleProject(); FreeStyleBuildExt buildExt = new FreeStyleBuildExt(project); FilePath workspace = new FilePath(Files.createTempDirectory(null).toFile()); @@ -471,8 +487,9 @@ public void testHardcodedVirtualEnvCommand() throws Exception { buildTest.setVirtualEnvCommand("/path/to/virtualenv"); ByteArrayOutputStream stream = new ByteArrayOutputStream(); - StreamTaskListener taskListener = new StreamTaskListener(stream); - buildTest.perform(buildExt, buildExt.getWorkspace(), new Launcher.DummyLauncher(taskListener), new BuildListenerAdapter(taskListener)); + StreamTaskListener taskListener = new StreamTaskListener(stream, StandardCharsets.UTF_8); + buildTest.perform(buildExt, buildExt.getWorkspace(), new Launcher.DummyLauncher(taskListener), + new BuildListenerAdapter(taskListener)); Iterator iterator = project.getPublishersList().iterator(); StringBuilder builder = new StringBuilder("\n\nList publishers:\n"); @@ -482,10 +499,11 @@ public void testHardcodedVirtualEnvCommand() throws Exception { String jobLog = new String(stream.toByteArray()) + builder.toString(); - assertEquals(jobLog, Result.SUCCESS, buildExt.getResult()); - assertEquals(jobLog, 5, buildTest.commands.size()); - assertTrue("Command should have been '/path/to/virtualenv', but instead it was: '" + buildTest.commands.get(0)[0] + "'", - buildTest.commands.get(0)[0].equals("/path/to/virtualenv")); + assertEquals(Result.SUCCESS, buildExt.getResult(), jobLog); + assertEquals(5, buildTest.commands.size(), jobLog); + assertTrue(buildTest.commands.get(0)[0].equals("/path/to/virtualenv"), + "Command should have been '/path/to/virtualenv', but instead it was: '" + buildTest.commands.get(0)[0] + + "'"); resetVirtualEnvCommands(); } @@ -494,7 +512,7 @@ public void testVariableVirtualEnvCommand() throws Exception { resetVirtualEnvCommands(); String path = getClass().getResource("/performanceTest.yml").getPath(); - FreeStyleProject project = createFreeStyleProject(); + FreeStyleProject project = jenkinsRule.createFreeStyleProject(); FreeStyleBuildExt buildExt = new FreeStyleBuildExt(project); FilePath workspace = new FilePath(Files.createTempDirectory(null).toFile()); @@ -512,8 +530,9 @@ public void testVariableVirtualEnvCommand() throws Exception { buildTest.setVirtualEnvCommand("$WORKSPACE/virtualenv"); ByteArrayOutputStream stream = new ByteArrayOutputStream(); - StreamTaskListener taskListener = new StreamTaskListener(stream); - buildTest.perform(buildExt, buildExt.getWorkspace(), new Launcher.DummyLauncher(taskListener), new BuildListenerAdapter(taskListener)); + StreamTaskListener taskListener = new StreamTaskListener(stream, StandardCharsets.UTF_8); + buildTest.perform(buildExt, buildExt.getWorkspace(), new Launcher.DummyLauncher(taskListener), + new BuildListenerAdapter(taskListener)); Iterator iterator = project.getPublishersList().iterator(); StringBuilder builder = new StringBuilder("\n\nList publishers:\n"); @@ -523,10 +542,11 @@ public void testVariableVirtualEnvCommand() throws Exception { String jobLog = new String(stream.toByteArray()) + builder.toString(); - assertEquals(jobLog, Result.SUCCESS, buildExt.getResult()); - assertEquals(jobLog, 5, buildTest.commands.size()); - assertTrue("Command should have been '" + workspace + "/virtualenv', but instead it was: '" + buildTest.commands.get(0)[0] + "'", - buildTest.commands.get(0)[0].equals(workspace + "/virtualenv")); + assertEquals(Result.SUCCESS, buildExt.getResult(), jobLog); + assertEquals(5, buildTest.commands.size(), jobLog); + assertTrue(buildTest.commands.get(0)[0].equals(workspace + "/virtualenv"), + "Command should have been '" + workspace + "/virtualenv', but instead it was: '" + + buildTest.commands.get(0)[0] + "'"); resetVirtualEnvCommands(); } } \ No newline at end of file diff --git a/src/test/java/hudson/plugins/performance/constraints/ConstraintCheckerTest.java b/src/test/java/hudson/plugins/performance/constraints/ConstraintCheckerTest.java index 6b252860..b3a4ddbe 100644 --- a/src/test/java/hudson/plugins/performance/constraints/ConstraintCheckerTest.java +++ b/src/test/java/hudson/plugins/performance/constraints/ConstraintCheckerTest.java @@ -3,7 +3,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; - import static org.mockito.Mockito.when; import java.io.IOException; @@ -18,13 +17,8 @@ import java.util.Iterator; import java.util.List; -import hudson.plugins.performance.constraints.blocks.PreviousResultsBlock; -import hudson.plugins.performance.constraints.blocks.TestCaseBlock; -import hudson.plugins.performance.data.ConstraintSettings; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -33,13 +27,16 @@ import hudson.model.AbstractBuild; import hudson.model.BuildListener; import hudson.model.Result; -import hudson.plugins.performance.actions.PerformanceBuildAction; -import hudson.plugins.performance.reports.PerformanceReport; import hudson.plugins.performance.PerformanceReportMap; -import hudson.plugins.performance.reports.UriReport; +import hudson.plugins.performance.actions.PerformanceBuildAction; import hudson.plugins.performance.constraints.AbstractConstraint.Escalation; import hudson.plugins.performance.constraints.AbstractConstraint.Metric; import hudson.plugins.performance.constraints.AbstractConstraint.Operator; +import hudson.plugins.performance.constraints.blocks.PreviousResultsBlock; +import hudson.plugins.performance.constraints.blocks.TestCaseBlock; +import hudson.plugins.performance.data.ConstraintSettings; +import hudson.plugins.performance.reports.PerformanceReport; +import hudson.plugins.performance.reports.UriReport; import jenkins.model.Jenkins; @RunWith(MockitoJUnitRunner.Silent.class) @@ -180,9 +177,6 @@ public class ConstraintCheckerTest { RelativeConstraint rc5; RelativeConstraint rc6; - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - /** * TestCase1 HappyPath - Testing every combination of constraints against some * builds diff --git a/src/test/java/hudson/plugins/performance/constraints/ConstraintFactoryTest.java b/src/test/java/hudson/plugins/performance/constraints/ConstraintFactoryTest.java index 44239879..9346b0a1 100644 --- a/src/test/java/hudson/plugins/performance/constraints/ConstraintFactoryTest.java +++ b/src/test/java/hudson/plugins/performance/constraints/ConstraintFactoryTest.java @@ -6,8 +6,7 @@ import java.util.ArrayList; import java.util.List; -import hudson.plugins.performance.constraints.blocks.PreviousResultsBlock; -import hudson.plugins.performance.constraints.blocks.TestCaseBlock; +import org.hamcrest.MatcherAssert; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -18,13 +17,15 @@ import org.mockito.junit.MockitoJUnitRunner; import hudson.model.AbstractBuild; -import hudson.plugins.performance.actions.PerformanceBuildAction; -import hudson.plugins.performance.reports.PerformanceReport; import hudson.plugins.performance.PerformanceReportMap; -import hudson.plugins.performance.reports.UriReport; +import hudson.plugins.performance.actions.PerformanceBuildAction; import hudson.plugins.performance.constraints.AbstractConstraint.Escalation; import hudson.plugins.performance.constraints.AbstractConstraint.Metric; import hudson.plugins.performance.constraints.AbstractConstraint.Operator; +import hudson.plugins.performance.constraints.blocks.PreviousResultsBlock; +import hudson.plugins.performance.constraints.blocks.TestCaseBlock; +import hudson.plugins.performance.reports.PerformanceReport; +import hudson.plugins.performance.reports.UriReport; @RunWith(MockitoJUnitRunner.class) @@ -113,26 +114,26 @@ public void testHappyPath() { /** * Check list samplesCount */ - Assert.assertThat(result.size(), is(16)); + MatcherAssert.assertThat(result.size(), is(16)); /** * Check test cases */ - Assert.assertThat(result.get(0).getTestCaseBlock().getTestCase(), is("tc1")); - Assert.assertThat(result.get(1).getTestCaseBlock().getTestCase(), is("tc1")); - Assert.assertThat(result.get(2).getTestCaseBlock().getTestCase(), is("tc2")); - Assert.assertThat(result.get(3).getTestCaseBlock().getTestCase(), is("tc3")); - Assert.assertThat(result.get(4).getTestCaseBlock().getTestCase(), is("tc4")); - Assert.assertThat(result.get(5).getTestCaseBlock().getTestCase(), is("tc1")); - Assert.assertThat(result.get(6).getTestCaseBlock().getTestCase(), is("tc2")); - Assert.assertThat(result.get(7).getTestCaseBlock().getTestCase(), is("tc3")); - Assert.assertThat(result.get(8).getTestCaseBlock().getTestCase(), is("tc1")); - Assert.assertThat(result.get(9).getTestCaseBlock().getTestCase(), is("tc1")); - Assert.assertThat(result.get(10).getTestCaseBlock().getTestCase(), is("tc2")); - Assert.assertThat(result.get(11).getTestCaseBlock().getTestCase(), is("tc3")); - Assert.assertThat(result.get(12).getTestCaseBlock().getTestCase(), is("tc4")); - Assert.assertThat(result.get(13).getTestCaseBlock().getTestCase(), is("tc1")); - Assert.assertThat(result.get(14).getTestCaseBlock().getTestCase(), is("tc2")); - Assert.assertThat(result.get(15).getTestCaseBlock().getTestCase(), is("tc3")); + MatcherAssert.assertThat(result.get(0).getTestCaseBlock().getTestCase(), is("tc1")); + MatcherAssert.assertThat(result.get(1).getTestCaseBlock().getTestCase(), is("tc1")); + MatcherAssert.assertThat(result.get(2).getTestCaseBlock().getTestCase(), is("tc2")); + MatcherAssert.assertThat(result.get(3).getTestCaseBlock().getTestCase(), is("tc3")); + MatcherAssert.assertThat(result.get(4).getTestCaseBlock().getTestCase(), is("tc4")); + MatcherAssert.assertThat(result.get(5).getTestCaseBlock().getTestCase(), is("tc1")); + MatcherAssert.assertThat(result.get(6).getTestCaseBlock().getTestCase(), is("tc2")); + MatcherAssert.assertThat(result.get(7).getTestCaseBlock().getTestCase(), is("tc3")); + MatcherAssert.assertThat(result.get(8).getTestCaseBlock().getTestCase(), is("tc1")); + MatcherAssert.assertThat(result.get(9).getTestCaseBlock().getTestCase(), is("tc1")); + MatcherAssert.assertThat(result.get(10).getTestCaseBlock().getTestCase(), is("tc2")); + MatcherAssert.assertThat(result.get(11).getTestCaseBlock().getTestCase(), is("tc3")); + MatcherAssert.assertThat(result.get(12).getTestCaseBlock().getTestCase(), is("tc4")); + MatcherAssert.assertThat(result.get(13).getTestCaseBlock().getTestCase(), is("tc1")); + MatcherAssert.assertThat(result.get(14).getTestCaseBlock().getTestCase(), is("tc2")); + MatcherAssert.assertThat(result.get(15).getTestCaseBlock().getTestCase(), is("tc3")); } @Test @@ -144,8 +145,8 @@ public void testOptionalBlock() { /** * Checking optional blocks */ - Assert.assertThat(result.get(0).getTestCaseBlock().getTestCase(), is("tc1")); - Assert.assertThat(result.get(1).isSpecifiedTestCase(), is(false)); + MatcherAssert.assertThat(result.get(0).getTestCaseBlock().getTestCase(), is("tc1")); + MatcherAssert.assertThat(result.get(1).isSpecifiedTestCase(), is(false)); Assert.assertNull(result.get(1).getTestCaseBlock()); } } diff --git a/src/test/java/hudson/plugins/performance/parsers/AbstractParserTest.java b/src/test/java/hudson/plugins/performance/parsers/AbstractParserTest.java index f7395e6e..30200d96 100644 --- a/src/test/java/hudson/plugins/performance/parsers/AbstractParserTest.java +++ b/src/test/java/hudson/plugins/performance/parsers/AbstractParserTest.java @@ -32,10 +32,10 @@ public void testUploadOldReport() throws Exception { assertNotNull(report); Map percentilesValues = report.getPercentilesValues(); assertEquals(4, percentilesValues.size()); - assertEquals(new Long(320), percentilesValues.get(50d)); - assertEquals(new Long(449), percentilesValues.get(90d)); - assertEquals(new Long(100), percentilesValues.get(0d)); - assertEquals(new Long(468), percentilesValues.get(100d)); + assertEquals(Long.valueOf(320), percentilesValues.get(50d)); + assertEquals(Long.valueOf(449), percentilesValues.get(90d)); + assertEquals(Long.valueOf(100), percentilesValues.get(0d)); + assertEquals(Long.valueOf(468), percentilesValues.get(100d)); assertEquals(320, report.getMedian()); assertEquals(449, report.get90Line()); diff --git a/src/test/java/hudson/plugins/performance/parsers/IagoParserTest.java b/src/test/java/hudson/plugins/performance/parsers/IagoParserTest.java index 31754862..c443d392 100644 --- a/src/test/java/hudson/plugins/performance/parsers/IagoParserTest.java +++ b/src/test/java/hudson/plugins/performance/parsers/IagoParserTest.java @@ -1,31 +1,37 @@ package hudson.plugins.performance.parsers; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.text.ParseException; +import java.util.Arrays; +import java.util.Collection; + +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; + import hudson.model.FreeStyleBuild; import hudson.plugins.performance.data.HttpSample; import hudson.plugins.performance.parsers.IagoParser.Stats; import hudson.plugins.performance.reports.PerformanceReport; import hudson.plugins.performance.reports.PerformanceReportTest; -import junit.framework.Assert; -import org.junit.Test; -import org.jvnet.hudson.test.HudsonTestCase; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.text.ParseException; -import java.util.Arrays; -import java.util.Collection; +public class IagoParserTest { -public class IagoParserTest extends HudsonTestCase { + @Rule + public final JenkinsRule jenkinsRule = new JenkinsRule(); @Test public void testParseValidLine() throws Exception { IagoParser parser = new IagoParser(null, PerformanceReportTest.DEFAULT_PERCENTILES); - //Line to parse + // Line to parse String line = "INF [20140611-21:34:01.224] stats: {\"400\":84,\"client\\/request_latency_ms_average\":3,\"client\\/request_latency_ms_count\":85,\"client\\/request_latency_ms_maximum\":105,\"client\\/request_latency_ms_minimum\":1,\"client\\/request_latency_ms_p50\":2,\"client\\/request_latency_ms_p90\":4,\"client\\/request_latency_ms_p95\":4,\"client\\/request_latency_ms_p99\":105,\"client\\/request_latency_ms_p999\":105,\"client\\/request_latency_ms_p9999\":105,\"client\\/request_latency_ms_sum\":276,\"client\\/requests\":85,\"client\\/sent_bytes\":11919,\"client\\/socket_unwritable_ms\":0,\"client\\/socket_writable_ms\":207,\"client\\/success\":84}"; String key = "TEST"; @@ -33,7 +39,7 @@ public void testParseValidLine() throws Exception { Assert.assertEquals(105, sample.getSummarizerMax()); Assert.assertEquals(1, sample.getSummarizerMin()); Assert.assertEquals(85, sample.getSummarizerSamples()); - Assert.assertEquals((float) 1.0, sample.getSummarizerErrors()); + Assert.assertEquals((float) 1.0, sample.getSummarizerErrors(), 0.0); Assert.assertEquals(3, sample.getDuration()); Assert.assertEquals(key, sample.getUri()); } @@ -42,7 +48,7 @@ public void testParseValidLine() throws Exception { public void testParseInvalidLine() throws Exception { IagoParser parser = new IagoParser("", PerformanceReportTest.DEFAULT_PERCENTILES); - //Valid line to parse + // Valid line to parse String line = "[20140611-21:34:01.224] stats: {\"400\":84,\"client\\/available\":1,\"client\\/cancelled_connects\":0,\"client\\/closechans\":85,\"client\\/closed\":85,\"client\\/closes\":84,\"client\\/codec_connection_preparation_latency_ms_average\":3,\"client\\/codec_connection_preparation_latency_ms_count\":85,\"client\\/codec_connection_preparation_latency_ms_maximum\":142,\"client\\/codec_connection_preparation_latency_ms_minimum\":1,\"client\\/codec_connection_preparation_latency_ms_p50\":2,\"client\\/codec_connection_preparation_latency_ms_p90\":4,\"client\\/codec_connection_preparation_latency_ms_p95\":4,\"client\\/codec_connection_preparation_latency_ms_p99\":142,\"client\\/codec_connection_preparation_latency_ms_p999\":142,\"client\\/codec_connection_preparation_latency_ms_p9999\":142,\"client\\/codec_connection_preparation_latency_ms_sum\":316,\"client\\/connect_latency_ms_average\":2,\"client\\/connect_latency_ms_count\":85,\"client\\/connect_latency_ms_maximum\":142,\"client\\/connect_latency_ms_minimum\":0,\"client\\/connect_latency_ms_p50\":1,\"client\\/connect_latency_ms_p90\":2,\"client\\/connect_latency_ms_p95\":4,\"client\\/connect_latency_ms_p99\":142,\"client\\/connect_latency_ms_p999\":142,\"client\\/connect_latency_ms_p9999\":142,\"client\\/connect_latency_ms_sum\":238,\"client\\/connection_duration_average\":5,\"client\\/connection_duration_count\":85,\"client\\/connection_duration_maximum\":173,\"client\\/connection_duration_minimum\":2,\"client\\/connection_duration_p50\":3,\"client\\/connection_duration_p90\":6,\"client\\/connection_duration_p95\":7,\"client\\/connection_duration_p99\":173,\"client\\/connection_duration_p999\":173,\"client\\/connection_duration_p9999\":173,\"client\\/connection_duration_sum\":477,\"client\\/connection_received_bytes_average\":604,\"client\\/connection_received_bytes_count\":85,\"client\\/connection_received_bytes_maximum\":576,\"client\\/connection_received_bytes_minimum\":576,\"client\\/connection_received_bytes_p50\":576,\"client\\/connection_received_bytes_p90\":576,\"client\\/connection_received_bytes_p95\":576,\"client\\/connection_received_bytes_p99\":576,\"client\\/connection_received_bytes_p999\":576,\"client\\/connection_received_bytes_p9999\":576,\"client\\/connection_received_bytes_sum\":51340,\"client\\/connection_requests_average\":1,\"client\\/connection_requests_count\":85,\"client\\/connection_requests_maximum\":1,\"client\\/connection_requests_minimum\":1,\"client\\/connection_requests_p50\":1,\"client\\/connection_requests_p90\":1,\"client\\/connection_requests_p95\":1,\"client\\/connection_requests_p99\":1,\"client\\/connection_requests_p999\":1,\"client\\/connection_requests_p9999\":1,\"client\\/connection_requests_sum\":85,\"client\\/connection_sent_bytes_average\":140,\"client\\/connection_sent_bytes_count\":85,\"client\\/connection_sent_bytes_maximum\":142,\"client\\/connection_sent_bytes_minimum\":142,\"client\\/connection_sent_bytes_p50\":142,\"client\\/connection_sent_bytes_p90\":142,\"client\\/connection_sent_bytes_p95\":142,\"client\\/connection_sent_bytes_p99\":142,\"client\\/connection_sent_bytes_p999\":142,\"client\\/connection_sent_bytes_p9999\":142,\"client\\/connection_sent_bytes_sum\":11919,\"client\\/connections\":0,\"client\\/connects\":85,\"client\\/failed_connect_latency_ms_count\":0,\"client\\/failfast\":0,\"client\\/failfast\\/unhealthy_for_ms\":0,\"client\\/failfast\\/unhealthy_num_tries\":0,\"client\\/failures\":1,\"client\\/failures\\/com.twitter.finagle.ChannelClosedException\":1,\"client\\/idle\":0,\"client\\/jonatstr-dt-otc_80\\/available\":1,\"client\\/jonatstr-dt-otc_80\\/cancelled_connects\":0,\"client\\/jonatstr-dt-otc_80\\/closechans\":85,\"client\\/jonatstr-dt-otc_80\\/closed\":85,\"client\\/jonatstr-dt-otc_80\\/closes\":84,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_average\":2,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_count\":85,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_maximum\":142,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_minimum\":0,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_p50\":1,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_p90\":2,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_p95\":4,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_p99\":142,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_p999\":142,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_p9999\":142,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_sum\":238,\"client\\/jonatstr-dt-otc_80\\/connection_duration_average\":5,\"client\\/jonatstr-dt-otc_80\\/connection_duration_count\":85,\"client\\/jonatstr-dt-otc_80\\/connection_duration_maximum\":173,\"client\\/jonatstr-dt-otc_80\\/connection_duration_minimum\":2,\"client\\/jonatstr-dt-otc_80\\/connection_duration_p50\":3,\"client\\/jonatstr-dt-otc_80\\/connection_duration_p90\":6,\"client\\/jonatstr-dt-otc_80\\/connection_duration_p95\":7,\"client\\/jonatstr-dt-otc_80\\/connection_duration_p99\":173,\"client\\/jonatstr-dt-otc_80\\/connection_duration_p999\":173,\"client\\/jonatstr-dt-otc_80\\/connection_duration_p9999\":173,\"client\\/jonatstr-dt-otc_80\\/connection_duration_sum\":477,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_average\":604,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_count\":85,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_maximum\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_minimum\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_p50\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_p90\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_p95\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_p99\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_p999\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_p9999\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_sum\":51340,\"client\\/jonatstr-dt-otc_80\\/connection_requests_average\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_count\":85,\"client\\/jonatstr-dt-otc_80\\/connection_requests_maximum\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_minimum\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_p50\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_p90\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_p95\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_p99\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_p999\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_p9999\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_sum\":85,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_average\":140,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_count\":85,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_maximum\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_minimum\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_p50\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_p90\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_p95\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_p99\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_p999\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_p9999\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_sum\":11919,\"client\\/jonatstr-dt-otc_80\\/connections\":0,\"client\\/jonatstr-dt-otc_80\\/connects\":85,\"client\\/jonatstr-dt-otc_80\\/failed_connect_latency_ms_count\":0,\"client\\/jonatstr-dt-otc_80\\/failfast\":0,\"client\\/jonatstr-dt-otc_80\\/failfast\\/unhealthy_for_ms\":0,\"client\\/jonatstr-dt-otc_80\\/failfast\\/unhealthy_num_tries\":0,\"client\\/jonatstr-dt-otc_80\\/failures\":1,\"client\\/jonatstr-dt-otc_80\\/failures\\/com.twitter.finagle.ChannelClosedException\":1,\"client\\/jonatstr-dt-otc_80\\/idle\":0,\"client\\/jonatstr-dt-otc_80\\/lifetime\":0,\"client\\/jonatstr-dt-otc_80\\/load\":0,\"client\\/jonatstr-dt-otc_80\\/pending\":0,\"client\\/jonatstr-dt-otc_80\\/pool_cached\":0,\"client\\/jonatstr-dt-otc_80\\/pool_num_waited\":0,\"client\\/jonatstr-dt-otc_80\\/pool_size\":0,\"client\\/jonatstr-dt-otc_80\\/pool_waiters\":0,\"client\\/jonatstr-dt-otc_80\\/received_bytes\":51340,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_average\":3,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_count\":85,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_maximum\":105,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_minimum\":1,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_p50\":2,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_p90\":4,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_p95\":4,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_p99\":105,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_p999\":105,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_p9999\":105,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_sum\":276,\"client\\/jonatstr-dt-otc_80\\/requests\":85,\"client\\/jonatstr-dt-otc_80\\/sent_bytes\":11919,\"client\\/jonatstr-dt-otc_80\\/socket_unwritable_ms\":0,\"client\\/jonatstr-dt-otc_80\\/socket_writable_ms\":207,\"client\\/jonatstr-dt-otc_80\\/success\":84,\"client\\/lifetime\":0,\"client\\/load\":0,\"client\\/loadbalancer\\/adds\":0,\"client\\/loadbalancer\\/available\":1,\"client\\/loadbalancer\\/load\":0,\"client\\/loadbalancer\\/removes\":0,\"client\\/loadbalancer\\/size\":1,\"client\\/pending\":0,\"client\\/pool_cached\":0,\"client\\/pool_num_waited\":0,\"client\\/pool_size\":0,\"client\\/pool_waiters\":0,\"client\\/received_bytes\":51340,\"client\\/request_latency_ms_average\":3,\"client\\/request_latency_ms_count\":85,\"client\\/request_latency_ms_maximum\":105,\"client\\/request_latency_ms_minimum\":1,\"client\\/request_latency_ms_p50\":2,\"client\\/request_latency_ms_p90\":4,\"client\\/request_latency_ms_p95\":4,\"client\\/request_latency_ms_p99\":105,\"client\\/request_latency_ms_p999\":105,\"client\\/request_latency_ms_p9999\":105,\"client\\/request_latency_ms_sum\":276,\"client\\/requests\":85,\"client\\/sent_bytes\":11919,\"client\\/socket_unwritable_ms\":0,\"client\\/socket_writable_ms\":207,\"client\\/success\":84,\"clock_error\":0,\"jvm_buffer_direct_count\":4,\"jvm_buffer_direct_max\":133120,\"jvm_buffer_direct_used\":133120,\"jvm_buffer_mapped_count\":0,\"jvm_buffer_mapped_max\":0,\"jvm_buffer_mapped_used\":0,\"jvm_current_mem_CMS_Old_Gen_max\":3657433088,\"jvm_current_mem_CMS_Old_Gen_used\":12173984,\"jvm_current_mem_CMS_Perm_Gen_max\":85983232,\"jvm_current_mem_CMS_Perm_Gen_used\":44355376,\"jvm_current_mem_Code_Cache_max\":50331648,\"jvm_current_mem_Code_Cache_used\":2425792,\"jvm_current_mem_Eden_Space_max\":429522944,\"jvm_current_mem_Eden_Space_used\":169518376,\"jvm_current_mem_Survivor_Space_max\":53673984,\"jvm_current_mem_Survivor_Space_used\":53673984,\"jvm_current_mem_used\":282147512,\"jvm_fd_count\":142,\"jvm_fd_limit\":4096,\"jvm_gc_ConcurrentMarkSweep_cycles\":0,\"jvm_gc_ConcurrentMarkSweep_msec\":0,\"jvm_gc_Copy_cycles\":0,\"jvm_gc_Copy_msec\":0,\"jvm_gc_cycles\":0,\"jvm_gc_msec\":0,\"jvm_heap_committed\":4140630016,\"jvm_heap_max\":4140630016,\"jvm_heap_used\":235366344,\"jvm_nonheap_committed\":47120384,\"jvm_nonheap_max\":136314880,\"jvm_nonheap_used\":46777704,\"jvm_num_cpus\":1,\"jvm_post_gc_CMS_Old_Gen_max\":3657433088,\"jvm_post_gc_CMS_Old_Gen_used\":0,\"jvm_post_gc_CMS_Perm_Gen_max\":85983232,\"jvm_post_gc_CMS_Perm_Gen_used\":0,\"jvm_post_gc_Eden_Space_max\":429522944,\"jvm_post_gc_Eden_Space_used\":0,\"jvm_post_gc_Survivor_Space_max\":53673984,\"jvm_post_gc_Survivor_Space_used\":53673984,\"jvm_post_gc_used\":53673984,\"jvm_start_time\":1402536778818,\"jvm_thread_count\":18,\"jvm_thread_daemon_count\":12,\"jvm_thread_peak_count\":18,\"jvm_uptime\":62216,\"queue_depth\":41,\"records-read\":126,\"requests_sent\":85,\"service\":\"parrot_web\",\"source\":\"jonatstr-dt-oneconnector\",\"timestamp\":1402536841,\"unexpected_error\":1,\"unexpected_error\\/com.twitter.finagle.ChannelClosedException\":1}"; String key = "TEST"; @@ -61,7 +67,7 @@ public void testParseInvalidLine() throws Exception { public void testParseInvalidDate() throws Exception { IagoParser parser = new IagoParser("", PerformanceReportTest.DEFAULT_PERCENTILES); - //Line to parse + // Line to parse String line = "INF [20140611+21:34:01.224] stats: {\"400\":84,\"client\\/available\":1,\"client\\/cancelled_connects\":0,\"client\\/closechans\":85,\"client\\/closed\":85,\"client\\/closes\":84,\"client\\/codec_connection_preparation_latency_ms_average\":3,\"client\\/codec_connection_preparation_latency_ms_count\":85,\"client\\/codec_connection_preparation_latency_ms_maximum\":142,\"client\\/codec_connection_preparation_latency_ms_minimum\":1,\"client\\/codec_connection_preparation_latency_ms_p50\":2,\"client\\/codec_connection_preparation_latency_ms_p90\":4,\"client\\/codec_connection_preparation_latency_ms_p95\":4,\"client\\/codec_connection_preparation_latency_ms_p99\":142,\"client\\/codec_connection_preparation_latency_ms_p999\":142,\"client\\/codec_connection_preparation_latency_ms_p9999\":142,\"client\\/codec_connection_preparation_latency_ms_sum\":316,\"client\\/connect_latency_ms_average\":2,\"client\\/connect_latency_ms_count\":85,\"client\\/connect_latency_ms_maximum\":142,\"client\\/connect_latency_ms_minimum\":0,\"client\\/connect_latency_ms_p50\":1,\"client\\/connect_latency_ms_p90\":2,\"client\\/connect_latency_ms_p95\":4,\"client\\/connect_latency_ms_p99\":142,\"client\\/connect_latency_ms_p999\":142,\"client\\/connect_latency_ms_p9999\":142,\"client\\/connect_latency_ms_sum\":238,\"client\\/connection_duration_average\":5,\"client\\/connection_duration_count\":85,\"client\\/connection_duration_maximum\":173,\"client\\/connection_duration_minimum\":2,\"client\\/connection_duration_p50\":3,\"client\\/connection_duration_p90\":6,\"client\\/connection_duration_p95\":7,\"client\\/connection_duration_p99\":173,\"client\\/connection_duration_p999\":173,\"client\\/connection_duration_p9999\":173,\"client\\/connection_duration_sum\":477,\"client\\/connection_received_bytes_average\":604,\"client\\/connection_received_bytes_count\":85,\"client\\/connection_received_bytes_maximum\":576,\"client\\/connection_received_bytes_minimum\":576,\"client\\/connection_received_bytes_p50\":576,\"client\\/connection_received_bytes_p90\":576,\"client\\/connection_received_bytes_p95\":576,\"client\\/connection_received_bytes_p99\":576,\"client\\/connection_received_bytes_p999\":576,\"client\\/connection_received_bytes_p9999\":576,\"client\\/connection_received_bytes_sum\":51340,\"client\\/connection_requests_average\":1,\"client\\/connection_requests_count\":85,\"client\\/connection_requests_maximum\":1,\"client\\/connection_requests_minimum\":1,\"client\\/connection_requests_p50\":1,\"client\\/connection_requests_p90\":1,\"client\\/connection_requests_p95\":1,\"client\\/connection_requests_p99\":1,\"client\\/connection_requests_p999\":1,\"client\\/connection_requests_p9999\":1,\"client\\/connection_requests_sum\":85,\"client\\/connection_sent_bytes_average\":140,\"client\\/connection_sent_bytes_count\":85,\"client\\/connection_sent_bytes_maximum\":142,\"client\\/connection_sent_bytes_minimum\":142,\"client\\/connection_sent_bytes_p50\":142,\"client\\/connection_sent_bytes_p90\":142,\"client\\/connection_sent_bytes_p95\":142,\"client\\/connection_sent_bytes_p99\":142,\"client\\/connection_sent_bytes_p999\":142,\"client\\/connection_sent_bytes_p9999\":142,\"client\\/connection_sent_bytes_sum\":11919,\"client\\/connections\":0,\"client\\/connects\":85,\"client\\/failed_connect_latency_ms_count\":0,\"client\\/failfast\":0,\"client\\/failfast\\/unhealthy_for_ms\":0,\"client\\/failfast\\/unhealthy_num_tries\":0,\"client\\/failures\":1,\"client\\/failures\\/com.twitter.finagle.ChannelClosedException\":1,\"client\\/idle\":0,\"client\\/jonatstr-dt-otc_80\\/available\":1,\"client\\/jonatstr-dt-otc_80\\/cancelled_connects\":0,\"client\\/jonatstr-dt-otc_80\\/closechans\":85,\"client\\/jonatstr-dt-otc_80\\/closed\":85,\"client\\/jonatstr-dt-otc_80\\/closes\":84,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_average\":2,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_count\":85,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_maximum\":142,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_minimum\":0,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_p50\":1,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_p90\":2,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_p95\":4,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_p99\":142,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_p999\":142,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_p9999\":142,\"client\\/jonatstr-dt-otc_80\\/connect_latency_ms_sum\":238,\"client\\/jonatstr-dt-otc_80\\/connection_duration_average\":5,\"client\\/jonatstr-dt-otc_80\\/connection_duration_count\":85,\"client\\/jonatstr-dt-otc_80\\/connection_duration_maximum\":173,\"client\\/jonatstr-dt-otc_80\\/connection_duration_minimum\":2,\"client\\/jonatstr-dt-otc_80\\/connection_duration_p50\":3,\"client\\/jonatstr-dt-otc_80\\/connection_duration_p90\":6,\"client\\/jonatstr-dt-otc_80\\/connection_duration_p95\":7,\"client\\/jonatstr-dt-otc_80\\/connection_duration_p99\":173,\"client\\/jonatstr-dt-otc_80\\/connection_duration_p999\":173,\"client\\/jonatstr-dt-otc_80\\/connection_duration_p9999\":173,\"client\\/jonatstr-dt-otc_80\\/connection_duration_sum\":477,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_average\":604,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_count\":85,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_maximum\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_minimum\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_p50\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_p90\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_p95\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_p99\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_p999\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_p9999\":576,\"client\\/jonatstr-dt-otc_80\\/connection_received_bytes_sum\":51340,\"client\\/jonatstr-dt-otc_80\\/connection_requests_average\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_count\":85,\"client\\/jonatstr-dt-otc_80\\/connection_requests_maximum\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_minimum\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_p50\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_p90\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_p95\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_p99\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_p999\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_p9999\":1,\"client\\/jonatstr-dt-otc_80\\/connection_requests_sum\":85,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_average\":140,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_count\":85,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_maximum\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_minimum\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_p50\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_p90\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_p95\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_p99\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_p999\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_p9999\":142,\"client\\/jonatstr-dt-otc_80\\/connection_sent_bytes_sum\":11919,\"client\\/jonatstr-dt-otc_80\\/connections\":0,\"client\\/jonatstr-dt-otc_80\\/connects\":85,\"client\\/jonatstr-dt-otc_80\\/failed_connect_latency_ms_count\":0,\"client\\/jonatstr-dt-otc_80\\/failfast\":0,\"client\\/jonatstr-dt-otc_80\\/failfast\\/unhealthy_for_ms\":0,\"client\\/jonatstr-dt-otc_80\\/failfast\\/unhealthy_num_tries\":0,\"client\\/jonatstr-dt-otc_80\\/failures\":1,\"client\\/jonatstr-dt-otc_80\\/failures\\/com.twitter.finagle.ChannelClosedException\":1,\"client\\/jonatstr-dt-otc_80\\/idle\":0,\"client\\/jonatstr-dt-otc_80\\/lifetime\":0,\"client\\/jonatstr-dt-otc_80\\/load\":0,\"client\\/jonatstr-dt-otc_80\\/pending\":0,\"client\\/jonatstr-dt-otc_80\\/pool_cached\":0,\"client\\/jonatstr-dt-otc_80\\/pool_num_waited\":0,\"client\\/jonatstr-dt-otc_80\\/pool_size\":0,\"client\\/jonatstr-dt-otc_80\\/pool_waiters\":0,\"client\\/jonatstr-dt-otc_80\\/received_bytes\":51340,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_average\":3,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_count\":85,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_maximum\":105,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_minimum\":1,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_p50\":2,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_p90\":4,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_p95\":4,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_p99\":105,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_p999\":105,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_p9999\":105,\"client\\/jonatstr-dt-otc_80\\/request_latency_ms_sum\":276,\"client\\/jonatstr-dt-otc_80\\/requests\":85,\"client\\/jonatstr-dt-otc_80\\/sent_bytes\":11919,\"client\\/jonatstr-dt-otc_80\\/socket_unwritable_ms\":0,\"client\\/jonatstr-dt-otc_80\\/socket_writable_ms\":207,\"client\\/jonatstr-dt-otc_80\\/success\":84,\"client\\/lifetime\":0,\"client\\/load\":0,\"client\\/loadbalancer\\/adds\":0,\"client\\/loadbalancer\\/available\":1,\"client\\/loadbalancer\\/load\":0,\"client\\/loadbalancer\\/removes\":0,\"client\\/loadbalancer\\/size\":1,\"client\\/pending\":0,\"client\\/pool_cached\":0,\"client\\/pool_num_waited\":0,\"client\\/pool_size\":0,\"client\\/pool_waiters\":0,\"client\\/received_bytes\":51340,\"client\\/request_latency_ms_average\":3,\"client\\/request_latency_ms_count\":85,\"client\\/request_latency_ms_maximum\":105,\"client\\/request_latency_ms_minimum\":1,\"client\\/request_latency_ms_p50\":2,\"client\\/request_latency_ms_p90\":4,\"client\\/request_latency_ms_p95\":4,\"client\\/request_latency_ms_p99\":105,\"client\\/request_latency_ms_p999\":105,\"client\\/request_latency_ms_p9999\":105,\"client\\/request_latency_ms_sum\":276,\"client\\/requests\":85,\"client\\/sent_bytes\":11919,\"client\\/socket_unwritable_ms\":0,\"client\\/socket_writable_ms\":207,\"client\\/success\":84,\"clock_error\":0,\"jvm_buffer_direct_count\":4,\"jvm_buffer_direct_max\":133120,\"jvm_buffer_direct_used\":133120,\"jvm_buffer_mapped_count\":0,\"jvm_buffer_mapped_max\":0,\"jvm_buffer_mapped_used\":0,\"jvm_current_mem_CMS_Old_Gen_max\":3657433088,\"jvm_current_mem_CMS_Old_Gen_used\":12173984,\"jvm_current_mem_CMS_Perm_Gen_max\":85983232,\"jvm_current_mem_CMS_Perm_Gen_used\":44355376,\"jvm_current_mem_Code_Cache_max\":50331648,\"jvm_current_mem_Code_Cache_used\":2425792,\"jvm_current_mem_Eden_Space_max\":429522944,\"jvm_current_mem_Eden_Space_used\":169518376,\"jvm_current_mem_Survivor_Space_max\":53673984,\"jvm_current_mem_Survivor_Space_used\":53673984,\"jvm_current_mem_used\":282147512,\"jvm_fd_count\":142,\"jvm_fd_limit\":4096,\"jvm_gc_ConcurrentMarkSweep_cycles\":0,\"jvm_gc_ConcurrentMarkSweep_msec\":0,\"jvm_gc_Copy_cycles\":0,\"jvm_gc_Copy_msec\":0,\"jvm_gc_cycles\":0,\"jvm_gc_msec\":0,\"jvm_heap_committed\":4140630016,\"jvm_heap_max\":4140630016,\"jvm_heap_used\":235366344,\"jvm_nonheap_committed\":47120384,\"jvm_nonheap_max\":136314880,\"jvm_nonheap_used\":46777704,\"jvm_num_cpus\":1,\"jvm_post_gc_CMS_Old_Gen_max\":3657433088,\"jvm_post_gc_CMS_Old_Gen_used\":0,\"jvm_post_gc_CMS_Perm_Gen_max\":85983232,\"jvm_post_gc_CMS_Perm_Gen_used\":0,\"jvm_post_gc_Eden_Space_max\":429522944,\"jvm_post_gc_Eden_Space_used\":0,\"jvm_post_gc_Survivor_Space_max\":53673984,\"jvm_post_gc_Survivor_Space_used\":53673984,\"jvm_post_gc_used\":53673984,\"jvm_start_time\":1402536778818,\"jvm_thread_count\":18,\"jvm_thread_daemon_count\":12,\"jvm_thread_peak_count\":18,\"jvm_uptime\":62216,\"queue_depth\":41,\"records-read\":126,\"requests_sent\":85,\"service\":\"parrot_web\",\"source\":\"jonatstr-dt-oneconnector\",\"timestamp\":1402536841,\"unexpected_error\":1,\"unexpected_error\\/com.twitter.finagle.ChannelClosedException\":1}"; String key = "TEST"; @@ -95,7 +101,6 @@ public void testParseValidFile() throws Exception { stats2.setClientRequests((long) 13); stats2.setClientSendBytes((long) 12000); - // Create a temp file. // We can move this to resources, but allow flexibility in // unit test to create on the fly @@ -125,25 +130,23 @@ public void testParseValidFile() throws Exception { } Assert.assertFalse(exceptionOccured); - IagoParser parser = new IagoParser("", PerformanceReportTest.DEFAULT_PERCENTILES); - Collection reports = parser.parse(new FreeStyleBuild(createFreeStyleProject()), Arrays.asList(temp), createTaskListener()); + Collection reports = parser.parse(new FreeStyleBuild(jenkinsRule.createFreeStyleProject()), + Arrays.asList(temp), jenkinsRule.createTaskListener()); Assert.assertEquals(1, reports.size()); PerformanceReport report = (PerformanceReport) reports.toArray()[0]; - Assert.assertEquals((stats1.getClientRequestLatencyMsAverage() + stats2.getClientRequestLatencyMsAverage()) / 2, report.getAverage()); + Assert.assertEquals((stats1.getClientRequestLatencyMsAverage() + stats2.getClientRequestLatencyMsAverage()) / 2, + report.getAverage()); } - - - - public void testUserRegexNoValidationErrors() throws Exception { - IagoParser parser = new IagoParser(null, PerformanceReportTest.DEFAULT_PERCENTILES);//, "4[0-9]+,5[0-9]+", ","); + IagoParser parser = new IagoParser(null, PerformanceReportTest.DEFAULT_PERCENTILES);// , "4[0-9]+,5[0-9]+", + // ","); - //Line to parse + // Line to parse String line = "INF [20140611-21:34:01.224] stats: {\"client\\/request_latency_ms_average\":3,\"client\\/request_latency_ms_count\":85,\"client\\/request_latency_ms_maximum\":105,\"client\\/request_latency_ms_minimum\":1,\"client\\/request_latency_ms_p50\":2,\"client\\/request_latency_ms_p90\":4,\"client\\/request_latency_ms_p95\":4,\"client\\/request_latency_ms_p99\":105,\"client\\/request_latency_ms_p999\":105,\"client\\/request_latency_ms_p9999\":105,\"client\\/request_latency_ms_sum\":276,\"client\\/requests\":85,\"client\\/sent_bytes\":11919,\"client\\/socket_unwritable_ms\":0,\"client\\/socket_writable_ms\":207,\"client\\/success\":84}"; String key = "TEST"; @@ -151,18 +154,17 @@ public void testUserRegexNoValidationErrors() throws Exception { Assert.assertEquals(105, sample.getSummarizerMax()); Assert.assertEquals(1, sample.getSummarizerMin()); Assert.assertEquals(85, sample.getSummarizerSamples()); - Assert.assertEquals((float) 1.0, sample.getSummarizerErrors()); + Assert.assertEquals((float) 1.0, sample.getSummarizerErrors(), 0.0); Assert.assertEquals(3, sample.getDuration()); Assert.assertEquals(key, sample.getUri()); } - - public void testNoErrors() throws Exception { - IagoParser parser = new IagoParser(null, PerformanceReportTest.DEFAULT_PERCENTILES);//, "4[0-9]+,5[0-9]+", ","); + IagoParser parser = new IagoParser(null, PerformanceReportTest.DEFAULT_PERCENTILES);// , "4[0-9]+,5[0-9]+", + // ","); - //Line to parse + // Line to parse String line = "INF [20140611-21:34:01.224] stats: {\"client\\/request_latency_ms_average\":3,\"client\\/request_latency_ms_count\":85,\"client\\/request_latency_ms_maximum\":105,\"client\\/request_latency_ms_minimum\":1,\"client\\/request_latency_ms_p50\":2,\"client\\/request_latency_ms_p90\":4,\"client\\/request_latency_ms_p95\":4,\"client\\/request_latency_ms_p99\":105,\"client\\/request_latency_ms_p999\":105,\"client\\/request_latency_ms_p9999\":105,\"client\\/request_latency_ms_sum\":276,\"client\\/requests\":85,\"client\\/sent_bytes\":11919,\"client\\/socket_unwritable_ms\":0,\"client\\/socket_writable_ms\":207,\"client\\/success\":85}"; String key = "TEST"; @@ -170,12 +172,9 @@ public void testNoErrors() throws Exception { Assert.assertEquals(105, sample.getSummarizerMax()); Assert.assertEquals(1, sample.getSummarizerMin()); Assert.assertEquals(85, sample.getSummarizerSamples()); - Assert.assertEquals((float) 0.0, sample.getSummarizerErrors()); + Assert.assertEquals((float) 0.0, sample.getSummarizerErrors(), 0.0); Assert.assertEquals(3, sample.getDuration()); Assert.assertEquals(key, sample.getUri()); } - - - } diff --git a/src/test/java/hudson/plugins/performance/parsers/WrkSummarizerParserTest.java b/src/test/java/hudson/plugins/performance/parsers/WrkSummarizerParserTest.java index fe1a3a0e..5560b467 100644 --- a/src/test/java/hudson/plugins/performance/parsers/WrkSummarizerParserTest.java +++ b/src/test/java/hudson/plugins/performance/parsers/WrkSummarizerParserTest.java @@ -8,6 +8,7 @@ import org.junit.Test; import java.io.File; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -22,7 +23,7 @@ public class WrkSummarizerParserTest { @Before public void before() { parser = new WrkSummarizerParser(null, PerformanceReportTest.DEFAULT_PERCENTILES); - listener = new StreamTaskListener((java.io.OutputStream) System.out); + listener = new StreamTaskListener((java.io.OutputStream) System.out, StandardCharsets.UTF_8); } @Test diff --git a/src/test/java/hudson/plugins/performance/reports/ConstraintReportTest.java b/src/test/java/hudson/plugins/performance/reports/ConstraintReportTest.java index d4bc61de..9f8cf1b7 100644 --- a/src/test/java/hudson/plugins/performance/reports/ConstraintReportTest.java +++ b/src/test/java/hudson/plugins/performance/reports/ConstraintReportTest.java @@ -160,10 +160,6 @@ public void setUp() throws IOException, InterruptedException { filePath = Mockito.mock(FilePath.class); - when(globBuild.getWorkspace()).thenReturn(filePath); - when(filePath.toURI()).thenReturn(uri); - when(uri.getPath()).thenReturn("test-jenkins-filepath/"); - final Jenkins jenkins = Mockito.mock(Jenkins.class); staticJenkins.when(Jenkins::get).thenReturn(jenkins); when(jenkins.getRootUrl()).thenReturn("test-jenkins-rooturl"); diff --git a/src/test/java/hudson/plugins/performance/reports/PerformanceReportTest.java b/src/test/java/hudson/plugins/performance/reports/PerformanceReportTest.java index fbd84f6b..45712d30 100644 --- a/src/test/java/hudson/plugins/performance/reports/PerformanceReportTest.java +++ b/src/test/java/hudson/plugins/performance/reports/PerformanceReportTest.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.io.PrintStream; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.Date; import java.util.List; @@ -104,12 +105,12 @@ public void testPerformanceReport() throws IOException, URISyntaxException { private PerformanceReport parseOneJMeter(File f) throws IOException { return new JMeterParser("", DEFAULT_PERCENTILES).parse(null, Collections.singleton(f), - new StreamTaskListener(System.out)).iterator().next(); + new StreamTaskListener(System.out, StandardCharsets.UTF_8)).iterator().next(); } private PerformanceReport parseOneJUnit(File f) throws IOException { return new JUnitParser("", PerformanceReportTest.DEFAULT_PERCENTILES).parse(null, Collections.singleton(f), - new StreamTaskListener(System.out)).iterator().next(); + new StreamTaskListener(System.out, StandardCharsets.UTF_8)).iterator().next(); } @Test diff --git a/src/test/java/hudson/plugins/performance/reports/ThroughputReportTest.java b/src/test/java/hudson/plugins/performance/reports/ThroughputReportTest.java index 36def351..7f2fc7f8 100644 --- a/src/test/java/hudson/plugins/performance/reports/ThroughputReportTest.java +++ b/src/test/java/hudson/plugins/performance/reports/ThroughputReportTest.java @@ -9,6 +9,7 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.Date; import java.util.Map; @@ -134,7 +135,7 @@ public void testThroughputTaurusReport() throws Exception { public void testDuration() throws IOException, URISyntaxException { File report = new File(getClass().getResource("/TaurusXmlWithDuration.xml").getPath()); TaurusParser parser = new TaurusParser(report.getAbsolutePath(), DEFAULT_PERCENTILES); - PerformanceReport performanceReport = parser.parse(null, Collections.singleton(report), new StreamTaskListener(System.out)).iterator().next(); + PerformanceReport performanceReport = parser.parse(null, Collections.singleton(report), new StreamTaskListener(System.out, StandardCharsets.UTF_8)).iterator().next(); ThroughputReport throughputReport = new ThroughputReport(performanceReport); Map uriReportMap = performanceReport.getUriReportMap(); diff --git a/src/test/java/hudson/plugins/performance/workflow/WorkflowActionsFactoryTest.java b/src/test/java/hudson/plugins/performance/workflow/WorkflowActionsFactoryTest.java index c27d0d47..37de7d0a 100644 --- a/src/test/java/hudson/plugins/performance/workflow/WorkflowActionsFactoryTest.java +++ b/src/test/java/hudson/plugins/performance/workflow/WorkflowActionsFactoryTest.java @@ -1,23 +1,24 @@ package hudson.plugins.performance.workflow; -import hudson.model.Action; -import hudson.model.Job; -import hudson.model.Result; -import hudson.plugins.performance.actions.PerformanceProjectAction; -import hudson.slaves.DumbSlave; +import static org.junit.Assert.assertEquals; + +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.Collection; + import org.apache.commons.io.IOUtils; import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; import org.jenkinsci.plugins.workflow.job.WorkflowJob; import org.jenkinsci.plugins.workflow.job.WorkflowRun; import org.junit.Rule; import org.junit.Test; -import org.junit.runners.model.Statement; import org.jvnet.hudson.test.RestartableJenkinsRule; -import java.net.URL; -import java.util.Collection; - -import static org.junit.Assert.assertEquals; +import hudson.model.Action; +import hudson.model.Job; +import hudson.model.Result; +import hudson.plugins.performance.actions.PerformanceProjectAction; +import hudson.slaves.DumbSlave; public class WorkflowActionsFactoryTest { private final WorkflowActionsFactory factory = new WorkflowActionsFactory(); @@ -29,20 +30,18 @@ public class WorkflowActionsFactoryTest { public void testFlow() throws Exception { assertEquals(Job.class, factory.type()); - story.addStep(new Statement() { - public void evaluate() throws Throwable { - DumbSlave s = story.j.createOnlineSlave(); - s.setLabelString("test performance report DSL function"); - WorkflowJob p = story.j.createProject(WorkflowJob.class, "demo"); - p.setDefinition(new CpsFlowDefinition( - "node{ echo 'hi, world!' }", true)); - WorkflowRun r = p.scheduleBuild2(0).waitForStart(); - story.j.assertBuildStatus(Result.SUCCESS, story.j.waitForCompletion(r)); - r = p.scheduleBuild2(1).waitForStart(); - story.j.assertBuildStatus(Result.SUCCESS, story.j.waitForCompletion(r)); - Collection actions = factory.createFor(p); - assertEquals(0, actions.size()); - } + story.then(step -> { + DumbSlave s = story.j.createOnlineSlave(); + s.setLabelString("test performance report DSL function"); + WorkflowJob p = story.j.createProject(WorkflowJob.class, "demo"); + p.setDefinition(new CpsFlowDefinition( + "node{ echo 'hi, world!' }", true)); + WorkflowRun r = p.scheduleBuild2(0).waitForStart(); + story.j.assertBuildStatus(Result.SUCCESS, story.j.waitForCompletion(r)); + r = p.scheduleBuild2(1).waitForStart(); + story.j.assertBuildStatus(Result.SUCCESS, story.j.waitForCompletion(r)); + Collection actions = factory.createFor(p); + assertEquals(0, actions.size()); }); } @@ -52,25 +51,25 @@ public void testFlowWithProjectAction() throws Exception { URL url = getClass().getResource("/TaurusXMLReport.xml"); if (url != null) { - fileContents = IOUtils.toString(url); + fileContents = IOUtils.toString(url, StandardCharsets.UTF_8); } final String report = fileContents; - story.addStep(new Statement() { - public void evaluate() throws Throwable { - DumbSlave s = story.j.createOnlineSlave(); - s.setLabelString("test performance report DSL function"); - WorkflowJob p = story.j.createProject(WorkflowJob.class, "demo2"); - p.setDefinition(new CpsFlowDefinition( - "node{ writeFile file: 'test.xml', text: '''" + report + "'''; perfReport errorFailedThreshold: 2, errorUnstableThreshold: 2, sourceDataFiles: 'test.xml' }", true)); - WorkflowRun r = p.scheduleBuild2(0).waitForStart(); - story.j.assertBuildStatus(Result.SUCCESS, story.j.waitForCompletion(r)); - r = p.scheduleBuild2(1).waitForStart(); - story.j.assertBuildStatus(Result.SUCCESS, story.j.waitForCompletion(r)); - Collection actions = factory.createFor(p); - assertEquals(1, actions.size()); - assertEquals(PerformanceProjectAction.class, actions.toArray()[0].getClass()); - } + story.then(step -> { + DumbSlave s = story.j.createOnlineSlave(); + s.setLabelString("test performance report DSL function"); + WorkflowJob p = story.j.createProject(WorkflowJob.class, "demo2"); + p.setDefinition(new CpsFlowDefinition( + "node{ writeFile file: 'test.xml', text: '''" + report + + "'''; perfReport errorFailedThreshold: 2, errorUnstableThreshold: 2, sourceDataFiles: 'test.xml' }", + true)); + WorkflowRun r = p.scheduleBuild2(0).waitForStart(); + story.j.assertBuildStatus(Result.SUCCESS, story.j.waitForCompletion(r)); + r = p.scheduleBuild2(1).waitForStart(); + story.j.assertBuildStatus(Result.SUCCESS, story.j.waitForCompletion(r)); + Collection actions = factory.createFor(p); + assertEquals(1, actions.size()); + assertEquals(PerformanceProjectAction.class, actions.toArray()[0].getClass()); }); } } \ No newline at end of file From d7bcf215b5a6f61a0672ad493b6550fbbf5e518f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 3 Sep 2023 09:54:35 +0000 Subject: [PATCH 5/7] Bump org.jenkins-ci.plugins:plugin from 4.71 to 4.73 Bumps [org.jenkins-ci.plugins:plugin](https://github.com/jenkinsci/plugin-pom) from 4.71 to 4.73. - [Release notes](https://github.com/jenkinsci/plugin-pom/releases) - [Changelog](https://github.com/jenkinsci/plugin-pom/blob/master/CHANGELOG.md) - [Commits](https://github.com/jenkinsci/plugin-pom/compare/plugin-4.71...plugin-4.73) --- updated-dependencies: - dependency-name: org.jenkins-ci.plugins:plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 09f5cbd3..b48adb37 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.jenkins-ci.plugins plugin - 4.71 + 4.73 From 6d8ecd5814c9eb1c66c30eb41bd435a82696bf66 Mon Sep 17 00:00:00 2001 From: Alexander Straube Date: Fri, 29 Sep 2023 14:38:48 +0200 Subject: [PATCH 6/7] Attempt to fix TrendReportGraphsTest --- .../hudson/plugins/performance/TrendReportGraphsTest.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/test/java/hudson/plugins/performance/TrendReportGraphsTest.java b/src/test/java/hudson/plugins/performance/TrendReportGraphsTest.java index cafb862a..5631704d 100644 --- a/src/test/java/hudson/plugins/performance/TrendReportGraphsTest.java +++ b/src/test/java/hudson/plugins/performance/TrendReportGraphsTest.java @@ -4,7 +4,6 @@ import hudson.model.FreeStyleProject; import hudson.plugins.performance.reports.PerformanceReport; import hudson.plugins.performance.reports.PerformanceReportTest; -import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; @@ -15,11 +14,6 @@ public class TrendReportGraphsTest { @Rule public JenkinsRule j = new JenkinsRule(); - @After - public void shutdown() throws Exception { - j.after(); - } - @Test public void test() throws Exception { FreeStyleProject project = j.createFreeStyleProject(); From c7fb7d79505e655623a0b91bab9942ac1b2baa8e Mon Sep 17 00:00:00 2001 From: Alexander Straube Date: Fri, 29 Sep 2023 15:01:47 +0200 Subject: [PATCH 7/7] Remove explicit call of JenkinsRule.after() --- .../performance/actions/PerformanceProjectActionTest.java | 7 ------- .../plugins/performance/constraints/ConstraintTest.java | 6 ------ .../performance/descriptors/ConstraintDescriptorTest.java | 6 ------ .../descriptors/PerformanceReportParserDescriptorTest.java | 6 ------ .../performance/details/GraphConfigurationDetailTest.java | 6 ------ .../performance/details/TestSuiteReportDetailTest.java | 6 ------ 6 files changed, 37 deletions(-) diff --git a/src/test/java/hudson/plugins/performance/actions/PerformanceProjectActionTest.java b/src/test/java/hudson/plugins/performance/actions/PerformanceProjectActionTest.java index fbbe7a31..68da9434 100644 --- a/src/test/java/hudson/plugins/performance/actions/PerformanceProjectActionTest.java +++ b/src/test/java/hudson/plugins/performance/actions/PerformanceProjectActionTest.java @@ -5,7 +5,6 @@ import hudson.plugins.performance.details.GraphConfigurationDetail; import hudson.plugins.performance.details.TestSuiteReportDetail; import hudson.plugins.performance.details.TrendReportDetail; -import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -27,12 +26,6 @@ public class PerformanceProjectActionTest { @Mock private StaplerRequest staplerRequest; - @After - public void shutdown() throws Exception { - j.after(); - } - - @Test public void testDynamic() throws Exception { FreeStyleProject freeStyleProject = j.createFreeStyleProject("testProject"); diff --git a/src/test/java/hudson/plugins/performance/constraints/ConstraintTest.java b/src/test/java/hudson/plugins/performance/constraints/ConstraintTest.java index 441eeac5..f733cd98 100644 --- a/src/test/java/hudson/plugins/performance/constraints/ConstraintTest.java +++ b/src/test/java/hudson/plugins/performance/constraints/ConstraintTest.java @@ -5,7 +5,6 @@ import java.util.List; import hudson.plugins.performance.constraints.blocks.TestCaseBlock; -import org.junit.After; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -28,11 +27,6 @@ public class ConstraintTest { @Rule public JenkinsRule j = new JenkinsRule(); - @After - public void shutdown() throws Exception { - j.after(); - } - /** * Testing: Escalation.INFORMATION * Build must stay successful if the value is exceeded. diff --git a/src/test/java/hudson/plugins/performance/descriptors/ConstraintDescriptorTest.java b/src/test/java/hudson/plugins/performance/descriptors/ConstraintDescriptorTest.java index 84192dbb..233b1af8 100644 --- a/src/test/java/hudson/plugins/performance/descriptors/ConstraintDescriptorTest.java +++ b/src/test/java/hudson/plugins/performance/descriptors/ConstraintDescriptorTest.java @@ -2,7 +2,6 @@ import hudson.plugins.performance.constraints.AbsoluteConstraint; import hudson.plugins.performance.constraints.RelativeConstraint; -import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; @@ -14,11 +13,6 @@ public class ConstraintDescriptorTest { @Rule public JenkinsRule j = new JenkinsRule(); - @After - public void shutdown() throws Exception { - j.after(); - } - @Test public void name() throws Exception { ConstraintDescriptor descriptor = ConstraintDescriptor.getById(AbsoluteConstraint.DescriptorImpl.class.getName()); diff --git a/src/test/java/hudson/plugins/performance/descriptors/PerformanceReportParserDescriptorTest.java b/src/test/java/hudson/plugins/performance/descriptors/PerformanceReportParserDescriptorTest.java index 18f2cdaa..6f45085f 100644 --- a/src/test/java/hudson/plugins/performance/descriptors/PerformanceReportParserDescriptorTest.java +++ b/src/test/java/hudson/plugins/performance/descriptors/PerformanceReportParserDescriptorTest.java @@ -7,7 +7,6 @@ import hudson.plugins.performance.parsers.JmeterSummarizerParser; import hudson.plugins.performance.parsers.TaurusParser; import hudson.plugins.performance.parsers.WrkSummarizerParser; -import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; @@ -19,11 +18,6 @@ public class PerformanceReportParserDescriptorTest { @Rule public JenkinsRule j = new JenkinsRule(); - @After - public void shutdown() throws Exception { - j.after(); - } - @Test public void name() throws Exception { PerformanceReportParserDescriptor descriptor = PerformanceReportParserDescriptor.getById(IagoParser.DescriptorImpl.class.getName()); diff --git a/src/test/java/hudson/plugins/performance/details/GraphConfigurationDetailTest.java b/src/test/java/hudson/plugins/performance/details/GraphConfigurationDetailTest.java index f1927f18..18b88bcb 100644 --- a/src/test/java/hudson/plugins/performance/details/GraphConfigurationDetailTest.java +++ b/src/test/java/hudson/plugins/performance/details/GraphConfigurationDetailTest.java @@ -1,7 +1,6 @@ package hudson.plugins.performance.details; import hudson.model.FreeStyleProject; -import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -24,11 +23,6 @@ public class GraphConfigurationDetailTest { @Mock private StaplerRequest request; - @After - public void shutdown() throws Exception { - j.after(); - } - @Test public void testDefault() throws Exception { FreeStyleProject project = j.createFreeStyleProject("testProject"); diff --git a/src/test/java/hudson/plugins/performance/details/TestSuiteReportDetailTest.java b/src/test/java/hudson/plugins/performance/details/TestSuiteReportDetailTest.java index d0f0c851..62be57dd 100644 --- a/src/test/java/hudson/plugins/performance/details/TestSuiteReportDetailTest.java +++ b/src/test/java/hudson/plugins/performance/details/TestSuiteReportDetailTest.java @@ -21,7 +21,6 @@ import hudson.plugins.performance.reports.PerformanceReport; import hudson.plugins.performance.reports.UriReport; import org.jfree.data.category.CategoryDataset; -import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -68,11 +67,6 @@ public void setUp() throws Exception { uriReportMap.put(TEST_URI, getUriReport()); } - @After - public void shutdown() throws Exception { - j.after(); - } - private UriReport getUriReport() { UriReport uriReport = new UriReport(report, TEST_URI, TEST_URI); final HttpSample sample1 = new HttpSample();