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 50f987b406e656157bdcbfbee5380f09259f0bef
Author: zhengyangyong <yangyong.zh...@huawei.com>
AuthorDate: Wed May 16 17:17:32 2018 +0800

    SCB-548 refactor and fix pr comment
    
    Signed-off-by: zhengyangyong <yangyong.zh...@huawei.com>
---
 .../org/apache/servicecomb/core/SCBEngine.java     | 61 +++++---------------
 .../core/provider/consumer/InvokerUtils.java       | 39 +++++++++----
 .../provider/consumer/ReferenceConfigUtils.java    | 34 -----------
 .../core/provider/consumer/TestInvokerUtils.java   | 66 +++++++++++++++++-----
 .../consumer/TestReferenceConfigUtils.java         | 62 --------------------
 .../apache/servicecomb/provider/pojo/Invoker.java  | 11 +---
 .../servicecomb/provider/pojo/TestInvoker.java     | 19 -------
 .../springmvc/reference/CseClientHttpRequest.java  | 12 ++--
 .../reference/TestCseClientHttpRequest.java        | 25 +-------
 .../async/CseAsyncClientHttpRequestTest.java       | 22 +-------
 10 files changed, 108 insertions(+), 243 deletions(-)

diff --git a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java 
b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
index f1411e1..772070c 100644
--- a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
+++ b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
@@ -17,7 +17,7 @@
 package org.apache.servicecomb.core;
 
 import java.util.Collection;
