(t *testing.T)
| 63 | ) |
| 64 | |
| 65 | func TestBulkLoaderSkipReducePhase(t *testing.T) { |
| 66 | tmpDir := t.TempDir() |
| 67 | |
| 68 | conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1). |
| 69 | WithACL(time.Hour).WithReplicas(1).WithBulkLoadOutDir(t.TempDir()) |
| 70 | c, err := dgraphtest.NewLocalCluster(conf) |
| 71 | require.NoError(t, err) |
| 72 | defer func() { c.Cleanup(t.Failed()) }() |
| 73 | |
| 74 | require.NoError(t, c.StartZero(0)) |
| 75 | require.NoError(t, c.HealthCheck(true)) |
| 76 | |
| 77 | baseDir := t.TempDir() |
| 78 | dataFile := filepath.Join(baseDir, "data.json") |
| 79 | require.NoError(t, os.WriteFile(dataFile, []byte(jsonData), os.ModePerm)) |
| 80 | gqlSchemaFile := filepath.Join(baseDir, "gql.schema") |
| 81 | require.NoError(t, os.WriteFile(gqlSchemaFile, []byte(gqlSchema), os.ModePerm)) |
| 82 | |
| 83 | // First run: map phase only, preserve tmp dir |
| 84 | mapOpts := dgraphtest.BulkOpts{ |
| 85 | DataFiles: []string{dataFile}, |
| 86 | GQLSchemaFiles: []string{gqlSchemaFile}, |
| 87 | TmpDir: tmpDir, |
| 88 | SkipReducePhase: true, |
| 89 | } |
| 90 | require.NoError(t, c.BulkLoad(mapOpts)) |
| 91 | |
| 92 | // Second run: reduce phase only, using the same tmp dir. |
| 93 | // Data and schema files are not needed; all input was processed in the map phase. |
| 94 | reduceOpts := dgraphtest.BulkOpts{ |
| 95 | TmpDir: tmpDir, |
| 96 | SkipMapPhase: true, |
| 97 | } |
| 98 | require.NoError(t, c.BulkLoad(reduceOpts)) |
| 99 | |
| 100 | require.NoError(t, c.Start()) |
| 101 | |
| 102 | hc, err := c.HTTPClient() |
| 103 | require.NoError(t, err) |
| 104 | require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser, |
| 105 | dgraphapi.DefaultPassword, x.RootNamespace)) |
| 106 | |
| 107 | params := dgraphapi.GraphQLParams{ |
| 108 | Query: `query { |
| 109 | getMessage(uniqueId: 3) { |
| 110 | content |
| 111 | author |
| 112 | } |
| 113 | }`, |
| 114 | } |
| 115 | data, err := hc.RunGraphqlQuery(params, false) |
| 116 | require.NoError(t, err) |
| 117 | require.NoError(t, dgraphapi.CompareJSON(`{ |
| 118 | "getMessage": { |
| 119 | "content": "DVTCTXCVYI", |
| 120 | "author": "USYMVFJYXA" |
| 121 | } |
| 122 | }`, string(data))) |
nothing calls this directly
no test coverage detected