Start raft and memberlist layers in NewEchoVault. Return error fron NewEchoVault function when TLS config does not match certificate options provided

This commit is contained in:
Kelvin Mwinuka
2024-04-01 23:24:22 +08:00
parent ede342a452
commit 389c871781
20 changed files with 943 additions and 943 deletions

View File

@@ -46,12 +46,16 @@ func main() {
cancelCh := make(chan os.Signal, 1)
signal.Notify(cancelCh, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
server := echovault.NewEchoVault(
server, err := echovault.NewEchoVault(
echovault.WithContext(ctx),
echovault.WithConfig(conf),
echovault.WithCommands(commands.All()),
)
if err != nil {
log.Fatal(err)
}
go server.Start()
<-cancelCh

File diff suppressed because it is too large Load Diff

View File

@@ -49,217 +49,217 @@ services:
networks:
- testnet
# cluster_node_1:
# container_name: cluster_node_1
# build:
# context: .
# dockerfile: Dockerfile.dev
# environment:
# - PORT=7480
# - RAFT_PORT=8000
# - ML_PORT=7946
# - SERVER_ID=1
# - JOIN_ADDR=cluster_node_2:7946
# - DATA_DIR=/var/lib/echovault
# - IN_MEMORY=false
# - TLS=false
# - MTLS=false
# - BOOTSTRAP_CLUSTER=true
# - ACL_CONFIG=/etc/config/echovault/acl.yml
# - REQUIRE_PASS=false
# - FORWARD_COMMAND=true
# - SNAPSHOT_THRESHOLD=1000
# - SNAPSHOT_INTERVAL=5m30s
# - RESTORE_SNAPSHOT=false
# - RESTORE_AOF=false
# - AOF_SYNC_STRATEGY=everysec
# - MAX_MEMORY=100mb
# - EVICTION_POLICY=noeviction
# - EVICTION_SAMPLE=20
# - EVICTION_INTERVAL=100ms
# # List of echovault cert/key pairs
# - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key
# - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key
# # List of client certificate authorities
# - CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
# ports:
# - "7481:7480"
# - "7945:7946"
# - "8000:8000"
# volumes:
# - ./config/acl.yml:/etc/config/echovault/acl.yml
# - ./volumes/cluster_node_1:/var/lib/echovault
# networks:
# - testnet
#
# cluster_node_2:
# container_name: cluster_node_2
# build:
# context: .
# dockerfile: Dockerfile.dev
# environment:
# - PORT=7480
# - RAFT_PORT=8000
# - ML_PORT=7946
# - SERVER_ID=2
# - JOIN_ADDR=cluster_node_3:7946
# - DATA_DIR=/var/lib/echovault
# - IN_MEMORY=false
# - TLS=false
# - MTLS=false
# - BOOTSTRAP_CLUSTER=false
# - ACL_CONFIG=/etc/config/echovault/acl.yml
# - REQUIRE_PASS=false
# - FORWARD_COMMAND=true
# - SNAPSHOT_THRESHOLD=1000
# - SNAPSHOT_INTERVAL=5m30s
# - RESTORE_SNAPSHOT=false
# - RESTORE_AOF=false
# - AOF_SYNC_STRATEGY=everysec
# - MAX_MEMORY=100mb
# - EVICTION_POLICY=noeviction
# - EVICTION_SAMPLE=20
# - EVICTION_INTERVAL=100ms
# # List of echovault cert/key pairs
# - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key
# - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key
# # List of client certificate authorities
# - CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
# ports:
# - "7482:7480"
# - "7947:7946"
# - "8001:8000"
# volumes:
# - ./config/acl.yml:/etc/config/echovault/acl.yml
# - ./volumes/cluster_node_2:/var/lib/echovault
# networks:
# - testnet
#
# cluster_node_3:
# container_name: cluster_node_3
# build:
# context: .
# dockerfile: Dockerfile.dev
# environment:
# - PORT=7480
# - RAFT_PORT=8000
# - ML_PORT=7946
# - SERVER_ID=3
# - JOIN_ADDR=cluster_node_4:7946
# - DATA_DIR=/var/lib/echovault
# - IN_MEMORY=false
# - TLS=false
# - MTLS=false
# - BOOTSTRAP_CLUSTER=false
# - ACL_CONFIG=/etc/config/echovault/acl.yml
# - REQUIRE_PASS=false
# - FORWARD_COMMAND=true
# - SNAPSHOT_THRESHOLD=1000
# - SNAPSHOT_INTERVAL=5m30s
# - RESTORE_SNAPSHOT=false
# - RESTORE_AOF=false
# - AOF_SYNC_STRATEGY=everysec
# - MAX_MEMORY=100mb
# - EVICTION_POLICY=noeviction
# - EVICTION_SAMPLE=20
# - EVICTION_INTERVAL=100ms
# # List of echovault cert/key pairs
# - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key
# - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key
# # List of client certificate authorities
# - CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
# ports:
# - "7483:7480"
# - "7948:7946"
# - "8002:8000"
# volumes:
# - ./config/acl.yml:/etc/config/echovault/acl.yml
# - ./volumes/cluster_node_3:/var/lib/echovault
# networks:
# - testnet
#
# cluster_node_4:
# container_name: cluster_node_4
# build:
# context: .
# dockerfile: Dockerfile.dev
# environment:
# - PORT=7480
# - RAFT_PORT=8000
# - ML_PORT=7946
# - SERVER_ID=4
# - JOIN_ADDR=cluster_node_5:7946
# - DATA_DIR=/var/lib/echovault
# - IN_MEMORY=false
# - TLS=false
# - MTLS=false
# - BOOTSTRAP_CLUSTER=false
# - ACL_CONFIG=/etc/config/echovault/acl.yml
# - REQUIRE_PASS=false
# - FORWARD_COMMAND=true
# - SNAPSHOT_THRESHOLD=1000
# - SNAPSHOT_INTERVAL=5m30s
# - RESTORE_SNAPSHOT=false
# - RESTORE_AOF=false
# - AOF_SYNC_STRATEGY=everysec
# - MAX_MEMORY=100mb
# - EVICTION_POLICY=noeviction
# - EVICTION_SAMPLE=20
# - EVICTION_INTERVAL=100ms
# # List of echovault cert/key pairs
# - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key
# - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key
# # List of client certificate authorities
# - CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
# ports:
# - "7484:7480"
# - "7949:7946"
# - "8003:8000"
# volumes:
# - ./config/acl.yml:/etc/config/echovault/acl.yml
# - ./volumes/cluster_node_4:/var/lib/echovault
# networks:
# - testnet
#
# cluster_node_5:
# container_name: cluster_node_5
# build:
# context: .
# dockerfile: Dockerfile.dev
# environment:
# - PORT=7480
# - RAFT_PORT=8000
# - ML_PORT=7946
# - SERVER_ID=5
# - JOIN_ADDR=cluster_node_1:7946
# - DATA_DIR=/var/lib/echovault
# - IN_MEMORY=false
# - TLS=false
# - MTLS=false
# - BOOTSTRAP_CLUSTER=false
# - ACL_CONFIG=/etc/config/echovault/acl.yml
# - REQUIRE_PASS=false
# - FORWARD_COMMAND=true
# - SNAPSHOT_THRESHOLD=1000
# - SNAPSHOT_INTERVAL=5m30s
# - RESTORE_SNAPSHOT=false
# - RESTORE_AOF=false
# - AOF_SYNC_STRATEGY=everysec
# - MAX_MEMORY=100mb
# - EVICTION_POLICY=noeviction
# - EVICTION_SAMPLE=20
# - EVICTION_INTERVAL=100ms
# # List of echovault cert/key pairs
# - CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key
# - CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key
# # List of client certificate authorities
# - CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
# ports:
# - "7485:7480"
# - "7950:7946"
# - "8004:8000"
# volumes:
# - ./config/acl.yml:/etc/config/echovault/acl.yml
# - ./volumes/cluster_node_5:/var/lib/echovault
# networks:
# - testnet
cluster_node_1:
container_name: cluster_node_1
build:
context: .
dockerfile: Dockerfile.dev
environment:
- PORT=7480
- RAFT_PORT=8000
- ML_PORT=7946
- SERVER_ID=1
- JOIN_ADDR=cluster_node_2:7946
- DATA_DIR=/var/lib/echovault
- IN_MEMORY=false
- TLS=false
- MTLS=false
- BOOTSTRAP_CLUSTER=true
- ACL_CONFIG=/etc/config/echovault/acl.yml
- REQUIRE_PASS=false
- FORWARD_COMMAND=true
- SNAPSHOT_THRESHOLD=1000
- SNAPSHOT_INTERVAL=5m30s
- RESTORE_SNAPSHOT=false
- RESTORE_AOF=false
- AOF_SYNC_STRATEGY=everysec
- MAX_MEMORY=100mb
- EVICTION_POLICY=noeviction
- EVICTION_SAMPLE=20
- EVICTION_INTERVAL=100ms
# List of echovault cert/key pairs
- CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key
- CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key
# List of client certificate authorities
- CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
ports:
- "7481:7480"
- "7945:7946"
- "8000:8000"
volumes:
- ./config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/cluster_node_1:/var/lib/echovault
networks:
- testnet
cluster_node_2:
container_name: cluster_node_2
build:
context: .
dockerfile: Dockerfile.dev
environment:
- PORT=7480
- RAFT_PORT=8000
- ML_PORT=7946
- SERVER_ID=2
- JOIN_ADDR=cluster_node_3:7946
- DATA_DIR=/var/lib/echovault
- IN_MEMORY=false
- TLS=false
- MTLS=false
- BOOTSTRAP_CLUSTER=false
- ACL_CONFIG=/etc/config/echovault/acl.yml
- REQUIRE_PASS=false
- FORWARD_COMMAND=true
- SNAPSHOT_THRESHOLD=1000
- SNAPSHOT_INTERVAL=5m30s
- RESTORE_SNAPSHOT=false
- RESTORE_AOF=false
- AOF_SYNC_STRATEGY=everysec
- MAX_MEMORY=100mb
- EVICTION_POLICY=noeviction
- EVICTION_SAMPLE=20
- EVICTION_INTERVAL=100ms
# List of echovault cert/key pairs
- CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key
- CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key
# List of client certificate authorities
- CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
ports:
- "7482:7480"
- "7947:7946"
- "8001:8000"
volumes:
- ./config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/cluster_node_2:/var/lib/echovault
networks:
- testnet
cluster_node_3:
container_name: cluster_node_3
build:
context: .
dockerfile: Dockerfile.dev
environment:
- PORT=7480
- RAFT_PORT=8000
- ML_PORT=7946
- SERVER_ID=3
- JOIN_ADDR=cluster_node_4:7946
- DATA_DIR=/var/lib/echovault
- IN_MEMORY=false
- TLS=false
- MTLS=false
- BOOTSTRAP_CLUSTER=false
- ACL_CONFIG=/etc/config/echovault/acl.yml
- REQUIRE_PASS=false
- FORWARD_COMMAND=true
- SNAPSHOT_THRESHOLD=1000
- SNAPSHOT_INTERVAL=5m30s
- RESTORE_SNAPSHOT=false
- RESTORE_AOF=false
- AOF_SYNC_STRATEGY=everysec
- MAX_MEMORY=100mb
- EVICTION_POLICY=noeviction
- EVICTION_SAMPLE=20
- EVICTION_INTERVAL=100ms
# List of echovault cert/key pairs
- CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key
- CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key
# List of client certificate authorities
- CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
ports:
- "7483:7480"
- "7948:7946"
- "8002:8000"
volumes:
- ./config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/cluster_node_3:/var/lib/echovault
networks:
- testnet
cluster_node_4:
container_name: cluster_node_4
build:
context: .
dockerfile: Dockerfile.dev
environment:
- PORT=7480
- RAFT_PORT=8000
- ML_PORT=7946
- SERVER_ID=4
- JOIN_ADDR=cluster_node_5:7946
- DATA_DIR=/var/lib/echovault
- IN_MEMORY=false
- TLS=false
- MTLS=false
- BOOTSTRAP_CLUSTER=false
- ACL_CONFIG=/etc/config/echovault/acl.yml
- REQUIRE_PASS=false
- FORWARD_COMMAND=true
- SNAPSHOT_THRESHOLD=1000
- SNAPSHOT_INTERVAL=5m30s
- RESTORE_SNAPSHOT=false
- RESTORE_AOF=false
- AOF_SYNC_STRATEGY=everysec
- MAX_MEMORY=100mb
- EVICTION_POLICY=noeviction
- EVICTION_SAMPLE=20
- EVICTION_INTERVAL=100ms
# List of echovault cert/key pairs
- CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key
- CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key
# List of client certificate authorities
- CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
ports:
- "7484:7480"
- "7949:7946"
- "8003:8000"
volumes:
- ./config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/cluster_node_4:/var/lib/echovault
networks:
- testnet
cluster_node_5:
container_name: cluster_node_5
build:
context: .
dockerfile: Dockerfile.dev
environment:
- PORT=7480
- RAFT_PORT=8000
- ML_PORT=7946
- SERVER_ID=5
- JOIN_ADDR=cluster_node_1:7946
- DATA_DIR=/var/lib/echovault
- IN_MEMORY=false
- TLS=false
- MTLS=false
- BOOTSTRAP_CLUSTER=false
- ACL_CONFIG=/etc/config/echovault/acl.yml
- REQUIRE_PASS=false
- FORWARD_COMMAND=true
- SNAPSHOT_THRESHOLD=1000
- SNAPSHOT_INTERVAL=5m30s
- RESTORE_SNAPSHOT=false
- RESTORE_AOF=false
- AOF_SYNC_STRATEGY=everysec
- MAX_MEMORY=100mb
- EVICTION_POLICY=noeviction
- EVICTION_SAMPLE=20
- EVICTION_INTERVAL=100ms
# List of echovault cert/key pairs
- CERT_KEY_PAIR_1=/etc/ssl/certs/echovault/echovault/server1.crt,/etc/ssl/certs/echovault/echovault/server1.key
- CERT_KEY_PAIR_2=/etc/ssl/certs/echovault/echovault/server2.crt,/etc/ssl/certs/echovault/echovault/server2.key
# List of client certificate authorities
- CLIENT_CA_1=/etc/ssl/certs/echovault/client/rootCA.crt
ports:
- "7485:7480"
- "7950:7946"
- "8004:8000"
volumes:
- ./config/acl.yml:/etc/config/echovault/acl.yml
- ./volumes/cluster_node_5:/var/lib/echovault
networks:
- testnet

View File

@@ -34,7 +34,7 @@ var timeNow = func() time.Time {
}
func TestEchoVault_DEL(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
EvictionPolicy: constants.NoEviction,
@@ -81,7 +81,7 @@ func TestEchoVault_DEL(t *testing.T) {
}
func TestEchoVault_EXPIRE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
EvictionPolicy: constants.NoEviction,
@@ -258,7 +258,7 @@ func TestEchoVault_EXPIRE(t *testing.T) {
}
func TestEchoVault_EXPIREAT(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
EvictionPolicy: constants.NoEviction,
@@ -446,7 +446,7 @@ func TestEchoVault_EXPIREAT(t *testing.T) {
}
func TestEchoVault_EXPIRETIME(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
EvictionPolicy: constants.NoEviction,
@@ -519,7 +519,7 @@ func TestEchoVault_EXPIRETIME(t *testing.T) {
}
func TestEchoVault_GET(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
EvictionPolicy: constants.NoEviction,
@@ -566,7 +566,7 @@ func TestEchoVault_GET(t *testing.T) {
}
func TestEchoVault_MGET(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
EvictionPolicy: constants.NoEviction,
@@ -623,7 +623,7 @@ func TestEchoVault_MGET(t *testing.T) {
}
func TestEchoVault_SET(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
EvictionPolicy: constants.NoEviction,
@@ -774,7 +774,7 @@ func TestEchoVault_SET(t *testing.T) {
}
func TestEchoVault_MSET(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
EvictionPolicy: constants.NoEviction,
@@ -809,7 +809,7 @@ func TestEchoVault_MSET(t *testing.T) {
}
func TestEchoVault_PERSIST(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
EvictionPolicy: constants.NoEviction,
@@ -869,7 +869,7 @@ func TestEchoVault_PERSIST(t *testing.T) {
}
func TestEchoVault_TTL(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
EvictionPolicy: constants.NoEviction,

View File

@@ -24,7 +24,7 @@ import (
)
func TestEchoVault_HDEL(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -91,7 +91,7 @@ func TestEchoVault_HDEL(t *testing.T) {
}
func TestEchoVault_HEXISTS(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -150,7 +150,7 @@ func TestEchoVault_HEXISTS(t *testing.T) {
}
func TestEchoVault_HGETALL(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -212,7 +212,7 @@ func TestEchoVault_HGETALL(t *testing.T) {
}
func TestEchoVault_HINCRBY(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -326,7 +326,7 @@ func TestEchoVault_HINCRBY(t *testing.T) {
}
func TestEchoVault_HKEYS(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -386,7 +386,7 @@ func TestEchoVault_HKEYS(t *testing.T) {
}
func TestEchoVault_HLEN(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -441,7 +441,7 @@ func TestEchoVault_HLEN(t *testing.T) {
}
func TestEchoVault_HRANDFIELD(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -575,7 +575,7 @@ func TestEchoVault_HRANDFIELD(t *testing.T) {
}
func TestEchoVault_HSET(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -665,7 +665,7 @@ func TestEchoVault_HSET(t *testing.T) {
}
func TestEchoVault_HSTRLEN(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -734,7 +734,7 @@ func TestEchoVault_HSTRLEN(t *testing.T) {
}
func TestEchoVault_HVALS(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",

View File

@@ -15,7 +15,6 @@
package echovault
import (
"fmt"
"github.com/echovault/echovault/internal/config"
"github.com/echovault/echovault/pkg/commands"
"github.com/echovault/echovault/pkg/constants"
@@ -24,7 +23,7 @@ import (
)
func TestEchoVault_LLEN(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -83,7 +82,7 @@ func TestEchoVault_LLEN(t *testing.T) {
}
func TestEchoVault_LINDEX(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -171,7 +170,6 @@ func TestEchoVault_LINDEX(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
got, err := server.LINDEX(tt.key, tt.index)
if (err != nil) != tt.wantErr {
fmt.Println("GOT: ", got, "ERROR: ", err, "KEY: ", tt.key)
t.Errorf("LINDEX() error = %v, wantErr %v", err, tt.wantErr)
return
}
@@ -183,7 +181,7 @@ func TestEchoVault_LINDEX(t *testing.T) {
}
func TestEchoVault_LMOVE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -355,7 +353,7 @@ func TestEchoVault_LMOVE(t *testing.T) {
}
func TestEchoVault_POP(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -427,7 +425,7 @@ func TestEchoVault_POP(t *testing.T) {
}
func TestEchoVault_LPUSH(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -504,7 +502,7 @@ func TestEchoVault_LPUSH(t *testing.T) {
}
func TestEchoVault_RPUSH(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -561,7 +559,7 @@ func TestEchoVault_RPUSH(t *testing.T) {
}
func TestEchoVault_LRANGE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -682,7 +680,7 @@ func TestEchoVault_LRANGE(t *testing.T) {
}
func TestEchoVault_LREM(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -749,7 +747,7 @@ func TestEchoVault_LREM(t *testing.T) {
}
func TestEchoVault_LSET(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -856,7 +854,7 @@ func TestEchoVault_LSET(t *testing.T) {
}
func TestEchoVault_LTRIM(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",

View File

@@ -25,7 +25,7 @@ import (
)
func TestEchoVault_SADD(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -84,7 +84,7 @@ func TestEchoVault_SADD(t *testing.T) {
}
func TestEchoVault_SCARD(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -139,7 +139,7 @@ func TestEchoVault_SCARD(t *testing.T) {
}
func TestEchoVault_SDIFF(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -233,7 +233,7 @@ func TestEchoVault_SDIFF(t *testing.T) {
}
func TestEchoVault_SDIFFSTORE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -328,7 +328,7 @@ func TestEchoVault_SDIFFSTORE(t *testing.T) {
}
func TestEchoVault_SINTER(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -422,7 +422,7 @@ func TestEchoVault_SINTER(t *testing.T) {
}
func TestEchoVault_SINTERCARD(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -528,7 +528,7 @@ func TestEchoVault_SINTERCARD(t *testing.T) {
}
func TestEchoVault_SINTERSTORE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -623,7 +623,7 @@ func TestEchoVault_SINTERSTORE(t *testing.T) {
}
func TestEchoVault_SISMEMBER(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -682,7 +682,7 @@ func TestEchoVault_SISMEMBER(t *testing.T) {
}
func TestEchoVault_SMEMBERS(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -742,7 +742,7 @@ func TestEchoVault_SMEMBERS(t *testing.T) {
}
func TestEchoVault_SMISMEMBER(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -820,7 +820,7 @@ func TestEchoVault_SMISMEMBER(t *testing.T) {
}
func TestEchoVault_SMOVE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -906,7 +906,7 @@ func TestEchoVault_SMOVE(t *testing.T) {
}
func TestEchoVault_SPOP(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -959,7 +959,7 @@ func TestEchoVault_SPOP(t *testing.T) {
}
func TestEchoVault_SRANDMEMBER(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -1028,7 +1028,7 @@ func TestEchoVault_SRANDMEMBER(t *testing.T) {
}
func TestEchoVault_SREM(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -1087,7 +1087,7 @@ func TestEchoVault_SREM(t *testing.T) {
}
func TestEchoVault_SUNION(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -1174,7 +1174,7 @@ func TestEchoVault_SUNION(t *testing.T) {
}
func TestEchoVault_SUNIONSTORE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",

View File

@@ -27,7 +27,7 @@ import (
)
func TestEchoVault_ZADD(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -253,7 +253,7 @@ func TestEchoVault_ZADD(t *testing.T) {
}
func TestEchoVault_ZCARD(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -316,7 +316,7 @@ func TestEchoVault_ZCARD(t *testing.T) {
}
func TestEchoVault_ZCOUNT(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -417,7 +417,7 @@ func TestEchoVault_ZCOUNT(t *testing.T) {
}
func TestEchoVault_ZDIFF(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -569,7 +569,7 @@ func TestEchoVault_ZDIFF(t *testing.T) {
}
func TestEchoVault_ZDIFFSTORE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -690,7 +690,7 @@ func TestEchoVault_ZDIFFSTORE(t *testing.T) {
}
func TestEchoVault_ZINCRBY(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -840,7 +840,7 @@ func TestEchoVault_ZINCRBY(t *testing.T) {
}
func TestEchoVault_ZINTER(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -1153,7 +1153,7 @@ func TestEchoVault_ZINTER(t *testing.T) {
}
func TestEchoVault_ZINTERSTORE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -1480,7 +1480,7 @@ func TestEchoVault_ZINTERSTORE(t *testing.T) {
}
func TestEchoVault_ZLEXCOUNT(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -1573,7 +1573,7 @@ func TestEchoVault_ZLEXCOUNT(t *testing.T) {
}
func TestEchoVault_ZMPOP(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -1729,7 +1729,7 @@ func TestEchoVault_ZMPOP(t *testing.T) {
}
func TestEchoVault_ZMSCORE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -1810,7 +1810,7 @@ func TestEchoVault_ZMSCORE(t *testing.T) {
}
func TestEchoVault_ZPOP(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -1918,7 +1918,7 @@ func TestEchoVault_ZPOP(t *testing.T) {
}
func TestEchoVault_ZRANDMEMBER(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -1994,7 +1994,7 @@ func TestEchoVault_ZRANDMEMBER(t *testing.T) {
}
func TestEchoVault_ZRANGE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -2159,7 +2159,7 @@ func TestEchoVault_ZRANGE(t *testing.T) {
}
func TestEchoVault_ZRANGESTORE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -2373,7 +2373,7 @@ func TestEchoVault_ZRANGESTORE(t *testing.T) {
}
func TestEchoVault_ZRANK(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -2472,7 +2472,7 @@ func TestEchoVault_ZRANK(t *testing.T) {
}
func TestEchoVault_ZREM(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -2543,7 +2543,7 @@ func TestEchoVault_ZREM(t *testing.T) {
}
func TestEchoVault_ZREMRANGEBYSCORE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -2615,7 +2615,7 @@ func TestEchoVault_ZREMRANGEBYSCORE(t *testing.T) {
}
func TestEchoVault_ZSCORE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -2695,7 +2695,7 @@ func TestEchoVault_ZSCORE(t *testing.T) {
}
func TestEchoVault_ZUNION(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -3033,7 +3033,7 @@ func TestEchoVault_ZUNION(t *testing.T) {
}
func TestEchoVault_ZUNIONSTORE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",

View File

@@ -22,7 +22,7 @@ import (
)
func TestEchoVault_SUBSTR(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -183,7 +183,7 @@ func TestEchoVault_SUBSTR(t *testing.T) {
}
func TestEchoVault_SETRANGE(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",
@@ -273,7 +273,7 @@ func TestEchoVault_SETRANGE(t *testing.T) {
}
func TestEchoVault_STRLEN(t *testing.T) {
server := NewEchoVault(
server, _ := NewEchoVault(
WithCommands(commands.All()),
WithConfig(config.Config{
DataDir: "",

View File

@@ -107,7 +107,7 @@ func WithCommands(commands []types.Command) func(echovault *EchoVault) {
}
}
func NewEchoVault(options ...func(echovault *EchoVault)) *EchoVault {
func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error) {
echovault := &EchoVault{
context: context.Background(),
commands: make([]types.Command, 0),
@@ -232,7 +232,39 @@ func NewEchoVault(options ...func(echovault *EchoVault)) *EchoVault {
}()
}
return echovault
if echovault.config.TLS && len(echovault.config.CertKeyPairs) <= 0 {
return nil, errors.New("must provide certificate and key file paths for TLS mode")
}
if echovault.isInCluster() {
// Initialise raft and memberlist
echovault.raft.RaftInit(echovault.context)
echovault.memberList.MemberListInit(echovault.context)
if echovault.raft.IsRaftLeader() {
echovault.initialiseCaches()
}
}
if !echovault.isInCluster() {
echovault.initialiseCaches()
// Restore from AOF by default if it's enabled
if echovault.config.RestoreAOF {
err := echovault.aofEngine.Restore()
if err != nil {
log.Println(err)
}
}
// Restore from snapshot if snapshot restore is enabled and AOF restore is disabled
if echovault.config.RestoreSnapshot && !echovault.config.RestoreAOF {
err := echovault.snapshotEngine.Restore()
if err != nil {
log.Println(err)
}
}
}
return echovault, nil
}
func (server *EchoVault) startTCP() {
@@ -385,41 +417,6 @@ func (server *EchoVault) handleConnection(conn net.Conn) {
}
func (server *EchoVault) Start() {
conf := server.config
if conf.TLS && len(conf.CertKeyPairs) <= 0 {
log.Fatal("must provide certificate and key file paths for TLS mode")
return
}
if server.isInCluster() {
// Initialise raft and memberlist
server.raft.RaftInit(server.context)
server.memberList.MemberListInit(server.context)
if server.raft.IsRaftLeader() {
server.initialiseCaches()
}
}
if !server.isInCluster() {
server.initialiseCaches()
// Restore from AOF by default if it's enabled
if conf.RestoreAOF {
err := server.aofEngine.Restore()
if err != nil {
log.Println(err)
}
}
// Restore from snapshot if snapshot restore is enabled and AOF restore is disabled
if conf.RestoreSnapshot && !conf.RestoreAOF {
err := server.snapshotEngine.Restore()
if err != nil {
log.Println(err)
}
}
}
server.startTCP()
}

View File

@@ -54,7 +54,7 @@ func setUpServer(bindAddr string, port uint16, requirePass bool, aclConfig strin
AclConfig: aclConfig,
}
mockServer := echovault.NewEchoVault(
mockServer, _ := echovault.NewEchoVault(
echovault.WithConfig(conf),
echovault.WithCommands(Commands()),
)

View File

@@ -26,7 +26,7 @@ import (
)
func Test_CommandsHandler(t *testing.T) {
mockServer := echovault.NewEchoVault(
mockServer, _ := echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
EvictionPolicy: constants.NoEviction,

View File

@@ -28,7 +28,7 @@ import (
var mockServer *echovault.EchoVault
func init() {
mockServer = echovault.NewEchoVault(
mockServer, _ = echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
EvictionPolicy: constants.NoEviction,

View File

@@ -35,7 +35,7 @@ type KeyData struct {
}
func init() {
mockServer = echovault.NewEchoVault(
mockServer, _ = echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
EvictionPolicy: constants.NoEviction,

View File

@@ -30,7 +30,7 @@ import (
var mockServer *echovault.EchoVault
func init() {
mockServer = echovault.NewEchoVault(
mockServer, _ = echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
EvictionPolicy: constants.NoEviction,

View File

@@ -29,7 +29,7 @@ import (
var mockServer *echovault.EchoVault
func init() {
mockServer = echovault.NewEchoVault(
mockServer, _ = echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
EvictionPolicy: constants.NoEviction,

View File

@@ -44,7 +44,7 @@ func init() {
}
func setUpServer(bindAddr string, port uint16) *echovault.EchoVault {
return echovault.NewEchoVault(
server, _ := echovault.NewEchoVault(
echovault.WithCommands(Commands()),
echovault.WithConfig(config.Config{
BindAddr: bindAddr,
@@ -53,6 +53,7 @@ func setUpServer(bindAddr string, port uint16) *echovault.EchoVault {
EvictionPolicy: constants.NoEviction,
}),
)
return server
}
func Test_HandleSubscribe(t *testing.T) {

View File

@@ -31,7 +31,7 @@ import (
var mockServer *echovault.EchoVault
func init() {
mockServer = echovault.NewEchoVault(
mockServer, _ = echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
EvictionPolicy: constants.NoEviction,

View File

@@ -33,7 +33,7 @@ import (
var mockServer *echovault.EchoVault
func init() {
mockServer = echovault.NewEchoVault(
mockServer, _ = echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
EvictionPolicy: constants.NoEviction,

View File

@@ -31,7 +31,7 @@ import (
var mockServer *echovault.EchoVault
func init() {
mockServer = echovault.NewEchoVault(
mockServer, _ = echovault.NewEchoVault(
echovault.WithConfig(config.Config{
DataDir: "",
EvictionPolicy: constants.NoEviction,