-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix master/slave issue & URL recognition
• Due to RMI usage of JMeter when running a master/slave test, users were experimenting a NullPointerException due to bad object serialization. • Improvement on URL recognition. IMPORTANT: For HLS protocol test (not MPG-DASH) is mandatory that the URL contains its extension ".m3u8" as is explained on ISO regulation: https://tools.ietf.org/html/rfc8216#section-4
- Loading branch information
Showing
14 changed files
with
438 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/com/blazemeter/jmeter/hls/logic/VideoStreamingSamplerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.blazemeter.jmeter.hls.logic; | ||
|
||
import com.blazemeter.jmeter.videostreaming.core.SampleResultProcessor; | ||
import com.blazemeter.jmeter.videostreaming.core.TimeMachine; | ||
import com.blazemeter.jmeter.videostreaming.core.VideoStreamingHttpClient; | ||
import com.blazemeter.jmeter.videostreaming.core.VideoStreamingSampler; | ||
import com.blazemeter.jmeter.videostreaming.dash.DashSampler; | ||
|
||
public class VideoStreamingSamplerFactory { | ||
|
||
public VideoStreamingSampler<?, ?> getVideoStreamingSampler(String url, HlsSampler baseSampler, | ||
VideoStreamingHttpClient httpClient, | ||
TimeMachine timeMachine, SampleResultProcessor sampleResultProcessor) { | ||
//HLS Master Playlist must contain this .m3u8 extension in their URLs | ||
if (url.contains(".m3u8")) { | ||
return createHlsSampler(baseSampler, httpClient, timeMachine, sampleResultProcessor); | ||
} else { | ||
return createDashSampler(baseSampler, httpClient, timeMachine, sampleResultProcessor); | ||
} | ||
} | ||
|
||
private DashSampler createDashSampler(HlsSampler baseSampler, VideoStreamingHttpClient httpClient, | ||
TimeMachine timeMachine, SampleResultProcessor sampleResultProcessor) { | ||
return new DashSampler(baseSampler, httpClient, timeMachine, sampleResultProcessor); | ||
} | ||
|
||
private com.blazemeter.jmeter.videostreaming.hls.HlsSampler createHlsSampler( | ||
HlsSampler baseSampler, VideoStreamingHttpClient httpClient, TimeMachine timeMachine, | ||
SampleResultProcessor sampleResultProcessor) { | ||
return new com.blazemeter.jmeter.videostreaming.hls.HlsSampler(baseSampler, httpClient, | ||
timeMachine, sampleResultProcessor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.blazemeter.jmeter; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.time.Duration; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.rules.RuleChain; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.Container.ExecResult; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; | ||
import org.testcontainers.images.builder.ImageFromDockerfile; | ||
|
||
@Category(MasterSlaveIT.class) | ||
public class MasterSlaveIT { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(MasterSlaveIT.class); | ||
private static final long TIMEOUT_MILLI = 120000; | ||
private static final String JMETER_HOME_PATH = "/jmeter/apache-jmeter-5.1.1/bin"; | ||
private static final Network network = Network.newNetwork(); | ||
|
||
public GenericContainer<?> wiremockContainer; | ||
public GenericContainer<?> container; | ||
|
||
@Rule | ||
public RuleChain chain = RuleChain | ||
.outerRule(wiremockContainer = buildWiremockContainerFromDockerfile()) | ||
.around(container = getJavaContainerFromDockerfile()); | ||
|
||
@Test(timeout = TIMEOUT_MILLI * 2) | ||
public void shouldRunHLSMasterSlaveTestWhenStartContainer() | ||
throws IOException, InterruptedException { | ||
ExecResult execResult = container.execInContainer("sh", JMETER_HOME_PATH + "/jmeter", | ||
"-n", "-r", "-t", "/test.jmx", "-l", "/result", "-j", "/master_logs"); | ||
|
||
assertThat(execResult.getStdout()).contains("... end of run"); | ||
} | ||
|
||
private GenericContainer<?> buildWiremockContainerFromDockerfile() { | ||
return new GenericContainer<>( | ||
new ImageFromDockerfile() | ||
//adding files to test-container context | ||
.withFileFromClasspath("mapping.json", "master-slave/mapping.json") | ||
.withFileFromClasspath("Dockerfile", "master-slave/WiremockDockerfile") | ||
.withDockerfilePath("Dockerfile")) | ||
.withLogConsumer(new Slf4jLogConsumer(LOG).withPrefix("WIREMOCK")) | ||
.withExposedPorts(8080) | ||
.withNetwork(network) | ||
.withNetworkAliases("wiremock") | ||
// wait for wiremock to be running | ||
.waitingFor(new LogMessageWaitStrategy() | ||
.withRegEx(".*(/\\$\\$ /\\$\\$ /\\$\\$ " | ||
+ " /\\$\\$ /\\$\\$ /\\$\\$ ).*") | ||
.withStartupTimeout(Duration.ofMillis(TIMEOUT_MILLI))); | ||
} | ||
|
||
private GenericContainer<?> getJavaContainerFromDockerfile() { | ||
return new GenericContainer<>( | ||
new ImageFromDockerfile() | ||
//adding files to test-container context | ||
.withFileFromClasspath("master-slave-test.sh", "master-slave/master-slave-test.sh") | ||
.withFileFromClasspath("Dockerfile", "master-slave/Dockerfile") | ||
.withFileFromClasspath("test.jmx", "master-slave/HLSSamplerSlaveRemoteTest.jmx") | ||
.withFileFromFile("jmeter-bzm-hls.jar", | ||
new File("target/jmeter-test/lib/jmeter-bzm-hls.jar")) | ||
.withFileFromFile("hlsparserj.jar", | ||
new File("target/jmeter-test/lib/hlsparserj.jar")) | ||
.withDockerfilePath("Dockerfile")) | ||
.withLogConsumer(new Slf4jLogConsumer(LOG).withPrefix("MAIN")) | ||
.withNetwork(network) | ||
.withNetworkAliases("master") | ||
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*Created\\sremote\\sobject.*") | ||
.withStartupTimeout(Duration.ofMillis(TIMEOUT_MILLI))); | ||
|
||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/test/java/com/blazemeter/jmeter/hls/logic/HlsSamplerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.blazemeter.jmeter.hls.logic; | ||
|
||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.only; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import com.blazemeter.jmeter.videostreaming.core.MediaSegment; | ||
import com.blazemeter.jmeter.videostreaming.core.SampleResultProcessor; | ||
import com.blazemeter.jmeter.videostreaming.core.TimeMachine; | ||
import com.blazemeter.jmeter.videostreaming.core.VideoStreamingHttpClient; | ||
import com.blazemeter.jmeter.videostreaming.core.VideoStreamingSampler; | ||
import com.blazemeter.jmeter.videostreaming.hls.Playlist; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class HlsSamplerTest { | ||
|
||
@Mock | ||
private VideoStreamingSampler<Playlist, MediaSegment> videoStreamingSampler; | ||
@Mock | ||
private VideoStreamingSamplerFactory factory; | ||
@Mock | ||
private VideoStreamingHttpClient client; | ||
@Mock | ||
private TimeMachine timeMachine; | ||
@Mock | ||
private SampleResultProcessor processor; | ||
|
||
private HlsSampler hlsSampler; | ||
|
||
@Before | ||
public void setUp() { | ||
hlsSampler = new HlsSampler(factory, client, processor, timeMachine); | ||
} | ||
|
||
@Test | ||
public void shouldFactoryGetVideoStreamingSamplerWhenSample() { | ||
String masterUrl = "hls_master_playlist.m3u8"; | ||
hlsSampler.setMasterUrl(masterUrl); | ||
|
||
doReturn(videoStreamingSampler) | ||
.when(factory) | ||
.getVideoStreamingSampler(masterUrl, hlsSampler, client, timeMachine, processor); | ||
|
||
hlsSampler.sample(); | ||
verify(factory, only()) | ||
.getVideoStreamingSampler(masterUrl, hlsSampler, client, timeMachine, processor); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/test/java/com/blazemeter/jmeter/hls/logic/VideoStreamingSamplerFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.blazemeter.jmeter.hls.logic; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.blazemeter.jmeter.videostreaming.core.SampleResultProcessor; | ||
import com.blazemeter.jmeter.videostreaming.core.TimeMachine; | ||
import com.blazemeter.jmeter.videostreaming.core.VideoStreamingHttpClient; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
|
||
public class VideoStreamingSamplerFactoryTest { | ||
|
||
@Mock | ||
private HlsSampler proxy; | ||
@Mock | ||
private VideoStreamingHttpClient client; | ||
@Mock | ||
private TimeMachine timeMachine; | ||
@Mock | ||
private SampleResultProcessor processor; | ||
|
||
private VideoStreamingSamplerFactory factory; | ||
|
||
@Before | ||
public void setUp() { | ||
factory = new VideoStreamingSamplerFactory(); | ||
} | ||
|
||
@Test | ||
public void shouldCreateHlsSamplerWhenUrlContainsExtension() { | ||
assertThat(factory | ||
.getVideoStreamingSampler("test.com/master.m3u8", proxy, client, timeMachine, processor)) | ||
.isInstanceOf(com.blazemeter.jmeter.videostreaming.hls.HlsSampler.class); | ||
} | ||
|
||
@Test | ||
public void shouldNotCreateHlsSamplerWhenUrlNotContainsExtension() { | ||
assertThat(factory | ||
.getVideoStreamingSampler("test.com/master.mpd", proxy, client, timeMachine, processor)) | ||
.isNotInstanceOf(com.blazemeter.jmeter.videostreaming.hls.HlsSampler.class); | ||
} | ||
} |
Oops, something went wrong.