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


Java PortFactory.findFreePort方法代码示例

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


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

示例1: startJetty

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@BeforeClass
public static void startJetty() throws Exception {
    port = PortFactory.findFreePort();
    server = new Server();
    SslSocketConnector sslSocketConnector = new SslSocketConnector();
    sslSocketConnector.setKeystore("src/test/resources/keystore");
    sslSocketConnector.setKeyPassword("password");
    sslSocketConnector.setPort(port);
    server.setConnectors(new Connector[]{sslSocketConnector});
    server.addHandler(new AbstractHandler() {
        public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException {
            response.setStatus(Response.Status.OK.getStatusCode());
            Request base_request = request instanceof Request ? (Request) request : HttpConnection.getCurrentConnection().getRequest();
            base_request.setHandled(true);
        }
    });
    server.start();
}
 
开发者ID:jenkinsci,项目名称:gitlab-plugin,代码行数:19,代码来源:GitLabConnectionConfigSSLTest.java

示例2: setupFixture

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@Before
public void setupFixture() {
    httpPort = PortFactory.findFreePort();

    mockServerRuleDynamicPorts = new MockServerRule(this);
    mockServerRuleSinglePort = new MockServerRule(this, false, httpPort);
    mockServerRuleMultiplePorts = new MockServerRule(this, false, httpPort, httpPort + 1);
    mockServerRulePerSuite = new MockServerRule(this, true, httpPort);
    mockServerRulePerSuiteDuplicate = new MockServerRule(this, true, httpPort);

    initMocks(this);

    when(mockClientAndServer.getLocalPort()).thenReturn(httpPort);
    when(mockClientAndServer.getLocalPorts()).thenReturn(Arrays.asList(httpPort + 1, httpPort + 2));
    when(clientAndServerFactory.newClientAndServer()).thenReturn(mockClientAndServer);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:17,代码来源:MockServerRuleTestWithMocks.java

示例3: shouldStartMockServer

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@Test
public void shouldStartMockServer() {
    // given
    final int freePort = PortFactory.findFreePort();
    MockServerClient mockServerClient = new MockServerClient("127.0.0.1", freePort);
    Level originalLogLevel = ConfigurationProperties.logLevel();

    try {
        // when
        Main.main(
            "-serverPort", String.valueOf(freePort),
            "-logLevel", "DEBUG"
        );

        // then
        assertThat(mockServerClient.isRunning(), is(true));
        assertThat(ConfigurationProperties.logLevel().toString(), is("DEBUG"));
    } finally {
        ConfigurationProperties.logLevel(originalLogLevel.toString());
        mockServerClient.stop();
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:23,代码来源:MainTest.java

示例4: shouldPrintOutUsageForInvalidRemotePort

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@Test
public void shouldPrintOutUsageForInvalidRemotePort() throws UnsupportedEncodingException {
    // given
    final int freePort = PortFactory.findFreePort();
    PrintStream originalPrintStream = Main.systemOut;
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Main.systemOut = new PrintStream(baos, true, StandardCharsets.UTF_8.name());

        // when
        Main.main("-serverPort", String.valueOf(freePort), "-proxyRemotePort", "A");

        // then
        String actual = new String(baos.toByteArray(), StandardCharsets.UTF_8);
        String expected = NEW_LINE +
            "   =======================================================================" + NEW_LINE +
            "   proxyRemotePort value \"A\" is invalid, please specify a port i.e. \"1080\"" + NEW_LINE +
            "   =======================================================================" + NEW_LINE +
            NEW_LINE +
            Main.USAGE;
        assertThat(actual, is(expected));
    } finally {
        Main.systemOut = originalPrintStream;
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:26,代码来源:MainTest.java

示例5: shouldPrintOutUsageForInvalidRemoteHost

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@Test
public void shouldPrintOutUsageForInvalidRemoteHost() throws UnsupportedEncodingException {
    // given
    final int freePort = PortFactory.findFreePort();
    PrintStream originalPrintStream = Main.systemOut;
    try {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        Main.systemOut = new PrintStream(byteArrayOutputStream, true, StandardCharsets.UTF_8.name());

        // when
        Main.main("-serverPort", String.valueOf(freePort), "-proxyRemoteHost", "%^&*(");

        // then
        String actual = new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8);
        String expected = NEW_LINE +
            "   ====================================================================================================" + NEW_LINE +
            "   proxyRemoteHost value \"%^&*(\" is invalid, please specify a host name i.e. \"localhost\" or \"127.0.0.1\"" + NEW_LINE +
            "   ====================================================================================================" + NEW_LINE +
            NEW_LINE +
            Main.USAGE;
        assertThat(actual, is(expected));
    } finally {
        Main.systemOut = originalPrintStream;
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:26,代码来源:MainTest.java

示例6: shouldPrintOutUsageForInvalidLogLevel

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@Test
public void shouldPrintOutUsageForInvalidLogLevel() throws UnsupportedEncodingException {
    // given
    final int freePort = PortFactory.findFreePort();
    PrintStream originalPrintStream = Main.systemOut;
    try {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        Main.systemOut = new PrintStream(byteArrayOutputStream, true, StandardCharsets.UTF_8.name());

        // when
        Main.main("-serverPort", String.valueOf(freePort), "-logLevel", "FOO");

        // then
        String actual = new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8);
        String expected = NEW_LINE +
            "   =======================================================================================================" + NEW_LINE +
            "   logLevel value \"FOO\" is invalid, please specify one of \"TRACE\", \"DEBUG\", \"INFO\", \"WARN\", \"ERROR\", \"OFF\"" + NEW_LINE +
            "   =======================================================================================================" + NEW_LINE +
            NEW_LINE +
            Main.USAGE;
        assertThat(actual, is(expected));
    } finally {
        Main.systemOut = originalPrintStream;
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:26,代码来源:MainTest.java

示例7: initialize

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@BeforeClass
public static void initialize() throws Exception {
  port = PortFactory.findFreePort();
  mockServer = startClientAndServer(port);
  rsContext = new ResourceSyncContext();
  httpclient = HttpClients.createDefault();
}
 
开发者ID:EHRI,项目名称:rs-aggregator,代码行数:8,代码来源:AbstractRemoteTest.java

示例8: startServer

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@BeforeClass
public static void startServer() throws Exception {
    int port = PortFactory.findFreePort();
    System.out.println("port is " + port);
    mockServer = ClientAndServer.startClientAndServer(port);
    baseUrl = "http://localhost:" + port;
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:8,代码来源:BaseMockServerTest.java

示例9: startProxy

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@BeforeClass
public static void startProxy() throws Exception {

  int port = PortFactory.findFreePort();
  clientAndProxy = startClientAndProxy(port);
  proxy = new HttpHost("localhost", port);
  // load truststore with MockServer CA
  sslContext = SSLContexts.custom().loadTrustMaterial(new File("src/test/resources/truststore.jks"), "changeit".toCharArray()).build();
  httpClientBuilder = HttpClients.custom().setSSLContext(sslContext);
  httpclient = httpClientBuilder.build();

  serverPort = PortFactory.findFreePort();
  clientAndServer = ClientAndServer.startClientAndServer(serverPort);
  clientAndServer.when(new HttpRequest().withMethod("GET")).respond(HttpResponse.response("OK"));
}
 
开发者ID:confluentinc,项目名称:support-metrics-common,代码行数:16,代码来源:WebClientProxyTest.java

示例10: setUp

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    creationUrl = new URL("http://master.tus.io");
    int port = PortFactory.findFreePort();
    mockServerURL = new URL("http://localhost:" + port + "/files");
    mockServer = startClientAndServer(port);
}
 
开发者ID:tus,项目名称:tus-java-client,代码行数:8,代码来源:MockServerProvider.java

示例11: shouldThrowSocketCommunicationExceptionForConnectException

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@Test
public void shouldThrowSocketCommunicationExceptionForConnectException() throws Exception {
    // then
    int freePort = PortFactory.findFreePort();
    exception.expect(ExecutionException.class);
    exception.expectMessage(anyOf(
        containsString("Connection refused: /127.0.0.1:" + freePort),
        containsString("Channel closed before valid response")
    ));

    // when
    new NettyHttpClient().sendRequest(request().withHeader(HOST.toString(), "127.0.0.1:" + freePort))
        .get(10, TimeUnit.SECONDS);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:15,代码来源:NettyHttpClientErrorHandlingTest.java

示例12: start

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@BeforeClass
public void start() {
    int port = PortFactory.findFreePort();
    tokenEndpointUri = "https://localhost:" + port + "/oauth2/token";
    mockServer = ClientAndServer.startClientAndServer(port);
}
 
开发者ID:Scalepoint,项目名称:oauth-token-java-client,代码行数:7,代码来源:MockServerTestBase.java

示例13: startProxy

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@BeforeClass
public static void startProxy() throws Exception {
  proxyPort = PortFactory.findFreePort();
  clientAndProxy = ClientAndProxy.startClientAndProxy(proxyPort);
}
 
开发者ID:confluentinc,项目名称:ksql,代码行数:6,代码来源:VersionCheckerIntegrationTest.java

示例14: FailingExpectationServer

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
public FailingExpectationServer() throws IOException {
    port = PortFactory.findFreePort();

    serverSocket = new ServerSocket(port);
}
 
开发者ID:tus,项目名称:tus-java-client,代码行数:6,代码来源:TestTusUploader.java

示例15: before

import org.mockserver.socket.PortFactory; //导入方法依赖的package包/类
@BeforeClass
public static void before() throws Exception {
    mockServerPort = PortFactory.findFreePort();
    mockServer = ClientAndServer.startClientAndServer(mockServerPort);
}
 
开发者ID:saalfeldlab,项目名称:render,代码行数:6,代码来源:LowLatencyMontageClientTest.java


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