Skip to content

Commit

Permalink
Removed logic to get unexported methods from the echovault package in…
Browse files Browse the repository at this point in the history
… all tests.
  • Loading branch information
kelvinmwinuka committed May 30, 2024
1 parent e1d5e82 commit 502e804
Show file tree
Hide file tree
Showing 14 changed files with 3,282 additions and 3,285 deletions.
2,636 changes: 1,318 additions & 1,318 deletions coverage/coverage.out

Large diffs are not rendered by default.

27 changes: 3 additions & 24 deletions echovault/echovault.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ import (

type EchoVault struct {
// clock is an implementation of a time interface that allows mocking of time functions during testing.
clock clock.Clock
getClock func() clock.Clock
clock clock.Clock

// config holds the echovault configuration variables.
config config.Config
Expand All @@ -69,7 +68,7 @@ type EchoVault struct {
rwMutex sync.RWMutex // Mutex as only one process should be able to update this list at a time.
keys []string // string slice of the volatile keys
}
// LFU cache used when eviction policy is allkeys-lfu or volatile-lfu
// LFU cache used when eviction policy is allkeys-lfu or volatile-lfu.
lfuCache struct {
mutex sync.Mutex // Mutex as only one goroutine can edit the LFU cache at a time.
cache eviction.CacheLFU // LFU cache represented by a min head.
Expand All @@ -83,18 +82,14 @@ type EchoVault struct {
// Holds the list of all commands supported by the echovault.
commandsRWMut sync.RWMutex
commands []internal.Command
getCommands func() []internal.Command

raft *raft.Raft // The raft replication layer for the echovault.
memberList *memberlist.MemberList // The memberlist layer for the echovault.

context context.Context

acl *acl.ACL
getACL func() interface{}

pubSub *pubsub.PubSub
getPubSub func() interface{}
pubSub *pubsub.PubSub

snapshotInProgress atomic.Bool // Atomic boolean that's true when actively taking a snapshot.
rewriteAOFInProgress atomic.Bool // Atomic boolean that's true when actively rewriting AOF file is in progress.
Expand Down Expand Up @@ -167,27 +162,11 @@ func NewEchoVault(options ...func(echovault *EchoVault)) (*EchoVault, error) {
log.Printf("loaded plugin %s\n", path)
}

// Function for server commands retrieval
echovault.getCommands = func() []internal.Command {
return echovault.commands
}

// Function for clock retrieval
echovault.getClock = func() clock.Clock {
return echovault.clock
}

// Set up ACL module
echovault.acl = acl.NewACL(echovault.config)
echovault.getACL = func() interface{} {
return echovault.acl
}

// Set up Pub/Sub module
echovault.pubSub = pubsub.NewPubSub()
echovault.getPubSub = func() interface{} {
return echovault.pubSub
}

if echovault.isInCluster() {
echovault.raft = raft.NewRaft(raft.Opts{
Expand Down
21 changes: 1 addition & 20 deletions echovault/echovault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,6 @@ func makeCluster(size int) ([]ClientServerPair, error) {
if err != nil {
return nil, fmt.Errorf("could not open tcp connection: %v", err)
}
for {
// Wait until connection is no longer nil.
if conn != nil {
break
}
}
client := resp.NewConn(conn)

pairs[i] = ClientServerPair{
Expand Down Expand Up @@ -502,13 +496,6 @@ func Test_TLS(t *testing.T) {
t.Error(err)
}

for {
// Break out when the connection is no longer nil.
if conn != nil {
break
}
}

client := resp.NewConn(conn)

// Test that we can set and get a value from the server.
Expand Down Expand Up @@ -624,13 +611,7 @@ func Test_MTLS(t *testing.T) {
})
if err != nil {
t.Error(err)
}

for {
// Break out when the connection is no longer nil.
if conn != nil {
break
}
return
}

client := resp.NewConn(conn)
Expand Down
19 changes: 18 additions & 1 deletion echovault/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"github.com/echovault/echovault/internal"
"github.com/echovault/echovault/internal/clock"
"github.com/echovault/echovault/internal/constants"
"net"
"strings"
Expand Down Expand Up @@ -51,10 +52,10 @@ func (server *EchoVault) getHandlerFuncParams(ctx context.Context, cmd []string,
LoadModule: server.LoadModule,
UnloadModule: server.UnloadModule,
ListModules: server.ListModules,
GetClock: server.getClock,
GetPubSub: server.getPubSub,
GetACL: server.getACL,
GetAllCommands: server.getCommands,
GetClock: server.getClock,
DeleteKey: func(key string) error {
server.storeLock.Lock()
defer server.storeLock.Unlock()
Expand Down Expand Up @@ -142,3 +143,19 @@ func (server *EchoVault) handleCommand(ctx context.Context, message []byte, conn

return nil, errors.New("not cluster leader, cannot carry out command")
}

func (server *EchoVault) getCommands() []internal.Command {
return server.commands
}

func (server *EchoVault) getACL() interface{} {
return server.acl
}

func (server *EchoVault) getPubSub() interface{} {
return server.pubSub
}

func (server *EchoVault) getClock() clock.Clock {
return server.clock
}
Loading

0 comments on commit 502e804

Please sign in to comment.