当前位置: 首页>>代码示例>>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;未经允许,请勿转载。