github.com/balzaczyy/golucene@v0.0.0-20151210033525-d0be9ee89713/core/store/directory_test.go (about) 1 package store 2 3 import ( 4 "github.com/balzaczyy/golucene/core/codec" 5 "github.com/balzaczyy/golucene/core/util" 6 "math/rand" 7 "testing" 8 ) 9 10 func newTestIOContext(r *rand.Rand) IOContext { 11 return newTestIOContextFrom(r, NewIOContextFromType(IOContextType(IO_CONTEXT_TYPE_DEFAULT))) 12 } 13 14 func newTestIOContextFrom(r *rand.Rand, oldContext IOContext) IOContext { 15 randomNumDocs := r.Intn(4192) 16 size := r.Intn(512) * randomNumDocs 17 // ignore flushInfo and mergeInfo for now 18 // Make a totally random IOContext: 19 var context IOContext 20 switch r.Intn(5) { 21 case 0: 22 context = IO_CONTEXT_DEFAULT 23 case 1: 24 context = IO_CONTEXT_READ 25 case 2: 26 context = IO_CONTEXT_READONCE 27 case 3: 28 context = NewIOContextForMerge(&MergeInfo{randomNumDocs, int64(size), true, -1}) 29 case 4: 30 context = NewIOContextForFlush(&FlushInfo{randomNumDocs, int64(size)}) 31 default: 32 context = IO_CONTEXT_DEFAULT 33 } 34 return context 35 } 36 37 func TestReadingFromSlicedIndexInputOSX(t *testing.T) { 38 t.Logf("TestReadingFromSlicedIndexInputOSX...") 39 path := "../search/testdata/osx/belfrysample" 40 d, err := OpenFSDirectory(path) 41 if err != nil { 42 t.Error(err) 43 } 44 ctx := NewIOContextBool(false) 45 cd, err := NewCompoundFileDirectory(d, "_0.cfs", ctx, false) 46 name := util.SegmentFileName("_0", "Lucene41_0", "pos") 47 posIn, err := cd.OpenInput(name, ctx) 48 if err != nil { 49 t.Error(err) 50 } 51 t.Log(posIn) 52 codec.CheckHeader(posIn, "Lucene41PostingsWriterPos", 0, 0) 53 // codec header mismatch: actual header=0 vs expected header=1071082519 (resource: SlicedIndexInput(SlicedIndexInput(_0_Lucene41_0.pos in SimpleFSIndexInput(path='/private/tmp/kc/index/belfrysample/_0.cfs')) in SimpleFSIndexInput(path='/private/tmp/kc/index/belfrysample/_0.cfs') slice=1461:3426)) 54 }