-import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.servicecomb.core.BootListener.BootEvent;
@@ -60,14 +60,16 @@ public class SCBEngine {
 
   private final AtomicLong invocationFinishedCounter = new AtomicLong();
 
-  private final Semaphore allInvocationFinished = new Semaphore(1);
-
   private volatile SCBStatus status = SCBStatus.DOWN;
 
   public void setStatus(SCBStatus status) {
     this.status = status;
   }
 
+  public SCBStatus getStatus() {
+    return status;
+  }
+
   private EventBus eventBus = EventManager.getEventBus();
 
   private static final SCBEngine INSTANCE = new SCBEngine();
@@ -123,7 +125,7 @@ public class SCBEngine {
     for (BootListener listener : bootListenerList) {
       try {
         listener.onBootEvent(event);
-        LOGGER.error("BootListener {} succeed to process {}.", 
listener.getClass().getName(), eventType);
+        LOGGER.info("BootListener {} succeed to process {}.", 
listener.getClass().getName(), eventType);
       } catch (Throwable e) {
         LOGGER.error("BootListener {} failed to process {}.", 
listener.getClass().getName(), eventType, e);
       }
@@ -166,13 +168,10 @@ public class SCBEngine {
   @Subscribe
   public void onInvocationFinish(InvocationFinishEvent event) {
     invocationFinishedCounter.incrementAndGet();
-    if (validIsStopping()) {
-      validAllInvocationFinished();
-    }
   }
 
   public synchronized void init() {
-    if (validIsDown()) {
+    if (SCBStatus.DOWN.equals(status)) {
       try {
         doInit();
         status = SCBStatus.UP;
@@ -190,8 +189,6 @@ public class SCBEngine {
 
     eventBus.register(this);
 
-    allInvocationFinished.acquire();
-
     AbstractEndpointsCache.init(RegistryUtils.getInstanceCacheManager(), 
transportManager);
 
     triggerEvent(EventType.BEFORE_HANDLER);
@@ -226,7 +223,7 @@ public class SCBEngine {
    * even some step throw exception, must catch it and go on, otherwise 
shutdown process will be broken.
    */
   public synchronized void uninit() {
-    if (validIsUp()) {
+    if (SCBStatus.UP.equals(status)) {
       LOGGER.info("ServiceComb is closing now...");
       try {
         doUninit();
@@ -252,7 +249,6 @@ public class SCBEngine {
     //Step 3: wait all invocation finished
     // forbit create new consumer invocation
     validAllInvocationFinished();
-    allInvocationFinished.acquire();
 
     //Step 4: Stop vertx to prevent blocking exit
     VertxUtils.blockCloseVertxByName("config-center");
@@ -263,43 +259,14 @@ public class SCBEngine {
 
     //Step 6: Clean flags for re-init
     eventBus.unregister(this);
-    allInvocationFinished.release();
-  }
-
-  private void validAllInvocationFinished() {
-    LOGGER.info("valid for all invocation finished, request count: {}, 
response count: {}.",
-        invocationStartedCounter.get(),
-        invocationFinishedCounter.get());
-    if (invocationFinishedCounter.get() == invocationStartedCounter.get()) {
-      allInvocationFinished.release();
-    }
-  }
-
-  public void assertIsStopping() {
-    if (validIsStopping()) {
-      throw new IllegalStateException(
-          "shutting down in progress, it's better to implement " + 
BootListener.class.getName()
-              + " and stop ... in EventType.BEFORE_CLOSE.");
-    }
   }
 
-  private boolean validIsStopping() {
-    return SCBStatus.STOPPING.equals(status);
-  }
-
-  public void assertIsUp() {
-    if (!SCBStatus.UP.equals(status)) {
-      throw new IllegalStateException("System is not ready for remote calls. "
-          + "When beans are making remote calls in initialization, it's better 
to "
-          + "implement " + BootListener.class.getName() + " and do it after 
EventType.AFTER_REGISTRY.");
+  private void validAllInvocationFinished() throws InterruptedException {
+    while (true) {
+      if (invocationFinishedCounter.get() == invocationStartedCounter.get()) {
+        return;
+      }
+      TimeUnit.SECONDS.sleep(1);
     }
   }
-
-  private boolean validIsUp() {
-    return SCBStatus.UP.equals(status);
-  }
-
-  private boolean validIsDown() {
-    return SCBStatus.DOWN.equals(status);
-  }
 }
diff --git 
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
 
b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
index 7dc01f3..78a4430 100644
--- 
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
+++ 
b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
@@ -17,7 +17,10 @@
 
 package org.apache.servicecomb.core.provider.consumer;
 
+import org.apache.servicecomb.core.CseContext;
 import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.core.SCBEngine;
+import org.apache.servicecomb.core.SCBStatus;
 import org.apache.servicecomb.core.definition.SchemaMeta;
 import org.apache.servicecomb.core.invocation.InvocationFactory;
 import org.apache.servicecomb.swagger.invocation.AsyncResponse;
@@ -32,31 +35,31 @@ public final class InvokerUtils {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(InvokerUtils.class);
 
   public static Object syncInvoke(String microserviceName, String schemaId, 
String operationName, Object[] args) {
-    ReferenceConfig referenceConfig = 
ReferenceConfigUtils.getForInvoke(microserviceName);
-    SchemaMeta schemaMeta = 
referenceConfig.getMicroserviceMeta().ensureFindSchemaMeta(schemaId);
-    Invocation invocation = InvocationFactory.forConsumer(referenceConfig, 
schemaMeta, operationName, args);
-    return syncInvoke(invocation);
+    validCanInvoke();
+    ReferenceConfig referenceConfig = 
CseContext.getInstance().getConsumerProviderManager()
+        .getReferenceConfig(microserviceName);
+    return syncInvoke(generateInvocation(schemaId, operationName, args, 
referenceConfig));
   }
 
   public static Object syncInvoke(String microserviceName, String 
microserviceVersion, String transport,
       String schemaId, String operationName, Object[] args) {
-    ReferenceConfig referenceConfig =
-        ReferenceConfigUtils.getForInvoke(microserviceName, 
microserviceVersion, transport);
-    SchemaMeta schemaMeta = 
referenceConfig.getMicroserviceMeta().ensureFindSchemaMeta(schemaId);
-    Invocation invocation = InvocationFactory.forConsumer(referenceConfig, 
schemaMeta, operationName, args);
-    return syncInvoke(invocation);
+    validCanInvoke();
+    ReferenceConfig referenceConfig = 
CseContext.getInstance().getConsumerProviderManager()
+        .createReferenceConfig(microserviceName, microserviceVersion, 
transport);
+    return syncInvoke(generateInvocation(schemaId, operationName, args, 
referenceConfig));
   }
 
   public static Object syncInvoke(Invocation invocation) throws 
InvocationException {
+    validCanInvoke();
     Response response = innerSyncInvoke(invocation);
     if (response.isSuccessed()) {
       return response.getResult();
     }
-
     throw ExceptionFactory.convertConsumerException(response.getResult());
   }
 
   public static Response innerSyncInvoke(Invocation invocation) {
+    validCanInvoke();
     try {
       invocation.onStart();
       SyncResponseExecutor respExecutor = new SyncResponseExecutor();
@@ -79,6 +82,7 @@ public final class InvokerUtils {
   }
 
   public static void reactiveInvoke(Invocation invocation, AsyncResponse 
asyncResp) {
+    validCanInvoke();
     try {
       invocation.onStart();
       invocation.setSync(false);
@@ -104,8 +108,23 @@ public final class InvokerUtils {
     }
   }
 
+  private static Invocation generateInvocation(String schemaId, String 
operationName, Object[] args,
+      ReferenceConfig referenceConfig) {
+    SchemaMeta schemaMeta = 
referenceConfig.getMicroserviceMeta().ensureFindSchemaMeta(schemaId);
+    return InvocationFactory.forConsumer(referenceConfig, schemaMeta, 
operationName, args);
+  }
+
+  private static void validCanInvoke() {
+    if (!SCBStatus.UP.equals(SCBEngine.getInstance().getStatus())) {
+      throw new IllegalStateException(
+          "System is starting and not ready for remote calls or shutting down 
in progress, STATUS = " + String
+              .valueOf(SCBEngine.getInstance().getStatus()));
+    }
+  }
+
   @Deprecated
   public static Object invoke(Invocation invocation) {
+    validCanInvoke();
     return syncInvoke(invocation);
   }
 }
diff --git 
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ReferenceConfigUtils.java
 
b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ReferenceConfigUtils.java
deleted file mode 100644
index b0bf2d2..0000000
--- 
a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/ReferenceConfigUtils.java
+++ /dev/null
@@ -1,34 +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.core.provider.consumer;
-
-import org.apache.servicecomb.core.CseContext;
-import org.apache.servicecomb.core.SCBEngine;
-
-public class ReferenceConfigUtils {
-  public static ReferenceConfig getForInvoke(String microserviceName) {
-    SCBEngine.getInstance().assertIsUp();
-    return 
CseContext.getInstance().getConsumerProviderManager().getReferenceConfig(microserviceName);
-  }
-
-  public static ReferenceConfig getForInvoke(String microserviceName, String 
microserviceVersion, String transport) {
-    SCBEngine.getInstance().assertIsUp();
-    return 
CseContext.getInstance().getConsumerProviderManager().createReferenceConfig(microserviceName,
-        microserviceVersion, transport);
-  }
-}
diff --git 
a/core/src/test/java/org/apache/servicecomb/core/provider/consumer/TestInvokerUtils.java
 
b/core/src/test/java/org/apache/servicecomb/core/provider/consumer/TestInvokerUtils.java
index 16adde7..8bf6cae 100644
--- 
a/core/src/test/java/org/apache/servicecomb/core/provider/consumer/TestInvokerUtils.java
+++ 
b/core/src/test/java/org/apache/servicecomb/core/provider/consumer/TestInvokerUtils.java
@@ -19,7 +19,6 @@ package org.apache.servicecomb.core.provider.consumer;
 
 import javax.xml.ws.Holder;
 
-import org.apache.servicecomb.core.BootListener;
 import org.apache.servicecomb.core.CseContext;
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.core.SCBEngine;
@@ -70,6 +69,9 @@ public class TestInvokerUtils {
   @Test
   public void testReactiveInvoke(@Mocked Invocation invocation, @Mocked 
InvocationContext parentContext,
       @Mocked Response response) {
+
+    SCBEngine.getInstance().setStatus(SCBStatus.UP);
+
     new MockUp<Invocation>(invocation) {
       @Mock
       InvocationContext getParentContext() {
@@ -83,9 +85,7 @@ public class TestInvokerUtils {
     };
 
     Holder<InvocationContext> holder = new Holder<>();
-    InvokerUtils.reactiveInvoke(invocation, ar -> {
-      holder.value = ContextUtils.getInvocationContext();
-    });
+    InvokerUtils.reactiveInvoke(invocation, ar -> holder.value = 
ContextUtils.getInvocationContext());
 
     Assert.assertNull(ContextUtils.getInvocationContext());
     Assert.assertSame(parentContext, holder.value);
@@ -94,6 +94,9 @@ public class TestInvokerUtils {
   @SuppressWarnings("deprecation")
   @Test
   public void invoke() {
+
+    SCBEngine.getInstance().setStatus(SCBStatus.UP);
+
     new MockUp<InvokerUtils>() {
       @Mock
       Object syncInvoke(Invocation invocation) {
@@ -105,33 +108,68 @@ public class TestInvokerUtils {
   }
 
   @Test
-  public void tetSyncInvokeNotReady() {
+  public void testSyncInvokeNotReady(@Mocked Invocation invocation) {
 
     SCBEngine.getInstance().setStatus(SCBStatus.DOWN);
 
     try {
+      InvokerUtils.syncInvoke(invocation);
+      Assert.fail("must throw exception");
+    } catch (IllegalStateException e) {
+      Assert
+          .assertEquals("System is starting and not ready for remote calls or 
shutting down in progress, STATUS = DOWN",
+              e.getMessage());
+    }
+
+    try {
       InvokerUtils.syncInvoke("ms", "schemaId", "opName", null);
       Assert.fail("must throw exception");
     } catch (IllegalStateException e) {
-      Assert.assertEquals("System is not ready for remote calls. "
-              + "When beans are making remote calls in initialization, it's 
better to "
-              + "implement " + BootListener.class.getName() + " and do it 
after EventType.AFTER_REGISTRY.",
-          e.getMessage());
+      Assert
+          .assertEquals("System is starting and not ready for remote calls or 
shutting down in progress, STATUS = DOWN",
+              e.getMessage());
     }
 
     try {
       InvokerUtils.syncInvoke("ms", "latest", "rest", "schemaId", "opName", 
null);
       Assert.fail("must throw exception");
     } catch (IllegalStateException e) {
-      Assert.assertEquals("System is not ready for remote calls. "
-              + "When beans are making remote calls in initialization, it's 
better to "
-              + "implement " + BootListener.class.getName() + " and do it 
after EventType.AFTER_REGISTRY.",
-          e.getMessage());
+      Assert
+          .assertEquals("System is starting and not ready for remote calls or 
shutting down in progress, STATUS = DOWN",
+              e.getMessage());
+    }
+  }
+
+  @Test
+  public void testReactiveInvokeNotReady(@Mocked Invocation invocation, 
@Mocked InvocationContext parentContext,
+      @Mocked Response response) {
+
+    SCBEngine.getInstance().setStatus(SCBStatus.DOWN);
+
+    new MockUp<Invocation>(invocation) {
+      @Mock
+      InvocationContext getParentContext() {
+        return parentContext;
+      }
+
+      @Mock
+      void next(AsyncResponse asyncResp) {
+        asyncResp.handle(response);
+      }
+    };
+
+    Holder<InvocationContext> holder = new Holder<>();
+    try {
+      InvokerUtils.reactiveInvoke(invocation, ar -> holder.value = 
ContextUtils.getInvocationContext());
+    } catch (IllegalStateException e) {
+      Assert
+          .assertEquals("System is starting and not ready for remote calls or 
shutting down in progress, STATUS = DOWN",
+              e.getMessage());
     }
   }
 
   @Test
-  public void tetSyncInvokeReady(@Injectable ConsumerProviderManager 
consumerProviderManager,
+  public void testSyncInvokeReady(@Injectable ConsumerProviderManager 
consumerProviderManager,
       @Injectable Invocation invocation) {
 
     SCBEngine.getInstance().setStatus(SCBStatus.UP);
diff --git 
a/core/src/test/java/org/apache/servicecomb/core/provider/consumer/TestReferenceConfigUtils.java
 
b/core/src/test/java/org/apache/servicecomb/core/provider/consumer/TestReferenceConfigUtils.java
deleted file mode 100644
index b31ee58..0000000
--- 
a/core/src/test/java/org/apache/servicecomb/core/provider/consumer/TestReferenceConfigUtils.java
+++ /dev/null
@@ -1,62 +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.core.provider.consumer;
-
-import org.apache.servicecomb.core.BootListener;
-import org.apache.servicecomb.core.CseContext;
-import org.apache.servicecomb.core.SCBEngine;
-import org.apache.servicecomb.core.SCBStatus;
-import org.junit.Assert;
-import org.junit.Test;
-
-import mockit.Injectable;
-
-public class TestReferenceConfigUtils {
-  @Test
-  public void testNotReady() {
-    String exceptionMessage = "System is not ready for remote calls. "
-        + "When beans are making remote calls in initialization, it's better 
to "
-        + "implement " + BootListener.class.getName() + " and do it after 
EventType.AFTER_REGISTRY.";
-
-    SCBEngine.getInstance().setStatus(SCBStatus.DOWN);
-
-    try {
-      ReferenceConfigUtils.getForInvoke("abc");
-      Assert.fail("must throw exception");
-    } catch (IllegalStateException e) {
-      Assert.assertEquals(exceptionMessage, e.getMessage());
-    }
-
-    try {
-      ReferenceConfigUtils.getForInvoke("abc", "v1", "");
-      Assert.fail("must throw exception");
-    } catch (IllegalStateException e) {
-      Assert.assertEquals(exceptionMessage, e.getMessage());
-    }
-  }
-
-  @Test
-  public void testReady(@Injectable ConsumerProviderManager 
consumerProviderManager) {
-
-    SCBEngine.getInstance().setStatus(SCBStatus.UP);
-
-    
CseContext.getInstance().setConsumerProviderManager(consumerProviderManager);
-
-    Assert.assertNotNull(ReferenceConfigUtils.getForInvoke("abc"));
-    Assert.assertNotNull(ReferenceConfigUtils.getForInvoke("abc", "v1", ""));
-  }
-}
diff --git 
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
 
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
index 1dd25e2..18fd64a 100644
--- 
a/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
+++ 
b/providers/provider-pojo/src/main/java/org/apache/servicecomb/provider/pojo/Invoker.java
@@ -24,13 +24,11 @@ import java.util.concurrent.CompletableFuture;
 
 import org.apache.servicecomb.core.CseContext;
 import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.SCBEngine;
 import org.apache.servicecomb.core.definition.MicroserviceMeta;
 import org.apache.servicecomb.core.definition.SchemaMeta;
 import org.apache.servicecomb.core.invocation.InvocationFactory;
 import org.apache.servicecomb.core.provider.consumer.InvokerUtils;
 import org.apache.servicecomb.core.provider.consumer.ReferenceConfig;
-import org.apache.servicecomb.core.provider.consumer.ReferenceConfigUtils;
 import org.apache.servicecomb.swagger.engine.SwaggerConsumer;
 import org.apache.servicecomb.swagger.engine.SwaggerConsumerOperation;
 import org.apache.servicecomb.swagger.invocation.Response;
@@ -65,7 +63,7 @@ public class Invoker implements InvocationHandler {
   }
 
   protected void prepare() {
-    referenceConfig = ReferenceConfigUtils.getForInvoke(microserviceName);
+    referenceConfig = 
CseContext.getInstance().getConsumerProviderManager().getReferenceConfig(microserviceName);
     MicroserviceMeta microserviceMeta = referenceConfig.getMicroserviceMeta();
 
     if (StringUtils.isEmpty(schemaId)) {
@@ -94,12 +92,9 @@ public class Invoker implements InvocationHandler {
       }
     }
 
-    SCBEngine.getInstance().assertIsStopping();
-
     SwaggerConsumerOperation consumerOperation = 
swaggerConsumer.findOperation(method.getName());
-    Invocation invocation =
-        InvocationFactory
-            .forConsumer(referenceConfig, schemaMeta, 
consumerOperation.getSwaggerMethod().getName(), null);
+    Invocation invocation = InvocationFactory
+        .forConsumer(referenceConfig, schemaMeta, 
consumerOperation.getSwaggerMethod().getName(), null);
 
     consumerOperation.getArgumentsMapper().toInvocation(args, invocation);
 
diff --git 
a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/TestInvoker.java
 
b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/TestInvoker.java
index 715edcc..c0682f9 100644
--- 
a/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/TestInvoker.java
+++ 
b/providers/provider-pojo/src/test/java/org/apache/servicecomb/provider/pojo/TestInvoker.java
@@ -19,7 +19,6 @@ package org.apache.servicecomb.provider.pojo;
 
 import java.util.concurrent.CompletableFuture;
 
-import org.apache.servicecomb.core.BootListener;
 import org.apache.servicecomb.core.CseContext;
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.core.SCBEngine;
@@ -66,24 +65,6 @@ public class TestInvoker {
   }
 
   @Test
-  public void testNotReady() throws Throwable {
-    String exceptionMessage = "System is not ready for remote calls. "
-        + "When beans are making remote calls in initialization, it's better 
to "
-        + "implement " + BootListener.class.getName() + " and do it after 
EventType.AFTER_REGISTRY.";
-
-    SCBEngine.getInstance().setStatus(SCBStatus.DOWN);
-
-    Invoker invoker = new Invoker("test", "schemaId", IPerson.class);
-
-    try {
-      invoker.invoke(null, null, null);
-      Assert.fail("must throw exception");
-    } catch (IllegalStateException e) {
-      Assert.assertEquals(exceptionMessage, e.getMessage());
-    }
-  }
-
-  @Test
   public void testNormalSchemaId(@Injectable ConsumerProviderManager manager,
       @Injectable ReferenceConfig config,
       @Injectable MicroserviceMeta microserviceMeta,
diff --git 
a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java
 
b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java
index a64d794..1e85f5a 100644
--- 
a/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java
+++ 
b/providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java
@@ -29,13 +29,12 @@ import org.apache.servicecomb.common.rest.codec.RestCodec;
 import org.apache.servicecomb.common.rest.definition.RestOperationMeta;
 import org.apache.servicecomb.common.rest.locator.OperationLocator;
 import org.apache.servicecomb.common.rest.locator.ServicePathManager;
+import org.apache.servicecomb.core.CseContext;
 import org.apache.servicecomb.core.Invocation;
-import org.apache.servicecomb.core.SCBEngine;
 import org.apache.servicecomb.core.definition.MicroserviceMeta;
 import org.apache.servicecomb.core.invocation.InvocationFactory;
 import org.apache.servicecomb.core.provider.consumer.InvokerUtils;
 import org.apache.servicecomb.core.provider.consumer.ReferenceConfig;
-import org.apache.servicecomb.core.provider.consumer.ReferenceConfigUtils;
 import org.apache.servicecomb.swagger.invocation.Response;
 import org.apache.servicecomb.swagger.invocation.context.InvocationContext;
 import org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory;
@@ -147,12 +146,11 @@ public class CseClientHttpRequest implements 
ClientHttpRequest {
     return this.invoke(args);
   }
 
-  protected RequestMeta createRequestMeta(String httpMetod, URI uri) {
+  protected RequestMeta createRequestMeta(String httpMethod, URI uri) {
     String microserviceName = uri.getAuthority();
 
-    SCBEngine.getInstance().assertIsStopping();
-
-    ReferenceConfig referenceConfig = 
ReferenceConfigUtils.getForInvoke(microserviceName);
+    ReferenceConfig referenceConfig = 
CseContext.getInstance().getConsumerProviderManager()
+        .getReferenceConfig(microserviceName);
 
     MicroserviceMeta microserviceMeta = referenceConfig.getMicroserviceMeta();
     ServicePathManager servicePathManager = 
ServicePathManager.getServicePathManager(microserviceMeta);
@@ -162,7 +160,7 @@ public class CseClientHttpRequest implements 
ClientHttpRequest {
           microserviceMeta.getName()));
     }
 
-    OperationLocator locator = 
servicePathManager.consumerLocateOperation(path, httpMetod);
+    OperationLocator locator = 
servicePathManager.consumerLocateOperation(path, httpMethod);
     RestOperationMeta swaggerRestOperation = locator.getOperation();
 
     Map<String, String> pathParams = locator.getPathVarMap();
diff --git 
a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
 
b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
index fe32d99..7de3860 100644
--- 
a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
+++ 
b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/TestCseClientHttpRequest.java
@@ -16,14 +16,12 @@
  */
 package org.apache.servicecomb.provider.springmvc.reference;
 
-import java.io.IOException;
 import java.net.URI;
-import java.util.Arrays;
+import java.util.Collections;
 
 import javax.xml.ws.Holder;
 
 import org.apache.servicecomb.common.rest.RestEngineSchemaListener;
-import org.apache.servicecomb.core.BootListener;
 import org.apache.servicecomb.core.CseContext;
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.core.SCBEngine;
@@ -64,25 +62,6 @@ public class TestCseClientHttpRequest {
   }
 
   @Test
-  public void testNotReady() {
-    String exceptionMessage = "System is not ready for remote calls. "
-        + "When beans are making remote calls in initialization, it's better 
to "
-        + "implement " + BootListener.class.getName() + " and do it after 
EventType.AFTER_REGISTRY.";
-
-    SCBEngine.getInstance().setStatus(SCBStatus.DOWN);
-
-    CseClientHttpRequest client =
-        new CseClientHttpRequest(URI.create("cse://app:test/"), 
HttpMethod.POST);
-
-    try {
-      client.execute();
-      Assert.fail("must throw exception");
-    } catch (IllegalStateException e) {
-      Assert.assertEquals(exceptionMessage, e.getMessage());
-    }
-  }
-
-  @Test
   public void testNormal() {
     ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
     serviceRegistry.init();
@@ -92,7 +71,7 @@ public class TestCseClientHttpRequest {
 
     CseContext.getInstance()
         .getSchemaListenerManager()
-        .setSchemaListenerList(Arrays.asList(new RestEngineSchemaListener()));
+        .setSchemaListenerList(Collections.singletonList(new 
RestEngineSchemaListener()));
 
     SchemaMeta schemaMeta = meta.getOrCreateSchemaMeta(SpringmvcImpl.class);
     
CseContext.getInstance().getSchemaListenerManager().notifySchemaListener(schemaMeta);
diff --git 
a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequestTest.java
 
b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequestTest.java
index d24a5ea..fcab920 100644
--- 
a/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequestTest.java
+++ 
b/providers/provider-springmvc/src/test/java/org/apache/servicecomb/provider/springmvc/reference/async/CseAsyncClientHttpRequestTest.java
@@ -18,13 +18,12 @@
 package org.apache.servicecomb.provider.springmvc.reference.async;
 
 import java.net.URI;
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.concurrent.CompletableFuture;
 
 import javax.xml.ws.Holder;
 
 import org.apache.servicecomb.common.rest.RestEngineSchemaListener;
-import org.apache.servicecomb.core.BootListener;
 import org.apache.servicecomb.core.CseContext;
 import org.apache.servicecomb.core.Invocation;
 import org.apache.servicecomb.core.SCBEngine;
@@ -70,21 +69,6 @@ public class CseAsyncClientHttpRequestTest {
   }
 
   @Test
-  public void testNotReady() {
-    String exceptionMessage = "System is not ready for remote calls. "
-        + "When beans are making remote calls in initialization, it's better 
to "
-        + "implement " + BootListener.class.getName() + " and do it after 
EventType.AFTER_REGISTRY.";
-    SCBEngine.getInstance().setStatus(SCBStatus.DOWN);
-    CseAsyncClientHttpRequest clientHttpRequest = new 
CseAsyncClientHttpRequest(URI.create("cse://app:test/"),
-        HttpMethod.POST);
-    try {
-      clientHttpRequest.executeAsync();
-    } catch (IllegalStateException e) {
-      Assert.assertEquals(exceptionMessage, e.getMessage());
-    }
-  }
-
-  @Test
   public void testNormal() {
     ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
     serviceRegistry.init();
@@ -93,7 +77,7 @@ public class CseAsyncClientHttpRequestTest {
 
     CseContext.getInstance()
         .getSchemaListenerManager()
-        .setSchemaListenerList(Arrays.asList(new RestEngineSchemaListener()));
+        .setSchemaListenerList(Collections.singletonList(new 
RestEngineSchemaListener()));
 
     SchemaMeta schemaMeta = meta
         
.getOrCreateSchemaMeta(CseAsyncClientHttpRequestTest.CseAsyncClientHttpRequestTestSchema.class);
@@ -127,7 +111,7 @@ public class CseAsyncClientHttpRequestTest {
     UnitTestMeta meta = new UnitTestMeta();
     CseContext.getInstance()
         .getSchemaListenerManager()
-        .setSchemaListenerList(Arrays.asList(new RestEngineSchemaListener()));
+        .setSchemaListenerList(Collections.singletonList(new 
RestEngineSchemaListener()));
     SchemaMeta schemaMeta = meta
         
.getOrCreateSchemaMeta(CseAsyncClientHttpRequestTest.CseAsyncClientHttpRequestTestSchema.class);
     
CseContext.getInstance().getSchemaListenerManager().notifySchemaListener(schemaMeta);

-- 
To stop receiving notification emails like this one, please contact
wuji...@apache.org.

Reply via email to