feat: enhance API and session management with Nacos and Redis integration
- Add Nacos registry for service registration and deregistration. - Implement Redis registry for session management with heartbeat and session claiming. - Improve completion service with session handling and request validation. - Enhance WebSocket handling for completion requests with JSON-RPC support. - Add tests for new registry implementations and completion manager functionalities. - Refactor existing code for better readability and maintainability.
This commit is contained in:
36
backend/internal/cluster/nacos_registry_test.go
Normal file
36
backend/internal/cluster/nacos_registry_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package cluster
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseServerAddr(t *testing.T) {
|
||||
host, port, err := parseServerAddr("10.0.0.10:8848")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
if host != "10.0.0.10" || port != 8848 {
|
||||
t.Fatalf("unexpected parse result %s:%d", host, port)
|
||||
}
|
||||
|
||||
host, port, err = parseServerAddr("nacos.internal")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
if host != "nacos.internal" || port != 8848 {
|
||||
t.Fatalf("unexpected parse result %s:%d", host, port)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseServerAddrInvalid(t *testing.T) {
|
||||
if _, _, err := parseServerAddr("10.0.0.10:"); err == nil {
|
||||
t.Fatalf("expected parse error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveRegisterIP(t *testing.T) {
|
||||
if got := ResolveRegisterIP("172.16.1.9", "http://127.0.0.1:8080"); got != "172.16.1.9" {
|
||||
t.Fatalf("expected explicit ip, got %q", got)
|
||||
}
|
||||
if got := ResolveRegisterIP("", "http://10.2.3.4:8080"); got != "10.2.3.4" {
|
||||
t.Fatalf("expected host from instance url, got %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user