diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-04-11 21:12:41 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-04-11 21:12:41 -0700 |
| commit | df97da25f902912dd527d4aed567408c3ca0f9ae (patch) | |
| tree | 3e5d4d6bcfb69b3ab869c0b519048943f26e69a1 /weed/util/chunk_cache/chunk_cache_on_disk_test.go | |
| parent | c8ca234773e2a0c57c503c1f3464d1ded4edd2df (diff) | |
| download | seaweedfs-df97da25f902912dd527d4aed567408c3ca0f9ae.tar.xz seaweedfs-df97da25f902912dd527d4aed567408c3ca0f9ae.zip | |
mount: add on disk caching
Diffstat (limited to 'weed/util/chunk_cache/chunk_cache_on_disk_test.go')
| -rw-r--r-- | weed/util/chunk_cache/chunk_cache_on_disk_test.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/weed/util/chunk_cache/chunk_cache_on_disk_test.go b/weed/util/chunk_cache/chunk_cache_on_disk_test.go new file mode 100644 index 000000000..256b10139 --- /dev/null +++ b/weed/util/chunk_cache/chunk_cache_on_disk_test.go @@ -0,0 +1,58 @@ +package chunk_cache + +import ( + "bytes" + "fmt" + "io/ioutil" + "math/rand" + "os" + "testing" +) + +func TestOnDisk(t *testing.T) { + + tmpDir, _ := ioutil.TempDir("", "c") + defer os.RemoveAll(tmpDir) + + totalDiskSizeMb := int64(6) + segmentCount := 2 + + cache := NewChunkCache(0, tmpDir, totalDiskSizeMb, segmentCount) + + writeCount := 5 + type test_data struct { + data []byte + fileId string + } + testData := make([]*test_data, writeCount) + for i:=0;i<writeCount;i++{ + buff := make([]byte, 1024*1024) + rand.Read(buff) + testData[i] = &test_data{ + data: buff, + fileId: fmt.Sprintf("1,%daabbccdd", i+1), + } + cache.SetChunk(testData[i].fileId, testData[i].data) + } + + for i:=0;i<writeCount;i++{ + data := cache.GetChunk(testData[i].fileId) + if bytes.Compare(data, testData[i].data) != 0 { + t.Errorf("failed to write to and read from cache: %d", i) + } + } + + cache.Shutdown() + + cache = NewChunkCache(0, tmpDir, totalDiskSizeMb, segmentCount) + + for i:=0;i<writeCount;i++{ + data := cache.GetChunk(testData[i].fileId) + if bytes.Compare(data, testData[i].data) != 0 { + t.Errorf("failed to write to and read from cache: %d", i) + } + } + + cache.Shutdown() + +} |
