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/03/15 11:12:17 UTC

[incubator-servicecomb-java-chassis] 01/05: SCB-374 define invocation life event

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 f81a8b9ec1bc9358ab9481c8c98ae0b29261f1cc
Author: wujimin <wu...@huawei.com>
AuthorDate: Fri Mar 9 12:40:10 2018 +0800

    SCB-374 define invocation life event
---
 .../core/event/InvocationFinishEvent.java          | 46 +++++++++++++++++++++
 .../core/event/InvocationStartEvent.java           | 32 +++++++++++++++
 .../core/event/TestInvocationFinishEvent.java      | 47 ++++++++++++++++++++++
 .../core/event/TestInvocationStartEvent.java       | 34 ++++++++++++++++
 4 files changed, 159 insertions(+)

diff --git a/core/src/main/java/org/apache/servicecomb/core/event/InvocationFinishEvent.java b/core/src/main/java/org/apache/servicecomb/core/event/InvocationFinishEvent.java
new file mode 100644
index 0000000..d611f76
--- /dev/null
+++ b/core/src/main/java/org/apache/servicecomb/core/event/InvocationFinishEvent.java
@@ -0,0 +1,46 @@
+/*
+ * 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.event;
+
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.swagger.invocation.Response;
+
+public class InvocationFinishEvent {
+  private long nanoCurrent;
+
+  private Invocation invocation;
+
+  private Response response;
+
+  public InvocationFinishEvent(Invocation invocation, Response response) {
+    this.nanoCurrent = System.nanoTime();
+    this.invocation = invocation;
+    this.response = response;
+  }
+
+  public long getNanoCurrent() {
+    return nanoCurrent;
+  }
+
+  public Invocation getInvocation() {
+    return invocation;
+  }
+
+  public Response getResponse() {
+    return response;
+  }
+}
diff --git a/core/src/main/java/org/apache/servicecomb/core/event/InvocationStartEvent.java b/core/src/main/java/org/apache/servicecomb/core/event/InvocationStartEvent.java
new file mode 100644
index 0000000..5b93e66
--- /dev/null
+++ b/core/src/main/java/org/apache/servicecomb/core/event/InvocationStartEvent.java
@@ -0,0 +1,32 @@
+/*
+ * 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.event;
+
+import org.apache.servicecomb.core.Invocation;
+
+public class InvocationStartEvent {
+  private Invocation invocation;
+
+  public InvocationStartEvent(Invocation invocation) {
+    super();
+    this.invocation = invocation;
+  }
+
+  public Invocation getInvocation() {
+    return invocation;
+  }
+}
diff --git a/core/src/test/java/org/apache/servicecomb/core/event/TestInvocationFinishEvent.java b/core/src/test/java/org/apache/servicecomb/core/event/TestInvocationFinishEvent.java
new file mode 100644
index 0000000..5fe6b83
--- /dev/null
+++ b/core/src/test/java/org/apache/servicecomb/core/event/TestInvocationFinishEvent.java
@@ -0,0 +1,47 @@
+/*
+ * 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.event;
+
+import org.apache.servicecomb.core.Invocation;
+import org.apache.servicecomb.swagger.invocation.Response;
+import org.junit.Assert;
+import org.junit.Test;
+
+import mockit.Mock;
+import mockit.MockUp;
+import mockit.Mocked;
+
+public class TestInvocationFinishEvent {
+  InvocationFinishEvent event;
+
+  @Test
+  public void construct(@Mocked Invocation invocation, @Mocked Response response) {
+    long time = 123;
+    new MockUp<System>() {
+      @Mock
+      long nanoTime() {
+        return time;
+      }
+    };
+
+    event = new InvocationFinishEvent(invocation, response);
+
+    Assert.assertEquals(time, event.getNanoCurrent());
+    Assert.assertSame(invocation, event.getInvocation());
+    Assert.assertSame(response, event.getResponse());
+  }
+}
diff --git a/core/src/test/java/org/apache/servicecomb/core/event/TestInvocationStartEvent.java b/core/src/test/java/org/apache/servicecomb/core/event/TestInvocationStartEvent.java
new file mode 100644
index 0000000..9181520
--- /dev/null
+++ b/core/src/test/java/org/apache/servicecomb/core/event/TestInvocationStartEvent.java
@@ -0,0 +1,34 @@
+/*
+ * 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.event;
+
+import org.apache.servicecomb.core.Invocation;
+import org.junit.Assert;
+import org.junit.Test;
+
+import mockit.Mocked;
+
+public class TestInvocationStartEvent {
+  InvocationStartEvent event;
+
+  @Test
+  public void construct(@Mocked Invocation invocation) {
+    event = new InvocationStartEvent(invocation);
+
+    Assert.assertSame(invocation, event.getInvocation());
+  }
+}

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