mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-12-02 00:19:15 +08:00
a23bcbb7ec
The io/ioutil package has been deprecated as of Go 1.16, see https://golang.org/doc/go1.16#ioutil. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package storage
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
|
"github.com/chrislusf/seaweedfs/weed/storage/super_block"
|
|
"github.com/chrislusf/seaweedfs/weed/storage/types"
|
|
)
|
|
|
|
func TestSearchVolumesWithDeletedNeedles(t *testing.T) {
|
|
dir, err := os.MkdirTemp("", "example")
|
|
if err != nil {
|
|
t.Fatalf("temp dir creation: %v", err)
|
|
}
|
|
defer os.RemoveAll(dir) // clean up
|
|
|
|
v, err := NewVolume(dir, dir, "", 1, NeedleMapInMemory, &super_block.ReplicaPlacement{}, &needle.TTL{}, 0, 0)
|
|
if err != nil {
|
|
t.Fatalf("volume creation: %v", err)
|
|
}
|
|
|
|
count := 20
|
|
|
|
for i := 1; i < count; i++ {
|
|
n := newRandomNeedle(uint64(i))
|
|
_, _, _, err := v.writeNeedle2(n, true, false)
|
|
if err != nil {
|
|
t.Fatalf("write needle %d: %v", i, err)
|
|
}
|
|
}
|
|
|
|
for i := 1; i < 15; i++ {
|
|
n := newEmptyNeedle(uint64(i))
|
|
err := v.nm.Put(n.Id, types.Offset{}, types.TombstoneFileSize)
|
|
if err != nil {
|
|
t.Fatalf("delete needle %d: %v", i, err)
|
|
}
|
|
}
|
|
|
|
ts1 := time.Now().UnixNano()
|
|
|
|
for i := 15; i < count; i++ {
|
|
n := newEmptyNeedle(uint64(i))
|
|
_, err := v.doDeleteRequest(n)
|
|
if err != nil {
|
|
t.Fatalf("delete needle %d: %v", i, err)
|
|
}
|
|
}
|
|
|
|
offset, isLast, err := v.BinarySearchByAppendAtNs(uint64(ts1))
|
|
if err != nil {
|
|
t.Fatalf("lookup by ts: %v", err)
|
|
}
|
|
fmt.Printf("offset: %v, isLast: %v\n", offset.ToActualOffset(), isLast)
|
|
|
|
}
|