当前位置: 首页>>代码示例>>Java>>正文


Java MockWebServer.play方法代码示例

本文整理汇总了Java中com.google.mockwebserver.MockWebServer.play方法的典型用法代码示例。如果您正苦于以下问题:Java MockWebServer.play方法的具体用法?Java MockWebServer.play怎么用?Java MockWebServer.play使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.mockwebserver.MockWebServer的用法示例。


在下文中一共展示了MockWebServer.play方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
    super.setUp();
    mMockitoHelper.setUp(getClass());

    // Since we're testing a system app, AppDataDirGuesser doesn't find our
    // cache dir, so set it explicitly.
    System.setProperty("dexmaker.dexcache", getContext().getCacheDir().toString());

    final Context realContext = getContext();
    mTestContext = new TestContext(realContext);
    setupProviderAndResolver();
    mTestContext.setResolver(mResolver);
    setContext(mTestContext);
    setupService();
    // getService().mSystemFacade = mSystemFacade;
    mSystemFacade.setUp();
    assertTrue(isDatabaseEmpty()); // ensure we're not messing with real data
    mServer = new MockWebServer();
    mServer.play();
}
 
开发者ID:wuyexiong,项目名称:android-downloadprovider,代码行数:22,代码来源:AbstractDownloadProviderFunctionalTest.java

示例2: getKeepAlive

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Test public void getKeepAlive() throws Exception {
  MockWebServer server = new MockWebServer();
  server.enqueue(new MockResponse().setBody("ABC"));
  server.play();

  // The request should work once and then fail
  URLConnection connection1 = client.open(server.getUrl(""));
  connection1.setReadTimeout(100);
  InputStream input = connection1.getInputStream();
  assertEquals("ABC", readAscii(input, Integer.MAX_VALUE));
  input.close();
  server.shutdown();
  try {
    HttpURLConnection connection2 = client.open(server.getUrl(""));
    connection2.setReadTimeout(100);
    connection2.getInputStream();
    fail();
  } catch (ConnectException expected) {
  }
}
 
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:21,代码来源:URLConnectionTest.java

示例3: setUp

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Before public void setUp() throws Exception {
  server = new MockWebServer();
  server.play();

  Activity activity = Robolectric.buildActivity(Activity.class).get();
  loader = new UrlConnectionDownloader(activity) {
    @Override protected HttpURLConnection openConnection(Uri path) throws IOException {
      return (HttpURLConnection) server.getUrl(path.toString()).openConnection();
    }
  };
}
 
开发者ID:Pixate,项目名称:picasso,代码行数:12,代码来源:UrlConnectionDownloaderTest.java

示例4: setUp

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Before public void setUp() throws Exception {
  server = new MockWebServer();
  server.play();

  Activity activity = Robolectric.buildActivity(Activity.class).get();
  loader = new OkHttpDownloader(activity) {
    @Override protected HttpURLConnection openConnection(Uri path) throws IOException {
      return (HttpURLConnection) server.getUrl(path.toString()).openConnection();
    }
  };
}
 
开发者ID:Pixate,项目名称:picasso,代码行数:12,代码来源:OkHttpDownloaderTest.java

示例5: testContainerInspect

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Test
public void testContainerInspect() throws IOException {
    String json = Resources.toString(getResource("container/inspect-4fa6e0f0c678.json"), Charsets.UTF_8);
    MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody(json));
    server.play();
    Docker docker = createDockerForMock(server);
    ContainerInfo containerInfo = docker.containerInspect("4fa6e0f0c678");
    assertNotNull(containerInfo);
}
 
开发者ID:jboss-fuse,项目名称:fuse-docker,代码行数:11,代码来源:ContainerTest.java

