本文整理汇总了Java中okhttp3.mockwebserver.MockWebServer.url方法的典型用法代码示例。如果您正苦于以下问题:Java MockWebServer.url方法的具体用法?Java MockWebServer.url怎么用?Java MockWebServer.url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类okhttp3.mockwebserver.MockWebServer
的用法示例。
在下文中一共展示了MockWebServer.url方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRequest
import okhttp3.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Test
public void testRequest() throws IOException {
MockWebServer server = new MockWebServer();
try {
server.enqueue(new MockResponse().setBody("hello, world!").setResponseCode(200));
HttpUrl httpUrl = server.url("/hello");
// TODO: Rule does not currently work when just using the OkHttpClient default constructor
OkHttpClient client = new OkHttpClient.Builder()
.build();
Request request = new Request.Builder()
.url(httpUrl)
.build();
Response response = client.newCall(request).execute();
assertEquals(200, response.code());
List<MockSpan> spans = getTracer().finishedSpans();
assertEquals(2, spans.size());
assertEquals("GET", spans.get(0).operationName());
assertEquals("GET", spans.get(1).operationName());
} finally {
server.shutdown();
server.close();
}
}
示例2: setUp
import okhttp3.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
mockWebServer = new MockWebServer();
mockWebServer.start();
waiter = new Waiter();
MockitoAnnotations.initMocks(this);
xmrToApi = new XmrToApiImpl(okHttpClient, mockWebServer.url("/"));
}
示例3: setUp
import okhttp3.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
mockWebServer = new MockWebServer();
mockWebServer.start();
waiter = new Waiter();
MockitoAnnotations.initMocks(this);
exchangeApi = new ExchangeApiImpl(okHttpClient, mockWebServer.url("/"));
}
示例4: run
import okhttp3.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@ArbitraryMeasurement(description = "requests per second")
public double run() throws Exception {
if (VERBOSE) System.out.println(toString());
HttpClient httpClient = client.create();
// Prepare the client & server
httpClient.prepare(this);
MockWebServer server = startServer();
HttpUrl url = server.url("/");
int requestCount = 0;
long reportStart = System.nanoTime();
long reportPeriod = TimeUnit.SECONDS.toNanos(1);
int reports = 0;
double best = 0.0;
// Run until we've printed enough reports.
while (reports < NUM_REPORTS) {
// Print a report if we haven't recently.
long now = System.nanoTime();
double reportDuration = now - reportStart;
if (reportDuration > reportPeriod) {
double requestsPerSecond = requestCount / reportDuration * TimeUnit.SECONDS.toNanos(1);
if (VERBOSE) {
System.out.println(String.format("Requests per second: %.1f", requestsPerSecond));
}
best = Math.max(best, requestsPerSecond);
requestCount = 0;
reportStart = now;
reports++;
}
// Fill the job queue with work.
while (httpClient.acceptingJobs()) {
httpClient.enqueue(url);
requestCount++;
}
// The job queue is full. Take a break.
sleep(1);
}
return best;
}