You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/01/31 02:36:09 UTC

[incubator-servicecomb-java-chassis] 02/03: SCB-310 vertx summary eventloop context created count

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit d68e86ac54f7a42d87c5bee14b4321e0304a3bfb
Author: wujimin <wu...@huawei.com>
AuthorDate: Fri Jan 26 16:56:14 2018 +0800

    SCB-310 vertx summary eventloop context created count
---
 .../main/java/io/vertx/core/impl/VertxImplEx.java  | 15 +++++++
 .../java/io/vertx/core/impl/TestVertxImplEx.java}  | 48 +++++++++++-----------
 2 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/foundations/foundation-vertx/src/main/java/io/vertx/core/impl/VertxImplEx.java b/foundations/foundation-vertx/src/main/java/io/vertx/core/impl/VertxImplEx.java
index be70aab..2020ff3 100644
--- a/foundations/foundation-vertx/src/main/java/io/vertx/core/impl/VertxImplEx.java
+++ b/foundations/foundation-vertx/src/main/java/io/vertx/core/impl/VertxImplEx.java
@@ -18,13 +18,17 @@
 package io.vertx.core.impl;
 
 import java.lang.reflect.Field;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.springframework.util.ReflectionUtils;
 import org.springframework.util.StringUtils;
 
 import io.vertx.core.VertxOptions;
+import io.vertx.core.json.JsonObject;
 
 public class VertxImplEx extends VertxImpl {
+  private AtomicLong eventLoopContextCreated = new AtomicLong();
+
   public VertxImplEx(String name, VertxOptions vertxOptions) {
     super(vertxOptions);
 
@@ -42,4 +46,15 @@ public class VertxImplEx extends VertxImpl {
     String prefix = (String) ReflectionUtils.getField(field, eventLoopThreadFactory);
     ReflectionUtils.setField(field, eventLoopThreadFactory, name + "-" + prefix);
   }
+
+  @Override
+  public EventLoopContext createEventLoopContext(String deploymentID, WorkerPool workerPool, JsonObject config,
+      ClassLoader tccl) {
+    eventLoopContextCreated.incrementAndGet();
+    return super.createEventLoopContext(deploymentID, workerPool, config, tccl);
+  }
+
+  public long getEventLoopContextCreatedCount() {
+    return eventLoopContextCreated.get();
+  }
 }
diff --git a/foundations/foundation-vertx/src/main/java/io/vertx/core/impl/VertxImplEx.java b/foundations/foundation-vertx/src/test/java/io/vertx/core/impl/TestVertxImplEx.java
similarity index 51%
copy from foundations/foundation-vertx/src/main/java/io/vertx/core/impl/VertxImplEx.java
copy to foundations/foundation-vertx/src/test/java/io/vertx/core/impl/TestVertxImplEx.java
index be70aab..733d150 100644
--- a/foundations/foundation-vertx/src/main/java/io/vertx/core/impl/VertxImplEx.java
+++ b/foundations/foundation-vertx/src/test/java/io/vertx/core/impl/TestVertxImplEx.java
@@ -14,32 +14,34 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package io.vertx.core.impl;
 
-import java.lang.reflect.Field;
-
-import org.springframework.util.ReflectionUtils;
-import org.springframework.util.StringUtils;
+import org.junit.Assert;
+import org.junit.Test;
 
 import io.vertx.core.VertxOptions;
-
-public class VertxImplEx extends VertxImpl {
-  public VertxImplEx(String name, VertxOptions vertxOptions) {
-    super(vertxOptions);
-
-    if (StringUtils.isEmpty(name)) {
-      return;
-    }
-
-    Field field = ReflectionUtils.findField(VertxImpl.class, "eventLoopThreadFactory");
-    field.setAccessible(true);
-    VertxThreadFactory eventLoopThreadFactory = (VertxThreadFactory) ReflectionUtils.getField(field, this);
-
-    field = ReflectionUtils.findField(eventLoopThreadFactory.getClass(), "prefix");
-    field.setAccessible(true);
-
-    String prefix = (String) ReflectionUtils.getField(field, eventLoopThreadFactory);
-    ReflectionUtils.setField(field, eventLoopThreadFactory, name + "-" + prefix);
+import io.vertx.core.json.JsonObject;
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Mocked;
+
+public class TestVertxImplEx {
+  @Test
+  public void testContextCreatedCount(@Mocked EventLoopContext context) {
+    new MockUp<VertxImpl>() {
+      @Mock
+      EventLoopContext createEventLoopContext(String deploymentID, WorkerPool workerPool, JsonObject config,
+          ClassLoader tccl) {
+        return context;
+      }
+    };
+
+    VertxImplEx vertx = new VertxImplEx("test", new VertxOptions());
+
+    vertx.createEventLoopContext(null, null, null, null);
+    Assert.assertEquals(1, vertx.getEventLoopContextCreatedCount());
+
+    vertx.createEventLoopContext(null, null, null, null);
+    Assert.assertEquals(2, vertx.getEventLoopContextCreatedCount());
   }
 }

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