示例6: survive

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Test
public void survive() throws IOException, ClientException, URISyntaxException, InterruptedException {

    String clientName = "RibbonClientTest-loadBalancingDefaultPolicyRoundRobin";
    String serverListKey = clientName + ".ribbon.listOfServers";
    int nbHitsPerServer = 60;
    MockWebServer server1 = new MockWebServer();
    MockWebServer server2 = new MockWebServer();

    for (int i = 0; i < nbHitsPerServer; i++) {
        server1.enqueue(new MockResponse().setResponseCode(200).setBody("server1 success <" + i + ">!"));
        server2.enqueue(new MockResponse().setResponseCode(200).setBody("server2 success <" + i + ">!"));
    }

    server1.play();
    server2.play();

    getConfigInstance().setProperty(serverListKey, hostAndPort(server1.getUrl("")) + "," + hostAndPort(server2.getUrl("")));

    RestClient client = (RestClient) ClientFactory.getNamedClient(clientName);
    HttpRequest request;
    for (int i = 0; i < nbHitsPerServer * 2; i++) {
        request = HttpRequest.newBuilder().uri(new URI("/")).build();
        HttpResponse response = client.executeWithLoadBalancer(request);
        response.close();
    }
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:28,代码来源:ManyShortLivedRequestsSurvivorTest.java

示例7: testCommand

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Test
public void testCommand() throws IOException, InterruptedException, ExecutionException {
    MockWebServer server = new MockWebServer();
    String content = "Hello world";
    MockResponse response = new MockResponse()
        .setResponseCode(200)
        .setHeader("Content-type", "text/plain")
        .setBody(content);
    
    server.enqueue(response);        
    server.enqueue(response);       
    server.enqueue(response);       
    server.play();
    
    HttpResourceGroup group = Ribbon.createHttpResourceGroup("myclient",
            ClientOptions.create()
            .withMaxAutoRetriesNextServer(3)
            .withReadTimeout(300000)
            .withConfigurationBasedServerList("localhost:12345, localhost:10092, localhost:" + server.getPort()));
    HttpRequestTemplate<ByteBuf> template = group.newTemplateBuilder("test", ByteBuf.class)
            .withUriTemplate("/")
            .withMethod("GET")
            .build();
    
    RibbonRequest<ByteBuf> request = template.requestBuilder().build();
    
    String result = request.execute().toString(Charset.defaultCharset());
    assertEquals(content, result);
    // repeat the same request
    ByteBuf raw = request.execute();
    result = raw.toString(Charset.defaultCharset());
    raw.release();
    assertEquals(content, result);
    
    result = request.queue().get().toString(Charset.defaultCharset());
    assertEquals(content, result);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:38,代码来源:RibbonTest.java

示例8: testListContainers

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Test
public void testListContainers() throws IOException {
    String json = Resources.toString(getResource("container/containers-all.json"), Charsets.UTF_8);
    MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody(json));
    server.play();
    Docker docker = createDockerForMock(server);
    List<Container> containers = docker.containers(1, 1, null, null, 1);
    assertNotNull(containers);
    assertEquals(containers.size(), 4);
    assertContainers(containers);
}
 
开发者ID:jboss-fuse,项目名称:fuse-docker,代码行数:13,代码来源:ContainerTest.java

示例9: testCacheMiss

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Test
public void testCacheMiss() throws IOException, InterruptedException {
    MockWebServer server = new MockWebServer();
    String content = "Hello world";
    server.enqueue(new MockResponse()
            .setResponseCode(200)
            .setHeader("Content-type", "text/plain")
            .setBody(content));       
    server.play();
            
    HttpResourceGroup group = Ribbon.createHttpResourceGroup("myclient", ClientOptions.create()
            .withConfigurationBasedServerList("localhost:" + server.getPort())
            .withMaxAutoRetriesNextServer(1));
    final String cacheKey = "somekey";
    HttpRequestTemplate<ByteBuf> template = group.newTemplateBuilder("test")
            .withCacheProvider(cacheKey, new CacheProvider<ByteBuf>(){
                @Override
                public Observable<ByteBuf> get(String key, Map<String, Object> vars) {
                    return Observable.error(new Exception("Cache miss again"));
                }
            })
            .withMethod("GET")
            .withUriTemplate("/").build();
    RibbonRequest<ByteBuf> request = template
            .requestBuilder().build();
    String result = toStringBlocking(request);
    assertEquals(content, result);
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:29,代码来源:RibbonTest.java

示例10: testServerListRefresh

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
/**
 * This test ensures that when server list is refreshed in the load balancer, the set of servers
 * which equals to (oldList - newList) should be removed from the map of cached RxClient. Any server
 * that is not part of oldList should stay in the map.
 *
 * @throws IOException
 */
@Test
public void testServerListRefresh() throws IOException {
    String content = "Hello world";
    MockWebServer server1 = new MockWebServer();
    MockWebServer server2 = new MockWebServer();
    MockWebServer server3 = new MockWebServer();
    MockResponse mockResponse = new MockResponse().setResponseCode(200).setHeader("Content-type", "text/plain")
            .setBody(content);
    server1.enqueue(mockResponse);
    server2.enqueue(mockResponse);
    server3.enqueue(mockResponse);
    server1.play();
    server2.play();
    server3.play();
    try {
        BaseLoadBalancer lb = new BaseLoadBalancer();
        List<Server> initialList = Lists.newArrayList(new Server("localhost", server1.getPort()), new Server("localhost", server2.getPort()));
        lb.setServersList(initialList);
        LoadBalancingHttpClient<ByteBuf, ByteBuf> client = RibbonTransport.newHttpClient(lb);
        HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/");
        client.submit(request).toBlocking().last();
        client.submit(request).toBlocking().last();
        HttpClientRequest<ByteBuf> request2 = HttpClientRequest.createGet("http://localhost:" + server3.getPort());
        client.submit(request2).toBlocking().last();
        Set<Server> cachedServers = client.getRxClients().keySet();
        assertEquals(Sets.newHashSet(new Server("localhost", server1.getPort()), new Server("localhost", server2.getPort()), new Server("localhost", server3.getPort())), cachedServers);
        List<Server> newList = Lists.newArrayList(new Server("localhost", server1.getPort()), new Server("localhost", 99999));
        lb.setServersList(newList);
        cachedServers = client.getRxClients().keySet();
        assertEquals(Sets.newHashSet(new Server("localhost", server1.getPort()), new Server("localhost", server3.getPort())), cachedServers);
    } finally {
        server1.shutdown();
        server2.shutdown();
        server3.shutdown();
    }
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:44,代码来源:ServerListRefreshTest.java

示例11: redirectToAnotherOriginServer

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
private void redirectToAnotherOriginServer(boolean https) throws Exception {
  server2 = new MockWebServer();
  if (https) {
    server.useHttps(sslContext.getSocketFactory(), false);
    server2.useHttps(sslContext.getSocketFactory(), false);
    client.setSslSocketFactory(sslContext.getSocketFactory());
    client.setHostnameVerifier(new RecordingHostnameVerifier());
  }

  server2.enqueue(new MockResponse().setBody("This is the 2nd server!"));
  server2.enqueue(new MockResponse().setBody("This is the 2nd server, again!"));
  server2.play();

  server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP)
      .addHeader("Location: " + server2.getUrl("/").toString())
      .setBody("This page has moved!"));
  server.enqueue(new MockResponse().setBody("This is the first server again!"));
  server.play();

  URLConnection connection = client.open(server.getUrl("/"));
  assertContent("This is the 2nd server!", connection);
  assertEquals(server2.getUrl("/"), connection.getURL());

  // make sure the first server was careful to recycle the connection
  assertContent("This is the first server again!", client.open(server.getUrl("/")));
  assertContent("This is the 2nd server, again!", client.open(server2.getUrl("/")));

  String server1Host = hostName + ":" + server.getPort();
  String server2Host = hostName + ":" + server2.getPort();
  assertContains(server.takeRequest().getHeaders(), "Host: " + server1Host);
  assertContains(server2.takeRequest().getHeaders(), "Host: " + server2Host);
  assertEquals("Expected connection reuse", 1, server.takeRequest().getSequenceNumber());
  assertEquals("Expected connection reuse", 1, server2.takeRequest().getSequenceNumber());
}
 
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:35,代码来源:URLConnectionTest.java

示例12: testContainerCreate

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Test
public void testContainerCreate() throws IOException {
    String json = Resources.toString(getResource("container/create-response.json"), Charsets.UTF_8);
    MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody(json));
    server.play();
    Docker docker = createDockerForMock(server);
    ContainerConfig cfg = null;
    ContainerConfig.builder().image("base").cmd(new String[]{"date"});
    ContainerCreateStatus containerCreateStatus = docker.containerCreate(cfg);
    assertNotNull(containerCreateStatus);
    assertEquals(containerCreateStatus.getId(), "e90e34656806");
}
 
