Skip to content

Commit

Permalink
â�â�fix test function
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoShuaiUp committed Jul 2, 2023
1 parent 5f0098f commit 27c0db4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
17 changes: 10 additions & 7 deletions data/data_file_test.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
package data

import (
"github.com/ByteStorage/FlyDB/fio"
"github.com/stretchr/testify/assert"
"os"
"testing"
)

const DefaultFileSize = 256 * 1024 * 1024

func TestOpenDataFile(t *testing.T) {
dataFile1, err := OpenDataFile(os.TempDir(), 0)
dataFile1, err := OpenDataFile(os.TempDir(), 0, DefaultFileSize, fio.FileIOType)
assert.Nil(t, err)
assert.NotNil(t, dataFile1)

dataFile2, err := OpenDataFile(os.TempDir(), 1)
dataFile2, err := OpenDataFile(os.TempDir(), 1, DefaultFileSize, fio.FileIOType)
assert.Nil(t, err)
assert.NotNil(t, dataFile2)

dataFile3, err := OpenDataFile(os.TempDir(), 1)
dataFile3, err := OpenDataFile(os.TempDir(), 1, DefaultFileSize, fio.FileIOType)
assert.Nil(t, err)
assert.NotNil(t, dataFile3)
}

func TestDataFile_Write(t *testing.T) {
dataFile, err := OpenDataFile(os.TempDir(), 12312)
dataFile, err := OpenDataFile(os.TempDir(), 12312, DefaultFileSize, fio.FileIOType)
assert.Nil(t, err)
assert.NotNil(t, dataFile)

Expand All @@ -36,7 +39,7 @@ func TestDataFile_Write(t *testing.T) {
}

func TestDataFile_Close(t *testing.T) {
dataFile, err := OpenDataFile(os.TempDir(), 1111111)
dataFile, err := OpenDataFile(os.TempDir(), 1111111, DefaultFileSize, fio.FileIOType)
assert.Nil(t, err)
assert.NotNil(t, dataFile)

Expand All @@ -45,7 +48,7 @@ func TestDataFile_Close(t *testing.T) {
}

func TestDataFile_Sync(t *testing.T) {
dataFile, err := OpenDataFile(os.TempDir(), 2222222)
dataFile, err := OpenDataFile(os.TempDir(), 2222222, DefaultFileSize, fio.FileIOType)
assert.Nil(t, err)
assert.NotNil(t, dataFile)

Expand All @@ -54,7 +57,7 @@ func TestDataFile_Sync(t *testing.T) {
}

func TestDataFile_ReadLogRecord(t *testing.T) {
dataFile, err := OpenDataFile(os.TempDir(), 123)
dataFile, err := OpenDataFile(os.TempDir(), 123, DefaultFileSize, fio.FileIOType)
assert.Nil(t, err)
assert.NotNil(t, dataFile)

Expand Down
2 changes: 2 additions & 0 deletions fio/io_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package fio

const DataFilePerm = 0644 //0644 表示创建了一个文件,文件所有者可以读写,其他人只能读

const DefaultFileSize = 256 * 1024 * 1024

const (
FileIOType = iota + 1 // Standard File IO
BufIOType // File IO with buffer
Expand Down
16 changes: 8 additions & 8 deletions fio/mmap_io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func TestNewMMapIOManager(t *testing.T) {
path := filepath.Join("/tmp", "a.data")
mio, err := NewMMapIOManager(path, 256*1024*1024)
mio, err := NewMMapIOManager(path, DefaultFileSize)
defer destoryFile(path)

assert.Nil(t, err)
Expand All @@ -17,7 +17,7 @@ func TestNewMMapIOManager(t *testing.T) {

func TestMMapIO_Write(t *testing.T) {
path := filepath.Join("/tmp", "a.data")
mio, err := NewMMapIOManager(path, 256*1024*1024)
mio, err := NewMMapIOManager(path, DefaultFileSize)
defer destoryFile(path)
assert.Nil(t, err)
assert.NotNil(t, mio)
Expand All @@ -36,7 +36,7 @@ func TestMMapIO_Write(t *testing.T) {

func TestMMapIO_Read(t *testing.T) {
path := filepath.Join("/tmp", "a.data")
mio, err := NewMMapIOManager(path, 256*1024*1024)
mio, err := NewMMapIOManager(path, DefaultFileSize)
defer destoryFile(path)

assert.Nil(t, err)
Expand All @@ -60,7 +60,7 @@ func TestMMapIO_Read(t *testing.T) {

func TestMMapIO_Sync(t *testing.T) {
path := filepath.Join("/tmp", "a.data")
mio, err := NewMMapIOManager(path, 256*1024*1024)
mio, err := NewMMapIOManager(path, DefaultFileSize)
defer destoryFile(path)

assert.Nil(t, err)
Expand All @@ -73,8 +73,8 @@ func TestMMapIO_Sync(t *testing.T) {

func TestMMapIO_Close(t *testing.T) {
path := filepath.Join("/tmp", "a.data")
mio, err := NewMMapIOManager(path, 256*1024*1024)
//defer destoryFile(path)
mio, err := NewMMapIOManager(path, DefaultFileSize)
defer destoryFile(path)

assert.Nil(t, err)
assert.NotNil(t, mio)
Expand All @@ -88,7 +88,7 @@ func TestMMapIO_Close(t *testing.T) {

func TestMMapIO_Write_Speed(t *testing.T) {
path := filepath.Join("/tmp", "a.data")
mio, err := NewMMapIOManager(path, 256*1024*1024)
mio, err := NewMMapIOManager(path, DefaultFileSize)
assert.Nil(t, err)
assert.NotNil(t, mio)

Expand All @@ -104,7 +104,7 @@ func TestMMapIO_Write_Speed(t *testing.T) {

func TestMMapIO_Read_Speed(t *testing.T) {
path := filepath.Join("/tmp", "a.data")
mio, err := NewMMapIOManager(path, 256*1024*1024)
mio, err := NewMMapIOManager(path, DefaultFileSize)
defer destoryFile(path)
assert.Nil(t, err)
assert.NotNil(t, mio)
Expand Down

0 comments on commit 27c0db4

Please sign in to comment.