You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by te...@apache.org on 2020/10/18 02:27:17 UTC
[shardingsphere-elasticjob] branch master updated: Add test case
for ElasticJobListenerFactory (#1564). (#1565)
This is an automated email from the ASF dual-hosted git repository.
technoboy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git
The following commit(s) were added to refs/heads/master by this push:
new 967acea Add test case for ElasticJobListenerFactory (#1564). (#1565)
967acea is described below
commit 967acea395befc45c4c5f03c277dca9265e1a102
Author: wwj <22...@qq.com>
AuthorDate: Sun Oct 18 10:27:06 2020 +0800
Add test case for ElasticJobListenerFactory (#1564). (#1565)
---
docs/content/features/failover.cn.md | 2 +-
.../listener/ElasticJobListenerFactoryTest.java | 38 ++++++++++++++++++++++
.../listener/fixture/FooElasticJobListener.java | 37 +++++++++++++++++++++
...re.elasticjob.infra.listener.ElasticJobListener | 35 ++++++++++++++++++++
4 files changed, 111 insertions(+), 1 deletion(-)
diff --git a/docs/content/features/failover.cn.md b/docs/content/features/failover.cn.md
index 12b7d77..297ed6d 100644
--- a/docs/content/features/failover.cn.md
+++ b/docs/content/features/failover.cn.md
@@ -12,7 +12,7 @@ ElasticJob 不会在本次执行过程中进行重新分片,而是等待下次
## 概念
-失效转移是当前执行作业的临时补偿执行机制,再下次作业运行时,会通过重分片对当前作业分配进行调整。
+失效转移是当前执行作业的临时补偿执行机制,在下次作业运行时,会通过重分片对当前作业分配进行调整。
举例说明,若作业以每小时为间隔执行,每次执行耗时 30 分钟。如下如图所示。
![定时作业](https://shardingsphere.apache.org/elasticjob/current/img/failover/job.png)
diff --git a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/listener/ElasticJobListenerFactoryTest.java b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/listener/ElasticJobListenerFactoryTest.java
new file mode 100644
index 0000000..e25ebb9
--- /dev/null
+++ b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/listener/ElasticJobListenerFactoryTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.shardingsphere.elasticjob.infra.listener;
+
+import org.apache.shardingsphere.elasticjob.infra.exception.JobConfigurationException;
+import org.apache.shardingsphere.elasticjob.infra.listener.fixture.FooElasticJobListener;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+
+public final class ElasticJobListenerFactoryTest {
+
+ @Test(expected = JobConfigurationException.class)
+ public void assertCreateInvalidJobListener() {
+ ElasticJobListenerFactory.createListener("INVALID").orElseThrow(() -> new JobConfigurationException("Invalid elastic job listener!"));
+ }
+
+ @Test
+ public void assertCreatJobListener() {
+ assertThat(ElasticJobListenerFactory.createListener("fooElasticJobListener").orElse(null), instanceOf(FooElasticJobListener.class));
+ }
+}
diff --git a/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/listener/fixture/FooElasticJobListener.java b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/listener/fixture/FooElasticJobListener.java
new file mode 100644
index 0000000..d09c6aa
--- /dev/null
+++ b/elasticjob-infra/elasticjob-infra-common/src/test/java/org/apache/shardingsphere/elasticjob/infra/listener/fixture/FooElasticJobListener.java
@@ -0,0 +1,37 @@
+/*
+ * 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.shardingsphere.elasticjob.infra.listener.fixture;
+
+import org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener;
+import org.apache.shardingsphere.elasticjob.infra.listener.ShardingContexts;
+
+public final class FooElasticJobListener implements ElasticJobListener {
+
+ @Override
+ public void beforeJobExecuted(final ShardingContexts shardingContexts) {
+ }
+
+ @Override
+ public void afterJobExecuted(final ShardingContexts shardingContexts) {
+ }
+
+ @Override
+ public String getType() {
+ return "fooElasticJobListener";
+ }
+}
diff --git a/elasticjob-infra/elasticjob-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener b/elasticjob-infra/elasticjob-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener
new file mode 100644
index 0000000..7da098d
--- /dev/null
+++ b/elasticjob-infra/elasticjob-infra-common/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener
@@ -0,0 +1,35 @@
+#
+# 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.
+#
+
+#
+# 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.
+#
+
+org.apache.shardingsphere.elasticjob.infra.listener.fixture.FooElasticJobListener