Skip to content

Commit

Permalink
renamed PIndexClient to IndexClient for generic'trification
Browse files Browse the repository at this point in the history
  • Loading branch information
steveyen committed Feb 10, 2015
1 parent 682e368 commit dc06325
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion pindex_impl_bleve.go
Expand Up @@ -705,7 +705,7 @@ func bleveIndexAlias(mgr *Manager, indexName, indexUUID string,
for _, remotePlanPIndex := range remotePlanPIndexes {
baseURL := "http://" + remotePlanPIndex.NodeDef.HostPort +
"/api/pindex/" + remotePlanPIndex.PlanPIndex.Name
alias.Add(&PIndexClient{
alias.Add(&IndexClient{
QueryURL: baseURL + "/query",
CountURL: baseURL + "/count",
Consistency: consistencyParams,
Expand Down
8 changes: 4 additions & 4 deletions pindex_impl_vlite.go
Expand Up @@ -110,7 +110,7 @@ type VLiteQueryResult struct {

type VLiteGatherer struct {
localVLites []*VLite
remoteClients []*PIndexClient
remoteClients []*IndexClient
}

var EMPTY_BYTES = []byte{}
Expand Down Expand Up @@ -774,7 +774,7 @@ func vliteGatherer(mgr *Manager, indexName, indexUUID string,
for _, remotePlanPIndex := range remotePlanPIndexes {
baseURL := "http://" + remotePlanPIndex.NodeDef.HostPort +
"/api/pindex/" + remotePlanPIndex.PlanPIndex.Name
rv.remoteClients = append(rv.remoteClients, &PIndexClient{
rv.remoteClients = append(rv.remoteClients, &IndexClient{
QueryURL: baseURL + "/query",
CountURL: baseURL + "/count",
Consistency: consistencyParams,
Expand Down Expand Up @@ -828,7 +828,7 @@ func (vg *VLiteGatherer) Count(cancelCh <-chan bool) (uint64, error) {

for _, remoteClient := range vg.remoteClients {
wg.Add(1)
go func(remoteClient *PIndexClient) {
go func(remoteClient *IndexClient) {
defer wg.Done()

t, err := remoteClient.Count()
Expand Down Expand Up @@ -890,7 +890,7 @@ func (vg *VLiteGatherer) Query(p *VLiteQueryParams, w io.Writer,
for _, remoteClient := range vg.remoteClients {
resultCh := make(chan *gkvlite.Item, 1)

go func(resultCh chan *gkvlite.Item, remoteClient *PIndexClient) {
go func(resultCh chan *gkvlite.Item, remoteClient *IndexClient) {
defer close(resultCh)

respBuf, err := remoteClient.Query(pBuf)
Expand Down
68 changes: 34 additions & 34 deletions remote.go
Expand Up @@ -26,38 +26,38 @@ import (
var httpPost = http.Post
var httpGet = http.Get

var pindexClientUnimplementedErr = errors.New("unimplemented")
var indexClientUnimplementedErr = errors.New("unimplemented")

// PIndexClient implements the Search() and DocCount() subset of the
// IndexClient implements the Search() and DocCount() subset of the
// bleve.Index interface by accessing a remote cbft server via REST
// protocol. This allows callers to add a PIndexClient as a target of
// protocol. This allows callers to add a IndexClient as a target of
// a bleve.IndexAlias, and implements cbft protocol features like
// query consistency and auth.
//
// TODO: Implement propagating auth info in PIndexClient.
type PIndexClient struct {
// TODO: Implement propagating auth info in IndexClient.
type IndexClient struct {
QueryURL string
CountURL string
Consistency *ConsistencyParams
}

func (r *PIndexClient) Index(id string, data interface{}) error {
return pindexClientUnimplementedErr
func (r *IndexClient) Index(id string, data interface{}) error {
return indexClientUnimplementedErr
}

func (r *PIndexClient) Delete(id string) error {
return pindexClientUnimplementedErr
func (r *IndexClient) Delete(id string) error {
return indexClientUnimplementedErr
}

func (r *PIndexClient) Batch(b *bleve.Batch) error {
return pindexClientUnimplementedErr
func (r *IndexClient) Batch(b *bleve.Batch) error {
return indexClientUnimplementedErr
}

func (r *PIndexClient) Document(id string) (*document.Document, error) {
return nil, pindexClientUnimplementedErr
func (r *IndexClient) Document(id string) (*document.Document, error) {
return nil, indexClientUnimplementedErr
}

func (r *PIndexClient) DocCount() (uint64, error) {
func (r *IndexClient) DocCount() (uint64, error) {
if r.CountURL == "" {
return 0, fmt.Errorf("remote: no CountURL provided")
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func (r *PIndexClient) DocCount() (uint64, error) {
return rv.Count, nil
}

func (r *PIndexClient) Search(req *bleve.SearchRequest) (*bleve.SearchResult, error) {
func (r *IndexClient) Search(req *bleve.SearchRequest) (*bleve.SearchResult, error) {
if r.QueryURL == "" {
return nil, fmt.Errorf("remote: no QueryURL provided")
}
Expand Down Expand Up @@ -116,53 +116,53 @@ func (r *PIndexClient) Search(req *bleve.SearchRequest) (*bleve.SearchResult, er
return rv, nil
}

func (r *PIndexClient) Fields() ([]string, error) {
return nil, pindexClientUnimplementedErr
func (r *IndexClient) Fields() ([]string, error) {
return nil, indexClientUnimplementedErr
}

func (r *PIndexClient) DumpAll() chan interface{} {
func (r *IndexClient) DumpAll() chan interface{} {
return nil
}

func (r *PIndexClient) DumpDoc(id string) chan interface{} {
func (r *IndexClient) DumpDoc(id string) chan interface{} {
return nil
}

func (r *PIndexClient) DumpFields() chan interface{} {
func (r *IndexClient) DumpFields() chan interface{} {
return nil
}

func (r *PIndexClient) Close() error {
return pindexClientUnimplementedErr
func (r *IndexClient) Close() error {
return indexClientUnimplementedErr
}

func (r *PIndexClient) Mapping() *bleve.IndexMapping {
func (r *IndexClient) Mapping() *bleve.IndexMapping {
return nil
}

func (r *PIndexClient) Stats() *bleve.IndexStat {
func (r *IndexClient) Stats() *bleve.IndexStat {
return nil
}

func (r *PIndexClient) GetInternal(key []byte) ([]byte, error) {
return nil, pindexClientUnimplementedErr
func (r *IndexClient) GetInternal(key []byte) ([]byte, error) {
return nil, indexClientUnimplementedErr
}

func (r *PIndexClient) SetInternal(key, val []byte) error {
return pindexClientUnimplementedErr
func (r *IndexClient) SetInternal(key, val []byte) error {
return indexClientUnimplementedErr
}

func (r *PIndexClient) DeleteInternal(key []byte) error {
return pindexClientUnimplementedErr
func (r *IndexClient) DeleteInternal(key []byte) error {
return indexClientUnimplementedErr
}

// -----------------------------------------------------

func (r *PIndexClient) Count() (uint64, error) {
func (r *IndexClient) Count() (uint64, error) {
return r.DocCount()
}

func (r *PIndexClient) Query(buf []byte) ([]byte, error) {
func (r *IndexClient) Query(buf []byte) ([]byte, error) {
resp, err := httpPost(r.QueryURL, "application/json", bytes.NewBuffer(buf))
if err != nil {
return nil, err
Expand All @@ -182,6 +182,6 @@ func (r *PIndexClient) Query(buf []byte) ([]byte, error) {
return respBuf, err
}

func (r *PIndexClient) Advanced() (index.Index, store.KVStore, error) {
return nil, nil, pindexClientUnimplementedErr
func (r *IndexClient) Advanced() (index.Index, store.KVStore, error) {
return nil, nil, indexClientUnimplementedErr
}
26 changes: 13 additions & 13 deletions remote_test.go
Expand Up @@ -15,19 +15,19 @@ import (
"testing"
)

func TestNegativePIndexClient(t *testing.T) {
bc := &PIndexClient{}
if bc.Index("", nil) != pindexClientUnimplementedErr {
func TestNegativeIndexClient(t *testing.T) {
bc := &IndexClient{}
if bc.Index("", nil) != indexClientUnimplementedErr {
t.Errorf("expected unimplemented")
}
if bc.Delete("") != pindexClientUnimplementedErr {
if bc.Delete("") != indexClientUnimplementedErr {
t.Errorf("expected unimplemented")
}
if bc.Batch(nil) != pindexClientUnimplementedErr {
if bc.Batch(nil) != indexClientUnimplementedErr {
t.Errorf("expected unimplemented")
}
d, err := bc.Document("")
if err != pindexClientUnimplementedErr || d != nil {
if err != indexClientUnimplementedErr || d != nil {
t.Errorf("expected unimplemented")
}
c, err := bc.DocCount()
Expand All @@ -39,7 +39,7 @@ func TestNegativePIndexClient(t *testing.T) {
t.Errorf("expected search error on empty QueryURL")
}
f, err := bc.Fields()
if err != pindexClientUnimplementedErr || f != nil {
if err != indexClientUnimplementedErr || f != nil {
t.Errorf("expected unimplemented")
}
if bc.DumpAll() != nil {
Expand All @@ -51,7 +51,7 @@ func TestNegativePIndexClient(t *testing.T) {
if bc.DumpFields() != nil {
t.Errorf("expected nil")
}
if bc.Close() != pindexClientUnimplementedErr {
if bc.Close() != indexClientUnimplementedErr {
t.Errorf("expected unimplemented")
}
if bc.Mapping() != nil {
Expand All @@ -61,19 +61,19 @@ func TestNegativePIndexClient(t *testing.T) {
t.Errorf("expected nil")
}
val, err := bc.GetInternal(nil)
if err != pindexClientUnimplementedErr || val != nil {
if err != indexClientUnimplementedErr || val != nil {
t.Errorf("expected unimplemented")
}
if bc.SetInternal(nil, nil) != pindexClientUnimplementedErr {
if bc.SetInternal(nil, nil) != indexClientUnimplementedErr {
t.Errorf("expected unimplemented")
}
if bc.DeleteInternal(nil) != pindexClientUnimplementedErr {
if bc.DeleteInternal(nil) != indexClientUnimplementedErr {
t.Errorf("expected unimplemented")
}
}

func TestBadURLsPIndexClient(t *testing.T) {
bc := &PIndexClient{
func TestBadURLsIndexClient(t *testing.T) {
bc := &IndexClient{
CountURL: "bogus url",
QueryURL: "fake url",
}
Expand Down

0 comments on commit dc06325

Please sign in to comment.