This is an automated email from the ASF dual-hosted git repository.
liuhongyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 2870eab95e fix(common): align PluginEnum sort values with DB
schema.sql (#6310) (#6311)
2870eab95e is described below
commit 2870eab95ed69700abd918f46a0cbc387b94dd74
Author: bwang <[email protected]>
AuthorDate: Tue Mar 31 15:31:06 2026 +0800
fix(common): align PluginEnum sort values with DB schema.sql (#6310) (#6311)
- Update PluginEnum.KEY_AUTH from 430 to 150 (Authentication phase)
- Update PluginEnum.RESILIENCE4J from 150 to 310 (FaultTolerance phase)
- Update PluginEnum.BASIC_AUTH from 35 to 150 (Authentication phase)
- Update PluginEnum.TCP from 0 to 320 (Proxy phase)
- Update PluginEnum.MQTT from 0 to 125 (Proxy phase)
- Update PluginEnum.MOCK from 8 to 1 (Mock phase)
- Fix H2 schema basicAuth sort from 500 to 150 to match other DBs
- Add parameterized test to prevent future drift between enum and DB
Co-authored-by: bwang <[email protected]>
---
.../src/main/resources/sql-script/h2/schema.sql | 2 +-
.../org/apache/shenyu/common/enums/PluginEnum.java | 12 ++--
.../apache/shenyu/common/enums/PluginEnumTest.java | 65 ++++++++++++++++++++++
3 files changed, 72 insertions(+), 7 deletions(-)
diff --git a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
index dc6a0c3854..16dd2dd278 100644
--- a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
+++ b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql
@@ -597,7 +597,7 @@ INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`,
`config`, `enabled`)
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`) VALUES
('40', 'keyAuth', 'Authentication', 150, '0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`) VALUES
('42','tcp','Proxy', 320, '1');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('43', 'loggingHuaweiLts', 'Logging', 177, '{
"totalSizeInBytes":"104857600","maxBlockMs":"0","ioThreadCount":"1","batchSizeThresholdInBytes":"524288","batchCountThreshold":"4096","lingerMs":"2000","retries":"100","baseRetryBackoffMs":"100","maxRetryBackoffMs":"100","enableLocalTest":"true","setGiveUpExtraLongSingleLog":"false"}',
'0');
-INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('44', 'basicAuth', 'Authentication', 500,
'{"defaultHandleJson":"{\"authorization\":\"test:test123\"}"}', '0');
+INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('44', 'basicAuth', 'Authentication', 150,
'{"defaultHandleJson":"{\"authorization\":\"test:test123\"}"}', '0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('45', 'loggingRabbitMQ', 'Logging', 171,
'{"host":"127.0.0.1","port":5672,"password":"admin","username":"admin","exchangeName":"exchange.logging.plugin","queueName":"queue.logging.plugin","routingKey":"topic.logging","virtualHost":"/","exchangeType":"direct","durable":"true","exclusive":"false","autoDelete":"false"}',
'0');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`,
`enabled`) VALUES ('50', 'aiProxy', 'Ai', 171,
'{"provider":"OpenAI","baseUrl":"https://api.openai.com/v1/chat/completions","model":"gpt-4o-mini","apiKey":"your_api_key","temperature":"0.5","maxTokens":"1000","stream":"false","proxyEnabled":"false","fallbackEnabled":"false","fallbackProvider":"OpenAI","fallbackModel":"gpt-4.1","prompt":""}',
'0');
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
index 0ef7c419b8..b184a0a235 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
@@ -35,17 +35,17 @@ public enum PluginEnum {
/**
* Tcp plugin enum.
*/
- TCP(0, 0, "tcp"),
+ TCP(320, 0, "tcp"),
/**
* Mqtt plugin enum.
*/
- MQTT(0, 0, "mqtt"),
+ MQTT(125, 0, "mqtt"),
/**
* the mock plugin enum.
*/
- MOCK(8, 0, "mock"),
+ MOCK(1, 0, "mock"),
/**
* the cache plugin enum.
@@ -145,7 +145,7 @@ public enum PluginEnum {
/**
* Resilience4J plugin enum.
*/
- RESILIENCE4J(150, 0, "resilience4j"),
+ RESILIENCE4J(310, 0, "resilience4j"),
/**
* Logging console plugin enum.
@@ -280,7 +280,7 @@ public enum PluginEnum {
/**
* Key-auth plugin enum.
*/
- KEY_AUTH(430, 0, "keyAuth"),
+ KEY_AUTH(150, 0, "keyAuth"),
/**
* Ai-proxy plugin enum.
@@ -300,7 +300,7 @@ public enum PluginEnum {
/**
* Basic-auth plugin enum.
*/
- BASIC_AUTH(35, 0, "basicAuth");
+ BASIC_AUTH(150, 0, "basicAuth");
/**
* When the application starts, the plugin is cached and we can obtained
by name.
diff --git
a/shenyu-common/src/test/java/org/apache/shenyu/common/enums/PluginEnumTest.java
b/shenyu-common/src/test/java/org/apache/shenyu/common/enums/PluginEnumTest.java
index 03efac4c44..a221bb502d 100644
---
a/shenyu-common/src/test/java/org/apache/shenyu/common/enums/PluginEnumTest.java
+++
b/shenyu-common/src/test/java/org/apache/shenyu/common/enums/PluginEnumTest.java
@@ -18,6 +18,8 @@
package org.apache.shenyu.common.enums;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
import java.util.Arrays;
import java.util.List;
@@ -52,6 +54,69 @@ public final class PluginEnumTest {
.forEach(pluginEnum -> assertEquals(pluginEnum.getCode(),
PluginEnum.getPluginEnumByName(pluginEnum.getName()).getCode()));
}
+ /**
+ * Verify that PluginEnum.getCode() matches the sort values in
db/init/mysql/schema.sql.
+ * This prevents drift between the Java enum and database initialization
scripts.
+ *
+ * @param pluginName plugin name
+ * @param expectedSort expected sort value from schema.sql
+ */
+ @ParameterizedTest
+ @CsvSource({
+ "sign, 20",
+ "waf, 50",
+ "rateLimiter, 60",
+ "contextPath, 80",
+ "rewrite, 90",
+ "cryptorRequest, 100",
+ "redirect, 110",
+ "request, 120",
+ "generalContext, 125",
+ "hystrix, 130",
+ "sentinel, 140",
+ "resilience4j, 310",
+ "loggingConsole, 160",
+ "loggingRocketMQ, 170",
+ "loggingRabbitMQ, 171",
+ "loggingAliyunSls, 175",
+ "loggingTencentCls, 176",
+ "loggingHuaweiLts, 177",
+ "loggingKafka, 180",
+ "loggingPulsar, 185",
+ "loggingElasticSearch, 190",
+ "loggingClickHouse, 195",
+ "divide, 200",
+ "websocket, 200",
+ "modifyResponse, 220",
+ "dubbo, 310",
+ "sofa, 310",
+ "tars, 310",
+ "grpc, 310",
+ "motan, 310",
+ "cryptorResponse, 410",
+ "mock, 1",
+ "jwt, 30",
+ "oauth2, 40",
+ "casdoor, 40",
+ "cache, 10",
+ "mqtt, 125",
+ "keyAuth, 150",
+ "basicAuth, 150",
+ "tcp, 320",
+ "aiProxy, 199",
+ "aiTokenLimiter, 171",
+ "aiPrompt, 170",
+ "aiRequestTransformer, 65",
+ "aiResponseTransformer, 66",
+ "mcpServer, 180"
+ })
+ public void pluginEnumSortShouldMatchDbSchema(final String pluginName,
final int expectedSort) {
+ PluginEnum pluginEnum = PluginEnum.getPluginEnumByName(pluginName);
+ assertEquals(expectedSort, pluginEnum.getCode(),
+ String.format("PluginEnum.%s sort value (%d) does not match DB
schema.sql sort value (%d). "
+ + "Please keep PluginEnum and schema.sql in sync.",
pluginEnum.name(), pluginEnum.getCode(), expectedSort));
+ }
+
@Test
public void testGetRole() {
Arrays.stream(PluginEnum.values())