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 287b34ffda301e7bd4bd4d0588e7ea15746bde7c Author: zhengyangyong <yangyong.zh...@huawei.com> AuthorDate: Thu May 17 10:10:48 2018 +0800 SCB-548 add SCBEngine UT Signed-off-by: zhengyangyong <yangyong.zh...@huawei.com> --- .../org/apache/servicecomb/core/TestSCBEngine.java | 68 ++++++++++++++++++++++ .../servicecomb/foundation/vertx/VertxUtils.java | 37 +----------- 2 files changed, 70 insertions(+), 35 deletions(-) diff --git a/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java b/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java new file mode 100644 index 0000000..da0a9db --- /dev/null +++ b/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java @@ -0,0 +1,68 @@ +/* + * 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.core; + +import java.util.ArrayList; + +import org.apache.servicecomb.core.definition.loader.SchemaListenerManager; +import org.apache.servicecomb.core.provider.consumer.ConsumerProviderManager; +import org.apache.servicecomb.core.provider.producer.ProducerProviderManager; +import org.apache.servicecomb.core.transport.TransportManager; +import org.apache.servicecomb.foundation.vertx.VertxUtils; +import org.apache.servicecomb.serviceregistry.RegistryUtils; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import mockit.Expectations; +import mockit.Injectable; + +public class TestSCBEngine { + @Test + public void test(@Injectable ProducerProviderManager producerProviderManager, + @Injectable ConsumerProviderManager consumerProviderManager, + @Injectable TransportManager transportManager) { + + new Expectations(RegistryUtils.class) { + { + RegistryUtils.getInstanceCacheManager(); + RegistryUtils.run(); + RegistryUtils.destroy(); + } + }; + + SchemaListenerManager schemaListenerManager = Mockito.mock(SchemaListenerManager.class); + + VertxUtils.getOrCreateVertxByName("transport", null); + + SCBEngine engine = new SCBEngine(); + engine.setBootListenerList(new ArrayList<>()); + engine.setConsumerProviderManager(consumerProviderManager); + engine.setProducerProviderManager(producerProviderManager); + engine.setTransportManager(transportManager); + engine.setSchemaListenerManager(schemaListenerManager); + + engine.init(); + + Assert.assertEquals(SCBStatus.UP, engine.getStatus()); + + engine.uninit(); + + Assert.assertEquals(SCBStatus.DOWN, engine.getStatus()); + } +} diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java index 5d4709f..a3aabd6 100644 --- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java +++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/VertxUtils.java @@ -36,7 +36,6 @@ import org.slf4j.LoggerFactory; import io.netty.buffer.ByteBuf; import io.vertx.core.AbstractVerticle; -import io.vertx.core.Context; import io.vertx.core.DeploymentOptions; import io.vertx.core.Verticle; import io.vertx.core.Vertx; @@ -112,9 +111,7 @@ public final class VertxUtils { } public static Vertx getOrCreateVertxByName(String name, VertxOptions vertxOptions) { - return vertxMap.computeIfAbsent(name, vertxName -> { - return (VertxImplEx) init(vertxName, vertxOptions); - }); + return vertxMap.computeIfAbsent(name, vertxName -> (VertxImplEx) init(vertxName, vertxOptions)); } public static Vertx init(VertxOptions vertxOptions) { @@ -126,7 +123,7 @@ public final class VertxUtils { vertxOptions = new VertxOptions(); } - boolean isDebug = ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("jdwp") >= 0; + boolean isDebug = ManagementFactory.getRuntimeMXBean().getInputArguments().toString().contains("jdwp"); if (isDebug) { vertxOptions.setBlockedThreadCheckInterval(BLOCKED_THREAD_CHECK_INTERVAL); LOGGER.info("in debug mode, disable blocked thread check."); @@ -145,36 +142,6 @@ public final class VertxUtils { } } - public static Vertx currentVertx() { - Context context = Vertx.currentContext(); - if (context == null) { - throw new RuntimeException("get currentVertx error, currentContext is null."); - } - - return context.owner(); - } - - public static Vertx getVertxByName(String name) { - return vertxMap.get(name); - } - - public static <T> void runInContext(Context context, AsyncResultCallback<T> callback, T result, Throwable e) { - if (context == Vertx.currentContext()) { - complete(callback, result, e); - } else { - context.runOnContext(v -> complete(callback, result, e)); - } - } - - private static <T> void complete(AsyncResultCallback<T> callback, T result, Throwable e) { - if (e != null) { - callback.fail(e.getCause()); - return; - } - - callback.success(result); - } - // try to reference byte[] // otherwise copy byte[] public static byte[] getBytesFast(InputStream inputStream) throws IOException { -- To stop receiving notification emails like this one, please contact wuji...@apache.org.