github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/cdc/puller/sorter/file_backend_test.go (about) 1 // Copyright 2021 PingCAP, Inc. 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package sorter 15 16 import ( 17 "io" 18 "os" 19 20 "github.com/pingcap/check" 21 "github.com/pingcap/ticdc/cdc/model" 22 cerrors "github.com/pingcap/ticdc/pkg/errors" 23 "github.com/pingcap/ticdc/pkg/util/testleak" 24 ) 25 26 type fileBackendSuite struct{} 27 28 var _ = check.SerialSuites(&fileBackendSuite{}) 29 30 func (s *fileBackendSuite) TestWrapIOError(c *check.C) { 31 defer testleak.AfterTest(c)() 32 33 fullFile, err := os.OpenFile("/dev/full", os.O_RDWR, 0) 34 c.Assert(err, check.IsNil) 35 defer fullFile.Close() //nolint:errcheck 36 _, err = fullFile.WriteString("test") 37 wrapped := wrapIOError(err) 38 // tests that the error message gives the user some informative description 39 c.Assert(wrapped, check.ErrorMatches, ".*review the settings.*no space.*") 40 41 eof := wrapIOError(io.EOF) 42 // tests that the function does not change io.EOF 43 c.Assert(eof, check.Equals, io.EOF) 44 } 45 46 func (s *fileBackendSuite) TestNoSpace(c *check.C) { 47 defer testleak.AfterTest(c)() 48 49 fb := &fileBackEnd{ 50 fileName: "/dev/full", 51 serde: &msgPackGenSerde{}, 52 } 53 w, err := fb.writer() 54 c.Assert(err, check.IsNil) 55 56 err = w.writeNext(model.NewPolymorphicEvent(generateMockRawKV(0))) 57 if err == nil { 58 // Due to write buffering, `writeNext` might not return an error when the filesystem is full. 59 err = w.flushAndClose() 60 } 61 62 c.Assert(err, check.ErrorMatches, ".*review the settings.*no space.*") 63 c.Assert(cerrors.ErrUnifiedSorterIOError.Equal(err), check.IsTrue) 64 }