Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename TracingListenerConfiguration to TracingListenerFactory #2357

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataSource> {
public final class RDBTracingListenerFactory implements TracingListenerFactory<DataSource> {

@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# limitations under the License.
#

org.apache.shardingsphere.elasticjob.tracing.rdb.listener.RDBTracingListenerConfiguration
org.apache.shardingsphere.elasticjob.tracing.rdb.listener.RDBTracingListenerFactory
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;

/**
* Tracing listener configuration.
* Tracing listener factory.
*
* @param <T> type of tracing storage
*/
@SingletonSPI
public interface TracingListenerConfiguration<T> extends TypedSPI {
public interface TracingListenerFactory<T> extends TypedSPI {

/**
* Create tracing listener.
Expand All @@ -36,7 +36,7 @@ public interface TracingListenerConfiguration<T> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}

Expand All @@ -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();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TracingStorageFixture> {
public final class TracingListenerFixtureFactory implements TracingListenerFactory<TracingStorageFixture> {

@Override
public TracingListener createTracingListener(final TracingStorageFixture storage) {
return new TestTracingListener(storage);
public TracingListener create(final TracingStorageFixture storage) {
return new TracingListenerFixture(storage);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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