diff options
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/reindex_test.go')
-rw-r--r-- | vendor/gopkg.in/olivere/elastic.v5/reindex_test.go | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/reindex_test.go b/vendor/gopkg.in/olivere/elastic.v5/reindex_test.go index 545d097f2..2ab604089 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/reindex_test.go +++ b/vendor/gopkg.in/olivere/elastic.v5/reindex_test.go @@ -82,6 +82,31 @@ func TestReindexSourceWithSourceAndDestinationAndVersionType(t *testing.T) { } } +func TestReindexSourceWithSourceAndRemoteAndDestination(t *testing.T) { + client := setupTestClient(t) + src := NewReindexSource().Index("twitter").RemoteInfo( + NewReindexRemoteInfo().Host("http://otherhost:9200"). + Username("alice"). + Password("secret"). + ConnectTimeout("10s"). + SocketTimeout("1m"), + ) + dst := NewReindexDestination().Index("new_twitter") + out, err := client.Reindex().Source(src).Destination(dst).getBody() + if err != nil { + t.Fatal(err) + } + b, err := json.Marshal(out) + if err != nil { + t.Fatal(err) + } + got := string(b) + want := `{"dest":{"index":"new_twitter"},"source":{"index":"twitter","remote":{"connect_timeout":"10s","host":"http://otherhost:9200","password":"secret","socket_timeout":"1m","username":"alice"}}}` + if got != want { + t.Fatalf("\ngot %s\nwant %s", got, want) + } +} + func TestReindexSourceWithSourceAndDestinationAndOpType(t *testing.T) { client := setupTestClient(t) src := NewReindexSource().Index("twitter") @@ -289,3 +314,88 @@ func TestReindex(t *testing.T) { t.Fatalf("expected %d documents; got: %d", sourceCount, targetCount) } } + +func TestReindexAsync(t *testing.T) { + client := setupTestClientAndCreateIndexAndAddDocs(t) //, SetTraceLog(log.New(os.Stdout, "", 0))) + esversion, err := client.ElasticsearchVersion(DefaultURL) + if err != nil { + t.Fatal(err) + } + if esversion < "2.3.0" { + t.Skipf("Elasticsearch %v does not support Reindex API yet", esversion) + } + + sourceCount, err := client.Count(testIndexName).Do(context.TODO()) + if err != nil { + t.Fatal(err) + } + if sourceCount <= 0 { + t.Fatalf("expected more than %d documents; got: %d", 0, sourceCount) + } + + targetCount, err := client.Count(testIndexName2).Do(context.TODO()) + if err != nil { + t.Fatal(err) + } + if targetCount != 0 { + t.Fatalf("expected %d documents; got: %d", 0, targetCount) + } + + // Simple copying + src := NewReindexSource().Index(testIndexName) + dst := NewReindexDestination().Index(testIndexName2) + res, err := client.Reindex().Source(src).Destination(dst).DoAsync(context.TODO()) + if err != nil { + t.Fatal(err) + } + if res == nil { + t.Fatal("expected result != nil") + } + if res.TaskId == "" { + t.Errorf("expected a task id, got %+v", res) + } + + tasksGetTask := client.TasksGetTask() + taskStatus, err := tasksGetTask.TaskId(res.TaskId).Do(context.TODO()) + if err != nil { + t.Fatal(err) + } + if taskStatus == nil { + t.Fatal("expected task status result != nil") + } +} + +func TestReindexWithWaitForCompletionTrueCannotBeStarted(t *testing.T) { + client := setupTestClientAndCreateIndexAndAddDocs(t) + esversion, err := client.ElasticsearchVersion(DefaultURL) + if err != nil { + t.Fatal(err) + } + if esversion < "2.3.0" { + t.Skipf("Elasticsearch %v does not support Reindex API yet", esversion) + } + + sourceCount, err := client.Count(testIndexName).Do(context.TODO()) + if err != nil { + t.Fatal(err) + } + if sourceCount <= 0 { + t.Fatalf("expected more than %d documents; got: %d", 0, sourceCount) + } + + targetCount, err := client.Count(testIndexName2).Do(context.TODO()) + if err != nil { + t.Fatal(err) + } + if targetCount != 0 { + t.Fatalf("expected %d documents; got: %d", 0, targetCount) + } + + // DoAsync should fail when WaitForCompletion is true + src := NewReindexSource().Index(testIndexName) + dst := NewReindexDestination().Index(testIndexName2) + _, err = client.Reindex().Source(src).Destination(dst).WaitForCompletion(true).DoAsync(context.TODO()) + if err == nil { + t.Fatal("error should have been returned") + } +} |