From ccd102c54b12ceaa22aaaccd6756e7b5f602ff28 Mon Sep 17 00:00:00 2001 From: reeyur Date: Wed, 18 Mar 2020 16:14:25 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0bandwidth=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=8E=B7=E5=8F=96/=E8=AE=BE=E7=BD=AE=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E5=B8=A6=E5=AE=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 16 +++++ .../java/com/meituan/lyrebird/Lyrebird.java | 22 ++++++ .../lyrebird/client/LyrebirdClient.java | 39 ++++++++++ .../lyrebird/client/LyrebirdService.java | 9 +++ .../client/api/bandwidth/BandWidth.java | 11 +++ .../api/bandwidth/BandWidthTemplate.java | 30 ++++++++ .../client/api/bandwidth/SpeedLimit.java | 15 ++++ .../meituan/lyrebird/test/TestFunctional.java | 71 ++++++++++++++++++- 8 files changed, 210 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java create mode 100644 src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java create mode 100644 src/main/java/com/meituan/lyrebird/client/api/bandwidth/SpeedLimit.java diff --git a/README.md b/README.md index 032b232..9174717 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ - [清空 Flow 数据](#清空-Flow-数据) - [获取指定频道的消息总线数据](#获取指定频道的消息总线数据) - [获取Socket对象进行事件监听](#获取Socket对象进行事件监听) + - [设置带宽限速](#设置带宽谢安素) - [应用场景](#应用场景) - [在UI自动化中校验请求参数是否符合预期](#在UI自动化中校验请求参数是否符合预期) - [在UI自动化中校验返回与客户端展示是否一致](#在UI自动化中校验返回与客户端展示是否一致) @@ -409,6 +410,21 @@ socket.connect(); socket.disconnect(); ``` +### 设置带宽谢安素 + +[Lyrebird 获取/设置网络带宽限速接口文档](https://meituan-dianping.github.io/lyrebird/guide/api.html#%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E7%BD%91%E7%BB%9C%E5%B8%A6%E5%AE%BD%E9%99%90%E9%80%9F) + +```java +// 设置带宽限速为2G +lyrebird.setSpeedLimit(BandWidth.MINIMUM); +// 设置带宽限速为2.5G +lyrebird.setSpeedLimit(BandWidth.LOW); +// 设置带宽限速为3G +lyrebird.setSpeedLimit(BandWidth.MEDIUM); +// 获取带宽速度 +int bandwidth = lyrebird.getSpeedLimit().getBandwidth(); +``` + ## 应用场景 在UI自动化中,可将移动设备通过代理的方式将请求数据接入Lyrebird,[操作指南](https://github.com/Meituan-Dianping/lyrebird#连接移动设备),在测试用例中通过调用Lyrebird API来校验网络请求参数是否符合预期。 diff --git a/src/main/java/com/meituan/lyrebird/Lyrebird.java b/src/main/java/com/meituan/lyrebird/Lyrebird.java index 58e9b75..a4a3193 100644 --- a/src/main/java/com/meituan/lyrebird/Lyrebird.java +++ b/src/main/java/com/meituan/lyrebird/Lyrebird.java @@ -1,5 +1,7 @@ package com.meituan.lyrebird; +import com.meituan.lyrebird.client.api.bandwidth.BandWidth; +import com.meituan.lyrebird.client.api.bandwidth.SpeedLimit; import io.socket.client.Socket; import java.lang.reflect.Method; @@ -153,6 +155,26 @@ public LBMockData getMockData(String dataId) throws LyrebirdClientException { return client.getMockData(dataId); } + /** + * set the speed limit + * + * @param bandWidth + * @throws LyrebirdClientException + */ + public void setSpeedLimit(BandWidth bandWidth) throws LyrebirdClientException { + client.setSpeedLimit(bandWidth); + } + + /** + * get the speed limit bandwidth + * + * @return + * @throws LyrebirdClientException + */ + public SpeedLimit getSpeedLimit() throws LyrebirdClientException { + return client.getSpeedLimit(); + } + /** * Get an object of socket io * diff --git a/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java b/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java index 430c575..d8788f5 100644 --- a/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java +++ b/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java @@ -1,5 +1,8 @@ package com.meituan.lyrebird.client; +import com.meituan.lyrebird.client.api.bandwidth.BandWidth; +import com.meituan.lyrebird.client.api.bandwidth.BandWidthTemplate; +import com.meituan.lyrebird.client.api.bandwidth.SpeedLimit; import com.meituan.lyrebird.client.exceptions.LyrebirdClientException; import com.meituan.lyrebird.client.api.*; import io.socket.client.IO; @@ -197,6 +200,42 @@ public LBMockData getMockData(String dataId) throws LyrebirdClientException { } } + /** + * set the speed limit + * + * @param bandWidth an enum of BandWidth + * @throws LyrebirdClientException + */ + public void setSpeedLimit(BandWidth bandWidth) throws LyrebirdClientException { + BandWidthTemplate template = new BandWidthTemplate(bandWidth); + BaseResponse resp; + try{ + resp = lyrebirdService.setSpeedLimit(template).execute().body(); + } catch (IOException e) { + throw new LyrebirdClientException("Catch exception while set the speed limit", e); + } + if (resp == null) { + throw new LyrebirdClientException("Got none response from the speed limit request"); + } + if (resp.getCode() != 1000) { + throw new LyrebirdClientException(resp.getMessage()); + } + } + + /** + * get the speed limit bandwidth + * + * @return + * @throws LyrebirdClientException + */ + public SpeedLimit getSpeedLimit() throws LyrebirdClientException { + try { + return lyrebirdService.getSpeedLimit().execute().body(); + } catch (IOException e) { + throw new LyrebirdClientException("Catch exception while get speed limit bandwidth.", e); + } + } + /** * Get an object of socket io * diff --git a/src/main/java/com/meituan/lyrebird/client/LyrebirdService.java b/src/main/java/com/meituan/lyrebird/client/LyrebirdService.java index a6b989a..3fddf7e 100644 --- a/src/main/java/com/meituan/lyrebird/client/LyrebirdService.java +++ b/src/main/java/com/meituan/lyrebird/client/LyrebirdService.java @@ -2,6 +2,8 @@ import com.meituan.lyrebird.client.api.*; +import com.meituan.lyrebird.client.api.bandwidth.BandWidthTemplate; +import com.meituan.lyrebird.client.api.bandwidth.SpeedLimit; import retrofit2.Call; import retrofit2.http.*; @@ -30,4 +32,11 @@ public interface LyrebirdService { @GET("api/data/{dataId}") Call getMockData(@Path("dataId") String dataId); + + @Headers("Content-Type: application/json") + @PUT("api/bandwidth") + Call setSpeedLimit(@Body BandWidthTemplate template); + + @GET("api/bandwidth") + Call getSpeedLimit(); } diff --git a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java new file mode 100644 index 0000000..711f242 --- /dev/null +++ b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java @@ -0,0 +1,11 @@ +package com.meituan.lyrebird.client.api.bandwidth; + +/** + * MINIMUM: 2G + * LOW: 2.5G + * MEDIUM: 3G + * UNLIMITED: UNLIMITED + */ +public enum BandWidth { + MINIMUM, LOW, MEDIUM, UNLIMITED +} diff --git a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java new file mode 100644 index 0000000..51186ae --- /dev/null +++ b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java @@ -0,0 +1,30 @@ +package com.meituan.lyrebird.client.api.bandwidth; + +public class BandWidthTemplate { + private String templateName; + + public BandWidthTemplate(BandWidth bandWidth) { + switch (bandWidth) { + case MINIMUM: + templateName = "2G"; + break; + case LOW: + templateName = "2.5G"; + break; + case MEDIUM: + templateName = "3G"; + break; + default: + templateName = "UNLIMITED"; + break; + } + } + + public String getTemplateName() { + return templateName; + } + + public void setTemplateName(String templateName) { + this.templateName = templateName; + } +} diff --git a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/SpeedLimit.java b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/SpeedLimit.java new file mode 100644 index 0000000..0838194 --- /dev/null +++ b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/SpeedLimit.java @@ -0,0 +1,15 @@ +package com.meituan.lyrebird.client.api.bandwidth; + +import com.meituan.lyrebird.client.api.BaseResponse; + +public class SpeedLimit extends BaseResponse { + private int bandwidth; + + public int getBandwidth() { + return bandwidth; + } + + public void setBandwidth(int bandwidth) { + this.bandwidth = bandwidth; + } +} diff --git a/src/test/java/com/meituan/lyrebird/test/TestFunctional.java b/src/test/java/com/meituan/lyrebird/test/TestFunctional.java index c1d67ed..d22954a 100644 --- a/src/test/java/com/meituan/lyrebird/test/TestFunctional.java +++ b/src/test/java/com/meituan/lyrebird/test/TestFunctional.java @@ -4,6 +4,7 @@ import com.jayway.jsonpath.JsonPath; import com.meituan.lyrebird.Lyrebird; import com.meituan.lyrebird.client.api.*; +import com.meituan.lyrebird.client.api.bandwidth.BandWidth; import com.meituan.lyrebird.client.exceptions.LyrebirdClientException; import java.util.List; import okhttp3.mockwebserver.*; @@ -171,10 +172,10 @@ public void testEventList() throws LyrebirdClientException, InterruptedException @Test public void testLBMockData() throws LyrebirdClientException { - this.mockServer.enqueue( - new MockResponse() + this.mockServer.enqueue(new MockResponse() .setBody( - "{\"code\": 1000,\"data\": {\"id\": \"cfa0c589-8ef0-4885-b4f4-b9688c5af0d5\", \"name\": \"test-data\", \"response\": {\"data\": \"[{\\\"type\\\": \\\"scheme\\\", \\\"info\\\":{\\\"value\\\": \\\"test://www.lyrebird.java.sdk.com\\\"}, \\\"desc\\\": \\\"The scheme of target page\\\"}]\"}}, \"message\": \"success\"}")); + "{\"code\": 1000,\"data\": {\"id\": \"cfa0c589-8ef0-4885-b4f4-b9688c5af0d5\", \"name\": \"test-data\", \"response\": {\"data\": \"[{\\\"type\\\": \\\"scheme\\\", \\\"info\\\":{\\\"value\\\": \\\"test://www.lyrebird.java.sdk.com\\\"}, \\\"desc\\\": \\\"The scheme of target page\\\"}]\"}}, \"message\": \"success\"}" + )); LBMockData lbMockData = this.lyrebird.getMockData("cfa0c589-8ef0-4885-b4f4-b9688c5af0d5"); assertEquals("cfa0c589-8ef0-4885-b4f4-b9688c5af0d5", lbMockData.getId()); @@ -184,4 +185,68 @@ public void testLBMockData() throws LyrebirdClientException { assertEquals(1, urlScheme.size()); assertEquals("test://www.lyrebird.java.sdk.com", urlScheme.get(0)); } + + @Test + public void testMinimumSpeedLimit() throws LyrebirdClientException, InterruptedException { + this.mockServer.enqueue(new MockResponse() + .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 10}" + )); + lyrebird.setSpeedLimit(BandWidth.MINIMUM); + RecordedRequest request = this.mockServer.takeRequest(); + assertEquals("{\"templateName\":\"2G\"}", request.getBody().readUtf8()); + + this.mockServer.enqueue(new MockResponse() + .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 10}" + )); + int bandwidth = lyrebird.getSpeedLimit().getBandwidth(); + assertEquals(10, bandwidth); + } + + @Test + public void testLowSpeedLimit() throws LyrebirdClientException, InterruptedException { + this.mockServer.enqueue(new MockResponse() + .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 35}" + )); + lyrebird.setSpeedLimit(BandWidth.LOW); + RecordedRequest request = this.mockServer.takeRequest(); + assertEquals("{\"templateName\":\"2.5G\"}", request.getBody().readUtf8()); + + this.mockServer.enqueue(new MockResponse() + .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 35}" + )); + int bandwidth = lyrebird.getSpeedLimit().getBandwidth(); + assertEquals(35, bandwidth); + } + + @Test + public void testMediumSpeedLimit() throws LyrebirdClientException, InterruptedException { + this.mockServer.enqueue(new MockResponse() + .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 120}" + )); + lyrebird.setSpeedLimit(BandWidth.MEDIUM); + RecordedRequest request = this.mockServer.takeRequest(); + assertEquals("{\"templateName\":\"3G\"}", request.getBody().readUtf8()); + + this.mockServer.enqueue(new MockResponse() + .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 120}" + )); + int bandwidth = lyrebird.getSpeedLimit().getBandwidth(); + assertEquals(120, bandwidth); + } + + @Test + public void testUnlimitedSpeedLimit() throws LyrebirdClientException, InterruptedException { + this.mockServer.enqueue(new MockResponse() + .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": -1}" + )); + lyrebird.setSpeedLimit(BandWidth.UNLIMITED); + RecordedRequest request = this.mockServer.takeRequest(); + assertEquals("{\"templateName\":\"UNLIMITED\"}", request.getBody().readUtf8()); + + this.mockServer.enqueue(new MockResponse() + .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": -1}" + )); + int bandwidth = lyrebird.getSpeedLimit().getBandwidth(); + assertEquals(-1, bandwidth); + } } From 0e8f8e4bef58ba3a244dde8c04234bd20e92cc92 Mon Sep 17 00:00:00 2001 From: reeyur Date: Wed, 18 Mar 2020 16:17:10 +0800 Subject: [PATCH 2/9] update pom version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6df377e..11907b9 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.meituan-dianping.lyrebird.sdk lyrebird-java-client - 1.1.1 + 1.1.2 lyrebird-java-client https://github.com/Meituan-Dianping/lyrebird-java-client From b98422f5ebb80a26f2317c1f9dfc76723fc528ca Mon Sep 17 00:00:00 2001 From: reeyur Date: Wed, 18 Mar 2020 16:23:49 +0800 Subject: [PATCH 3/9] =?UTF-8?q?Fix=20=E6=96=87=E5=AD=97=E6=8B=BC=E5=86=99?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9174717..9eac9dd 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ - [清空 Flow 数据](#清空-Flow-数据) - [获取指定频道的消息总线数据](#获取指定频道的消息总线数据) - [获取Socket对象进行事件监听](#获取Socket对象进行事件监听) - - [设置带宽限速](#设置带宽谢安素) + - [设置带宽限速](#设置带宽限速) - [应用场景](#应用场景) - [在UI自动化中校验请求参数是否符合预期](#在UI自动化中校验请求参数是否符合预期) - [在UI自动化中校验返回与客户端展示是否一致](#在UI自动化中校验返回与客户端展示是否一致) @@ -410,7 +410,7 @@ socket.connect(); socket.disconnect(); ``` -### 设置带宽谢安素 +### 设置带宽限速 [Lyrebird 获取/设置网络带宽限速接口文档](https://meituan-dianping.github.io/lyrebird/guide/api.html#%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E7%BD%91%E7%BB%9C%E5%B8%A6%E5%AE%BD%E9%99%90%E9%80%9F) From 8ba844b8af9f5e5bb26010e2c3359313aaf31c03 Mon Sep 17 00:00:00 2001 From: reeyur Date: Wed, 18 Mar 2020 16:33:13 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +++++--- .../java/com/meituan/lyrebird/Lyrebird.java | 3 +-- .../meituan/lyrebird/client/LyrebirdClient.java | 3 +-- .../client/api/bandwidth/BandWidth.java | 11 ----------- .../client/api/bandwidth/BandWidthTemplate.java | 17 ++--------------- .../meituan/lyrebird/test/TestFunctional.java | 15 +++++++-------- 6 files changed, 16 insertions(+), 41 deletions(-) delete mode 100644 src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java diff --git a/README.md b/README.md index 9eac9dd..26ab331 100644 --- a/README.md +++ b/README.md @@ -416,11 +416,13 @@ socket.disconnect(); ```java // 设置带宽限速为2G -lyrebird.setSpeedLimit(BandWidth.MINIMUM); +lyrebird.setSpeedLimit("2G"); // 设置带宽限速为2.5G -lyrebird.setSpeedLimit(BandWidth.LOW); +lyrebird.setSpeedLimit("2.5G"); // 设置带宽限速为3G -lyrebird.setSpeedLimit(BandWidth.MEDIUM); +lyrebird.setSpeedLimit("3G"); +// 关闭限速 +lyrebird.setSpeedLimit("UNLIMITED"); // 获取带宽速度 int bandwidth = lyrebird.getSpeedLimit().getBandwidth(); ``` diff --git a/src/main/java/com/meituan/lyrebird/Lyrebird.java b/src/main/java/com/meituan/lyrebird/Lyrebird.java index a4a3193..a07a37e 100644 --- a/src/main/java/com/meituan/lyrebird/Lyrebird.java +++ b/src/main/java/com/meituan/lyrebird/Lyrebird.java @@ -1,6 +1,5 @@ package com.meituan.lyrebird; -import com.meituan.lyrebird.client.api.bandwidth.BandWidth; import com.meituan.lyrebird.client.api.bandwidth.SpeedLimit; import io.socket.client.Socket; import java.lang.reflect.Method; @@ -161,7 +160,7 @@ public LBMockData getMockData(String dataId) throws LyrebirdClientException { * @param bandWidth * @throws LyrebirdClientException */ - public void setSpeedLimit(BandWidth bandWidth) throws LyrebirdClientException { + public void setSpeedLimit(String bandWidth) throws LyrebirdClientException { client.setSpeedLimit(bandWidth); } diff --git a/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java b/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java index d8788f5..f99c532 100644 --- a/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java +++ b/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java @@ -1,6 +1,5 @@ package com.meituan.lyrebird.client; -import com.meituan.lyrebird.client.api.bandwidth.BandWidth; import com.meituan.lyrebird.client.api.bandwidth.BandWidthTemplate; import com.meituan.lyrebird.client.api.bandwidth.SpeedLimit; import com.meituan.lyrebird.client.exceptions.LyrebirdClientException; @@ -206,7 +205,7 @@ public LBMockData getMockData(String dataId) throws LyrebirdClientException { * @param bandWidth an enum of BandWidth * @throws LyrebirdClientException */ - public void setSpeedLimit(BandWidth bandWidth) throws LyrebirdClientException { + public void setSpeedLimit(String bandWidth) throws LyrebirdClientException { BandWidthTemplate template = new BandWidthTemplate(bandWidth); BaseResponse resp; try{ diff --git a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java deleted file mode 100644 index 711f242..0000000 --- a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.meituan.lyrebird.client.api.bandwidth; - -/** - * MINIMUM: 2G - * LOW: 2.5G - * MEDIUM: 3G - * UNLIMITED: UNLIMITED - */ -public enum BandWidth { - MINIMUM, LOW, MEDIUM, UNLIMITED -} diff --git a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java index 51186ae..df39f67 100644 --- a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java +++ b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java @@ -3,21 +3,8 @@ public class BandWidthTemplate { private String templateName; - public BandWidthTemplate(BandWidth bandWidth) { - switch (bandWidth) { - case MINIMUM: - templateName = "2G"; - break; - case LOW: - templateName = "2.5G"; - break; - case MEDIUM: - templateName = "3G"; - break; - default: - templateName = "UNLIMITED"; - break; - } + public BandWidthTemplate(String bandWidth) { + templateName = bandWidth; } public String getTemplateName() { diff --git a/src/test/java/com/meituan/lyrebird/test/TestFunctional.java b/src/test/java/com/meituan/lyrebird/test/TestFunctional.java index d22954a..cd7a94b 100644 --- a/src/test/java/com/meituan/lyrebird/test/TestFunctional.java +++ b/src/test/java/com/meituan/lyrebird/test/TestFunctional.java @@ -4,7 +4,6 @@ import com.jayway.jsonpath.JsonPath; import com.meituan.lyrebird.Lyrebird; import com.meituan.lyrebird.client.api.*; -import com.meituan.lyrebird.client.api.bandwidth.BandWidth; import com.meituan.lyrebird.client.exceptions.LyrebirdClientException; import java.util.List; import okhttp3.mockwebserver.*; @@ -187,11 +186,11 @@ public void testLBMockData() throws LyrebirdClientException { } @Test - public void testMinimumSpeedLimit() throws LyrebirdClientException, InterruptedException { + public void test2GSpeedLimit() throws LyrebirdClientException, InterruptedException { this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 10}" )); - lyrebird.setSpeedLimit(BandWidth.MINIMUM); + lyrebird.setSpeedLimit("2G"); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"2G\"}", request.getBody().readUtf8()); @@ -203,11 +202,11 @@ public void testMinimumSpeedLimit() throws LyrebirdClientException, InterruptedE } @Test - public void testLowSpeedLimit() throws LyrebirdClientException, InterruptedException { + public void test2Point5GSpeedLimit() throws LyrebirdClientException, InterruptedException { this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 35}" )); - lyrebird.setSpeedLimit(BandWidth.LOW); + lyrebird.setSpeedLimit("2.5G"); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"2.5G\"}", request.getBody().readUtf8()); @@ -219,11 +218,11 @@ public void testLowSpeedLimit() throws LyrebirdClientException, InterruptedExcep } @Test - public void testMediumSpeedLimit() throws LyrebirdClientException, InterruptedException { + public void test3GSpeedLimit() throws LyrebirdClientException, InterruptedException { this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 120}" )); - lyrebird.setSpeedLimit(BandWidth.MEDIUM); + lyrebird.setSpeedLimit("3G"); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"3G\"}", request.getBody().readUtf8()); @@ -239,7 +238,7 @@ public void testUnlimitedSpeedLimit() throws LyrebirdClientException, Interrupte this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": -1}" )); - lyrebird.setSpeedLimit(BandWidth.UNLIMITED); + lyrebird.setSpeedLimit("UNLIMITED"); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"UNLIMITED\"}", request.getBody().readUtf8()); From cf8a736cbd0050e33073e3e8e70c52f9fa7c827a Mon Sep 17 00:00:00 2001 From: reeyur Date: Thu, 19 Mar 2020 10:17:34 +0800 Subject: [PATCH 5/9] =?UTF-8?q?Revert=20"=E5=8E=BB=E6=8E=89=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 8ba844b8af9f5e5bb26010e2c3359313aaf31c03. --- README.md | 8 +++----- .../java/com/meituan/lyrebird/Lyrebird.java | 3 ++- .../meituan/lyrebird/client/LyrebirdClient.java | 3 ++- .../client/api/bandwidth/BandWidth.java | 11 +++++++++++ .../client/api/bandwidth/BandWidthTemplate.java | 17 +++++++++++++++-- .../meituan/lyrebird/test/TestFunctional.java | 15 ++++++++------- 6 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java diff --git a/README.md b/README.md index 26ab331..9eac9dd 100644 --- a/README.md +++ b/README.md @@ -416,13 +416,11 @@ socket.disconnect(); ```java // 设置带宽限速为2G -lyrebird.setSpeedLimit("2G"); +lyrebird.setSpeedLimit(BandWidth.MINIMUM); // 设置带宽限速为2.5G -lyrebird.setSpeedLimit("2.5G"); +lyrebird.setSpeedLimit(BandWidth.LOW); // 设置带宽限速为3G -lyrebird.setSpeedLimit("3G"); -// 关闭限速 -lyrebird.setSpeedLimit("UNLIMITED"); +lyrebird.setSpeedLimit(BandWidth.MEDIUM); // 获取带宽速度 int bandwidth = lyrebird.getSpeedLimit().getBandwidth(); ``` diff --git a/src/main/java/com/meituan/lyrebird/Lyrebird.java b/src/main/java/com/meituan/lyrebird/Lyrebird.java index a07a37e..a4a3193 100644 --- a/src/main/java/com/meituan/lyrebird/Lyrebird.java +++ b/src/main/java/com/meituan/lyrebird/Lyrebird.java @@ -1,5 +1,6 @@ package com.meituan.lyrebird; +import com.meituan.lyrebird.client.api.bandwidth.BandWidth; import com.meituan.lyrebird.client.api.bandwidth.SpeedLimit; import io.socket.client.Socket; import java.lang.reflect.Method; @@ -160,7 +161,7 @@ public LBMockData getMockData(String dataId) throws LyrebirdClientException { * @param bandWidth * @throws LyrebirdClientException */ - public void setSpeedLimit(String bandWidth) throws LyrebirdClientException { + public void setSpeedLimit(BandWidth bandWidth) throws LyrebirdClientException { client.setSpeedLimit(bandWidth); } diff --git a/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java b/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java index f99c532..d8788f5 100644 --- a/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java +++ b/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java @@ -1,5 +1,6 @@ package com.meituan.lyrebird.client; +import com.meituan.lyrebird.client.api.bandwidth.BandWidth; import com.meituan.lyrebird.client.api.bandwidth.BandWidthTemplate; import com.meituan.lyrebird.client.api.bandwidth.SpeedLimit; import com.meituan.lyrebird.client.exceptions.LyrebirdClientException; @@ -205,7 +206,7 @@ public LBMockData getMockData(String dataId) throws LyrebirdClientException { * @param bandWidth an enum of BandWidth * @throws LyrebirdClientException */ - public void setSpeedLimit(String bandWidth) throws LyrebirdClientException { + public void setSpeedLimit(BandWidth bandWidth) throws LyrebirdClientException { BandWidthTemplate template = new BandWidthTemplate(bandWidth); BaseResponse resp; try{ diff --git a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java new file mode 100644 index 0000000..711f242 --- /dev/null +++ b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java @@ -0,0 +1,11 @@ +package com.meituan.lyrebird.client.api.bandwidth; + +/** + * MINIMUM: 2G + * LOW: 2.5G + * MEDIUM: 3G + * UNLIMITED: UNLIMITED + */ +public enum BandWidth { + MINIMUM, LOW, MEDIUM, UNLIMITED +} diff --git a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java index df39f67..51186ae 100644 --- a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java +++ b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java @@ -3,8 +3,21 @@ public class BandWidthTemplate { private String templateName; - public BandWidthTemplate(String bandWidth) { - templateName = bandWidth; + public BandWidthTemplate(BandWidth bandWidth) { + switch (bandWidth) { + case MINIMUM: + templateName = "2G"; + break; + case LOW: + templateName = "2.5G"; + break; + case MEDIUM: + templateName = "3G"; + break; + default: + templateName = "UNLIMITED"; + break; + } } public String getTemplateName() { diff --git a/src/test/java/com/meituan/lyrebird/test/TestFunctional.java b/src/test/java/com/meituan/lyrebird/test/TestFunctional.java index cd7a94b..d22954a 100644 --- a/src/test/java/com/meituan/lyrebird/test/TestFunctional.java +++ b/src/test/java/com/meituan/lyrebird/test/TestFunctional.java @@ -4,6 +4,7 @@ import com.jayway.jsonpath.JsonPath; import com.meituan.lyrebird.Lyrebird; import com.meituan.lyrebird.client.api.*; +import com.meituan.lyrebird.client.api.bandwidth.BandWidth; import com.meituan.lyrebird.client.exceptions.LyrebirdClientException; import java.util.List; import okhttp3.mockwebserver.*; @@ -186,11 +187,11 @@ public void testLBMockData() throws LyrebirdClientException { } @Test - public void test2GSpeedLimit() throws LyrebirdClientException, InterruptedException { + public void testMinimumSpeedLimit() throws LyrebirdClientException, InterruptedException { this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 10}" )); - lyrebird.setSpeedLimit("2G"); + lyrebird.setSpeedLimit(BandWidth.MINIMUM); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"2G\"}", request.getBody().readUtf8()); @@ -202,11 +203,11 @@ public void test2GSpeedLimit() throws LyrebirdClientException, InterruptedExcept } @Test - public void test2Point5GSpeedLimit() throws LyrebirdClientException, InterruptedException { + public void testLowSpeedLimit() throws LyrebirdClientException, InterruptedException { this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 35}" )); - lyrebird.setSpeedLimit("2.5G"); + lyrebird.setSpeedLimit(BandWidth.LOW); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"2.5G\"}", request.getBody().readUtf8()); @@ -218,11 +219,11 @@ public void test2Point5GSpeedLimit() throws LyrebirdClientException, Interrupted } @Test - public void test3GSpeedLimit() throws LyrebirdClientException, InterruptedException { + public void testMediumSpeedLimit() throws LyrebirdClientException, InterruptedException { this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 120}" )); - lyrebird.setSpeedLimit("3G"); + lyrebird.setSpeedLimit(BandWidth.MEDIUM); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"3G\"}", request.getBody().readUtf8()); @@ -238,7 +239,7 @@ public void testUnlimitedSpeedLimit() throws LyrebirdClientException, Interrupte this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": -1}" )); - lyrebird.setSpeedLimit("UNLIMITED"); + lyrebird.setSpeedLimit(BandWidth.UNLIMITED); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"UNLIMITED\"}", request.getBody().readUtf8()); From ec04d5ea80b508eb7bac8e69546da538471b6905 Mon Sep 17 00:00:00 2001 From: reeyur Date: Thu, 19 Mar 2020 10:22:36 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E6=9E=9A=E4=B8=BE=E5=90=8D=E5=AD=97?= =?UTF-8?q?=E6=94=B9=E6=88=90BAND=5FWIDTH=5F2G,BAND=5FWIDTH=5F2=5F5G,BAND?= =?UTF-8?q?=5FWIDTH=5F3G?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +++++--- src/main/java/com/meituan/lyrebird/Lyrebird.java | 2 +- .../lyrebird/client/api/bandwidth/BandWidth.java | 7 ++----- .../client/api/bandwidth/BandWidthTemplate.java | 6 +++--- .../com/meituan/lyrebird/test/TestFunctional.java | 12 ++++++------ 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 9eac9dd..01281db 100644 --- a/README.md +++ b/README.md @@ -416,11 +416,13 @@ socket.disconnect(); ```java // 设置带宽限速为2G -lyrebird.setSpeedLimit(BandWidth.MINIMUM); +lyrebird.setSpeedLimit(BandWidth.BAND_WIDTH_2G); // 设置带宽限速为2.5G -lyrebird.setSpeedLimit(BandWidth.LOW); +lyrebird.setSpeedLimit(BandWidth.BAND_WIDTH_2_5G); // 设置带宽限速为3G -lyrebird.setSpeedLimit(BandWidth.MEDIUM); +lyrebird.setSpeedLimit(BandWidth.BAND_WIDTH_3G); +// 设置带宽不限速 +lyrebird.setSpeedLimit(BandWidth.UNLIMITED); // 获取带宽速度 int bandwidth = lyrebird.getSpeedLimit().getBandwidth(); ``` diff --git a/src/main/java/com/meituan/lyrebird/Lyrebird.java b/src/main/java/com/meituan/lyrebird/Lyrebird.java index a4a3193..9478a4b 100644 --- a/src/main/java/com/meituan/lyrebird/Lyrebird.java +++ b/src/main/java/com/meituan/lyrebird/Lyrebird.java @@ -158,7 +158,7 @@ public LBMockData getMockData(String dataId) throws LyrebirdClientException { /** * set the speed limit * - * @param bandWidth + * @param bandWidth BAND_WIDTH_2G对应2G;BAND_WIDTH_2_5G对应2.5G;BAND_WIDTH_3G对应3G;UNLIMITED对应无限制 * @throws LyrebirdClientException */ public void setSpeedLimit(BandWidth bandWidth) throws LyrebirdClientException { diff --git a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java index 711f242..d084823 100644 --- a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java +++ b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java @@ -1,11 +1,8 @@ package com.meituan.lyrebird.client.api.bandwidth; /** - * MINIMUM: 2G - * LOW: 2.5G - * MEDIUM: 3G - * UNLIMITED: UNLIMITED + * 网络带宽枚举 */ public enum BandWidth { - MINIMUM, LOW, MEDIUM, UNLIMITED + BAND_WIDTH_2G, BAND_WIDTH_2_5G, BAND_WIDTH_3G, UNLIMITED } diff --git a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java index 51186ae..30026a3 100644 --- a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java +++ b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java @@ -5,13 +5,13 @@ public class BandWidthTemplate { public BandWidthTemplate(BandWidth bandWidth) { switch (bandWidth) { - case MINIMUM: + case BAND_WIDTH_2G: templateName = "2G"; break; - case LOW: + case BAND_WIDTH_2_5G: templateName = "2.5G"; break; - case MEDIUM: + case BAND_WIDTH_3G: templateName = "3G"; break; default: diff --git a/src/test/java/com/meituan/lyrebird/test/TestFunctional.java b/src/test/java/com/meituan/lyrebird/test/TestFunctional.java index d22954a..18c2365 100644 --- a/src/test/java/com/meituan/lyrebird/test/TestFunctional.java +++ b/src/test/java/com/meituan/lyrebird/test/TestFunctional.java @@ -187,11 +187,11 @@ public void testLBMockData() throws LyrebirdClientException { } @Test - public void testMinimumSpeedLimit() throws LyrebirdClientException, InterruptedException { + public void test2GSpeedLimit() throws LyrebirdClientException, InterruptedException { this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 10}" )); - lyrebird.setSpeedLimit(BandWidth.MINIMUM); + lyrebird.setSpeedLimit(BandWidth.BAND_WIDTH_2G); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"2G\"}", request.getBody().readUtf8()); @@ -203,11 +203,11 @@ public void testMinimumSpeedLimit() throws LyrebirdClientException, InterruptedE } @Test - public void testLowSpeedLimit() throws LyrebirdClientException, InterruptedException { + public void test2_5GSpeedLimit() throws LyrebirdClientException, InterruptedException { this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 35}" )); - lyrebird.setSpeedLimit(BandWidth.LOW); + lyrebird.setSpeedLimit(BandWidth.BAND_WIDTH_2_5G); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"2.5G\"}", request.getBody().readUtf8()); @@ -219,11 +219,11 @@ public void testLowSpeedLimit() throws LyrebirdClientException, InterruptedExcep } @Test - public void testMediumSpeedLimit() throws LyrebirdClientException, InterruptedException { + public void test3GSpeedLimit() throws LyrebirdClientException, InterruptedException { this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 120}" )); - lyrebird.setSpeedLimit(BandWidth.MEDIUM); + lyrebird.setSpeedLimit(BandWidth.BAND_WIDTH_3G); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"3G\"}", request.getBody().readUtf8()); From 40b562a974ef78b176637ec56ec4ecb5fafe8605 Mon Sep 17 00:00:00 2001 From: reeyur Date: Thu, 19 Mar 2020 10:29:31 +0800 Subject: [PATCH 7/9] Fix The JUnit 4 test method name 'test2_5GSpeedLimit doesn't match '[a-z][a-zA-Z0-9]*' --- src/test/java/com/meituan/lyrebird/test/TestFunctional.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/meituan/lyrebird/test/TestFunctional.java b/src/test/java/com/meituan/lyrebird/test/TestFunctional.java index 18c2365..ac63da1 100644 --- a/src/test/java/com/meituan/lyrebird/test/TestFunctional.java +++ b/src/test/java/com/meituan/lyrebird/test/TestFunctional.java @@ -203,7 +203,7 @@ public void test2GSpeedLimit() throws LyrebirdClientException, InterruptedExcept } @Test - public void test2_5GSpeedLimit() throws LyrebirdClientException, InterruptedException { + public void test25GSpeedLimit() throws LyrebirdClientException, InterruptedException { this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 35}" )); From d77755e02c58f809699ef548aea943672b6705c3 Mon Sep 17 00:00:00 2001 From: reeyur Date: Tue, 24 Mar 2020 09:35:34 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E6=8B=BC=E6=8E=A5=E4=B8=8D=E7=AC=A6=E5=90=88=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++---- src/main/java/com/meituan/lyrebird/Lyrebird.java | 8 ++++---- .../com/meituan/lyrebird/client/LyrebirdClient.java | 12 ++++++------ .../com/meituan/lyrebird/client/LyrebirdService.java | 4 ++-- .../api/bandwidth/{BandWidth.java => Bandwidth.java} | 4 ++-- ...BandWidthTemplate.java => BandwidthTemplate.java} | 12 ++++++------ .../com/meituan/lyrebird/test/TestFunctional.java | 10 +++++----- 7 files changed, 29 insertions(+), 29 deletions(-) rename src/main/java/com/meituan/lyrebird/client/api/bandwidth/{BandWidth.java => Bandwidth.java} (50%) rename src/main/java/com/meituan/lyrebird/client/api/bandwidth/{BandWidthTemplate.java => BandwidthTemplate.java} (70%) diff --git a/README.md b/README.md index 01281db..1467004 100644 --- a/README.md +++ b/README.md @@ -416,13 +416,13 @@ socket.disconnect(); ```java // 设置带宽限速为2G -lyrebird.setSpeedLimit(BandWidth.BAND_WIDTH_2G); +lyrebird.setSpeedLimit(Bandwidth.BAND_WIDTH_2G); // 设置带宽限速为2.5G -lyrebird.setSpeedLimit(BandWidth.BAND_WIDTH_2_5G); +lyrebird.setSpeedLimit(Bandwidth.BAND_WIDTH_2_5G); // 设置带宽限速为3G -lyrebird.setSpeedLimit(BandWidth.BAND_WIDTH_3G); +lyrebird.setSpeedLimit(Bandwidth.BAND_WIDTH_3G); // 设置带宽不限速 -lyrebird.setSpeedLimit(BandWidth.UNLIMITED); +lyrebird.setSpeedLimit(Bandwidth.UNLIMITED); // 获取带宽速度 int bandwidth = lyrebird.getSpeedLimit().getBandwidth(); ``` diff --git a/src/main/java/com/meituan/lyrebird/Lyrebird.java b/src/main/java/com/meituan/lyrebird/Lyrebird.java index 9478a4b..98adb07 100644 --- a/src/main/java/com/meituan/lyrebird/Lyrebird.java +++ b/src/main/java/com/meituan/lyrebird/Lyrebird.java @@ -1,6 +1,6 @@ package com.meituan.lyrebird; -import com.meituan.lyrebird.client.api.bandwidth.BandWidth; +import com.meituan.lyrebird.client.api.bandwidth.Bandwidth; import com.meituan.lyrebird.client.api.bandwidth.SpeedLimit; import io.socket.client.Socket; import java.lang.reflect.Method; @@ -158,11 +158,11 @@ public LBMockData getMockData(String dataId) throws LyrebirdClientException { /** * set the speed limit * - * @param bandWidth BAND_WIDTH_2G对应2G;BAND_WIDTH_2_5G对应2.5G;BAND_WIDTH_3G对应3G;UNLIMITED对应无限制 + * @param bandwidth BANDWIDTH_2G对应2G;BANDWIDTH_2_5G对应2.5G;BANDWIDTH_3G对应3G;UNLIMITED对应无限制 * @throws LyrebirdClientException */ - public void setSpeedLimit(BandWidth bandWidth) throws LyrebirdClientException { - client.setSpeedLimit(bandWidth); + public void setSpeedLimit(Bandwidth bandwidth) throws LyrebirdClientException { + client.setSpeedLimit(bandwidth); } /** diff --git a/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java b/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java index d8788f5..a1adf2e 100644 --- a/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java +++ b/src/main/java/com/meituan/lyrebird/client/LyrebirdClient.java @@ -1,7 +1,7 @@ package com.meituan.lyrebird.client; -import com.meituan.lyrebird.client.api.bandwidth.BandWidth; -import com.meituan.lyrebird.client.api.bandwidth.BandWidthTemplate; +import com.meituan.lyrebird.client.api.bandwidth.Bandwidth; +import com.meituan.lyrebird.client.api.bandwidth.BandwidthTemplate; import com.meituan.lyrebird.client.api.bandwidth.SpeedLimit; import com.meituan.lyrebird.client.exceptions.LyrebirdClientException; import com.meituan.lyrebird.client.api.*; @@ -203,14 +203,14 @@ public LBMockData getMockData(String dataId) throws LyrebirdClientException { /** * set the speed limit * - * @param bandWidth an enum of BandWidth + * @param bandwidth an enum of Bandwidth * @throws LyrebirdClientException */ - public void setSpeedLimit(BandWidth bandWidth) throws LyrebirdClientException { - BandWidthTemplate template = new BandWidthTemplate(bandWidth); + public void setSpeedLimit(Bandwidth bandwidth) throws LyrebirdClientException { + BandwidthTemplate bandwidthTemplate = new BandwidthTemplate(bandwidth); BaseResponse resp; try{ - resp = lyrebirdService.setSpeedLimit(template).execute().body(); + resp = lyrebirdService.setSpeedLimit(bandwidthTemplate).execute().body(); } catch (IOException e) { throw new LyrebirdClientException("Catch exception while set the speed limit", e); } diff --git a/src/main/java/com/meituan/lyrebird/client/LyrebirdService.java b/src/main/java/com/meituan/lyrebird/client/LyrebirdService.java index 3fddf7e..68f3d7d 100644 --- a/src/main/java/com/meituan/lyrebird/client/LyrebirdService.java +++ b/src/main/java/com/meituan/lyrebird/client/LyrebirdService.java @@ -2,7 +2,7 @@ import com.meituan.lyrebird.client.api.*; -import com.meituan.lyrebird.client.api.bandwidth.BandWidthTemplate; +import com.meituan.lyrebird.client.api.bandwidth.BandwidthTemplate; import com.meituan.lyrebird.client.api.bandwidth.SpeedLimit; import retrofit2.Call; import retrofit2.http.*; @@ -35,7 +35,7 @@ public interface LyrebirdService { @Headers("Content-Type: application/json") @PUT("api/bandwidth") - Call setSpeedLimit(@Body BandWidthTemplate template); + Call setSpeedLimit(@Body BandwidthTemplate template); @GET("api/bandwidth") Call getSpeedLimit(); diff --git a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/Bandwidth.java similarity index 50% rename from src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java rename to src/main/java/com/meituan/lyrebird/client/api/bandwidth/Bandwidth.java index d084823..11d918b 100644 --- a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidth.java +++ b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/Bandwidth.java @@ -3,6 +3,6 @@ /** * 网络带宽枚举 */ -public enum BandWidth { - BAND_WIDTH_2G, BAND_WIDTH_2_5G, BAND_WIDTH_3G, UNLIMITED +public enum Bandwidth { + BANDWIDTH_2G, BANDWIDTH_2_5G, BANDWIDTH_3G, UNLIMITED } diff --git a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandwidthTemplate.java similarity index 70% rename from src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java rename to src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandwidthTemplate.java index 30026a3..212a83a 100644 --- a/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandWidthTemplate.java +++ b/src/main/java/com/meituan/lyrebird/client/api/bandwidth/BandwidthTemplate.java @@ -1,17 +1,17 @@ package com.meituan.lyrebird.client.api.bandwidth; -public class BandWidthTemplate { +public class BandwidthTemplate { private String templateName; - public BandWidthTemplate(BandWidth bandWidth) { - switch (bandWidth) { - case BAND_WIDTH_2G: + public BandwidthTemplate(Bandwidth bandwidth) { + switch (bandwidth) { + case BANDWIDTH_2G: templateName = "2G"; break; - case BAND_WIDTH_2_5G: + case BANDWIDTH_2_5G: templateName = "2.5G"; break; - case BAND_WIDTH_3G: + case BANDWIDTH_3G: templateName = "3G"; break; default: diff --git a/src/test/java/com/meituan/lyrebird/test/TestFunctional.java b/src/test/java/com/meituan/lyrebird/test/TestFunctional.java index ac63da1..beb6078 100644 --- a/src/test/java/com/meituan/lyrebird/test/TestFunctional.java +++ b/src/test/java/com/meituan/lyrebird/test/TestFunctional.java @@ -4,7 +4,7 @@ import com.jayway.jsonpath.JsonPath; import com.meituan.lyrebird.Lyrebird; import com.meituan.lyrebird.client.api.*; -import com.meituan.lyrebird.client.api.bandwidth.BandWidth; +import com.meituan.lyrebird.client.api.bandwidth.Bandwidth; import com.meituan.lyrebird.client.exceptions.LyrebirdClientException; import java.util.List; import okhttp3.mockwebserver.*; @@ -191,7 +191,7 @@ public void test2GSpeedLimit() throws LyrebirdClientException, InterruptedExcept this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 10}" )); - lyrebird.setSpeedLimit(BandWidth.BAND_WIDTH_2G); + lyrebird.setSpeedLimit(Bandwidth.BANDWIDTH_2G); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"2G\"}", request.getBody().readUtf8()); @@ -207,7 +207,7 @@ public void test25GSpeedLimit() throws LyrebirdClientException, InterruptedExcep this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 35}" )); - lyrebird.setSpeedLimit(BandWidth.BAND_WIDTH_2_5G); + lyrebird.setSpeedLimit(Bandwidth.BANDWIDTH_2_5G); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"2.5G\"}", request.getBody().readUtf8()); @@ -223,7 +223,7 @@ public void test3GSpeedLimit() throws LyrebirdClientException, InterruptedExcept this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": 120}" )); - lyrebird.setSpeedLimit(BandWidth.BAND_WIDTH_3G); + lyrebird.setSpeedLimit(Bandwidth.BANDWIDTH_3G); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"3G\"}", request.getBody().readUtf8()); @@ -239,7 +239,7 @@ public void testUnlimitedSpeedLimit() throws LyrebirdClientException, Interrupte this.mockServer.enqueue(new MockResponse() .setBody("{\"code\": 1000, \"message\": \"success\", \"bandwidth\": -1}" )); - lyrebird.setSpeedLimit(BandWidth.UNLIMITED); + lyrebird.setSpeedLimit(Bandwidth.UNLIMITED); RecordedRequest request = this.mockServer.takeRequest(); assertEquals("{\"templateName\":\"UNLIMITED\"}", request.getBody().readUtf8()); From 00f8c787517a38f5e90e95b7387a08b410d2b2bf Mon Sep 17 00:00:00 2001 From: reeyur Date: Tue, 24 Mar 2020 09:49:20 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E6=8B=BC=E6=8E=A5=E4=B8=8D=E7=AC=A6=E5=90=88=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1467004..003d351 100644 --- a/README.md +++ b/README.md @@ -416,11 +416,11 @@ socket.disconnect(); ```java // 设置带宽限速为2G -lyrebird.setSpeedLimit(Bandwidth.BAND_WIDTH_2G); +lyrebird.setSpeedLimit(Bandwidth.BANDWIDTH_2G); // 设置带宽限速为2.5G -lyrebird.setSpeedLimit(Bandwidth.BAND_WIDTH_2_5G); +lyrebird.setSpeedLimit(Bandwidth.BANDWIDTH_2_5G); // 设置带宽限速为3G -lyrebird.setSpeedLimit(Bandwidth.BAND_WIDTH_3G); +lyrebird.setSpeedLimit(Bandwidth.BANDWIDTH_3G); // 设置带宽不限速 lyrebird.setSpeedLimit(Bandwidth.UNLIMITED); // 获取带宽速度