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

iluo pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo-website.git

commit 2202024983fe7872e84c345c97154d3d36f6d87b
Author: beiwei30 <[email protected]>
AuthorDate: Tue Nov 6 16:49:00 2018 +0800

    rebuild website
---
 en-us/docs/user/demos/local-mock.html | 32 ++++++++++++++++++++++++++++++++
 en-us/docs/user/demos/local-mock.json |  2 +-
 zh-cn/docs/user/demos/local-mock.html | 32 ++++++++++++++++++++++++++++++++
 zh-cn/docs/user/demos/local-mock.json |  2 +-
 4 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/en-us/docs/user/demos/local-mock.html 
b/en-us/docs/user/demos/local-mock.html
index 3ded33c..b5bc8cd 100644
--- a/en-us/docs/user/demos/local-mock.html
+++ b/en-us/docs/user/demos/local-mock.html
@@ -40,6 +40,38 @@
 <p>Consider changing to Mock implementation and return null in Mock 
implementation. If you just want to simply ignore the exception, 
<code>2.0.11</code> version or later version is available:</p>
 <pre><code class="language-xml"><span class="hljs-tag">&lt;<span 
class="hljs-name">dubbo:reference</span> <span 
class="hljs-attr">interface</span>=<span 
class="hljs-string">"com.foo.BarService"</span> <span 
class="hljs-attr">mock</span>=<span class="hljs-string">"return null"</span> 
/&gt;</span>
 </code></pre>
+<h2>Advanced Usage</h2>
+<h3>return</h3>
+<p><code>return</code> can be used to return an object's string representation 
as the mocked return value. The legal values incude:</p>
+<ul>
+<li><em>empty</em>: empty value, default value for primary type, and empty 
value for collections.</li>
+<li><em>null</em>: <code>null</code></li>
+<li><em>true</em>: <code>true</code></li>
+<li><em>false</em>: <code>false</code></li>
+<li><em>JSON format</em>: a mocked return value in JSON format, will be 
deserialized at runtime</li>
+</ul>
+<h3>throw</h3>
+<p><code>throw</code> can be used to throw an exception object as the mocked 
return value.</p>
+<p>Throw a default RPCException when invocation gets wrong:</p>
+<pre><code class="language-xml"><span class="hljs-tag">&lt;<span 
class="hljs-name">dubbo:reference</span> <span 
class="hljs-attr">interface</span>=<span 
class="hljs-string">"com.foo.BarService"</span> <span 
class="hljs-attr">mock</span>=<span class="hljs-string">"throw"</span> 
/&gt;</span>
+</code></pre>
+<p>Throw a specified exception when invocation gets wrong:</p>
+<pre><code class="language-xml"><span class="hljs-tag">&lt;<span 
class="hljs-name">dubbo:reference</span> <span 
class="hljs-attr">interface</span>=<span 
class="hljs-string">"com.foo.BarService"</span> <span 
class="hljs-attr">mock</span>=<span class="hljs-string">"throw 
com.foo.MockException"</span> /&gt;</span>
+</code></pre>
+<h3>force &amp; fail</h3>
+<p>Since <code>2.6.6</code> and above, it is possible to use 
<code>fail:</code> and <code>force:</code> in Spring's XML configuration to 
define mock behavior. <code>force:</code> means the mocked value is forced to 
use no matter the invocation gets wrong or not, in fact, the remote invocation 
will not happen at all. <code>fail:</code> is consistent with the default 
behavior, that is, mock happens only when invocation gets wrong. Futhermore, 
both <code>force:</code> and <code>fail:</code> [...]
+<p>Force to return the specified value:</p>
+<pre><code class="language-xml"><span class="hljs-tag">&lt;<span 
class="hljs-name">dubbo:reference</span> <span 
class="hljs-attr">interface</span>=<span 
class="hljs-string">"com.foo.BarService"</span> <span 
class="hljs-attr">mock</span>=<span class="hljs-string">"force:return 
fake"</span> /&gt;</span>
+</code></pre>
+<p>Force to throw the specified exception:</p>
+<pre><code class="language-xml"><span class="hljs-tag">&lt;<span 
class="hljs-name">dubbo:reference</span> <span 
class="hljs-attr">interface</span>=<span 
class="hljs-string">"com.foo.BarService"</span> <span 
class="hljs-attr">mock</span>=<span class="hljs-string">"force:throw 
com.foo.MockException"</span> /&gt;</span>
+</code></pre>
+<h3>Specify Mock For Particular Method Only</h3>
+<p>Mock behavior can be specified on the method level. Assume there are a 
couple of methods on <code>com.foo.BarService</code>, we can specify the mock 
behavior for one particular method only, say <code>sayHello()</code>. In the 
example below, &quot;fake&quot; is forced to return everytime when 
<code>sayHello()</code> is called, but other methods will not be effected:</p>
+<pre><code class="language-xml"><span class="hljs-tag">&lt;<span 
class="hljs-name">dubbo:reference</span> <span 
class="hljs-attr">id</span>=<span class="hljs-string">"demoService"</span> 
<span class="hljs-attr">check</span>=<span class="hljs-string">"false"</span> 
<span class="hljs-attr">interface</span>=<span 
class="hljs-string">"com.foo.BarService"</span>&gt;</span>
+    <span class="hljs-tag">&lt;<span class="hljs-name">dubbo:parameter</span> 
<span class="hljs-attr">key</span>=<span 
class="hljs-string">"sayHello.mock"</span> <span 
class="hljs-attr">value</span>=<span class="hljs-string">"force:return 
fake"</span>/&gt;</span>
+<span class="hljs-tag">&lt;/<span 
class="hljs-name">dubbo:reference</span>&gt;</span>
+</code></pre>
 <hr class="footnotes-sep">
 <section class="footnotes">
 <ol class="footnotes-list">