开发者ID:jboss-fuse,项目名称:fuse-docker,代码行数:14,代码来源:ContainerTest.java

示例13: testSuccessExecution

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Test
public void testSuccessExecution() throws IOException {
    MockWebServer server = new MockWebServer();
    String content = "OK";
    server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-type", "application/json")
            .setBody(content));
    server.play();

    IClientConfig config = DefaultClientConfigImpl
            .getClientConfigWithDefaultValues()
            .withProperty(CommonClientConfigKey.ConnectTimeout, "2000")
            .withProperty(CommonClientConfigKey.MaxAutoRetries, 1)
            .withProperty(CommonClientConfigKey.MaxAutoRetriesNextServer, 1);
    
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/testAsync/person");
    Server badServer  = new Server("localhost:12345");
    Server goodServer = new Server("localhost:" + server.getPort());
    List<Server> servers = Lists.newArrayList(goodServer, badServer);

    BaseLoadBalancer lb = LoadBalancerBuilder.<Server>newBuilder()
            .withRule(new AvailabilityFilteringRule())
            .withPing(new DummyPing())
            .buildFixedServerListLoadBalancer(servers);
    IClientConfig overrideConfig = DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.ConnectTimeout, 500);
    TestExecutionListener<ByteBuf, ByteBuf> listener = new TestExecutionListener<ByteBuf, ByteBuf>(request, overrideConfig);
    List<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>> listeners = Lists.<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>>newArrayList(listener);
    LoadBalancingHttpClient<ByteBuf, ByteBuf> client = RibbonTransport.newHttpClient(lb, config, new NettyHttpLoadBalancerErrorHandler(config), listeners);
    HttpClientResponse<ByteBuf> response = client.submit(request, null, overrideConfig).toBlocking().last();
    assertEquals(200, response.getStatus().code());
    assertEquals(1, listener.executionStartCounter.get());
    assertEquals(3, listener.startWithServerCounter.get());
    assertEquals(2, listener.exceptionWithServerCounter.get());
    assertEquals(0, listener.executionFailedCounter.get());
    assertEquals(1, listener.executionSuccessCounter.get());
    assertEquals(500, listener.getContext().getClientProperty(CommonClientConfigKey.ConnectTimeout).intValue());
    assertTrue(listener.isContextChecked());
    assertTrue(listener.isCheckExecutionInfo());
    assertSame(response, listener.getResponse());
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:40,代码来源:ListenerTest.java

