github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/pkg/index/export_test.go (about) 1 /* 2 Copyright 2012 Google Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package index 18 19 import ( 20 "testing" 21 "time" 22 23 "camlistore.org/pkg/blob" 24 "camlistore.org/pkg/types/camtypes" 25 ) 26 27 func ExpReverseTimeString(s string) string { 28 return reverseTimeString(s) 29 } 30 31 func ExpUnreverseTimeString(s string) string { 32 return unreverseTimeString(s) 33 } 34 35 func ExpNewCorpus() *Corpus { 36 return newCorpus() 37 } 38 39 func (c *Corpus) Exp_mergeFileInfoRow(k, v string) error { 40 return c.mergeFileInfoRow([]byte(k), []byte(v)) 41 } 42 43 func (c *Corpus) Exp_files(br blob.Ref) camtypes.FileInfo { 44 return c.files[br] 45 } 46 47 func ExpKvClaim(k, v string, blobParse func(string) (blob.Ref, bool)) (c camtypes.Claim, ok bool) { 48 return kvClaim(k, v, blobParse) 49 } 50 51 func (c *Corpus) SetClaims(pn blob.Ref, claims *PermanodeMeta) { 52 c.permanodes[pn] = claims 53 } 54 55 func (x *Index) NeededMapsForTest() (needs, neededBy map[blob.Ref][]blob.Ref, ready map[blob.Ref]bool) { 56 return x.needs, x.neededBy, x.readyReindex 57 } 58 59 func Exp_missingKey(have, missing blob.Ref) string { 60 return keyMissing.Key(have, missing) 61 } 62 63 func Exp_schemaVersion() int { return requiredSchemaVersion } 64 65 func (x *Index) Exp_noteBlobIndexed(br blob.Ref) { 66 x.noteBlobIndexed(br) 67 } 68 69 func (x *Index) Exp_AwaitReindexing(t *testing.T) { 70 deadline := time.Now().Add(5 * time.Second) 71 for time.Now().Before(deadline) { 72 x.mu.Lock() 73 n := len(x.readyReindex) 74 x.mu.Unlock() 75 if n == 0 { 76 return 77 } 78 time.Sleep(50 * time.Millisecond) 79 } 80 t.Fatal("timeout waiting for readyReindex to drain") 81 }