diff --git a/en-us/docs/user/demos/local-mock.json 
b/en-us/docs/user/demos/local-mock.json
index b6b6911..8f62100 100644
--- a/en-us/docs/user/demos/local-mock.json
+++ b/en-us/docs/user/demos/local-mock.json
@@ -1,4 +1,4 @@
 {
   "filename": "local-mock.md",
-  "__html": "<h1>Local mock</h1>\n<p>Local mock <sup class=\"footnote-ref\"><a 
href=\"#fn1\" id=\"fnref1\">[1]</a></sup> is usually used for service 
downgrade, such as a verification service, the client does not throw an 
exception when the service provider hangs up all the time, but returns the 
authorization failed through the Mock data.</p>\n<p>Configured in the spring 
configuration file as follows:</p>\n<pre><code class=\"language-xml\"><span 
class=\"hljs-tag\">&lt;<span class=\"hljs-n [...]
+  "__html": "<h1>Local mock</h1>\n<p>Local mock <sup class=\"footnote-ref\"><a 
href=\"#fn1\" id=\"fnref1\">[1]</a></sup> is usually used for service 
downgrade, such as a verification service, the client does not throw an 
exception when the service provider hangs up all the time, but returns the 
authorization failed through the Mock data.</p>\n<p>Configured in the spring 
configuration file as follows:</p>\n<pre><code class=\"language-xml\"><span 
class=\"hljs-tag\">&lt;<span class=\"hljs-n [...]
 }
\ No newline at end of file
diff --git a/zh-cn/docs/user/demos/local-mock.html 
b/zh-cn/docs/user/demos/local-mock.html
index 15c2031..a74c424 100644
--- a/zh-cn/docs/user/demos/local-mock.html
+++ b/zh-cn/docs/user/demos/local-mock.html
@@ -40,6 +40,38 @@
 <p>请考虑改为 Mock 实现,并在 Mock 实现中 return null。如果只是想简单的忽略异常,在 <code>2.0.11</code> 
以上版本可用:</p>
 <pre><code class="language-xml"><span class="hljs-tag">&lt;<span 
class="hljs-name">dubbo:reference</span> <span 
class="hljs-attr">interface</span>=<span 
class="hljs-string">"com.foo.BarService"</span> <span 
class="hljs-attr">mock</span>=<span class="hljs-string">"return null"</span> 
/&gt;</span>
 </code></pre>
