lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [05/14] lucy git commit: Rework OpenIn for multi-value return.
Date Sat, 31 Oct 2015 22:22:20 GMT
Rework OpenIn for multi-value return.

The Go binding for Folder's OpenIn method should return a tuple of the
InStream and an error.


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

Branch: refs/heads/master
Commit: b2a6e66680a09b6df82e2870c08510468e25f124
Parents: c8950d0
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Wed Oct 21 14:38:37 2015 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Fri Oct 23 16:41:42 2015 -0700

----------------------------------------------------------------------
 go/build.go            |  1 +
 go/lucy/search_test.go |  8 ++++----
 go/lucy/store.go       | 15 +++++++++++++++
 go/lucy/store_test.go  | 10 ++++++----
 4 files changed, 26 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/b2a6e666/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 96f01ed..b1c155d 100644
--- a/go/build.go
+++ b/go/build.go
@@ -255,6 +255,7 @@ func specClasses(parcel *cfc.Parcel) {
 
 	folderBinding := cfc.NewGoClass(parcel, "Lucy::Store::Folder")
 	folderBinding.SpecMethod("Open_Out", "OpenOut(string) (OutStream, error)")
+	folderBinding.SpecMethod("Open_In", "OpenIn(string) (InStream, error)")
 	folderBinding.Register()
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/b2a6e666/go/lucy/search_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/search_test.go b/go/lucy/search_test.go
index c4cd282..319f0f7 100644
--- a/go/lucy/search_test.go
+++ b/go/lucy/search_test.go
@@ -26,7 +26,7 @@ func checkQuerySerialize(t *testing.T, query Query) {
 	outStream, _ := folder.OpenOut("foo")
 	query.Serialize(outStream)
 	outStream.Close()
-	inStream := folder.OpenIn("foo")
+	inStream, _ := folder.OpenIn("foo")
 	dupe := clownfish.GetClass(query).MakeObj().(Query).Deserialize(inStream)
 	if !query.Equals(dupe) {
 		t.Errorf("Unsuccessful serialization round trip -- expected '%v', got '%v'",
@@ -404,7 +404,7 @@ func TestTopDocsBasics(t *testing.T) {
 	outstream, _ := folder.OpenOut("foo")
 	td.Serialize(outstream)
 	outstream.Close()
-	inStream := folder.OpenIn("foo")
+	inStream, _ := folder.OpenIn("foo")
 	dupe := clownfish.GetClass(td).MakeObj().(TopDocs).Deserialize(inStream)
 	if dupe.GetTotalHits() != td.GetTotalHits() {
 		t.Errorf("Failed round-trip serializetion of TopDocs")
@@ -493,7 +493,7 @@ func TestSortSpecBasics(t *testing.T) {
 	outstream, _ := folder.OpenOut("foo")
 	sortSpec.Serialize(outstream)
 	outstream.Close()
-	inStream := folder.OpenIn("foo")
+	inStream, _ := folder.OpenIn("foo")
 	dupe := clownfish.GetClass(sortSpec).MakeObj().(SortSpec).Deserialize(inStream)
 	if len(dupe.GetRules()) != len(rules) {
 		t.Errorf("Failed round-trip serializetion of SortSpec")
@@ -701,7 +701,7 @@ func TestMatchDocSerialization(t *testing.T) {
 	outstream, _ := folder.OpenOut("foo")
 	matchDoc.Serialize(outstream)
 	outstream.Close()
-	inStream := folder.OpenIn("foo")
+	inStream, _ := folder.OpenIn("foo")
 	dupe := clownfish.GetClass(matchDoc).MakeObj().(MatchDoc).Deserialize(inStream)
 	if got := dupe.GetValues(); !reflect.DeepEqual(got, values) {
 		t.Errorf("Failed round-trip serializetion of MatchDoc")

http://git-wip-us.apache.org/repos/asf/lucy/blob/b2a6e666/go/lucy/store.go
----------------------------------------------------------------------
diff --git a/go/lucy/store.go b/go/lucy/store.go
index f23241e..111347c 100644
--- a/go/lucy/store.go
+++ b/go/lucy/store.go
@@ -345,3 +345,18 @@ func (f *FolderIMP) OpenOut(path string) (retval OutStream, err error)
{
 	})
 	return retval, err
 }
+
+func (f *FolderIMP) OpenIn(path string) (retval InStream, err error) {
+	err = clownfish.TrapErr(func() {
+		self := (*C.lucy_Folder)(clownfish.Unwrap(f, "f"))
+		pathC := (*C.cfish_String)(clownfish.GoToClownfish(path, unsafe.Pointer(C.CFISH_STRING),
false))
+		defer C.cfish_decref(unsafe.Pointer(pathC))
+		retvalC := C.LUCY_Folder_Open_In(self, pathC)
+		if retvalC == nil {
+			cfErr := C.cfish_Err_get_error();
+			panic(clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(unsafe.Pointer(cfErr)))).(error))
+		}
+		retval = WRAPInStream(unsafe.Pointer(retvalC))
+	})
+	return retval, err
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/b2a6e666/go/lucy/store_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/store_test.go b/go/lucy/store_test.go
index d75dbf0..f972c96 100644
--- a/go/lucy/store_test.go
+++ b/go/lucy/store_test.go
@@ -288,13 +288,15 @@ func TestIOStreamMisc(t *testing.T) {
 	outStream.Flush()
 	outStream.Close()
 
-	inStream := folder.OpenIn("file.dat")
+	inStream, _ := folder.OpenIn("file.dat")
 	if got := inStream.GetFilename(); got != "mydir/file.dat" {
 		t.Errorf("GetFilename: %s", got)
 	}
 }
 
 func runFolderTests(t *testing.T, folder Folder) {
+	var err error
+
 	folder.Initialize()
 	if !folder.Check() {
 		t.Errorf("Check")
@@ -307,9 +309,9 @@ func runFolderTests(t *testing.T, folder Folder) {
 	}
 	outStream.WriteBytes([]byte("hi"), 2)
 	outStream.Close()
-	inStream := folder.OpenIn("stuff/hello")
-	if inStream == nil {
-		t.Errorf("OpenIn")
+	inStream, err := folder.OpenIn("stuff/hello")
+	if inStream == nil || err != nil {
+		t.Errorf("OpenIn: %s", err)
 	}
 	inStream.Close()
 	fh := folder.OpenFileHandle("stuff/hello", 0x1) // 0x1 == FH_READ_ONLY


Mime
View raw message