Skip to content

Commit

Permalink
- fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau committed Sep 27, 2023
1 parent f6cf07c commit c36344b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
27 changes: 27 additions & 0 deletions leveldb/leveldbSerial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,30 @@ func TestSerialDB_PutRemoveGet(t *testing.T) {

_ = ldb.Close()
}

func TestSerialDB_PutRemovePutHas(t *testing.T) {
ldb := createSerialLevelDb(t, 100000, 1000000, 10)

key := []byte("key")
value := []byte("value")

_ = ldb.Put(key, value)

// manually put the <key, value> pair in storage
ldb.PutBatch()
time.Sleep(time.Second)
assert.Nil(t, ldb.Has(key)) // key was found

// we now remove the key
_ = ldb.Remove(key)

// manually delete the key from the storage
ldb.PutBatch()
time.Sleep(time.Second)
assert.NotNil(t, ldb.Has(key)) // missing key

_ = ldb.Put(key, value) // put the key again
assert.Nil(t, ldb.Has(key)) // key was found

_ = ldb.Close()
}
4 changes: 2 additions & 2 deletions rtcache/removalTrackingCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func (cache *removalTrackingCache) GetRemovalStatus(key []byte) types.RemovalSta

// Clear is used to completely clear both caches.
func (cache *removalTrackingCache) Clear() {
cache.mutCriticalArea.RLock()
defer cache.mutCriticalArea.RUnlock()
cache.mutCriticalArea.Lock()
defer cache.mutCriticalArea.Unlock()

cache.removalCache.Clear()
cache.unexportedCacher.Clear()
Expand Down
4 changes: 2 additions & 2 deletions storageUnit/storageunit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestUnit_GetWithExplicitlyRemovedKeyShouldNotCallThePersister(t *testing.T)
return nil
},
GetCalled: func(key []byte) ([]byte, error) {
assert.Fail(t, "should have not called Has")
assert.Fail(t, "should have not called Get")
return nil, nil
},
}
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestUnit_HasWithExplicitlyRemovedKeyShouldNotCallThePersister(t *testing.T)
return nil
},
GetCalled: func(key []byte) ([]byte, error) {
assert.Fail(t, "should have not called Has")
assert.Fail(t, "should have not called Get")
return nil, nil
},
}
Expand Down
5 changes: 4 additions & 1 deletion testscommon/cacherMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ func (mock *cacherMock) HasOrAdd(key []byte, value interface{}, _ int) (has, add
defer mock.mut.Unlock()

_, found := mock.data[string(key)]
if found {
return found, !found
}

mock.data[string(key)] = value

return !found, found
return found, !found
}

// Remove -
Expand Down
2 changes: 1 addition & 1 deletion types/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
UnknownRemovalStatus RemovalStatus = "unknown"
// ExplicitlyRemovedStatus defines the explicitly removed status
ExplicitlyRemovedStatus RemovalStatus = "explicitly removed"
// NotRemovedStatus the key is not removed
// NotRemovedStatus defines the not removed status
NotRemovedStatus RemovalStatus = "not removed"
)

Expand Down

0 comments on commit c36344b

Please sign in to comment.