Created
July 5, 2017 13:49
-
-
Save neilg/f46b24bcf4af8da2f1f28874b0beb97e to your computer and use it in GitHub Desktop.
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
package com.github.tomakehurst.wiremock; | |
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | |
import static com.github.tomakehurst.wiremock.client.WireMock.get; | |
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.net.URL; | |
import java.net.URLConnection; | |
import com.github.tomakehurst.wiremock.junit.WireMockRule; | |
import org.junit.Test; | |
import org.junit.runners.model.Statement; | |
public class StartStopInterferenceTest { | |
private WireMockRule wireMockRule = new WireMockRule(9876); | |
@Test | |
public void go() throws Throwable { | |
int i = 0; | |
try { | |
for (; i < 100_000; i++) { | |
System.out.println(i); | |
final Statement statement = new Statement() { | |
@Override | |
public void evaluate() throws Throwable { | |
wireMockRule.stubFor(get(urlEqualTo("/bob")) | |
.willReturn(aResponse() | |
.withHeader("Content-type", "application/json") | |
.withBody("{\"id\": 11,\"desc\": \"bob\"}"))); | |
final String url = "http://localhost:" + wireMockRule.port() + "/bob"; | |
final URLConnection urlConnection = new URL(url).openConnection(); | |
try (final InputStream inputStream = urlConnection.getInputStream()) { | |
consumeFully(inputStream); | |
} | |
} | |
}; | |
final Statement apply = wireMockRule.apply(statement, null); | |
apply.evaluate(); | |
} | |
} catch (final Throwable e) { | |
System.out.println(i); | |
throw e; | |
} | |
} | |
private void consumeFully(final InputStream inputStream) throws IOException { | |
byte[] buffer = new byte[1024]; | |
int bytesRead; | |
do { | |
bytesRead = inputStream.read(buffer); | |
} while (bytesRead != -1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment