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


Java MockWebServer.setServerSocketFactory方法代码示例

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


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

示例1: setUp

import okhttp3.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Before public void setUp() throws Exception {
  // Sockets on some platforms can have large buffers that mean writes do not block when
  // required. These socket factories explicitly set the buffer sizes on sockets created.
  server = new MockWebServer();
  server.setServerSocketFactory(
      new DelegatingServerSocketFactory(ServerSocketFactory.getDefault()) {
        @Override protected ServerSocket configureServerSocket(
            ServerSocket serverSocket) throws IOException {
          serverSocket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          return serverSocket;
        }
      });
  client = defaultClient().newBuilder()
      .socketFactory(new DelegatingSocketFactory(SocketFactory.getDefault()) {
        @Override protected Socket configureSocket(Socket socket) throws IOException {
          socket.setSendBufferSize(SOCKET_BUFFER_SIZE);
          socket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          return socket;
        }
      })
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:DisconnectTest.java

示例2: setUp

import okhttp3.mockwebserver.MockWebServer; //导入方法依赖的package包/类
@Before public void setUp() throws Exception {
  // Sockets on some platforms can have large buffers that mean writes do not block when
  // required. These socket factories explicitly set the buffer sizes on sockets created.
  server = new MockWebServer();
  server.setServerSocketFactory(
      new DelegatingServerSocketFactory(ServerSocketFactory.getDefault()) {
        @Override
        protected ServerSocket configureServerSocket(ServerSocket serverSocket)
            throws IOException {
          serverSocket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          return serverSocket;
        }
      });
  client = defaultClient().newBuilder()
      .socketFactory(new DelegatingSocketFactory(SocketFactory.getDefault()) {
        @Override
        protected Socket configureSocket(Socket socket) throws IOException {
          socket.setSendBufferSize(SOCKET_BUFFER_SIZE);
          socket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          return socket;
        }
      })
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:ThreadInterruptTest.java

示例3: writeTimeouts

import okhttp3.mockwebserver.MockWebServer; //导入方法依赖的package包/类
/** Confirm that an unacknowledged write times out. */
@Test public void writeTimeouts() throws IOException {
  MockWebServer server = new MockWebServer();
  // Sockets on some platforms can have large buffers that mean writes do not block when
  // required. These socket factories explicitly set the buffer sizes on sockets created.
  final int SOCKET_BUFFER_SIZE = 4 * 1024;
  server.setServerSocketFactory(
      new DelegatingServerSocketFactory(ServerSocketFactory.getDefault()) {
        @Override
        protected ServerSocket configureServerSocket(ServerSocket serverSocket)
            throws IOException {
          serverSocket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          return serverSocket;
        }
      });
  urlFactory.setClient(urlFactory.client().newBuilder()
      .socketFactory(new DelegatingSocketFactory(SocketFactory.getDefault()) {
        @Override protected Socket configureSocket(Socket socket) throws IOException {
          socket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          socket.setSendBufferSize(SOCKET_BUFFER_SIZE);
          return socket;
        }
      })
      .writeTimeout(500, TimeUnit.MILLISECONDS)
      .build());

  server.start();
  server.enqueue(new MockResponse()
      .throttleBody(1, 1, TimeUnit.SECONDS)); // Prevent the server from reading!

  connection = urlFactory.open(server.url("/").url());
  connection.setDoOutput(true);
  connection.setChunkedStreamingMode(0);
  OutputStream out = connection.getOutputStream();
  try {
    byte[] data = new byte[2 * 1024 * 1024]; // 2 MiB.
    out.write(data);
    fail();
  } catch (SocketTimeoutException expected) {
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:42,代码来源:URLConnectionTest.java


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