...

Source file src/go.etcd.io/etcd/server/v3/wal/file_pipeline_test.go

Documentation: go.etcd.io/etcd/server/v3/wal

     1  // Copyright 2018 The etcd Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package wal
    16  
    17  import (
    18  	"io/ioutil"
    19  	"math"
    20  	"os"
    21  	"testing"
    22  
    23  	"go.uber.org/zap"
    24  )
    25  
    26  func TestFilePipeline(t *testing.T) {
    27  	tdir, err := ioutil.TempDir(os.TempDir(), "wal-test")
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  	defer os.RemoveAll(tdir)
    32  
    33  	fp := newFilePipeline(zap.NewExample(), tdir, SegmentSizeBytes)
    34  	defer fp.Close()
    35  
    36  	f, ferr := fp.Open()
    37  	if ferr != nil {
    38  		t.Fatal(ferr)
    39  	}
    40  	f.Close()
    41  }
    42  
    43  func TestFilePipelineFailPreallocate(t *testing.T) {
    44  	tdir, err := ioutil.TempDir(os.TempDir(), "wal-test")
    45  	if err != nil {
    46  		t.Fatal(err)
    47  	}
    48  	defer os.RemoveAll(tdir)
    49  
    50  	fp := newFilePipeline(zap.NewExample(), tdir, math.MaxInt64)
    51  	defer fp.Close()
    52  
    53  	f, ferr := fp.Open()
    54  	if f != nil || ferr == nil { // no space left on device
    55  		t.Fatal("expected error on invalid pre-allocate size, but no error")
    56  	}
    57  }
    58  
    59  func TestFilePipelineFailLockFile(t *testing.T) {
    60  	tdir, err := ioutil.TempDir(os.TempDir(), "wal-test")
    61  	if err != nil {
    62  		t.Fatal(err)
    63  	}
    64  	os.RemoveAll(tdir)
    65  
    66  	fp := newFilePipeline(zap.NewExample(), tdir, math.MaxInt64)
    67  	defer fp.Close()
    68  
    69  	f, ferr := fp.Open()
    70  	if f != nil || ferr == nil { // no such file or directory
    71  		t.Fatal("expected error on invalid pre-allocate size, but no error")
    72  	}
    73  }
    74  

View as plain text