Skip to content

Commit

Permalink
add tests for estimate command
Browse files Browse the repository at this point in the history
  • Loading branch information
kutluhanmetin committed Nov 1, 2023
1 parent f2b1d9e commit cddaad4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
59 changes: 58 additions & 1 deletion base/commands/migration/estimate_it_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,58 @@
package migration
//go:build std || migration

package migration_test

import (
"context"
"encoding/json"
"os"
"sync"
"testing"
"time"

"github.com/hazelcast/hazelcast-commandline-client/base/commands/migration"
"github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/it"
"github.com/hazelcast/hazelcast-go-client/serialization"
)

func TestEstimate(t *testing.T) {
tcx := it.TestContext{T: t}
ctx := context.Background()
tcx.Tester(func(tcx it.TestContext) {
createMapping(ctx, tcx)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
check.Must(tcx.CLC().Execute(ctx, "estimate", "dmt-config"))
}()
c := make(chan string)
go findEstimationID(ctx, tcx, c)
mID := <-c
go estimateRunner(t, ctx, tcx, mID)
wg.Wait()
tcx.AssertStdoutContains("OK Estimation completed successfully")
})
}

func estimateRunner(t *testing.T, ctx context.Context, tcx it.TestContext, migrationID string) {
statusMap := check.MustValue(tcx.Client.GetMap(ctx, migration.StatusMapName))
b := check.MustValue(os.ReadFile("testdata/estimate/estimate_completed.json"))
it.Eventually(t, func() bool {
return statusMap.Set(ctx, migrationID, serialization.JSON(b)) == nil
})
}

func findEstimationID(ctx context.Context, tcx it.TestContext, c chan string) {
q := check.MustValue(tcx.Client.GetQueue(ctx, migration.EstimateQueueName))
var b migration.ConfigBundle
for {
v := check.MustValue(q.PollWithTimeout(ctx, time.Second))
if v != nil {
check.Must(json.Unmarshal(v.(serialization.JSON), &b))
c <- b.MigrationID
break
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"status": "COMPLETED",
"estimatedTime": 1,
"estimatedSize": 1
}

0 comments on commit cddaad4

Please sign in to comment.