示例14: testSuccessExecutionOnAbosoluteURI

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Test
public void testSuccessExecutionOnAbosoluteURI() throws IOException {
    MockWebServer server = new MockWebServer();
    String content = "OK";
    server.enqueue(new MockResponse().setResponseCode(200).setHeader("Content-type", "application/json")
            .setBody(content));
    server.play();

    IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues().withProperty(CommonClientConfigKey.ConnectTimeout, "2000")
            .withProperty(CommonClientConfigKey.MaxAutoRetries, 1)
            .withProperty(CommonClientConfigKey.MaxAutoRetriesNextServer, 1);
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("http://localhost:" + server.getPort() + "/testAsync/person");
    Server badServer = new Server("localhost:12345");
    Server goodServer = new Server("localhost:" + server.getPort());
    List<Server> servers = Lists.newArrayList(goodServer, badServer);

    BaseLoadBalancer lb = LoadBalancerBuilder.<Server>newBuilder()
            .withRule(new AvailabilityFilteringRule())
            .withPing(new DummyPing())
            .buildFixedServerListLoadBalancer(servers);
    IClientConfig overrideConfig = DefaultClientConfigImpl.getEmptyConfig().set(CommonClientConfigKey.ConnectTimeout, 500);
    TestExecutionListener<ByteBuf, ByteBuf> listener = new TestExecutionListener<ByteBuf, ByteBuf>(request, overrideConfig);
    List<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>> listeners = Lists.<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>>newArrayList(listener);
    LoadBalancingHttpClient<ByteBuf, ByteBuf> client = RibbonTransport.newHttpClient(lb, config, new NettyHttpLoadBalancerErrorHandler(config), listeners);
    HttpClientResponse<ByteBuf> response = client.submit(request, null, overrideConfig).toBlocking().last();
    assertEquals(200, response.getStatus().code());
    assertEquals(1, listener.executionStartCounter.get());
    assertEquals(1, listener.startWithServerCounter.get());
    assertEquals(0, listener.exceptionWithServerCounter.get());
    assertEquals(0, listener.executionFailedCounter.get());
    assertEquals(1, listener.executionSuccessCounter.get());
    assertEquals(500, listener.getContext().getClientProperty(CommonClientConfigKey.ConnectTimeout).intValue());
    assertTrue(listener.isContextChecked());
    assertTrue(listener.isCheckExecutionInfo());
    assertSame(response, listener.getResponse());
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:37,代码来源:ListenerTest.java

示例15: testInfo

import com.google.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Test
public void testInfo() throws IOException {
    String json = Resources.toString(getResource("info.json"), Charsets.UTF_8);
    MockWebServer server = new MockWebServer();
    server.enqueue(new MockResponse().setBody(json));
    server.play();
    Docker docker = createDockerForMock(server);
    Info info = docker.info();
    assertNotNull(info);
    assertEquals(info.getContainers(), 11);
    assertEquals(info.getImages(), 16);
}
 
开发者ID:jboss-fuse,项目名称:fuse-docker,代码行数:13,代码来源:InfoTest.java


注:本文中的com.google.mockwebserver.MockWebServer.play方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。