github.com/matrixorigin/matrixone@v1.2.0/pkg/fileservice/memorycache/checks/interval/overlap_test.go (about) 1 // Copyright 2023 Matrix Origin 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 interval 16 17 import ( 18 "github.com/stretchr/testify/assert" 19 "testing" 20 ) 21 22 func TestIntervalChecker(t *testing.T) { 23 24 tree := NewOverlapChecker("MemCache_LRU") 25 26 // [0,5) 27 err := tree.Insert("s3://db1/table1/A", 0, 5) 28 assert.Nil(t, err) 29 30 //[0,5), [5,10) 31 err = tree.Insert("s3://db1/table1/A", 5, 10) 32 assert.Nil(t, err) 33 34 //[0,5), [5,10) 35 err = tree.Insert("s3://db1/table1/A", 6, 7) 36 assert.NotNil(t, err) 37 38 //[0,5) 39 err = tree.Remove("s3://db1/table1/A", 5, 10) 40 assert.Nil(t, err) 41 42 //[0,5), [6,7) 43 err = tree.Insert("s3://db1/table1/A", 6, 7) 44 assert.Nil(t, err) 45 46 //[0,5), [5,6), [6,7) 47 err = tree.Insert("s3://db1/table1/A", 5, 6) 48 assert.Nil(t, err) 49 50 //[0,5), [3,5), [5,6), [6,7) 51 err = tree.Insert("s3://db1/table1/A", 3, 5) 52 assert.NotNil(t, err) 53 assert.Equal(t, "internal error: Overlapping key range found in MemCache_LRU when inserting [3 5). The key s3://db1/table1/A contains overlapping intervals [0 5), ", err.Error()) 54 55 //[0,5), [3,6), [5,6), [6,7) 56 err = tree.Insert("s3://db1/table1/A", 3, 6) 57 assert.NotNil(t, err) 58 assert.Equal(t, "internal error: Overlapping key range found in MemCache_LRU when inserting [3 6). The key s3://db1/table1/A contains overlapping intervals [0 5), [5 6), ", err.Error()) 59 60 //[3,7) 61 err = tree.Insert("s3://db1/table1/B", 3, 7) 62 assert.Nil(t, err) 63 }