diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md index 0dc00393b96..6156d310073 100644 --- a/changes/en-us/2.x.md +++ b/changes/en-us/2.x.md @@ -12,7 +12,7 @@ Add changes here for all PR submitted to the 2.x branch. ### optimize: -- [[#PR_NO](https://github.com/apache/incubator-seata/pull/PR_NO)] optimize XXX +- [[#6828](https://github.com/apache/incubator-seata/pull/6828)] spring boot compatible with file.conf and registry.conf ### security: @@ -31,6 +31,6 @@ Thanks to these contributors for their code commits. Please report an unintended - [slievrly](https://github.com/slievrly) -- [GITHUB_ID](https://github.com/GITHUB_ID) +- [lyl2008dsg](https://github.com/lyl2008dsg) Also, we receive many valuable issues, questions and advices from our community. Thanks for you all. \ No newline at end of file diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md index 5c76d15a1b0..0b91dae095d 100644 --- a/changes/zh-cn/2.x.md +++ b/changes/zh-cn/2.x.md @@ -12,7 +12,7 @@ ### optimize: -- [[#PR_NO](https://github.com/apache/incubator-seata/pull/PR_NO)] 优化XXX +- [[#6828](https://github.com/apache/incubator-seata/pull/6828)] seata-spring-boot-starter兼容file.conf和registry.conf ### security: @@ -31,6 +31,6 @@ - [slievrly](https://github.com/slievrly) -- [GITHUB_ID](https://github.com/GITHUB_ID) +- [lyl2008dsg](https://github.com/lyl2008dsg) 同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。 \ No newline at end of file diff --git a/common/src/main/java/org/apache/seata/common/store/LockMode.java b/common/src/main/java/org/apache/seata/common/store/LockMode.java new file mode 100644 index 00000000000..e36c6547f86 --- /dev/null +++ b/common/src/main/java/org/apache/seata/common/store/LockMode.java @@ -0,0 +1,69 @@ +/* + * 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.seata.common.store; + +public enum LockMode { + /** + * The File store mode. + */ + FILE("file"), + /** + * The Db store mode. + */ + DB("db"), + /** + * The Redis store mode. + */ + REDIS("redis"), + /** + * raft store + */ + RAFT("raft"); + + private String name; + + LockMode(String name) { + this.name = name; + } + + public static LockMode get(String name) { + for (LockMode mode : LockMode.values()) { + if (mode.getName().equalsIgnoreCase(name)) { + return mode; + } + } + throw new IllegalArgumentException("unknown lock mode:" + name); + } + + /** + * whether contains value of store mode + * + * @param name the mode name + * @return the boolean + */ + public static boolean contains(String name) { + try { + return get(name) != null ? true : false; + } catch (IllegalArgumentException e) { + return false; + } + } + + public String getName() { + return name; + } +} \ No newline at end of file diff --git a/common/src/main/java/org/apache/seata/common/store/SessionMode.java b/common/src/main/java/org/apache/seata/common/store/SessionMode.java new file mode 100644 index 00000000000..3db1307d82b --- /dev/null +++ b/common/src/main/java/org/apache/seata/common/store/SessionMode.java @@ -0,0 +1,69 @@ +/* + * 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.seata.common.store; + +public enum SessionMode { + /** + * The File store mode. + */ + FILE("file"), + /** + * The Db store mode. + */ + DB("db"), + /** + * The Redis store mode. + */ + REDIS("redis"), + /** + * raft store + */ + RAFT("raft"); + + private String name; + + SessionMode(String name) { + this.name = name; + } + + public static SessionMode get(String name) { + for (SessionMode mode : SessionMode.values()) { + if (mode.getName().equalsIgnoreCase(name)) { + return mode; + } + } + throw new IllegalArgumentException("unknown session mode:" + name); + } + + /** + * whether contains value of store mode + * + * @param name the mode name + * @return the boolean + */ + public static boolean contains(String name) { + try { + return get(name) != null ? true : false; + } catch (IllegalArgumentException e) { + return false; + } + } + + public String getName() { + return name; + } +} \ No newline at end of file diff --git a/seata-spring-autoconfigure/seata-spring-autoconfigure-core/pom.xml b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/pom.xml index a3767ecb0ab..9c24e75a961 100644 --- a/seata-spring-autoconfigure/seata-spring-autoconfigure-core/pom.xml +++ b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/pom.xml @@ -38,5 +38,16 @@ ${project.version} test + + org.springframework.boot + spring-boot-starter-test + test + + + ch.qos.logback + logback-classic + + + \ No newline at end of file diff --git a/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/main/java/org/apache/seata/spring/boot/autoconfigure/listener/SeataApplicationListener.java b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/main/java/org/apache/seata/spring/boot/autoconfigure/listener/SeataApplicationListener.java new file mode 100644 index 00000000000..b347490a1a4 --- /dev/null +++ b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/main/java/org/apache/seata/spring/boot/autoconfigure/listener/SeataApplicationListener.java @@ -0,0 +1,59 @@ +/* + * 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.seata.spring.boot.autoconfigure.listener; + +import org.apache.seata.common.holder.ObjectHolder; +import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.boot.context.logging.LoggingApplicationListener; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.event.GenericApplicationListener; +import org.springframework.core.ResolvableType; +import org.springframework.core.env.ConfigurableEnvironment; + +import static org.apache.seata.common.Constants.OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT; + + +public class SeataApplicationListener implements GenericApplicationListener { + + @Override + public boolean supportsEventType(ResolvableType eventType) { + return eventType.getRawClass() != null + && (ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(eventType.getRawClass()) || + ApplicationReadyEvent.class.isAssignableFrom(eventType.getRawClass())); + } + + @Override + public void onApplicationEvent(ApplicationEvent event) { + if (!(event instanceof ApplicationEnvironmentPreparedEvent)) { + return; + } + ApplicationEnvironmentPreparedEvent environmentPreparedEvent = (ApplicationEnvironmentPreparedEvent)event; + ConfigurableEnvironment environment = environmentPreparedEvent.getEnvironment(); + ObjectHolder.INSTANCE.setObject(OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT, environment); + } + + /** + * higher than LoggingApplicationListener + * + * @return the order + */ + @Override + public int getOrder() { + return LoggingApplicationListener.DEFAULT_ORDER - 1; + } +} \ No newline at end of file diff --git a/server/src/main/java/org/apache/seata/server/spring/listener/SeataPropertiesLoader.java b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/main/java/org/apache/seata/spring/boot/autoconfigure/loader/SeataPropertiesLoader.java similarity index 70% rename from server/src/main/java/org/apache/seata/server/spring/listener/SeataPropertiesLoader.java rename to seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/main/java/org/apache/seata/spring/boot/autoconfigure/loader/SeataPropertiesLoader.java index 974416b26c5..05931662eee 100644 --- a/server/src/main/java/org/apache/seata/server/spring/listener/SeataPropertiesLoader.java +++ b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/main/java/org/apache/seata/spring/boot/autoconfigure/loader/SeataPropertiesLoader.java @@ -14,14 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.seata.server.spring.listener; +package org.apache.seata.spring.boot.autoconfigure.loader; import org.apache.seata.common.util.CollectionUtils; import org.apache.seata.common.util.StringUtils; import org.apache.seata.config.ConfigurationFactory; import org.apache.seata.config.FileConfiguration; import org.apache.seata.config.file.FileConfig; -import org.apache.seata.server.store.StoreConfig; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.Ordered; @@ -29,6 +28,8 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.PropertiesPropertySource; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -74,8 +75,30 @@ public void initialize(ConfigurableApplicationContext applicationContext) { environment.getPropertySources().addLast(new PropertiesPropertySource("seataOldConfig", properties)); } // Load by priority - System.setProperty("sessionMode", StoreConfig.getSessionMode().getName()); - System.setProperty("lockMode", StoreConfig.getLockMode().getName()); + loadSessionAndLockModes(); } + public void loadSessionAndLockModes() { + try { + Class storeConfigClass = Class.forName("org.apache.seata.server.store.StoreConfig"); + Optional sessionMode = invokeEnumMethod(storeConfigClass, "getSessionMode", "getName"); + Optional lockMode = invokeEnumMethod(storeConfigClass, "getLockMode", "getName"); + sessionMode.ifPresent(value -> System.setProperty("sessionMode", value)); + lockMode.ifPresent(value -> System.setProperty("lockMode", value)); + } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + // The exception is not printed because it is an expected behavior and does not affect the normal operation of the program. + // StoreConfig only exists on the server side + } + } + + private Optional invokeEnumMethod(Class clazz, String enumMethodName, String getterMethodName) + throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + Method enumMethod = clazz.getMethod(enumMethodName); + Object enumValue = enumMethod.invoke(null); + if (enumValue != null) { + Method getterMethod = enumValue.getClass().getMethod(getterMethodName); + return Optional.ofNullable((String) getterMethod.invoke(enumValue)); + } + return Optional.empty(); + } } diff --git a/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/main/resources/META-INF/spring.factories b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/main/resources/META-INF/spring.factories index df445bb6973..27e069aa2ef 100644 --- a/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/main/resources/META-INF/spring.factories +++ b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/main/resources/META-INF/spring.factories @@ -21,3 +21,9 @@ org.apache.seata.spring.boot.autoconfigure.SeataCoreAutoConfiguration # Environment Post Processors org.springframework.boot.env.EnvironmentPostProcessor=\ org.apache.seata.spring.boot.autoconfigure.SeataCoreEnvironmentPostProcessor + +org.springframework.context.ApplicationContextInitializer=\ +org.apache.seata.spring.boot.autoconfigure.loader.SeataPropertiesLoader + +org.springframework.context.ApplicationListener=\ +org.apache.seata.spring.boot.autoconfigure.listener.SeataApplicationListener \ No newline at end of file diff --git a/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/java/org/apache/seata/spring/boot/autoconfigure/SeataCoreAutoConfigurationTest.java b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/java/org/apache/seata/spring/boot/autoconfigure/SeataCoreAutoConfigurationTest.java new file mode 100644 index 00000000000..8fbf0075e43 --- /dev/null +++ b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/java/org/apache/seata/spring/boot/autoconfigure/SeataCoreAutoConfigurationTest.java @@ -0,0 +1,88 @@ +/* + * 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.seata.spring.boot.autoconfigure; + +import org.apache.seata.config.Configuration; +import org.apache.seata.config.ConfigurationFactory; +import org.apache.seata.config.FileConfiguration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.env.Environment; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(classes = SeataCoreAutoConfiguration.class) +@TestPropertySource(locations = "classpath:application-test.properties") +public class SeataCoreAutoConfigurationTest { + + @Autowired + private Environment environment; + + @Test + public void testSeataPropertiesLoaded() { + ConfigurationFactory.reload(); + + // default file.conf + String dbUrl = environment.getProperty("seata.store.db.url"); + assertEquals("jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true", dbUrl, "The DB URL should be correctly loaded from configuration"); + + // overridden by application-test.properties + String registryType = environment.getProperty("seata.config.type"); + assertEquals("file", registryType, "The config type should be 'file'"); + + // overridden by application-test.properties + String seataNamespaces = environment.getProperty("seata.config.nacos.namespace"); + assertEquals("seata-test-application.yml", seataNamespaces, "The Nacos namespace should be 'seata-test-application.yml'"); + } + + @Test + public void testConfigFromFileUsingGetInstance() { + Configuration configFromFile = ConfigurationFactory.getInstance(); + String dbUrlFromFile = configFromFile.getConfig("store.db.url"); + assertEquals("jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true", dbUrlFromFile, "The DB URL should be correctly loaded from file.conf"); + String storeFileDirFromFile = configFromFile.getConfig("store.file.dir"); + assertEquals("sessionStore", storeFileDirFromFile, "The storeFileDir should be 'sessionStore' in file.conf"); + } + + @Test + public void testConfigFromFileUsingGetOriginFileInstance() { + Optional optionalConfigFromFile = ConfigurationFactory.getOriginFileInstance(); + assertTrue(optionalConfigFromFile.isPresent(), "The configuration from file.conf should be present"); + FileConfiguration configFromFile = optionalConfigFromFile.get(); + String dbUrlFromFile = configFromFile.getConfig("store.db.url"); + assertEquals("jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true", dbUrlFromFile, "The DB URL should be correctly loaded from file.conf"); + String storeFileDirFromFile = configFromFile.getConfig("store.file.dir"); + assertEquals("sessionStore", storeFileDirFromFile, "The storeFileDir should be 'sessionStore' in file.conf"); + } + + @Test + public void testConfigFromRegistryUsingGetOriginFileInstanceRegistry() { + Configuration configFromRegistry = ConfigurationFactory.getOriginFileInstanceRegistry(); + String registryTypeFromRegistry = configFromRegistry.getConfig("config.type"); + assertEquals("file", registryTypeFromRegistry, "The config type should be 'file' in registry.conf"); + String seataNamespaceFromRegistry = configFromRegistry.getConfig("config.nacos.namespace"); + assertEquals("seata-test", seataNamespaceFromRegistry, "The Nacos namespace should be 'seata-test' in registry.conf"); + } +} \ No newline at end of file diff --git a/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/resources/application-test.properties b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/resources/application-test.properties index 8467d6cc7b9..c492f36092b 100755 --- a/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/resources/application-test.properties +++ b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/resources/application-test.properties @@ -17,7 +17,7 @@ seata.config.type=file seata.config.data-type=bbb -seata.config.file.name=aaa +seata.config.file.name=file.conf seata.config.consul.server-addr=aaa seata.config.consul.acl-token=bbb @@ -33,7 +33,7 @@ seata.config.apollo.apollo-config-service=fff seata.config.etcd3.server-addr=aaa seata.config.etcd3.key=bbb -seata.config.nacos.namespace=ddd +seata.config.nacos.namespace=seata-test-application.yml seata.config.nacos.server-addr=aaa seata.config.nacos.group=ccc seata.config.nacos.username=eee diff --git a/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/resources/file.conf b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/resources/file.conf new file mode 100644 index 00000000000..422c6dd5836 --- /dev/null +++ b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/resources/file.conf @@ -0,0 +1,67 @@ +# +# 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. +# + +#reduce delay for test +## transaction log store, only used in seata-server +store { + ## store mode: file、db + mode = "file" + + ## file store property + file { + ## store location dir + dir = "sessionStore" + } + + ## database store property + db { + ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc. + datasource = "dbcp" + ## mysql/oracle/h2/oceanbase etc. + dbType = "mysql" + driverClassName = "com.mysql.jdbc.Driver" + ## if using mysql to store the data, recommend add rewriteBatchedStatements=true in jdbc connection param + url = "jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true" + user = "mysql" + password = "mysql" + } +} +server { + recovery { + #schedule committing retry period in milliseconds + committingRetryPeriod = 100 + #schedule asyn committing retry period in milliseconds + asynCommittingRetryPeriod = 100 + #schedule rollbacking retry period in milliseconds + rollbackingRetryPeriod = 100 + #schedule timeout retry period in milliseconds + timeoutRetryPeriod = 100 + } + undo { + logSaveDays = 2 + #schedule delete expired undo_log in milliseconds + logDeletePeriod = 86400000 + } +} +## metrics settings +metrics { + enabled = true + registryType = "compact" + # multi exporters use comma divided + exporterList = "prometheus" + exporterPrometheusPort = 9898 +} \ No newline at end of file diff --git a/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/resources/registry.conf b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/resources/registry.conf new file mode 100644 index 00000000000..ceb312b5e7e --- /dev/null +++ b/seata-spring-autoconfigure/seata-spring-autoconfigure-core/src/test/resources/registry.conf @@ -0,0 +1,30 @@ +# +# 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. +# + +config { + type = "file" + + file { + name = "file.conf" + } + nacos { + application = "seata-server" + serverAddr = "127.0.0.1:8848" + namespace = "seata-test" + cluster = "default" + } +} \ No newline at end of file diff --git a/server/src/main/java/org/apache/seata/server/cluster/raft/RaftServerManager.java b/server/src/main/java/org/apache/seata/server/cluster/raft/RaftServerManager.java index b891bea8484..47e7ee4432b 100644 --- a/server/src/main/java/org/apache/seata/server/cluster/raft/RaftServerManager.java +++ b/server/src/main/java/org/apache/seata/server/cluster/raft/RaftServerManager.java @@ -38,6 +38,7 @@ import com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl; import org.apache.seata.common.ConfigurationKeys; import org.apache.seata.common.XID; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.common.util.StringUtils; import org.apache.seata.config.ConfigurationFactory; import org.apache.seata.core.serializer.SerializerType; @@ -87,7 +88,7 @@ public static CliClientService getCliClientServiceInstance() { public static void init() { if (INIT.compareAndSet(false, true)) { String initConfStr = CONFIG.getConfig(ConfigurationKeys.SERVER_RAFT_SERVER_ADDR); - RAFT_MODE = StoreConfig.getSessionMode().equals(StoreConfig.SessionMode.RAFT); + RAFT_MODE = StoreConfig.getSessionMode().equals(SessionMode.RAFT); if (StringUtils.isBlank(initConfStr)) { if (RAFT_MODE) { throw new IllegalArgumentException( diff --git a/server/src/main/java/org/apache/seata/server/cluster/raft/RaftStateMachine.java b/server/src/main/java/org/apache/seata/server/cluster/raft/RaftStateMachine.java index 9b49ba011ff..2b14b2a5cb9 100644 --- a/server/src/main/java/org/apache/seata/server/cluster/raft/RaftStateMachine.java +++ b/server/src/main/java/org/apache/seata/server/cluster/raft/RaftStateMachine.java @@ -49,6 +49,8 @@ import org.apache.seata.common.holder.ObjectHolder; import org.apache.seata.common.metadata.ClusterRole; import org.apache.seata.common.metadata.Node; +import org.apache.seata.common.store.SessionMode; +import org.apache.seata.common.store.StoreMode; import org.apache.seata.common.thread.NamedThreadFactory; import org.apache.seata.common.util.CollectionUtils; import org.apache.seata.common.util.StringUtils; @@ -140,7 +142,7 @@ public RaftStateMachine(String group) { return null; }); registryStoreSnapshotFile(new LeaderMetadataSnapshotFile(group)); - if (StoreConfig.StoreMode.RAFT.getName().equalsIgnoreCase(mode)) { + if (StoreMode.RAFT.getName().equalsIgnoreCase(mode)) { registryStoreSnapshotFile(new SessionSnapshotFile(group)); EXECUTES.put(ADD_GLOBAL_SESSION, new AddGlobalSessionExecute()); EXECUTES.put(ADD_BRANCH_SESSION, new AddBranchSessionExecute()); @@ -180,7 +182,7 @@ public void onApply(Iterator iterator) { @Override public void onSnapshotSave(final SnapshotWriter writer, final Closure done) { - if (!StringUtils.equals(StoreConfig.SessionMode.RAFT.getName(), mode)) { + if (!StringUtils.equals(SessionMode.RAFT.getName(), mode)) { done.run(Status.OK()); return; } @@ -198,7 +200,7 @@ public void onSnapshotSave(final SnapshotWriter writer, final Closure done) { @Override public boolean onSnapshotLoad(final SnapshotReader reader) { - if (!StringUtils.equals(StoreConfig.SessionMode.RAFT.getName(), mode)) { + if (!StringUtils.equals(SessionMode.RAFT.getName(), mode)) { return true; } if (isLeader()) { @@ -232,7 +234,7 @@ public void onLeaderStart(final long term) { try { // become the leader again,reloading global session SessionHolder.reload(SessionHolder.getRootSessionManager().allSessions(), - StoreConfig.SessionMode.RAFT, false); + SessionMode.RAFT, false); } finally { SeataClusterContext.unbindGroup(); } diff --git a/server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java b/server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java index ddfd5f35d66..468e9ccc5ff 100644 --- a/server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java +++ b/server/src/main/java/org/apache/seata/server/coordinator/DefaultCoordinator.java @@ -30,6 +30,7 @@ import io.netty.channel.Channel; import org.apache.commons.lang.time.DateFormatUtils; import org.apache.seata.common.DefaultValues; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.common.thread.NamedThreadFactory; import org.apache.seata.common.util.CollectionUtils; import org.apache.seata.config.ConfigurationFactory; @@ -216,7 +217,7 @@ protected DefaultCoordinator(RemotingServer remotingServer) { boolean enableBranchAsyncRemove = CONFIG.getBoolean( ConfigurationKeys.ENABLE_BRANCH_ASYNC_REMOVE, DEFAULT_ENABLE_BRANCH_ASYNC_REMOVE); // create branchRemoveExecutor - if (enableBranchAsyncRemove && StoreConfig.getSessionMode() != StoreConfig.SessionMode.FILE) { + if (enableBranchAsyncRemove && StoreConfig.getSessionMode() != SessionMode.FILE) { branchRemoveExecutor = new ThreadPoolExecutor(BRANCH_ASYNC_POOL_SIZE, BRANCH_ASYNC_POOL_SIZE, Integer.MAX_VALUE, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>( @@ -232,8 +233,8 @@ public static DefaultCoordinator getInstance(RemotingServer remotingServer) { if (null == instance) { synchronized (DefaultCoordinator.class) { if (null == instance) { - StoreConfig.SessionMode storeMode = StoreConfig.getSessionMode(); - instance = Objects.equals(StoreConfig.SessionMode.RAFT, storeMode) + SessionMode storeMode = StoreConfig.getSessionMode(); + instance = Objects.equals(SessionMode.RAFT, storeMode) ? new RaftCoordinator(remotingServer) : new DefaultCoordinator(remotingServer); } } diff --git a/server/src/main/java/org/apache/seata/server/coordinator/RaftCoordinator.java b/server/src/main/java/org/apache/seata/server/coordinator/RaftCoordinator.java index db9af1926bf..8e01601b953 100644 --- a/server/src/main/java/org/apache/seata/server/coordinator/RaftCoordinator.java +++ b/server/src/main/java/org/apache/seata/server/coordinator/RaftCoordinator.java @@ -16,6 +16,7 @@ */ package org.apache.seata.server.coordinator; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.core.exception.TransactionException; import org.apache.seata.core.exception.TransactionExceptionCode; import org.apache.seata.core.protocol.transaction.AbstractTransactionRequest; @@ -64,7 +65,7 @@ private boolean isPass(String group) { } public static void setPrevent(String group, boolean prevent) { - if (StoreConfig.getSessionMode() == StoreConfig.SessionMode.RAFT) { + if (StoreConfig.getSessionMode() == SessionMode.RAFT) { GROUP_PREVENT.put(group, prevent); } } diff --git a/server/src/main/java/org/apache/seata/server/lock/LockerManagerFactory.java b/server/src/main/java/org/apache/seata/server/lock/LockerManagerFactory.java index ae9e2534115..45129d12f93 100644 --- a/server/src/main/java/org/apache/seata/server/lock/LockerManagerFactory.java +++ b/server/src/main/java/org/apache/seata/server/lock/LockerManagerFactory.java @@ -17,10 +17,11 @@ package org.apache.seata.server.lock; import org.apache.seata.common.loader.EnhancedServiceLoader; +import org.apache.seata.common.store.LockMode; +import org.apache.seata.common.store.StoreMode; import org.apache.seata.config.Configuration; import org.apache.seata.config.ConfigurationFactory; import org.apache.seata.server.store.StoreConfig; -import org.apache.seata.server.store.StoreConfig.LockMode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -65,7 +66,7 @@ public static void init(LockMode lockMode) { } LOGGER.info("use lock store mode: {}", lockMode.getName()); //if not exist the lock mode, throw exception - if (null != StoreConfig.StoreMode.get(lockMode.name())) { + if (null != StoreMode.get(lockMode.name())) { LOCK_MANAGER = EnhancedServiceLoader.load(LockManager.class, lockMode.getName()); } } diff --git a/server/src/main/java/org/apache/seata/server/session/SessionHelper.java b/server/src/main/java/org/apache/seata/server/session/SessionHelper.java index 17cd084505e..356a50cb109 100644 --- a/server/src/main/java/org/apache/seata/server/session/SessionHelper.java +++ b/server/src/main/java/org/apache/seata/server/session/SessionHelper.java @@ -28,6 +28,7 @@ import java.util.stream.StreamSupport; import org.apache.seata.common.ConfigurationKeys; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.common.util.CollectionUtils; import org.apache.seata.config.Configuration; import org.apache.seata.config.ConfigurationFactory; @@ -42,7 +43,6 @@ import org.apache.seata.server.coordinator.DefaultCoordinator; import org.apache.seata.server.metrics.MetricsPublisher; import org.apache.seata.server.store.StoreConfig; -import org.apache.seata.server.store.StoreConfig.SessionMode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; diff --git a/server/src/main/java/org/apache/seata/server/session/SessionHolder.java b/server/src/main/java/org/apache/seata/server/session/SessionHolder.java index cd6f6273c7e..e0e7a41b795 100644 --- a/server/src/main/java/org/apache/seata/server/session/SessionHolder.java +++ b/server/src/main/java/org/apache/seata/server/session/SessionHolder.java @@ -29,6 +29,7 @@ import org.apache.seata.common.exception.ShouldNeverHappenException; import org.apache.seata.common.exception.StoreException; import org.apache.seata.common.loader.EnhancedServiceLoader; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.common.util.CollectionUtils; import org.apache.seata.common.util.StringUtils; import org.apache.seata.config.Configuration; @@ -42,7 +43,6 @@ import org.apache.seata.server.cluster.raft.context.SeataClusterContext; import org.apache.seata.server.lock.distributed.DistributedLockerFactory; import org.apache.seata.server.store.StoreConfig; -import org.apache.seata.server.store.StoreConfig.SessionMode; import org.apache.seata.server.store.VGroupMappingStoreManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/server/src/main/java/org/apache/seata/server/store/StoreConfig.java b/server/src/main/java/org/apache/seata/server/store/StoreConfig.java index adf949cf880..057753e21c7 100644 --- a/server/src/main/java/org/apache/seata/server/store/StoreConfig.java +++ b/server/src/main/java/org/apache/seata/server/store/StoreConfig.java @@ -16,6 +16,9 @@ */ package org.apache.seata.server.store; +import org.apache.seata.common.store.LockMode; +import org.apache.seata.common.store.SessionMode; +import org.apache.seata.common.store.StoreMode; import org.apache.seata.common.util.StringUtils; import org.apache.seata.config.Configuration; import org.apache.seata.config.ConfigurationFactory; @@ -142,119 +145,4 @@ public static LockMode getLockMode() { // complication old config return LockMode.get(getStoreMode().name()); } - - public enum StoreMode { - /** - * The File store mode. - */ - FILE("file"), - /** - * The Db store mode. - */ - DB("db"), - /** - * The Redis store mode. - */ - REDIS("redis"), - /** - * The Raft store mode. - */ - RAFT("raft"); - - private String name; - - StoreMode(String name) { - this.name = name; - } - - public static StoreMode get(String name) { - for (StoreMode mode : StoreMode.values()) { - if (mode.getName().equalsIgnoreCase(name)) { - return mode; - } - } - throw new IllegalArgumentException("unknown store mode:" + name); - } - - public String getName() { - return name; - } - } - - public enum SessionMode { - /** - * The File store mode. - */ - FILE("file"), - /** - * The Db store mode. - */ - DB("db"), - /** - * The Redis store mode. - */ - REDIS("redis"), - /** - * raft store - */ - RAFT("raft"); - - private String name; - - SessionMode(String name) { - this.name = name; - } - - public static SessionMode get(String name) { - for (SessionMode mode : SessionMode.values()) { - if (mode.getName().equalsIgnoreCase(name)) { - return mode; - } - } - throw new IllegalArgumentException("unknown session mode:" + name); - } - - public String getName() { - return name; - } - } - - public enum LockMode { - /** - * The File store mode. - */ - FILE("file"), - /** - * The Db store mode. - */ - DB("db"), - /** - * The Redis store mode. - */ - REDIS("redis"), - /** - * raft store - */ - RAFT("raft"); - - private String name; - - LockMode(String name) { - this.name = name; - } - - public static LockMode get(String name) { - for (LockMode mode : LockMode.values()) { - if (mode.getName().equalsIgnoreCase(name)) { - return mode; - } - } - throw new IllegalArgumentException("unknown lock mode:" + name); - } - - public String getName() { - return name; - } - } - } diff --git a/server/src/main/resources/META-INF/spring.factories b/server/src/main/resources/META-INF/spring.factories index 4b97deb2101..649fa8a356c 100644 --- a/server/src/main/resources/META-INF/spring.factories +++ b/server/src/main/resources/META-INF/spring.factories @@ -15,6 +15,4 @@ # limitations under the License. # org.springframework.context.ApplicationListener=\ -org.apache.seata.server.spring.listener.ServerApplicationListener -org.springframework.context.ApplicationContextInitializer=\ -org.apache.seata.server.spring.listener.SeataPropertiesLoader \ No newline at end of file +org.apache.seata.server.spring.listener.ServerApplicationListener \ No newline at end of file diff --git a/server/src/test/java/org/apache/seata/server/coordinator/DefaultCoordinatorTest.java b/server/src/test/java/org/apache/seata/server/coordinator/DefaultCoordinatorTest.java index 1de1f04c0ca..02a31496a5f 100644 --- a/server/src/test/java/org/apache/seata/server/coordinator/DefaultCoordinatorTest.java +++ b/server/src/test/java/org/apache/seata/server/coordinator/DefaultCoordinatorTest.java @@ -27,6 +27,7 @@ import org.apache.seata.common.DefaultValues; import org.apache.seata.common.XID; import org.apache.seata.common.loader.EnhancedServiceLoader; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.common.util.NetUtil; import org.apache.seata.common.util.ReflectionUtil; import org.apache.seata.config.Configuration; @@ -45,7 +46,6 @@ import org.apache.seata.server.metrics.MetricsManager; import org.apache.seata.server.session.GlobalSession; import org.apache.seata.server.session.SessionHolder; -import org.apache.seata.server.store.StoreConfig.SessionMode; import org.apache.seata.server.util.StoreUtil; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; diff --git a/server/src/test/java/org/apache/seata/server/coordinator/DefaultCoreTest.java b/server/src/test/java/org/apache/seata/server/coordinator/DefaultCoreTest.java index 6db53df7db9..93a5fbc0542 100644 --- a/server/src/test/java/org/apache/seata/server/coordinator/DefaultCoreTest.java +++ b/server/src/test/java/org/apache/seata/server/coordinator/DefaultCoreTest.java @@ -19,6 +19,7 @@ import java.util.Collection; import java.util.stream.Stream; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.core.exception.TransactionException; import org.apache.seata.core.model.BranchStatus; import org.apache.seata.core.model.BranchType; @@ -28,7 +29,6 @@ import org.apache.seata.server.session.GlobalSession; import org.apache.seata.server.session.SessionHelper; import org.apache.seata.server.session.SessionHolder; -import org.apache.seata.server.store.StoreConfig.SessionMode; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; diff --git a/server/src/test/java/org/apache/seata/server/event/DefaultCoreForEventBusTest.java b/server/src/test/java/org/apache/seata/server/event/DefaultCoreForEventBusTest.java index 8b94efd10a8..0569efe000e 100644 --- a/server/src/test/java/org/apache/seata/server/event/DefaultCoreForEventBusTest.java +++ b/server/src/test/java/org/apache/seata/server/event/DefaultCoreForEventBusTest.java @@ -26,6 +26,7 @@ import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.core.event.GlobalTransactionEvent; import org.apache.seata.core.exception.TransactionException; import org.apache.seata.core.model.GlobalStatus; @@ -37,7 +38,6 @@ import org.apache.seata.server.metrics.MetricsManager; import org.apache.seata.server.session.SessionHolder; import org.apache.seata.server.store.StoreConfig; -import org.apache.seata.server.store.StoreConfig.SessionMode; import org.apache.seata.server.util.StoreUtil; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; diff --git a/server/src/test/java/org/apache/seata/server/lock/LockManagerTest.java b/server/src/test/java/org/apache/seata/server/lock/LockManagerTest.java index 6d6889c8045..c96c002ee29 100644 --- a/server/src/test/java/org/apache/seata/server/lock/LockManagerTest.java +++ b/server/src/test/java/org/apache/seata/server/lock/LockManagerTest.java @@ -26,6 +26,7 @@ import javax.annotation.Resource; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.common.util.CollectionUtils; import org.apache.seata.common.result.PageResult; import org.apache.seata.core.exception.TransactionException; @@ -39,7 +40,6 @@ import org.apache.seata.server.session.GlobalSession; import org.apache.seata.server.session.SessionHolder; import org.apache.seata.server.session.SessionManager; -import org.apache.seata.server.store.StoreConfig.SessionMode; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; diff --git a/server/src/test/java/org/apache/seata/server/raft/RaftSyncMessageTest.java b/server/src/test/java/org/apache/seata/server/raft/RaftSyncMessageTest.java index 187135108a7..3e36d55a520 100644 --- a/server/src/test/java/org/apache/seata/server/raft/RaftSyncMessageTest.java +++ b/server/src/test/java/org/apache/seata/server/raft/RaftSyncMessageTest.java @@ -28,6 +28,7 @@ import org.apache.seata.common.exception.SeataRuntimeException; import org.apache.seata.common.metadata.ClusterRole; import org.apache.seata.common.metadata.Node; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.core.exception.TransactionException; import org.apache.seata.core.model.BranchType; import org.apache.seata.server.cluster.raft.snapshot.RaftSnapshot; @@ -44,7 +45,6 @@ import org.apache.seata.server.session.GlobalSession; import org.apache.seata.server.session.SessionHelper; import org.apache.seata.server.session.SessionHolder; -import org.apache.seata.server.store.StoreConfig; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -59,7 +59,7 @@ public class RaftSyncMessageTest { @BeforeAll public static void setUp(ApplicationContext context){ - SessionHolder.init(StoreConfig.SessionMode.FILE); + SessionHolder.init(SessionMode.FILE); } @AfterAll diff --git a/server/src/test/java/org/apache/seata/server/raft/execute/BranchSessionExecuteTest.java b/server/src/test/java/org/apache/seata/server/raft/execute/BranchSessionExecuteTest.java index 7c499f410ce..df21b9216ff 100644 --- a/server/src/test/java/org/apache/seata/server/raft/execute/BranchSessionExecuteTest.java +++ b/server/src/test/java/org/apache/seata/server/raft/execute/BranchSessionExecuteTest.java @@ -16,6 +16,8 @@ */ package org.apache.seata.server.raft.execute; +import org.apache.seata.common.store.LockMode; +import org.apache.seata.common.store.SessionMode; import java.util.ArrayList; import java.util.List; import org.apache.seata.common.XID; @@ -35,7 +37,6 @@ import org.apache.seata.server.session.GlobalSession; import org.apache.seata.server.session.SessionHolder; import org.apache.seata.server.storage.SessionConverter; -import org.apache.seata.server.store.StoreConfig; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -58,9 +59,9 @@ class BranchSessionExecuteTest { @BeforeAll public static void setUp(ApplicationContext context) throws TransactionException { System.setProperty("server.raft.serverAddr", NetUtil.getLocalIp() + ":9091"); - SessionHolder.init(StoreConfig.SessionMode.RAFT); + SessionHolder.init(SessionMode.RAFT); LockerManagerFactory.destroy(); - LockerManagerFactory.init(StoreConfig.LockMode.RAFT); + LockerManagerFactory.init(LockMode.RAFT); GLOBAL_SESSION = mockGlobalSession(); SessionHolder.getRootSessionManager().addGlobalSession(GLOBAL_SESSION); } diff --git a/server/src/test/java/org/apache/seata/server/raft/execute/GlobalSessionExecuteTest.java b/server/src/test/java/org/apache/seata/server/raft/execute/GlobalSessionExecuteTest.java index 9594eb7de56..45d191790ee 100644 --- a/server/src/test/java/org/apache/seata/server/raft/execute/GlobalSessionExecuteTest.java +++ b/server/src/test/java/org/apache/seata/server/raft/execute/GlobalSessionExecuteTest.java @@ -16,6 +16,8 @@ */ package org.apache.seata.server.raft.execute; +import org.apache.seata.common.store.LockMode; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.common.util.NetUtil; import org.apache.seata.config.ConfigurationCache; import org.apache.seata.core.exception.TransactionException; @@ -30,7 +32,6 @@ import org.apache.seata.server.session.SessionHolder; import org.apache.seata.server.session.SessionManager; import org.apache.seata.server.storage.SessionConverter; -import org.apache.seata.server.store.StoreConfig; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; @@ -47,9 +48,9 @@ class GlobalSessionExecuteTest { @BeforeAll public static void setUp(ApplicationContext context){ System.setProperty("server.raft.serverAddr", NetUtil.getLocalIp() + ":9091"); - SessionHolder.init(StoreConfig.SessionMode.RAFT); + SessionHolder.init(SessionMode.RAFT); LockerManagerFactory.destroy(); - LockerManagerFactory.init(StoreConfig.LockMode.RAFT); + LockerManagerFactory.init(LockMode.RAFT); } @AfterAll diff --git a/server/src/test/java/org/apache/seata/server/raft/execute/LockExecuteTest.java b/server/src/test/java/org/apache/seata/server/raft/execute/LockExecuteTest.java index 50aece25893..19c4c24f230 100644 --- a/server/src/test/java/org/apache/seata/server/raft/execute/LockExecuteTest.java +++ b/server/src/test/java/org/apache/seata/server/raft/execute/LockExecuteTest.java @@ -16,6 +16,8 @@ */ package org.apache.seata.server.raft.execute; +import org.apache.seata.common.store.LockMode; +import org.apache.seata.common.store.SessionMode; import java.util.ArrayList; import java.util.List; import org.apache.seata.common.util.NetUtil; @@ -36,7 +38,6 @@ import org.apache.seata.server.session.GlobalSession; import org.apache.seata.server.session.SessionHolder; import org.apache.seata.server.storage.SessionConverter; -import org.apache.seata.server.store.StoreConfig; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; @@ -63,9 +64,9 @@ class LockExecuteTest { @BeforeAll public static void setUp(ApplicationContext context) throws TransactionException { System.setProperty("server.raft.serverAddr", NetUtil.getLocalIp() + ":9091"); - SessionHolder.init(StoreConfig.SessionMode.RAFT); + SessionHolder.init(SessionMode.RAFT); LockerManagerFactory.destroy(); - LockerManagerFactory.init(StoreConfig.LockMode.RAFT); + LockerManagerFactory.init(LockMode.RAFT); } @AfterAll diff --git a/server/src/test/java/org/apache/seata/server/session/FileSessionManagerTest.java b/server/src/test/java/org/apache/seata/server/session/FileSessionManagerTest.java index 56ce51d343f..478529866af 100644 --- a/server/src/test/java/org/apache/seata/server/session/FileSessionManagerTest.java +++ b/server/src/test/java/org/apache/seata/server/session/FileSessionManagerTest.java @@ -30,6 +30,7 @@ import org.apache.seata.common.XID; import org.apache.seata.common.loader.EnhancedServiceLoader; import org.apache.seata.common.result.PageResult; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.core.model.BranchStatus; import org.apache.seata.core.model.BranchType; import org.apache.seata.core.model.GlobalStatus; @@ -38,10 +39,8 @@ import org.apache.seata.server.console.service.GlobalSessionService; import org.apache.seata.server.console.vo.GlobalSessionVO; import org.apache.seata.server.storage.file.session.FileSessionManager; -import org.apache.seata.server.store.StoreConfig.SessionMode; import org.apache.seata.server.util.StoreUtil; import org.apache.commons.lang.time.DateUtils; -import org.apache.seata.server.session.SessionHolder; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; diff --git a/server/src/test/java/org/apache/seata/server/session/GlobalSessionTest.java b/server/src/test/java/org/apache/seata/server/session/GlobalSessionTest.java index b9083874c19..08529720e2f 100644 --- a/server/src/test/java/org/apache/seata/server/session/GlobalSessionTest.java +++ b/server/src/test/java/org/apache/seata/server/session/GlobalSessionTest.java @@ -19,11 +19,10 @@ import java.io.IOException; import java.util.stream.Stream; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.core.model.BranchStatus; import org.apache.seata.core.model.BranchType; import org.apache.seata.core.model.GlobalStatus; -import org.apache.seata.server.store.StoreConfig; -import org.apache.seata.server.session.SessionHolder; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -47,7 +46,7 @@ public class GlobalSessionTest { @BeforeAll public static void init(ApplicationContext context){ - SessionHolder.init(StoreConfig.SessionMode.FILE); + SessionHolder.init(SessionMode.FILE); } @AfterAll public static void destroy(){ diff --git a/server/src/test/java/org/apache/seata/server/session/SessionHolderTest.java b/server/src/test/java/org/apache/seata/server/session/SessionHolderTest.java index 9ac513731c4..6e6fe855c6f 100644 --- a/server/src/test/java/org/apache/seata/server/session/SessionHolderTest.java +++ b/server/src/test/java/org/apache/seata/server/session/SessionHolderTest.java @@ -19,9 +19,8 @@ import java.io.File; import java.io.IOException; import org.apache.seata.common.XID; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.core.constants.ConfigurationKeys; -import org.apache.seata.server.store.StoreConfig.SessionMode; -import org.apache.seata.server.session.SessionHolder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; diff --git a/server/src/test/java/org/apache/seata/server/session/redis/RedisDistributedLockerTest.java b/server/src/test/java/org/apache/seata/server/session/redis/RedisDistributedLockerTest.java index d4f38a2bcc3..215571d3eb9 100644 --- a/server/src/test/java/org/apache/seata/server/session/redis/RedisDistributedLockerTest.java +++ b/server/src/test/java/org/apache/seata/server/session/redis/RedisDistributedLockerTest.java @@ -20,6 +20,8 @@ import org.apache.seata.common.XID; import org.apache.seata.common.loader.EnhancedServiceLoader; +import org.apache.seata.common.store.SessionMode; +import org.apache.seata.common.store.StoreMode; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -33,8 +35,6 @@ import org.apache.seata.server.lock.distributed.DistributedLockerFactory; import org.apache.seata.server.session.SessionHolder; import org.apache.seata.server.storage.redis.JedisPooledFactory; -import org.apache.seata.server.store.StoreConfig.SessionMode; -import static org.apache.seata.server.store.StoreConfig.StoreMode; /** * @description redis distributed lock test diff --git a/server/src/test/java/org/apache/seata/server/store/SessionStoreTest.java b/server/src/test/java/org/apache/seata/server/store/SessionStoreTest.java index 50c677df211..23da64b7297 100644 --- a/server/src/test/java/org/apache/seata/server/store/SessionStoreTest.java +++ b/server/src/test/java/org/apache/seata/server/store/SessionStoreTest.java @@ -19,6 +19,7 @@ import java.io.File; import org.apache.seata.common.XID; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.config.Configuration; import org.apache.seata.config.ConfigurationFactory; import org.apache.seata.core.constants.ConfigurationKeys; @@ -31,7 +32,6 @@ import org.apache.seata.server.session.GlobalSession; import org.apache.seata.server.session.SessionHelper; import org.apache.seata.server.session.SessionHolder; -import org.apache.seata.server.store.StoreConfig.SessionMode; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; diff --git a/server/src/test/java/org/apache/seata/server/store/file/FileTransactionStoreManagerTest.java b/server/src/test/java/org/apache/seata/server/store/file/FileTransactionStoreManagerTest.java index d9c8ec08310..dca761e1238 100644 --- a/server/src/test/java/org/apache/seata/server/store/file/FileTransactionStoreManagerTest.java +++ b/server/src/test/java/org/apache/seata/server/store/file/FileTransactionStoreManagerTest.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.List; +import org.apache.seata.common.store.SessionMode; import org.apache.seata.server.session.SessionHolder; import org.assertj.core.util.Files; import org.junit.jupiter.api.AfterAll; @@ -51,7 +52,7 @@ public class FileTransactionStoreManagerTest { @BeforeAll public static void init(ApplicationContext context){ - SessionHolder.init(StoreConfig.SessionMode.FILE); + SessionHolder.init(SessionMode.FILE); } @AfterAll public static void destroy(){