From 215be106697733b9b99b10b253eb583ae05e0eff Mon Sep 17 00:00:00 2001 From: zhangliang Date: Tue, 31 Oct 2023 21:35:57 +0800 Subject: [PATCH] Rename TracingListenerConfiguration to TracingListenerFactory --- ...on.java => RDBTracingListenerFactory.java} | 8 ++--- ...l.tracing.listener.TracingListenerFactory} | 2 +- ...ava => RDBTracingListenerFactoryTest.java} | 6 ++-- .../tracing/event/JobTracingEventBus.java | 4 +-- ...ation.java => TracingListenerFactory.java} | 6 ++-- .../tracing/event/JobTracingEventBusTest.java | 8 ++--- .../TestTracingFailureConfiguration.java | 35 ------------------- ...tener.java => TracingListenerFixture.java} | 10 +++--- ...ava => TracingListenerFixtureFactory.java} | 8 ++--- ...l.tracing.listener.TracingListenerFactory} | 3 +- 10 files changed, 27 insertions(+), 63 deletions(-) rename ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/{RDBTracingListenerConfiguration.java => RDBTracingListenerFactory.java} (83%) rename ecosystem/tracing/rdb/src/main/resources/META-INF/services/{org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerConfiguration => org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerFactory} (97%) rename ecosystem/tracing/rdb/src/test/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/{RDBTracingListenerConfigurationTest.java => RDBTracingListenerFactoryTest.java} (89%) rename kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/tracing/listener/{TracingListenerConfiguration.java => TracingListenerFactory.java} (87%) delete mode 100644 kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TestTracingFailureConfiguration.java rename kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/{TestTracingListener.java => TracingListenerFixture.java} (87%) rename kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/{TestTracingListenerConfiguration.java => TracingListenerFixtureFactory.java} (81%) rename kernel/src/test/resources/META-INF/services/{org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerConfiguration => org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerFactory} (85%) diff --git a/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerConfiguration.java b/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerFactory.java similarity index 83% rename from ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerConfiguration.java rename to ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerFactory.java index 789bf1fb7a..41ab709416 100644 --- a/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerConfiguration.java +++ b/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerFactory.java @@ -19,18 +19,18 @@ import org.apache.shardingsphere.elasticjob.kernel.tracing.exception.TracingConfigurationException; import org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListener; -import org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerConfiguration; +import org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerFactory; import javax.sql.DataSource; import java.sql.SQLException; /** - * RDB tracing listener configuration. + * RDB tracing listener factory. */ -public final class RDBTracingListenerConfiguration implements TracingListenerConfiguration { +public final class RDBTracingListenerFactory implements TracingListenerFactory { @Override - public TracingListener createTracingListener(final DataSource storage) throws TracingConfigurationException { + public TracingListener create(final DataSource storage) throws TracingConfigurationException { try { return new RDBTracingListener(storage); } catch (final SQLException ex) { diff --git a/ecosystem/tracing/rdb/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerConfiguration b/ecosystem/tracing/rdb/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerFactory similarity index 97% rename from ecosystem/tracing/rdb/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerConfiguration rename to ecosystem/tracing/rdb/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerFactory index 567ef3f0a9..b4a29631c8 100644 --- a/ecosystem/tracing/rdb/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerConfiguration +++ b/ecosystem/tracing/rdb/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerFactory @@ -15,4 +15,4 @@ # limitations under the License. # -org.apache.shardingsphere.elasticjob.tracing.rdb.listener.RDBTracingListenerConfiguration +org.apache.shardingsphere.elasticjob.tracing.rdb.listener.RDBTracingListenerFactory diff --git a/ecosystem/tracing/rdb/src/test/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerConfigurationTest.java b/ecosystem/tracing/rdb/src/test/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerFactoryTest.java similarity index 89% rename from ecosystem/tracing/rdb/src/test/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerConfigurationTest.java rename to ecosystem/tracing/rdb/src/test/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerFactoryTest.java index 2b03d79775..31384fb2ad 100644 --- a/ecosystem/tracing/rdb/src/test/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerConfigurationTest.java +++ b/ecosystem/tracing/rdb/src/test/java/org/apache/shardingsphere/elasticjob/tracing/rdb/listener/RDBTracingListenerFactoryTest.java @@ -31,7 +31,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -class RDBTracingListenerConfigurationTest { +class RDBTracingListenerFactoryTest { @Test void assertCreateTracingListenerSuccess() throws TracingConfigurationException { @@ -40,13 +40,13 @@ void assertCreateTracingListenerSuccess() throws TracingConfigurationException { dataSource.setUrl("jdbc:h2:mem:job_event_storage"); dataSource.setUsername("sa"); dataSource.setPassword(""); - assertThat(new RDBTracingListenerConfiguration().createTracingListener(dataSource), instanceOf(RDBTracingListener.class)); + assertThat(new RDBTracingListenerFactory().create(dataSource), instanceOf(RDBTracingListener.class)); } @Test void assertCreateTracingListenerFailure() throws SQLException { DataSource dataSource = mock(DataSource.class); when(dataSource.getConnection()).thenThrow(new SQLException()); - assertThrows(TracingConfigurationException.class, () -> new RDBTracingListenerConfiguration().createTracingListener(dataSource)); + assertThrows(TracingConfigurationException.class, () -> new RDBTracingListenerFactory().create(dataSource)); } } diff --git a/kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/tracing/event/JobTracingEventBus.java b/kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/tracing/event/JobTracingEventBus.java index b0acf3b007..6dbd317899 100644 --- a/kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/tracing/event/JobTracingEventBus.java +++ b/kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/tracing/event/JobTracingEventBus.java @@ -24,7 +24,7 @@ import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.apache.shardingsphere.elasticjob.kernel.tracing.config.TracingConfiguration; import org.apache.shardingsphere.elasticjob.kernel.tracing.exception.TracingConfigurationException; -import org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerConfiguration; +import org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerFactory; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import java.util.concurrent.ExecutorService; @@ -71,7 +71,7 @@ private void register(final TracingConfiguration tracingConfig) { throw new TracingConfigurationException(String.format("Can not find executor service handler type '%s'.", tracingConfig.getType())); } eventBus.register( - TypedSPILoader.getService(TracingListenerConfiguration.class, tracingConfig.getType()).createTracingListener(tracingConfig.getTracingStorageConfiguration().getStorage())); + TypedSPILoader.getService(TracingListenerFactory.class, tracingConfig.getType()).create(tracingConfig.getTracingStorageConfiguration().getStorage())); isRegistered = true; } catch (final TracingConfigurationException ex) { log.error("Elastic job: create tracing listener failure, error is: ", ex); diff --git a/kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/tracing/listener/TracingListenerConfiguration.java b/kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/tracing/listener/TracingListenerFactory.java similarity index 87% rename from kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/tracing/listener/TracingListenerConfiguration.java rename to kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/tracing/listener/TracingListenerFactory.java index 29211ad7fc..44485502ef 100644 --- a/kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/tracing/listener/TracingListenerConfiguration.java +++ b/kernel/src/main/java/org/apache/shardingsphere/elasticjob/kernel/tracing/listener/TracingListenerFactory.java @@ -22,12 +22,12 @@ import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI; /** - * Tracing listener configuration. + * Tracing listener factory. * * @param type of tracing storage */ @SingletonSPI -public interface TracingListenerConfiguration extends TypedSPI { +public interface TracingListenerFactory extends TypedSPI { /** * Create tracing listener. @@ -36,7 +36,7 @@ public interface TracingListenerConfiguration extends TypedSPI { * @return tracing listener * @throws TracingConfigurationException tracing configuration exception */ - TracingListener createTracingListener(T storage) throws TracingConfigurationException; + TracingListener create(T storage) throws TracingConfigurationException; @Override String getType(); diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/event/JobTracingEventBusTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/event/JobTracingEventBusTest.java index 6534a1288c..3387d530ab 100644 --- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/event/JobTracingEventBusTest.java +++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/event/JobTracingEventBusTest.java @@ -20,7 +20,7 @@ import com.google.common.eventbus.EventBus; import org.apache.shardingsphere.elasticjob.kernel.tracing.config.TracingConfiguration; import org.apache.shardingsphere.elasticjob.kernel.tracing.fixture.config.TracingStorageFixture; -import org.apache.shardingsphere.elasticjob.kernel.tracing.fixture.listener.TestTracingListener; +import org.apache.shardingsphere.elasticjob.kernel.tracing.fixture.listener.TracingListenerFixture; import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils; import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; @@ -48,8 +48,8 @@ class JobTracingEventBusTest { private JobTracingEventBus jobTracingEventBus; @Test - void assertRegisterFailure() { - jobTracingEventBus = new JobTracingEventBus(new TracingConfiguration<>("FAIL", null)); + void assertRegisterWithoutTracingStorageConfiguration() { + jobTracingEventBus = new JobTracingEventBus(new TracingConfiguration<>("TEST", null)); assertFalse((Boolean) ReflectionUtils.getFieldValue(jobTracingEventBus, "isRegistered")); } @@ -58,7 +58,7 @@ void assertPost() { jobTracingEventBus = new JobTracingEventBus(new TracingConfiguration<>("TEST", tracingStorage)); assertTrue((Boolean) ReflectionUtils.getFieldValue(jobTracingEventBus, "isRegistered")); jobTracingEventBus.post(new JobExecutionEvent("localhost", "127.0.0.1", "fake_task_id", "test_event_bus_job", JobExecutionEvent.ExecutionSource.NORMAL_TRIGGER, 0)); - Awaitility.await().pollDelay(100L, TimeUnit.MILLISECONDS).until(TestTracingListener::isExecutionEventCalled); + Awaitility.await().pollDelay(100L, TimeUnit.MILLISECONDS).until(TracingListenerFixture::isExecutionEventCalled); verify(tracingStorage).call(); } diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TestTracingFailureConfiguration.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TestTracingFailureConfiguration.java deleted file mode 100644 index 7175f02d16..0000000000 --- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TestTracingFailureConfiguration.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.kernel.tracing.fixture.listener; - -import org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerConfiguration; -import org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListener; -import org.apache.shardingsphere.elasticjob.kernel.tracing.exception.TracingConfigurationException; - -public final class TestTracingFailureConfiguration implements TracingListenerConfiguration { - - @Override - public TracingListener createTracingListener(final Object storage) throws TracingConfigurationException { - throw new TracingConfigurationException(new RuntimeException("assert failure")); - } - - @Override - public String getType() { - return "FAIL"; - } -} diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TestTracingListener.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TracingListenerFixture.java similarity index 87% rename from kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TestTracingListener.java rename to kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TracingListenerFixture.java index 85d4375328..e92be453f0 100644 --- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TestTracingListener.java +++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TracingListenerFixture.java @@ -25,26 +25,26 @@ import org.apache.shardingsphere.elasticjob.kernel.tracing.event.JobStatusTraceEvent; @RequiredArgsConstructor -public final class TestTracingListener implements TracingListener { +public final class TracingListenerFixture implements TracingListener { @Getter private static volatile boolean executionEventCalled; - private final TracingStorageFixture tracingStorageFixture; + private final TracingStorageFixture tracingStorage; @Override public void listen(final JobExecutionEvent jobExecutionEvent) { - tracingStorageFixture.call(); + tracingStorage.call(); executionEventCalled = true; } @Override public void listen(final JobStatusTraceEvent jobStatusTraceEvent) { - tracingStorageFixture.call(); + tracingStorage.call(); } /** - * Set executionEventCalled to false. + * Reset. */ public static void reset() { executionEventCalled = false; diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TestTracingListenerConfiguration.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TracingListenerFixtureFactory.java similarity index 81% rename from kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TestTracingListenerConfiguration.java rename to kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TracingListenerFixtureFactory.java index 238bfc5b33..c61c7250e7 100644 --- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TestTracingListenerConfiguration.java +++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/tracing/fixture/listener/TracingListenerFixtureFactory.java @@ -18,14 +18,14 @@ package org.apache.shardingsphere.elasticjob.kernel.tracing.fixture.listener; import org.apache.shardingsphere.elasticjob.kernel.tracing.fixture.config.TracingStorageFixture; -import org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerConfiguration; +import org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerFactory; import org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListener; -public final class TestTracingListenerConfiguration implements TracingListenerConfiguration { +public final class TracingListenerFixtureFactory implements TracingListenerFactory { @Override - public TracingListener createTracingListener(final TracingStorageFixture storage) { - return new TestTracingListener(storage); + public TracingListener create(final TracingStorageFixture storage) { + return new TracingListenerFixture(storage); } @Override diff --git a/kernel/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerConfiguration b/kernel/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerFactory similarity index 85% rename from kernel/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerConfiguration rename to kernel/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerFactory index 24e9ed4f63..8db8f4759d 100644 --- a/kernel/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerConfiguration +++ b/kernel/src/test/resources/META-INF/services/org.apache.shardingsphere.elasticjob.kernel.tracing.listener.TracingListenerFactory @@ -15,5 +15,4 @@ # limitations under the License. # -org.apache.shardingsphere.elasticjob.kernel.tracing.fixture.listener.TestTracingListenerConfiguration -org.apache.shardingsphere.elasticjob.kernel.tracing.fixture.listener.TestTracingFailureConfiguration +org.apache.shardingsphere.elasticjob.kernel.tracing.fixture.listener.TracingListenerFixtureFactory