2011-07-01 19:00:10 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google 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.
|
|
|
|
*/
|
|
|
|
|
2011-07-06 18:20:25 +00:00
|
|
|
package test
|
2011-07-01 19:00:10 +00:00
|
|
|
|
|
|
|
import (
|
2011-07-06 18:59:50 +00:00
|
|
|
"fmt"
|
2011-07-01 19:00:10 +00:00
|
|
|
"os"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"camli/blobref"
|
2011-07-06 18:20:25 +00:00
|
|
|
"camli/search"
|
2011-07-01 19:00:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type FakeIndex struct {
|
2011-07-06 18:59:50 +00:00
|
|
|
lk sync.Mutex
|
|
|
|
mimeType map[string]string // blobref -> type
|
|
|
|
size map[string]int64
|
|
|
|
ownerClaims map[string]search.ClaimList // "<permanode>/<owner>" -> ClaimList
|
|
|
|
signerAttrValue map[string]*blobref.BlobRef // "<signer>\0<attr>\0<value>" -> blobref
|
2011-07-01 21:33:15 +00:00
|
|
|
|
|
|
|
cllk sync.Mutex
|
|
|
|
clock int64
|
2011-07-01 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 18:20:25 +00:00
|
|
|
var _ search.Index = (*FakeIndex)(nil)
|
2011-07-01 19:00:10 +00:00
|
|
|
|
|
|
|
func NewFakeIndex() *FakeIndex {
|
|
|
|
return &FakeIndex{
|
2011-07-06 18:59:50 +00:00
|
|
|
mimeType: make(map[string]string),
|
|
|
|
size: make(map[string]int64),
|
|
|
|
ownerClaims: make(map[string]search.ClaimList),
|
|
|
|
signerAttrValue: make(map[string]*blobref.BlobRef),
|
2011-07-01 19:00:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-01 19:38:00 +00:00
|
|
|
//
|
|
|
|
// Test methods
|
|
|
|
//
|
|
|
|
|
2011-07-01 21:33:15 +00:00
|
|
|
func (fi *FakeIndex) nextDate() *time.Time {
|
|
|
|
fi.cllk.Lock()
|
|
|
|
fi.clock++
|
|
|
|
clock := fi.clock
|
|
|
|
fi.cllk.Unlock()
|
|
|
|
return time.SecondsToUTC(clock)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fi *FakeIndex) AddMeta(blob *blobref.BlobRef, mime string, size int64) {
|
|
|
|
fi.lk.Lock()
|
|
|
|
defer fi.lk.Unlock()
|
|
|
|
fi.mimeType[blob.String()] = mime
|
|
|
|
fi.size[blob.String()] = size
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fi *FakeIndex) AddClaim(owner, permanode *blobref.BlobRef, claimType, attr, value string) {
|
2011-07-01 19:38:00 +00:00
|
|
|
fi.lk.Lock()
|
|
|
|
defer fi.lk.Unlock()
|
2011-07-01 21:33:15 +00:00
|
|
|
date := fi.nextDate()
|
|
|
|
|
2011-07-06 18:20:25 +00:00
|
|
|
claim := &search.Claim{
|
2011-07-01 21:33:15 +00:00
|
|
|
Permanode: permanode,
|
|
|
|
Signer: nil,
|
|
|
|
BlobRef: nil,
|
|
|
|
Date: date,
|
|
|
|
Type: claimType,
|
|
|
|
Attr: attr,
|
|
|
|
Value: value,
|
|
|
|
}
|
|
|
|
key := permanode.String() + "/" + owner.String()
|
|
|
|
fi.ownerClaims[key] = append(fi.ownerClaims[key], claim)
|
2011-07-01 19:38:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Interface implementation
|
|
|
|
//
|
2011-07-01 19:00:10 +00:00
|
|
|
|
2011-07-06 18:20:25 +00:00
|
|
|
func (fi *FakeIndex) GetRecentPermanodes(dest chan *search.Result, owner []*blobref.BlobRef, limit int) os.Error {
|
2011-07-01 19:00:10 +00:00
|
|
|
panic("NOIMPL")
|
|
|
|
}
|
|
|
|
|
2011-07-06 18:20:25 +00:00
|
|
|
func (fi *FakeIndex) GetTaggedPermanodes(dest chan<- *blobref.BlobRef, signer *blobref.BlobRef, tag string, limit int) os.Error {
|
2011-07-02 16:06:15 +00:00
|
|
|
panic("NOIMPL")
|
|
|
|
}
|
|
|
|
|
2011-07-06 18:20:25 +00:00
|
|
|
func (fi *FakeIndex) GetOwnerClaims(permaNode, owner *blobref.BlobRef) (search.ClaimList, os.Error) {
|
2011-07-01 21:33:15 +00:00
|
|
|
fi.lk.Lock()
|
|
|
|
defer fi.lk.Unlock()
|
|
|
|
return fi.ownerClaims[permaNode.String()+"/"+owner.String()], nil
|
2011-07-01 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fi *FakeIndex) GetBlobMimeType(blob *blobref.BlobRef) (mime string, size int64, err os.Error) {
|
2011-07-01 19:38:00 +00:00
|
|
|
fi.lk.Lock()
|
|
|
|
defer fi.lk.Unlock()
|
|
|
|
bs := blob.String()
|
|
|
|
mime, ok := fi.mimeType[bs]
|
|
|
|
if !ok {
|
|
|
|
return "", 0, os.ENOENT
|
|
|
|
}
|
|
|
|
return mime, fi.size[bs], nil
|
2011-07-01 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fi *FakeIndex) ExistingFileSchemas(bytesRef *blobref.BlobRef) ([]*blobref.BlobRef, os.Error) {
|
|
|
|
panic("NOIMPL")
|
|
|
|
}
|
|
|
|
|
2011-07-06 18:20:25 +00:00
|
|
|
func (fi *FakeIndex) GetFileInfo(fileRef *blobref.BlobRef) (*search.FileInfo, os.Error) {
|
2011-07-01 19:00:10 +00:00
|
|
|
panic("NOIMPL")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fi *FakeIndex) PermanodeOfSignerAttrValue(signer *blobref.BlobRef, attr, val string) (*blobref.BlobRef, os.Error) {
|
2011-07-06 18:59:50 +00:00
|
|
|
fi.lk.Lock()
|
|
|
|
defer fi.lk.Unlock()
|
|
|
|
if b, ok := fi.signerAttrValue[fmt.Sprintf("%s\x00%s\x00%s", signer, attr, val)]; ok {
|
|
|
|
return b, nil
|
|
|
|
}
|
|
|
|
return nil, os.ENOENT
|
2011-07-01 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 18:20:25 +00:00
|
|
|
func (fi *FakeIndex) PathsOfSignerTarget(signer, target *blobref.BlobRef) ([]*search.Path, os.Error) {
|
2011-07-01 19:00:10 +00:00
|
|
|
panic("NOIMPL")
|
|
|
|
}
|
|
|
|
|
2011-07-06 18:20:25 +00:00
|
|
|
func (fi *FakeIndex) PathsLookup(signer, base *blobref.BlobRef, suffix string) ([]*search.Path, os.Error) {
|
2011-07-01 19:00:10 +00:00
|
|
|
panic("NOIMPL")
|
|
|
|
}
|
|
|
|
|
2011-07-06 18:20:25 +00:00
|
|
|
func (fi *FakeIndex) PathLookup(signer, base *blobref.BlobRef, suffix string, at *time.Time) (*search.Path, os.Error) {
|
2011-07-01 19:00:10 +00:00
|
|
|
panic("NOIMPL")
|
|
|
|
}
|