Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Mihir Gandhi <[email protected]>
  • Loading branch information
cisse21 and mihir20 committed Aug 9, 2024
1 parent 69f170e commit 4edc80d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
21 changes: 9 additions & 12 deletions services/dedup/badger/badger_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package badger

import (
"os"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -18,9 +17,7 @@ func Test_Badger(t *testing.T) {
logger.Reset()
misc.Init()

dbPath := os.TempDir() + "/dedup_test"
defer func() { _ = os.RemoveAll(dbPath) }()
_ = os.RemoveAll(dbPath)
dbPath := t.TempDir()
conf := config.New()
t.Setenv("RUDDER_TMPDIR", dbPath)
badger := NewBadgerDB(conf, stats.NOP, DefaultPath())
Expand All @@ -29,23 +26,23 @@ func Test_Badger(t *testing.T) {
t.Run("Same messageID should be deduped from badger", func(t *testing.T) {
key1 := types.KeyValue{Key: "a", Value: 1, WorkspaceId: "test"}
key2 := types.KeyValue{Key: "a", Value: 1, WorkspaceId: "test"}
found, _, err := badger.Get(key1)
require.Nil(t, err)
require.True(t, found)
notAvailable, _, err := badger.Get(key1)
require.NoError(t, err)
require.True(t, notAvailable)
err = badger.Commit([]string{key1.Key})
require.NoError(t, err)
found, _, err = badger.Get(key2)
require.Nil(t, err)
require.False(t, found)
notAvailable, _, err = badger.Get(key2)
require.NoError(t, err)
require.False(t, notAvailable)
})
t.Run("Same messageID should be deduped from cache", func(t *testing.T) {
key1 := types.KeyValue{Key: "b", Value: 1, WorkspaceId: "test"}
key2 := types.KeyValue{Key: "b", Value: 1, WorkspaceId: "test"}
found, _, err := badger.Get(key1)
require.Nil(t, err)
require.NoError(t, err)
require.True(t, found)
found, _, err = badger.Get(key2)
require.Nil(t, err)
require.NoError(t, err)
require.False(t, found)
})
}
6 changes: 2 additions & 4 deletions services/dedup/dedup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ func Test_Dedup(t *testing.T) {
logger.Reset()
misc.Init()

dbPath := os.TempDir() + "/dedup_test"
defer func() { _ = os.RemoveAll(dbPath) }()
_ = os.RemoveAll(dbPath)
dbPath := t.TempDir()
conf := config.New()
t.Setenv("RUDDER_TMPDIR", dbPath)
pool, err := dockertest.NewPool("")
Expand All @@ -70,7 +68,7 @@ func Test_Dedup(t *testing.T) {

t.Run("if message id is not present in cache and badger db", func(t *testing.T) {
found, _, err := d.Get(types.KeyValue{Key: "a", Value: 1, WorkspaceId: "test"})
require.Nil(t, err)
require.NoError(t, err)
require.Equal(t, true, found)

// Checking it again should give us the previous value from the cache
Expand Down
1 change: 1 addition & 0 deletions services/dedup/mirrorBadger/mirrorBadger.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (mb *MirrorBadger) Close() {
}

func (mb *MirrorBadger) Get(kv types.KeyValue) (bool, int64, error) {
_, _, _ = mb.scylla.Get(kv)
return mb.badger.Get(kv)
}

Expand Down
1 change: 1 addition & 0 deletions services/dedup/mirrorScylla/mirrorScylla.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (ms *MirrorScylla) Close() {
}

func (ms *MirrorScylla) Get(kv types.KeyValue) (bool, int64, error) {
_, _, _ = ms.badger.Get(kv)
return ms.scylla.Get(kv)
}

Expand Down

0 comments on commit 4edc80d

Please sign in to comment.