本文整理匯總了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;
}