You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by st...@apache.org on 2017/01/20 09:45:05 UTC
[08/14] incubator-rocketmq git commit: [ROCKETMQ-52] Add unit tests
for LatencyFaultTolerance
[ROCKETMQ-52] Add unit tests for LatencyFaultTolerance
Project: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/commit/0f9f55f0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/tree/0f9f55f0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/diff/0f9f55f0
Branch: refs/heads/master
Commit: 0f9f55f0f39107b304ee26c603307e9bc5bf2c99
Parents: 4dd6c38
Author: yukon <yu...@apache.org>
Authored: Tue Jan 17 22:03:07 2017 +0800
Committer: yukon <yu...@apache.org>
Committed: Tue Jan 17 22:03:07 2017 +0800
----------------------------------------------------------------------
.../latency/LatencyFaultToleranceImplTest.java | 67 ++++++++++++++++++++
1 file changed, 67 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/0f9f55f0/client/src/test/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImplTest.java
----------------------------------------------------------------------
diff --git a/client/src/test/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImplTest.java b/client/src/test/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImplTest.java
new file mode 100644
index 0000000..86690e4
--- /dev/null
+++ b/client/src/test/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImplTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.rocketmq.client.latency;
+
+import java.util.concurrent.TimeUnit;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class LatencyFaultToleranceImplTest {
+ private LatencyFaultTolerance<String> latencyFaultTolerance;
+ private String brokerName = "BrokerA";
+ private String anotherBrokerName = "BrokerB";
+
+ @Before
+ public void init() {
+ latencyFaultTolerance = new LatencyFaultToleranceImpl();
+ }
+
+ @Test
+ public void testUpdateFaultItem() throws Exception {
+ latencyFaultTolerance.updateFaultItem(brokerName, 3000, 3000);
+ assertThat(latencyFaultTolerance.isAvailable(brokerName)).isFalse();
+ assertThat(latencyFaultTolerance.isAvailable(anotherBrokerName)).isTrue();
+ }
+
+ @Test
+ public void testIsAvailable() throws Exception {
+ latencyFaultTolerance.updateFaultItem(brokerName, 3000, 50);
+ assertThat(latencyFaultTolerance.isAvailable(brokerName)).isFalse();
+
+ TimeUnit.MILLISECONDS.sleep(70);
+ assertThat(latencyFaultTolerance.isAvailable(brokerName)).isTrue();
+ }
+
+ @Test
+ public void testRemove() throws Exception {
+ latencyFaultTolerance.updateFaultItem(brokerName, 3000, 3000);
+ assertThat(latencyFaultTolerance.isAvailable(brokerName)).isFalse();
+ latencyFaultTolerance.remove(brokerName);
+ assertThat(latencyFaultTolerance.isAvailable(brokerName)).isTrue();
+ }
+
+ @Test
+ public void testPickOneAtLeast() throws Exception {
+ latencyFaultTolerance.updateFaultItem(brokerName, 1000, 3000);
+ assertThat(latencyFaultTolerance.pickOneAtLeast()).isEqualTo(brokerName);
+
+ latencyFaultTolerance.updateFaultItem(anotherBrokerName, 1001, 3000);
+ assertThat(latencyFaultTolerance.pickOneAtLeast()).isEqualTo(brokerName);
+ }
+}
\ No newline at end of file