예제 #1
0
func TestSearchRequest(t *testing.T) {
	qry := map[string]interface{}{
		"query": map[string]interface{}{
			"wildcard": map[string]string{"actor": "a*"},
		},
	}
	out, err := SearchRequest(true, "github", "", qry, "", 0)
	//log.Println(out)
	Assert(&out != nil && err == nil, t, "Should get docs")
	Assert(out.Hits.Len() == 10, t, "Should have 10 docs but was %v", out.Hits.Len())
	Assert(u.CloseInt(out.Hits.Total, 588), t, "Should have 588 hits but was %v", out.Hits.Total)
}
예제 #2
0
func TestBulkIndexorBasic(t *testing.T) {
	InitTests(true)
	indexor := NewBulkIndexor(3)
	indexor.BulkSendor = func(buf *bytes.Buffer) error {
		messageSets += 1
		totalBytesSent += buf.Len()
		buffers = append(buffers, buf)
		u.Debug(string(buf.Bytes()))
		return BulkSend(buf)
	}
	done := make(chan bool)
	indexor.Run(done)

	date := time.Unix(1257894000, 0)
	data := map[string]interface{}{"name": "smurfs", "age": 22, "date": time.Unix(1257894000, 0)}
	err := indexor.Index("users", "user", "1", "", &date, data)

	WaitFor(func() bool {
		return len(buffers) > 0
	}, 5)
	// part of request is url, so lets factor that in
	//totalBytesSent = totalBytesSent - len(*eshost)
	u.Assert(len(buffers) == 1, t, "Should have sent one operation but was %d", len(buffers))
	u.Assert(BulkErrorCt == 0 && err == nil, t, "Should not have any errors  %v", err)
	u.Assert(totalBytesSent == 145, t, "Should have sent 135 bytes but was %v", totalBytesSent)

	err = indexor.Index("users", "user", "2", "", nil, data)
	<-time.After(time.Millisecond * 10) // we need to wait for doc to hit send channel
	// this will test to ensure that Flush actually catches a doc
	indexor.Flush()
	totalBytesSent = totalBytesSent - len(*eshost)
	u.Assert(err == nil, t, "Should have nil error  =%v", err)
	u.Assert(len(buffers) == 2, t, "Should have another buffer ct=%d", len(buffers))

	u.Assert(BulkErrorCt == 0, t, "Should not have any errors %d", BulkErrorCt)
	u.Assert(u.CloseInt(totalBytesSent, 257), t, "Should have sent 257 bytes but was %v", totalBytesSent)

}