From e786afeb79758e5926fb6fa578cf4816fcb9b7d4 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sun, 15 Dec 2024 11:01:19 +0800 Subject: [PATCH] Move ClusterEventSubscriberRegistry to mode-core module (#34064) * Refactor RuleItemManager * Refactor RuleItemManager * Move ClusterEventSubscriberRegistry to mode-core module --- .../cluster/ClusterContextManagerBuilder.java | 4 +- .../ClusterEventSubscriberRegistry.java} | 6 +-- .../ClusterEventSubscriberRegistryTest.java | 39 +++++++++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) rename mode/{core/src/main/java/org/apache/shardingsphere/mode/event/subsciber/EventSubscriberRegistry.java => type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/ClusterEventSubscriberRegistry.java} (89%) create mode 100644 mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/ClusterEventSubscriberRegistryTest.java diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java index c942b31c0fca5..ebe7b89f7a9db 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; -import org.apache.shardingsphere.mode.event.subsciber.EventSubscriberRegistry; +import org.apache.shardingsphere.mode.manager.cluster.event.ClusterEventSubscriberRegistry; import org.apache.shardingsphere.mode.lock.GlobalLockContext; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.ContextManagerBuilder; @@ -79,7 +79,7 @@ private void registerOnline(final ComputeNodeInstanceContext computeNodeInstance contextManager.getPersistServiceFacade().getComputeNodePersistService().registerOnline(computeNodeInstanceContext.getInstance()); contextManager.getComputeNodeInstanceContext().getAllClusterInstances().addAll(contextManager.getPersistServiceFacade().getComputeNodePersistService().loadAllComputeNodeInstances()); new DataChangedEventListenerRegistry(contextManager, getDatabaseNames(param, contextManager.getPersistServiceFacade().getMetaDataPersistService())).register(); - EventSubscriberRegistry eventSubscriberRegistry = new EventSubscriberRegistry(contextManager.getComputeNodeInstanceContext().getEventBusContext()); + ClusterEventSubscriberRegistry eventSubscriberRegistry = new ClusterEventSubscriberRegistry(contextManager.getComputeNodeInstanceContext().getEventBusContext()); eventSubscriberRegistry.register(ShardingSphereServiceLoader.getServiceInstances(DeliverEventSubscriberFactory.class).stream() .map(each -> each.create(repository, contextManager.getComputeNodeInstanceContext().getEventBusContext())).collect(Collectors.toList())); eventSubscriberRegistry.register(new ClusterDispatchEventSubscriberRegistry(contextManager).getSubscribers()); diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/subsciber/EventSubscriberRegistry.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/ClusterEventSubscriberRegistry.java similarity index 89% rename from mode/core/src/main/java/org/apache/shardingsphere/mode/event/subsciber/EventSubscriberRegistry.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/ClusterEventSubscriberRegistry.java index 137896a6810c8..5fdff6c4de8c4 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/subsciber/EventSubscriberRegistry.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/ClusterEventSubscriberRegistry.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.event.subsciber; +package org.apache.shardingsphere.mode.manager.cluster.event; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; @@ -24,10 +24,10 @@ import java.util.Collection; /** - * Event subscriber registry. + * Cluster event subscriber registry. */ @RequiredArgsConstructor -public final class EventSubscriberRegistry { +public final class ClusterEventSubscriberRegistry { private final EventBusContext eventBusContext; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/ClusterEventSubscriberRegistryTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/ClusterEventSubscriberRegistryTest.java new file mode 100644 index 0000000000000..17ff210230c5f --- /dev/null +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/ClusterEventSubscriberRegistryTest.java @@ -0,0 +1,39 @@ +/* + * 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.mode.manager.cluster.event; + +import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; +import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; +import org.junit.jupiter.api.Test; + +import java.util.Collections; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +class ClusterEventSubscriberRegistryTest { + + @Test + void assertRegister() { + EventBusContext eventBusContext = mock(EventBusContext.class); + ClusterEventSubscriberRegistry registry = new ClusterEventSubscriberRegistry(eventBusContext); + EventSubscriber subscriber = mock(EventSubscriber.class); + registry.register(Collections.singleton(subscriber)); + verify(eventBusContext).register(subscriber); + } +}