From 1cc377426c0b2cd8563859a551f0cda2cf8cd21d Mon Sep 17 00:00:00 2001 From: CascadingRadium Date: Fri, 15 Nov 2024 12:48:32 +0530 Subject: [PATCH] fix tests --- section_inverted_text_index.go | 5 --- synonym_test.go | 15 ------- thesaurus_test.go | 82 +++++++++++++++++----------------- 3 files changed, 41 insertions(+), 61 deletions(-) delete mode 100644 synonym_test.go diff --git a/section_inverted_text_index.go b/section_inverted_text_index.go index 5170272..86a15f6 100644 --- a/section_inverted_text_index.go +++ b/section_inverted_text_index.go @@ -451,11 +451,6 @@ func (io *invertedIndexOpaque) writeDicts(w *CountHashWriter) (dictOffsets []uin for fieldID, terms := range io.DictKeys { dict := io.Dicts[fieldID] - // dict is nil if the field is excluded from inverted index - // processing, so skip it - if len(dict) == 0 { - continue - } if cap(docTermMap) < len(io.results) { docTermMap = make([][]byte, len(io.results)) diff --git a/synonym_test.go b/synonym_test.go deleted file mode 100644 index fc710c5..0000000 --- a/synonym_test.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2024 Couchbase, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package zap diff --git a/thesaurus_test.go b/thesaurus_test.go index 735e4fd..a545c2f 100644 --- a/thesaurus_test.go +++ b/thesaurus_test.go @@ -59,7 +59,7 @@ func buildTestSynonymDocument(id string, collection string, terms []string, syno } func buildTestSegmentForThesaurus(results []index.Document) (*SegmentBase, error) { - seg, _, err := zapPlugin.newWithChunkMode(results, 1024) + seg, _, err := zapPlugin.newWithChunkMode(results, DefaultChunkMode) return seg.(*SegmentBase), err } @@ -182,15 +182,6 @@ func createExpectedSynonymMap(input []testSynonymDefinition) map[string][]string } func buildSegment(testSynonymDefinitions []testSynonymDefinition) (segment.Segment, error) { - tmpDir, err := os.MkdirTemp("", "zap-") - if err != nil { - return nil, err - } - - err = os.RemoveAll(tmpDir) - if err != nil { - return nil, err - } var testSynonymDocuments []index.Document for i, testSynonymDefinition := range testSynonymDefinitions { testSynonymDocuments = append(testSynonymDocuments, buildTestSynonymDocument( @@ -204,6 +195,15 @@ func buildSegment(testSynonymDefinitions []testSynonymDefinition) (segment.Segme if err != nil { return nil, err } + tmpDir, err := os.MkdirTemp("", "zap-") + if err != nil { + return nil, err + } + + err = os.RemoveAll(tmpDir) + if err != nil { + return nil, err + } err = PersistSegmentBase(sb, tmpDir) if err != nil { return nil, err @@ -327,39 +327,39 @@ func TestSynonymSegment(t *testing.T) { }() // // multiple segment test - // numSegs := 3 - // numDocs := 5 - // segData := make([][]testSynonymDefinition, numSegs) + numSegs := 3 + numDocs := 5 + segData := make([][]testSynonymDefinition, numSegs) - // segData[0] = make([]testSynonymDefinition, 0) - // segData[0] = testSynonymDefinitions[:2] // 2 docs + segData[0] = make([]testSynonymDefinition, 0) + segData[0] = testSynonymDefinitions[:2] // 2 docs - // segData[1] = make([]testSynonymDefinition, 0) - // segData[1] = testSynonymDefinitions[2:4] // 2 docs + segData[1] = make([]testSynonymDefinition, 0) + segData[1] = testSynonymDefinitions[2:4] // 2 docs - // segData[2] = make([]testSynonymDefinition, 0) - // segData[2] = testSynonymDefinitions[4:] // 1 doc + segData[2] = make([]testSynonymDefinition, 0) + segData[2] = testSynonymDefinitions[4:] // 1 doc - // segs := make([]segment.Segment, numSegs) - // for i, data := range segData { - // seg, err := buildSegment(data) - // if err != nil { - // t.Fatalf("error building segment: %v", err) - // } - // segs[i] = seg - // } - // drops := make([]*roaring.Bitmap, numDocs) - // for i := 0; i < numDocs; i++ { - // drops[i] = roaring.New() - // } - // err = mergeSegments(segs, drops, testSynonymDefinitions) - // if err != nil { - // t.Fatalf("error merging segments: %v", err) - // } - // for _, seg := range segs { - // cerr := seg.Close() - // if cerr != nil { - // t.Fatalf("error closing seg: %v", err) - // } - // } + segs := make([]segment.Segment, numSegs) + for i, data := range segData { + seg, err := buildSegment(data) + if err != nil { + t.Fatalf("error building segment: %v", err) + } + segs[i] = seg + } + drops := make([]*roaring.Bitmap, numDocs) + for i := 0; i < numDocs; i++ { + drops[i] = roaring.New() + } + err = mergeSegments(segs, drops, testSynonymDefinitions) + if err != nil { + t.Fatalf("error merging segments: %v", err) + } + for _, seg := range segs { + cerr := seg.Close() + if cerr != nil { + t.Fatalf("error closing seg: %v", err) + } + } }