lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [18/20] lucy git commit: Tune and test Go bindings for IndexManager.
Date Sat, 31 Oct 2015 21:02:55 GMT
Tune and test Go bindings for IndexManager.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/101c075e
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/101c075e
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/101c075e

Branch: refs/heads/LUCY-282-test-index-go-pt1
Commit: 101c075e6dc807173416ec71390337fd0a020bdc
Parents: 1be76f6
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Thu Oct 29 19:12:58 2015 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Fri Oct 30 12:03:02 2015 -0700

----------------------------------------------------------------------
 go/build.go           |   8 ++++
 go/lucy/index.go      |  59 +++++++++++++++++++++++++
 go/lucy/index_test.go | 106 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 173 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/101c075e/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 72446d4..52de435 100644
--- a/go/build.go
+++ b/go/build.go
@@ -162,6 +162,14 @@ func specClasses(parcel *cfc.Parcel) {
 	bgMergerBinding.SpecMethod("Commit", "Commit() error")
 	bgMergerBinding.Register()
 
+	managerBinding := cfc.NewGoClass(parcel, "Lucy::Index::IndexManager")
+	managerBinding.SpecMethod("Write_Merge_Data", "WriteMergeData(int64) error")
+	managerBinding.SpecMethod("Read_Merge_Data", "ReadMergeData() (map[string]interface{}, error)")
+	managerBinding.SpecMethod("Remove_Merge_Data", "RemoveMergeData() error")
+	managerBinding.SpecMethod("Make_Snapshot_Filename", "MakeSnapshotFilename() (string, error)")
+	managerBinding.SpecMethod("Recycle", "Recycle(PolyReader, DeletionsWriter, int64, bool)
([]SegReader, error)")
+	managerBinding.Register()
+
 	schemaBinding := cfc.NewGoClass(parcel, "Lucy::Plan::Schema")
 	schemaBinding.SpecMethod("All_Fields", "AllFields() []string")
 	schemaBinding.Register()

http://git-wip-us.apache.org/repos/asf/lucy/blob/101c075e/go/lucy/index.go
----------------------------------------------------------------------
diff --git a/go/lucy/index.go b/go/lucy/index.go
index 83b36df..ba26f95 100644
--- a/go/lucy/index.go
+++ b/go/lucy/index.go
@@ -248,3 +248,62 @@ func (bgm *BackgroundMergerIMP) Commit() error {
 		C.LUCY_BGMerger_Commit(self)
 	})
 }
+
+func (im *IndexManagerIMP) WriteMergeData(cutoff int64) error {
+	return clownfish.TrapErr(func() {
+		self := (*C.lucy_IndexManager)(clownfish.Unwrap(im, "im"))
+		C.LUCY_IxManager_Write_Merge_Data(self, C.int64_t(cutoff))
+	})
+}
+
+func (im *IndexManagerIMP) ReadMergeData() (retval map[string]interface{}, err error) {
+	err = clownfish.TrapErr(func() {
+		self := (*C.lucy_IndexManager)(clownfish.Unwrap(im, "im"))
+		retvalC := C.LUCY_IxManager_Read_Merge_Data(self)
+		if retvalC != nil {
+			defer C.cfish_decref(unsafe.Pointer(retvalC))
+			retval = clownfish.ToGo(unsafe.Pointer(retvalC)).(map[string]interface{})
+		}
+	})
+	return retval, err
+}
+
+func (im *IndexManagerIMP) RemoveMergeData() error {
+	return clownfish.TrapErr(func() {
+		self := (*C.lucy_IndexManager)(clownfish.Unwrap(im, "im"))
+		C.LUCY_IxManager_Remove_Merge_Data(self)
+	})
+}
+
+func (im *IndexManagerIMP) MakeSnapshotFilename() (retval string, err error) {
+	err = clownfish.TrapErr(func() {
+		self := (*C.lucy_IndexManager)(clownfish.Unwrap(im, "im"))
+		retvalC := C.LUCY_IxManager_Make_Snapshot_Filename(self)
+		if retvalC != nil {
+			defer C.cfish_decref(unsafe.Pointer(retvalC))
+			retval = clownfish.ToGo(unsafe.Pointer(retvalC)).(string)
+		}
+	})
+	return retval, err
+}
+
+func (im *IndexManagerIMP) Recycle(reader PolyReader, delWriter DeletionsWriter,
+	cutoff int64, optimize bool) (retval []SegReader, err error) {
+	err = clownfish.TrapErr(func() {
+		self := (*C.lucy_IndexManager)(clownfish.Unwrap(im, "im"))
+		readerC := (*C.lucy_PolyReader)(clownfish.Unwrap(reader, "reader"))
+		delWriterC := (*C.lucy_DeletionsWriter)(clownfish.Unwrap(delWriter, "delWriter"))
+		vec := C.LUCY_IxManager_Recycle(self, readerC, delWriterC,
+			C.int64_t(cutoff), C.bool(optimize))
+		if vec != nil {
+			defer C.cfish_decref(unsafe.Pointer(vec))
+			size := int(C.CFISH_Vec_Get_Size(vec))
+			retval = make([]SegReader, size)
+			for i := 0; i < size; i++ {
+				elem := C.CFISH_Vec_Fetch(vec, C.size_t(i))
+				retval[i] = WRAPSegReader(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(elem))))
+			}
+		}
+	})
+	return retval, err
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/101c075e/go/lucy/index_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/index_test.go b/go/lucy/index_test.go
index 86055ae..a9aa279 100644
--- a/go/lucy/index_test.go
+++ b/go/lucy/index_test.go
@@ -18,6 +18,8 @@ package lucy
 
 import "testing"
 import "os"
