下面列出了io.vertx.core.http.HttpServer#actualPort ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void testVersionDetectionOpenShift39(VertxTestContext context) throws InterruptedException {
String version = "{\n" +
" \"major\": \"1\",\n" +
" \"minor\": \"9\",\n" +
" \"gitVersion\": \"v1.9.1+a0ce1bc657\",\n" +
" \"gitCommit\": \"a0ce1bc\",\n" +
" \"gitTreeState\": \"clean\",\n" +
" \"buildDate\": \"2018-06-24T01:54:00Z\",\n" +
" \"goVersion\": \"go1.9\",\n" +
" \"compiler\": \"gc\",\n" +
" \"platform\": \"linux/amd64\"\n" +
"}";
HttpServer mockHttp = startMockApi(context, version, Collections.EMPTY_LIST);
KubernetesClient client = new DefaultKubernetesClient("127.0.0.1:" + mockHttp.actualPort());
Checkpoint a = context.checkpoint();
PlatformFeaturesAvailability.create(vertx, client).onComplete(context.succeeding(pfa -> context.verify(() -> {
assertThat("Versions are not equal", pfa.getKubernetesVersion(), is(KubernetesVersion.V1_9));
stopMockApi(context, mockHttp);
a.flag();
})));
}
@Test
public void testVersionDetectionMinikube114(VertxTestContext context) throws InterruptedException {
String version = "{\n" +
" \"major\": \"1\",\n" +
" \"minor\": \"14\",\n" +
" \"gitVersion\": \"v1.14.0\",\n" +
" \"gitCommit\": \"641856db18352033a0d96dbc99153fa3b27298e5\",\n" +
" \"gitTreeState\": \"clean\",\n" +
" \"buildDate\": \"2019-03-25T15:45:25Z\",\n" +
" \"goVersion\": \"go1.12.1\",\n" +
" \"compiler\": \"gc\",\n" +
" \"platform\": \"linux/amd64\"\n" +
"}";
HttpServer mockHttp = startMockApi(context, version, Collections.EMPTY_LIST);
KubernetesClient client = new DefaultKubernetesClient("127.0.0.1:" + mockHttp.actualPort());
Checkpoint async = context.checkpoint();
PlatformFeaturesAvailability.create(vertx, client).onComplete(context.succeeding(pfa -> context.verify(() -> {
assertThat("Versions are not equal", pfa.getKubernetesVersion(), is(KubernetesVersion.V1_14));
stopMockApi(context, mockHttp);
async.flag();
})));
}
@Test
public void testApiDetectionOce(VertxTestContext context) throws InterruptedException {
List<String> apis = new ArrayList<>();
apis.add("/apis/route.openshift.io/v1");
apis.add("/apis/build.openshift.io/v1");
HttpServer mockHttp = startMockApi(context, apis);
KubernetesClient client = new DefaultKubernetesClient("127.0.0.1:" + mockHttp.actualPort());
Checkpoint async = context.checkpoint();
PlatformFeaturesAvailability.create(vertx, client).onComplete(context.succeeding(pfa -> context.verify(() -> {
assertThat(pfa.hasRoutes(), is(true));
assertThat(pfa.hasBuilds(), is(true));
assertThat(pfa.hasImages(), is(false));
assertThat(pfa.hasApps(), is(false));
stopMockApi(context, mockHttp);
async.flag();
})));
}
@Test
public void testApiDetectionOpenshift(VertxTestContext context) throws InterruptedException {
List<String> apis = new ArrayList<>();
apis.add("/apis/route.openshift.io/v1");
apis.add("/apis/build.openshift.io/v1");
apis.add("/apis/apps.openshift.io/v1");
apis.add("/apis/image.openshift.io/v1");
HttpServer mockHttp = startMockApi(context, apis);
KubernetesClient client = new DefaultKubernetesClient("127.0.0.1:" + mockHttp.actualPort());
Checkpoint async = context.checkpoint();
PlatformFeaturesAvailability.create(vertx, client).onComplete(context.succeeding(pfa -> context.verify(() -> {
assertThat(pfa.hasRoutes(), is(true));
assertThat(pfa.hasBuilds(), is(true));
assertThat(pfa.hasImages(), is(true));
assertThat(pfa.hasApps(), is(true));
stopMockApi(context, mockHttp);
async.flag();
})));
}
@Test
public void testApiDetectionKubernetes(VertxTestContext context) throws InterruptedException {
HttpServer mockHttp = startMockApi(context, Collections.EMPTY_LIST);
KubernetesClient client = new DefaultKubernetesClient("127.0.0.1:" + mockHttp.actualPort());
Checkpoint async = context.checkpoint();
PlatformFeaturesAvailability.create(vertx, client).onComplete(context.succeeding(pfa -> context.verify(() -> {
assertThat(pfa.hasRoutes(), is(false));
assertThat(pfa.hasBuilds(), is(false));
assertThat(pfa.hasImages(), is(false));
assertThat(pfa.hasApps(), is(false));
stopMockApi(context, mockHttp);
async.flag();
})));
}
/**
* Sets the http server instance configured to serve requests over a TLS secured socket.
* <p>
* If no server is set using this method, then a server instance is created during
* startup of this adapter based on the <em>config</em> properties and the server options
* returned by {@link #getHttpServerOptions()}.
*
* @param server The http server.
* @throws NullPointerException if server is {@code null}.
* @throws IllegalArgumentException if the server is already started and listening on an address/port.
*/
@Autowired(required = false)
public final void setHttpServer(final HttpServer server) {
Objects.requireNonNull(server);
if (server.actualPort() > 0) {
throw new IllegalArgumentException("http server must not be started already");
} else {
this.server = server;
}
}
/**
* Sets the http server instance configured to serve requests over a plain socket.
* <p>
* If no server is set using this method, then a server instance is created during
* startup of this adapter based on the <em>config</em> properties and the server options
* returned by {@link #getInsecureHttpServerOptions()}.
*
* @param server The http server.
* @throws NullPointerException if server is {@code null}.
* @throws IllegalArgumentException if the server is already started and listening on an address/port.
*/
@Autowired(required = false)
public final void setInsecureHttpServer(final HttpServer server) {
Objects.requireNonNull(server);
if (server.actualPort() > 0) {
throw new IllegalArgumentException("http server must not be started already");
} else {
this.insecureServer = server;
}
}