예제 #1
0
// New creates a new server instance backed by a local directory in diskPath.
// Keys not updated for forgetAfter duration are evicted from the in-memory replica of the shard's data.
// Keys not in memory are not reflected in read operations.
func New(diskPath string, forgetAfter time.Duration) (*Server, error) {
	s := &Server{}

	os.MkdirAll(diskPath, 0700)

	// Mount disk
	disk, err := diskfs.Mount(diskPath, false)
	if err != nil {
		return nil, err
	}
	// Make db block
	if s.block, err = block.NewBlock(disk, forgetAfter); err != nil {
		return nil, err
	}
	// Prepare incoming call rate-limiter
	s.lmtr = limiter.New(10)
	return s, nil
}
예제 #2
0
func TestFile(t *testing.T) {
	disk, err := diskfs.Mount(".", false)
	if err != nil {
		t.Fatalf("mount (%s)", err)
	}

	file, err := Create(disk, "_test_log_file")
	if err != nil {
		t.Fatalf("open (%s)", err)
	}
	write(t, file)
	if err := file.Close(); err != nil {
		t.Errorf("close (%s)", err)
	}

	file, err = Open(disk, "_test_log_file")
	if err != nil {
		t.Fatalf("open2 (%s)", err)
	}
	read(t, file)
	if err := file.Close(); err != nil {
		t.Errorf("close2 (%s)", err)
	}
}