+import "reflect"
+import "strings"
 
 func TestIndexerAddDoc(t *testing.T) {
 	schema := createTestSchema()
@@ -141,3 +143,107 @@ func TestBackgroundMergerMisc(t *testing.T) {
 		t.Errorf("Commit: %v", err)
 	}
 }
+
+func TestIndexManagerAccessors(t *testing.T) {
+	host := "dev.example.com"
+	manager := NewIndexManager(host, nil)
+	if got := manager.GetHost(); got != host {
+		t.Errorf("GetHost: %v", got)
+	}
+	folder := NewRAMFolder("")
+	manager.SetFolder(folder)
+	if got := manager.GetFolder(); !reflect.DeepEqual(folder, got) {
+		t.Errorf("SetFolder/GetFolder")
+	}
+	manager.SetWriteLockTimeout(72)
+	if got := manager.GetWriteLockTimeout(); got != 72 {
+		t.Errorf("Set/GetWriteLockTimeout: %d", got)
+	}
+	manager.SetWriteLockInterval(42)
+	if got := manager.GetWriteLockInterval(); got != 42 {
+		t.Errorf("Set/GetWriteLockInterval: %d", got)
+	}
+	manager.SetMergeLockTimeout(73)
+	if got := manager.GetMergeLockTimeout(); got != 73 {
+		t.Errorf("Set/GetMergeLockTimeout: %d", got)
+	}
+	manager.SetMergeLockInterval(43)
+	if got := manager.GetMergeLockInterval(); got != 43 {
+		t.Errorf("Set/GetMergeLockInterval: %d", got)
+	}
+	manager.SetDeletionLockTimeout(71)
+	if got := manager.GetDeletionLockTimeout(); got != 71 {
+		t.Errorf("Set/GetDeletionLockTimeout: %d", got)
+	}
+	manager.SetDeletionLockInterval(41)
+	if got := manager.GetDeletionLockInterval(); got != 41 {
+		t.Errorf("Set/GetDeletionLockInterval: %d", got)
+	}
+}
+
+func TestIndexManagerLocks(t *testing.T) {
+	manager := NewIndexManager("", nil)
+	manager.SetFolder(NewRAMFolder(""))
+	if _, ok := manager.MakeWriteLock().(Lock); !ok {
+		t.Errorf("MakeWriteLock")
+	}
+	if _, ok := manager.MakeMergeLock().(Lock); !ok {
+		t.Errorf("MakeMergeLock")
+	}
+	if _, ok := manager.MakeDeletionLock().(Lock); !ok {
+		t.Errorf("MakeDeletionLock")
+	}
+	snapFile := "snapshot_4a.json"
+	if _, ok := manager.MakeSnapshotReadLock(snapFile).(SharedLock); !ok {
+		t.Errorf("MakeDeletionLock")
+	}
+}
+
+func TestIndexManagerMergeData(t *testing.T) {
+	var err error
+	manager := NewIndexManager("", nil)
+	manager.SetFolder(NewRAMFolder(""))
+	err = manager.WriteMergeData(42)
+	if err != nil {
+		t.Errorf("WriteMergeData: %v", err)
+	}
+	mergeData, err := manager.ReadMergeData()
+	if err != nil {
+		t.Errorf("ReadMergeData: %v", err)
+	}
+	if got, ok := mergeData["cutoff"].(string); !ok || got != "42" {
+		t.Errorf("ReadMergeData: %v", got)
+	}
+	err = manager.RemoveMergeData()
+	if err != nil {
+		t.Errorf("RemoveMergeData: %v", err)
+	}
+}
+
+func TestIndexManagerMisc(t *testing.T) {
+	manager := NewIndexManager("", nil)
+	manager.SetFolder(NewRAMFolder(""))
+	if got, err := manager.MakeSnapshotFilename(); !strings.Contains(got, "snapshot") || err
!= nil {
+		t.Errorf("MakeSnapshotFilename: %s, %v", got, err)
+	}
+	snapshot := NewSnapshot()
+	snapshot.AddEntry("seg_4")
+	snapshot.AddEntry("seg_5")
+	if got := manager.HighestSegNum(snapshot); got != 5 {
+		t.Errorf("HighestSegNum: %d", got)
+	}
+}
+
+func TestIndexManagerRecycle(t *testing.T) {
+	index := createTestIndex("foo", "bar", "baz")
+	manager := NewIndexManager("", nil)
+	manager.SetFolder(index)
+	indexer, _ := OpenIndexer(&OpenIndexerArgs{Index: index})
+	searcher, _ := OpenIndexSearcher(index)
+	reader := searcher.GetReader().(PolyReader)
+	delWriter := indexer.GetSegWriter().GetDelWriter()
+	segReaders, err := manager.Recycle(reader, delWriter, 0, true)
+	if err != nil || len(segReaders) != 1 {
+		t.Errorf("Recycle: (%d SegReaders) %v", len(segReaders), err)
+	}
+}


Mime
View raw message