當前位置: 首頁>>代碼示例>>Java>>正文


Java MockWebServer.url方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:opentracing-contrib,項目名稱:java-agent,代碼行數:32,代碼來源:OkHttpITest.java

示例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("/"));
}
 
開發者ID:m2049r,項目名稱:xmrwallet,代碼行數:12,代碼來源:XmrToApiOrderParameterTest.java

示例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("/"));
}
 
開發者ID:m2049r,項目名稱:xmrwallet,代碼行數:12,代碼來源:ExchangeRateTest.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:45,代碼來源:Benchmark.java


注:本文中的okhttp3.mockwebserver.MockWebServer.url方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。