+<h2>进阶用法</h2>
+<h3>return</h3>
+<p>使用 <code>return</code> 来返回一个字符串表示的对象,作为 Mock 的返回值。合法的字符串可以是:</p>
+<ul>
+<li><em>empty</em>: 代表空,基本类型的默认值,或者集合类的空值</li>
+<li><em>null</em>: <code>null</code></li>
+<li><em>true</em>: <code>true</code></li>
+<li><em>false</em>: <code>false</code></li>
+<li><em>JSON 格式</em>: 反序列化 JSON 所得到的对象</li>
+</ul>
+<h3>throw</h3>
+<p>使用 <code>throw</code> 来返回一个 Exception 对象,作为 Mock 的返回值。</p>
+<p>当调用出错时,抛出一个默认的 RPCException:</p>
+<pre><code class="language-xml"><span class="hljs-tag">&lt;<span 
class="hljs-name">dubbo:reference</span> <span 
class="hljs-attr">interface</span>=<span 
class="hljs-string">"com.foo.BarService"</span> <span 
class="hljs-attr">mock</span>=<span class="hljs-string">"throw"</span> 
/&gt;</span>
+</code></pre>
+<p>当调用出错时,抛出指定的 Exception:</p>
+<pre><code class="language-xml"><span class="hljs-tag">&lt;<span 
class="hljs-name">dubbo:reference</span> <span 
class="hljs-attr">interface</span>=<span 
class="hljs-string">"com.foo.BarService"</span> <span 
class="hljs-attr">mock</span>=<span class="hljs-string">"throw 
com.foo.MockException"</span> /&gt;</span>
+</code></pre>
+<h3>force 和 fail</h3>
+<p>在 <code>2.6.6</code> 以上的版本,可以开始在 Spring XML 配置文件中使用 <code>fail:</code> 和 
<code>force:</code>。<code>force:</code> 代表强制使用 Mock 
行为,在这种情况下不会走远程调用。<code>fail:</code> 与默认行为一致,只有当远程调用发生错误时才使用 Mock 
行为。<code>force:</code> 和 <code>fail:</code> 都支持与 <code>throw</code> 或者 
<code>return</code> 组合使用。</p>
+<p>强制返回指定值:</p>
+<pre><code class="language-xml"><span class="hljs-tag">&lt;<span 
class="hljs-name">dubbo:reference</span> <span 
class="hljs-attr">interface</span>=<span 
class="hljs-string">"com.foo.BarService"</span> <span 
class="hljs-attr">mock</span>=<span class="hljs-string">"force:return 
fake"</span> /&gt;</span>
+</code></pre>
+<p>强制抛出指定异常:</p>
+<pre><code class="language-xml"><span class="hljs-tag">&lt;<span 
class="hljs-name">dubbo:reference</span> <span 
class="hljs-attr">interface</span>=<span 
class="hljs-string">"com.foo.BarService"</span> <span 
class="hljs-attr">mock</span>=<span class="hljs-string">"force:throw 
com.foo.MockException"</span> /&gt;</span>
+</code></pre>
+<h3>在方法级别配置 Mock</h3>
+<p>Mock 可以在方法级别上指定,假定 <code>com.foo.BarService</code> 上有好几个方法,我们可以单独为 
<code>sayHello()</code> 方法指定 Mock 行为。具体配置如下所示,在本例中,只要 <code>sayHello()</code> 
被调用到时,强制返回 &quot;fake&quot;:</p>
+<pre><code class="language-xml"><span class="hljs-tag">&lt;<span 
class="hljs-name">dubbo:reference</span> <span 
class="hljs-attr">id</span>=<span class="hljs-string">"demoService"</span> 
<span class="hljs-attr">check</span>=<span class="hljs-string">"false"</span> 
<span class="hljs-attr">interface</span>=<span 
class="hljs-string">"com.foo.BarService"</span>&gt;</span>
+    <span class="hljs-tag">&lt;<span class="hljs-name">dubbo:parameter</span> 
<span class="hljs-attr">key</span>=<span 
class="hljs-string">"sayHello.mock"</span> <span 
class="hljs-attr">value</span>=<span class="hljs-string">"force:return 
fake"</span>/&gt;</span>
+<span class="hljs-tag">&lt;/<span 
class="hljs-name">dubbo:reference</span>&gt;</span>
+</code></pre>
 <hr class="footnotes-sep">
 <section class="footnotes">
 <ol class="footnotes-list">
diff --git a/zh-cn/docs/user/demos/local-mock.json 
b/zh-cn/docs/user/demos/local-mock.json
index 0c00266..55672e7 100644
--- a/zh-cn/docs/user/demos/local-mock.json
+++ b/zh-cn/docs/user/demos/local-mock.json
@@ -1,4 +1,4 @@
 {
   "filename": "local-mock.md",
-  "__html": "<h1>本地伪装</h1>\n<p>本地伪装 <sup class=\"footnote-ref\"><a 
href=\"#fn1\" id=\"fnref1\">[1]</a></sup> 
通常用于服务降级,比如某验权服务,当服务提供方全部挂掉后,客户端不抛出异常,而是通过 Mock 数据返回授权失败。</p>\n<p>在 spring 
配置文件中按以下方式配置:</p>\n<pre><code class=\"language-xml\"><span 
class=\"hljs-tag\">&lt;<span class=\"hljs-name\">dubbo:reference</span> <span 
class=\"hljs-attr\">interface</span>=<span 
class=\"hljs-string\">\"com.foo.BarService\"</span> <span 
class=\"hljs-attr\">mock</span>=<span class=\"hljs-string\">\"true\"</ [...]
+  "__html": "<h1>本地伪装</h1>\n<p>本地伪装 <sup class=\"footnote-ref\"><a 
href=\"#fn1\" id=\"fnref1\">[1]</a></sup> 
通常用于服务降级,比如某验权服务,当服务提供方全部挂掉后,客户端不抛出异常,而是通过 Mock 数据返回授权失败。</p>\n<p>在 spring 
配置文件中按以下方式配置:</p>\n<pre><code class=\"language-xml\"><span 
class=\"hljs-tag\">&lt;<span class=\"hljs-name\">dubbo:reference</span> <span 
class=\"hljs-attr\">interface</span>=<span 
class=\"hljs-string\">\"com.foo.BarService\"</span> <span 
class=\"hljs-attr\">mock</span>=<span class=\"hljs-string\">\"true\"</ [...]
 }
\ No newline at end of file

Reply via email to