You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/06/24 11:30:05 UTC
[shardingsphere-elasticjob-lite] branch master updated: Remove
default tracing listener (#832)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob-lite.git
The following commit(s) were added to refs/heads/master by this push:
new 7d29c31 Remove default tracing listener (#832)
7d29c31 is described below
commit 7d29c31c36efeee3633e19a1f1e2134977136d2d
Author: Liang Zhang <te...@163.com>
AuthorDate: Wed Jun 24 19:29:55 2020 +0800
Remove default tracing listener (#832)
* refactor TracingListenerFactory
* Add test case for TracingListenerFactory
---
.../tracing/listener/TracingListenerFactory.java | 7 +---
.../listener/TracingListenerFactoryTest.java | 44 ++++++++++++++++++++++
2 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/elastic-job-lite-tracing/elastic-job-lite-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/lite/tracing/listener/TracingListenerFactory.java b/elastic-job-lite-tracing/elastic-job-lite-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/lite/tracing/listener/TracingListenerFactory.java
index a99375e..38a73b3 100644
--- a/elastic-job-lite-tracing/elastic-job-lite-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/lite/tracing/listener/TracingListenerFactory.java
+++ b/elastic-job-lite-tracing/elastic-job-lite-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/lite/tracing/listener/TracingListenerFactory.java
@@ -35,8 +35,6 @@ public final class TracingListenerFactory {
private static final Map<String, TracingListenerConfiguration> LISTENER_CONFIGS = new HashMap<>();
- private static final String DEFAULT_LISTENER = "NONE";
-
static {
for (TracingListenerConfiguration each : ServiceLoader.load(TracingListenerConfiguration.class)) {
LISTENER_CONFIGS.put(each.getType(), each);
@@ -52,10 +50,7 @@ public final class TracingListenerFactory {
*/
@SuppressWarnings("unchecked")
public static TracingListener getListener(final TracingConfiguration tracingConfig) throws TracingConfigurationException {
- if (Strings.isNullOrEmpty(tracingConfig.getType())) {
- return LISTENER_CONFIGS.get(DEFAULT_LISTENER).createTracingListener(tracingConfig.getStorage());
- }
- if (!LISTENER_CONFIGS.containsKey(tracingConfig.getType())) {
+ if (Strings.isNullOrEmpty(tracingConfig.getType()) || !LISTENER_CONFIGS.containsKey(tracingConfig.getType())) {
throw new TracingConfigurationException(String.format("Can not find executor service handler type '%s'.", tracingConfig.getType()));
}
return LISTENER_CONFIGS.get(tracingConfig.getType()).createTracingListener(tracingConfig.getStorage());
diff --git a/elastic-job-lite-tracing/elastic-job-lite-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/lite/tracing/listener/TracingListenerFactoryTest.java b/elastic-job-lite-tracing/elastic-job-lite-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/lite/tracing/listener/TracingListenerFactoryTest.java
new file mode 100644
index 0000000..8381739
--- /dev/null
+++ b/elastic-job-lite-tracing/elastic-job-lite-tracing-api/src/test/java/org/apache/shardingsphere/elasticjob/lite/tracing/listener/TracingListenerFactoryTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.lite.tracing.listener;
+
+import org.apache.shardingsphere.elasticjob.lite.tracing.api.TracingConfiguration;
+import org.apache.shardingsphere.elasticjob.lite.tracing.exception.TracingConfigurationException;
+import org.apache.shardingsphere.elasticjob.lite.tracing.fixture.TestTracingListener;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+
+public final class TracingListenerFactoryTest {
+
+ @Test(expected = TracingConfigurationException.class)
+ public void assertGetListenerWithNullType() throws TracingConfigurationException {
+ TracingListenerFactory.getListener(new TracingConfiguration<>("", null));
+ }
+
+ @Test(expected = TracingConfigurationException.class)
+ public void assertGetInvalidListener() throws TracingConfigurationException {
+ TracingListenerFactory.getListener(new TracingConfiguration<>("INVALID", null));
+ }
+
+ @Test
+ public void assertGetListener() throws TracingConfigurationException {
+ assertThat(TracingListenerFactory.getListener(new TracingConfiguration<>("TEST", null)), instanceOf(TestTracingListener.class));
+ }
+}