This is an automated email from the ASF dual-hosted git repository. wujimin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit 7ecb066571eed787b299dc510092939fa58af155 Author: wujimin <wuji...@huawei.com> AuthorDate: Tue Apr 3 11:03:34 2018 +0800 SCB-422 avoid random UT fail --- .../client/http/TestAbstractClientPool.java | 102 +++++++++++++++++++++ .../client/http/TestClientPool.java | 59 ------------ .../client/http/TestHttpClientPool.java | 88 ++++++++++++++++++ .../client/http/TestServiceRegistryClientImpl.java | 13 --- .../client/http/TestWebsocketClientPool.java | 56 +++++++++++ 5 files changed, 246 insertions(+), 72 deletions(-) diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestAbstractClientPool.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestAbstractClientPool.java new file mode 100644 index 0000000..56b609b --- /dev/null +++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestAbstractClientPool.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.servicecomb.serviceregistry.client.http; + +import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils; +import org.apache.servicecomb.foundation.vertx.VertxUtils; +import org.apache.servicecomb.foundation.vertx.client.ClientPoolManager; +import org.apache.servicecomb.foundation.vertx.client.ClientVerticle; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.DeploymentOptions; +import io.vertx.core.Vertx; +import io.vertx.core.VertxOptions; +import mockit.Mock; +import mockit.MockUp; +import mockit.Mocked; + +public class TestAbstractClientPool { + @Mocked + Vertx vertx; + + String vertxName; + + VertxOptions vertxOptions; + + Class<?> verticleCls; + + DeploymentOptions deployOptions; + + + @Before + public void setup() { + new MockUp<VertxUtils>() { + @Mock + Vertx getOrCreateVertxByName(String name, VertxOptions vertxOptions) { + TestAbstractClientPool.this.vertxName = name; + TestAbstractClientPool.this.vertxOptions = vertxOptions; + + return vertx; + } + + @Mock + <VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx, + Class<VERTICLE> cls, + DeploymentOptions options) { + TestAbstractClientPool.this.verticleCls = cls; + TestAbstractClientPool.this.deployOptions = options; + + return true; + } + }; + ArchaiusUtils.resetConfig(); + } + + @After + public void teardown() { + ArchaiusUtils.resetConfig(); + } + + @Test + public void create() { + HttpClientPool.INSTANCE.create(); + + Assert.assertEquals("registry", vertxName); + Assert.assertEquals( + "{" + + "\"cacheMaxTimeToLive\":2147483647," + + "\"cacheMinTimeToLive\":0," + + "\"cacheNegativeTimeToLive\":0," + + "\"maxQueries\":4," + + "\"ndots\":0," + + "\"optResourceEnabled\":true," + + "\"queryTimeout\":5000," + + "\"rdFlag\":true," + + "\"rotateServers\":false" + + "}", + vertxOptions.getAddressResolverOptions().toJson().toString()); + + Assert.assertEquals(ClientVerticle.class, verticleCls); + Assert.assertEquals(ClientPoolManager.class, + deployOptions.getConfig().getValue(ClientVerticle.CLIENT_MGR).getClass()); + System.out.println(deployOptions); + } +} diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestClientPool.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestClientPool.java deleted file mode 100644 index 3f80108..0000000 --- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestClientPool.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.serviceregistry.client.http; - -import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig; -import org.junit.Test; - -import io.vertx.core.http.HttpVersion; -import mockit.Mock; -import mockit.MockUp; - -public class TestClientPool { - @Test - public void testHttpClientPool() { - new MockUp<ServiceRegistryConfig>() { - @Mock - public HttpVersion getHttpVersion() { - return HttpVersion.HTTP_2; - } - - @Mock - public boolean isSsl() { - return true; - } - }; - HttpClientPool.INSTANCE.create(); - } - - @Test - public void testWebsocketClientPool() { - new MockUp<ServiceRegistryConfig>() { - @Mock - public HttpVersion getHttpVersion() { - return HttpVersion.HTTP_2; - } - - @Mock - public boolean isSsl() { - return true; - } - }; - WebsocketClientPool.INSTANCE.create(); - } -} diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestHttpClientPool.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestHttpClientPool.java new file mode 100644 index 0000000..e4ddb79 --- /dev/null +++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestHttpClientPool.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.servicecomb.serviceregistry.client.http; + +import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils; +import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import io.vertx.core.http.HttpClientOptions; +import io.vertx.core.http.HttpVersion; + +public class TestHttpClientPool { + @Before + public void setup() { + ArchaiusUtils.resetConfig(); + } + + @After + public void teardown() { + ArchaiusUtils.resetConfig(); + } + + @Test + public void createHttpClientOptions_proxy() { + ArchaiusUtils.setProperty(ServiceRegistryConfig.PROXY_ENABLE, "true"); + ArchaiusUtils.setProperty(ServiceRegistryConfig.PROXY_HOST, "host"); + ArchaiusUtils.setProperty(ServiceRegistryConfig.PROXY_PORT, "1234"); + ArchaiusUtils.setProperty(ServiceRegistryConfig.PROXY_USERNAME, "user"); + ArchaiusUtils.setProperty(ServiceRegistryConfig.PROXY_PASSWD, "pass"); + + HttpClientOptions httpClientOptions = HttpClientPool.INSTANCE.createHttpClientOptions(); + + Assert.assertEquals( + "{" + + "\"host\":\"host\"," + + "\"password\":\"pass\"," + + "\"port\":1234," + + "\"type\":\"HTTP\"," + + "\"username\":\"user\"" + + "}", + httpClientOptions.getProxyOptions().toJson().toString()); + } + + @Test + public void createHttpClientOptions_noProxy() { + ArchaiusUtils.setProperty(ServiceRegistryConfig.PROXY_ENABLE, "false"); + + HttpClientOptions httpClientOptions = HttpClientPool.INSTANCE.createHttpClientOptions(); + + Assert.assertNull(httpClientOptions.getProxyOptions()); + } + + @Test + public void createHttpClientOptions_http2() { + ArchaiusUtils.setProperty("cse.service.registry.client.httpVersion", HttpVersion.HTTP_2.name()); + + HttpClientOptions httpClientOptions = HttpClientPool.INSTANCE.createHttpClientOptions(); + + Assert.assertEquals(HttpVersion.HTTP_2, httpClientOptions.getProtocolVersion()); + Assert.assertFalse(httpClientOptions.isHttp2ClearTextUpgrade()); + } + + @Test + public void createHttpClientOptions_notHttp2() { + HttpClientOptions httpClientOptions = HttpClientPool.INSTANCE.createHttpClientOptions(); + + Assert.assertEquals(HttpVersion.HTTP_1_1, httpClientOptions.getProtocolVersion()); + Assert.assertTrue(httpClientOptions.isHttp2ClearTextUpgrade()); + } +} diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java index 23bdf94..925f77c 100644 --- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java +++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java @@ -38,7 +38,6 @@ import org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse; import org.apache.servicecomb.serviceregistry.client.ClientException; import org.apache.servicecomb.serviceregistry.client.IpPortManager; import org.apache.servicecomb.serviceregistry.client.http.ServiceRegistryClientImpl.ResponseWrapper; -import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -49,7 +48,6 @@ import io.vertx.core.Handler; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpClientOptions; import io.vertx.core.http.HttpClientResponse; -import io.vertx.core.http.HttpVersion; import mockit.Deencapsulation; import mockit.Expectations; import mockit.Mock; @@ -90,17 +88,6 @@ public class TestServiceRegistryClientImpl { Microservice microservice = microserviceFactory.create("app", "ms"); oClient.registerMicroservice(microservice); oClient.registerMicroserviceInstance(microservice.getInstance()); - new MockUp<ServiceRegistryConfig>() { - @Mock - public HttpVersion getHttpVersion() { - return HttpVersion.HTTP_2; - } - - @Mock - public boolean isSsl() { - return true; - } - }; try { oClient.init(); HttpClientOptions httpClientOptions = Deencapsulation.invoke(oClient, "createHttpClientOptions"); diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestWebsocketClientPool.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestWebsocketClientPool.java new file mode 100644 index 0000000..9c31e64 --- /dev/null +++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestWebsocketClientPool.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.servicecomb.serviceregistry.client.http; + +import org.apache.servicecomb.foundation.test.scaffolding.config.ArchaiusUtils; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import io.vertx.core.http.HttpClientOptions; +import io.vertx.core.http.HttpVersion; + +public class TestWebsocketClientPool { + @Before + public void setup() { + ArchaiusUtils.resetConfig(); + } + + @After + public void teardown() { + ArchaiusUtils.resetConfig(); + } + + @Test + public void createHttpClientOptions_http2() { + ArchaiusUtils.setProperty("cse.service.registry.client.httpVersion", HttpVersion.HTTP_2.name()); + + HttpClientOptions httpClientOptions = WebsocketClientPool.INSTANCE.createHttpClientOptions(); + + Assert.assertEquals(HttpVersion.HTTP_2, httpClientOptions.getProtocolVersion()); + Assert.assertFalse(httpClientOptions.isHttp2ClearTextUpgrade()); + } + + @Test + public void createHttpClientOptions_notHttp2() { + HttpClientOptions httpClientOptions = WebsocketClientPool.INSTANCE.createHttpClientOptions(); + + Assert.assertEquals(HttpVersion.HTTP_1_1, httpClientOptions.getProtocolVersion()); + Assert.assertTrue(httpClientOptions.isHttp2ClearTextUpgrade()); + } +} -- To stop receiving notification emails like this one, please contact wuji...@apache.org.