Skip to content

Commit

Permalink
[3.0] 连接中心 (#655)
Browse files Browse the repository at this point in the history
* 增加 connection-center 连接中心组件

* 新增连接中心抽象和总是创建新连接管理器

* 修复测试

* 修复测试

* 重构代码修复测试

* 新增请求上下文连接管理器

* 修复 Windows 测试

* 修复测试

* 优化代码

* 补充测试

* 新增单例连接管理器

* 新增支持在获取资源时检查状态

* 新增连接池连接管理器

* 重构测试

* 增加 ConnectionCenter 测试

* 支持请求上下文销毁自动释放连接

* 修复测试

* 移除无用配置

* 支持负载均衡

* 修复每日测试

* 完善测试用例,修复一些问题

* 完善测试

* 新事件兼容

* 修复

* 修复一些问题
  • Loading branch information
Yurunsoft authored Dec 21, 2023
1 parent 6a43170 commit 93f3eae
Show file tree
Hide file tree
Showing 79 changed files with 5,184 additions and 7 deletions.
11 changes: 11 additions & 0 deletions .github/print-logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,14 @@
}
}
}

echo '[connection-center]', \PHP_EOL;
$fileName = \dirname(__DIR__) . '/src/Components/connection-center/tests/.runtime/logs/log-' . date('Y-m-d') . '.log';
if (is_file($fileName))
{
echo file_get_contents($fileName), \PHP_EOL;
}
else
{
echo 'Not found!', \PHP_EOL;
}
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ jobs:
- name: Test phar
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-phar
- name: Test connection-center
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-connection-center
- name: Print logs
if: failure()
run: docker exec ${ENV_SERVICE} php .github/print-logs.php
Expand Down Expand Up @@ -189,6 +192,9 @@ jobs:
- name: Test pgsql
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-pgsql
- name: Test connection-center
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-connection-center
- name: Print logs
if: failure()
run: docker exec ${ENV_SERVICE} php .github/print-logs.php
Expand Down Expand Up @@ -291,6 +297,9 @@ jobs:
- name: Test phar
if: ${{ env.test_prepared && always() }}
run: composer test-phar
- name: Test connection-center
if: ${{ env.test_prepared && always() }}
run: composer test-connection-center
- name: Print logs
if: failure()
run: php .github/print-logs.php
Expand Down Expand Up @@ -421,6 +430,9 @@ jobs:
- name: Test phar
if: ${{ env.test_prepared && always() }}
run: composer test-phar
- name: Test connection-center
if: ${{ env.test_prepared && always() }}
run: composer test-connection-center
- name: Print logs
if: failure()
run: php .github/print-logs.php
Expand Down Expand Up @@ -526,6 +538,9 @@ jobs:
- name: Test snowflake
if: ${{ env.test_prepared && always() }}
run: composer test-snowflake
- name: Test connection-center
if: ${{ env.test_prepared && always() }}
run: composer test-connection-center-common
- name: Print logs
if: failure()
run: php .github\print-logs.php
9 changes: 6 additions & 3 deletions .github/workflows/daily-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ jobs:
- name: Test phar
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-phar
- name: Test connection-center
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-connection-center
- name: Print logs
if: failure()
run: docker exec ${ENV_SERVICE} php .github/print-logs.php
Expand All @@ -105,10 +108,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ 8.2 ]
php: [8.2]
swoole:
- version: master
roadrunner: [ 2.7.* ]
roadrunner: [2.7.*]
env:
ENV_SERVICE: php
PHP_VERSION: ${{ matrix.php }}
Expand Down Expand Up @@ -185,4 +188,4 @@ jobs:
run: docker exec ${ENV_SERVICE} composer test-phar
- name: Print logs
if: failure()
run: docker exec ${ENV_SERVICE} php .github/print-logs.php
run: docker exec ${ENV_SERVICE} php .github/print-logs.php
7 changes: 6 additions & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ jobs:
run: |
docker exec ${ENV_SERVICE} ./dev/phpstan.sh phar
- name: Analyse connection-center
if: ${{ env.test_prepared && always() }}
run: |
docker exec ${ENV_SERVICE} ./dev/phpstan.sh connection-center
- name: Save All composer.lock And autoloader-suffix
if: ${{ env.test_prepared && always() }}
run: |
Expand All @@ -194,4 +199,4 @@ jobs:
name: phpstan-cache
path: |
/tmp/base_cache/phpstan
!/tmp/base_cache/phpstan/cache/PHPStan/
!/tmp/base_cache/phpstan/cache/PHPStan/
7 changes: 6 additions & 1 deletion .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
with:
path: /tmp/base_cache/rector
key: ${{ runner.os }}-rector-${{ env.IMAGE_VERSION }}-${{ github.run_id }}
restore-keys: |
restore-keys: |
${{ runner.os }}-rector-${{ env.IMAGE_VERSION }}-
- name: Analyse core
Expand Down Expand Up @@ -167,3 +167,8 @@ jobs:
if: ${{ env.test_prepared && always() }}
run: |
docker exec -w /imi/src/Components/workerman-gateway ${ENV_SERVICE} /imi/vendor/bin/rector process --dry-run
- name: Analyse connection-center
if: ${{ env.test_prepared && always() }}
run: |
docker exec -w /imi/src/Components/connection-center ${ENV_SERVICE} /imi/vendor/bin/rector process --dry-run
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
"test-smarty": "@php vendor/bin/phpunit -c src/Components/smarty/tests/phpunit.xml",
"test-pgsql": "@php src/Components/swoole/bin/swoole-phpunit -c src/Components/pgsql/tests/phpunit.xml",
"test-phar": "@php src/Components/phar/tests/run-tests.php",
"test-connection-center-common": "@php vendor/bin/phpunit -c src/Components/connection-center/tests/phpunit.xml",
"test-connection-center-swoole": "CONNECTION_CENTER_TEST_MODE=swoole php src/Components/swoole/bin/swoole-phpunit -c src/Components/connection-center/tests/phpunit.xml",
"test-connection-center": [
"@composer test-connection-center-common",
"@composer test-connection-center-swoole"
],
"test-components": [
"@composer test-swoole",
"@composer test-workerman",
Expand All @@ -125,7 +131,8 @@
"@composer test-mqtt",
"@composer test-smarty",
"@composer test-pgsql",
"@composer test-phar"
"@composer test-phar",
"@composer test-connection-center"
]
},
"extra": {
Expand Down
6 changes: 5 additions & 1 deletion dev/generate-facade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ src/Cli/bin/imi-cli --app-namespace "Imi\Swoole" --bootstrap "src/Components/swo

src/Cli/bin/imi-cli --app-namespace "Imi" generate/facade "Imi\Server\Session\Session" "SessionManager" --request=true && \

vendor/bin/php-cs-fixer fix
src/Cli/bin/imi-cli --app-namespace "Imi\ConnectionCenter" --bootstrap "src/Components/connection-center/vendor/autoload.php" generate/facade "Imi\ConnectionCenter\Facade\ConnectionCenter" "Imi\ConnectionCenter\AppConnectionCenter" && \

dev/rector.sh core jwt queue swoole connection-center && \

vendor/bin/php-cs-fixer fix
1 change: 1 addition & 0 deletions dev/phpstan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ components=(
"swoole-tracker"
"workerman"
"workerman-gateway"
"connection-center"
)

analyze_component() {
Expand Down
1 change: 1 addition & 0 deletions dev/rector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ components=(
"swoole-tracker"
"workerman"
"workerman-gateway"
"connection-center"
)

analyze_component() {
Expand Down
1 change: 1 addition & 0 deletions dev/test-coverage-actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ elif [[ $testType = "components" ]]; then
"mqtt"
"smarty"
"pgsql"
"connection-center"
)
phpUnitCommands=(
"workerman"
Expand Down
1 change: 1 addition & 0 deletions dev/test-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ swoolePhpUnitCommands=(
"mqtt"
"smarty"
"pgsql"
"connection-center"
)

for name in "${phpUnitCommands[@]}"
Expand Down
1 change: 1 addition & 0 deletions doc/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
* [配置](components/config/index.md)
* [配置读写](components/config/index.md)
* [配置中心](components/config/center.md)
* [连接中心](components/connectionCenter/index.md)
* [连接池](components/pool/index.md)
* [关系型数据库 (Db)](components/db/index.md)
* [数据库驱动](components/db/index.md)
Expand Down
Loading

0 comments on commit 93f3eae

Please sign in to comment.