MCPcopy
hub / github.com/dgraph-io/dgraph / TestExportRdf

Function TestExportRdf

worker/export_test.go:227–327  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

225}
226
227func TestExportRdf(t *testing.T) {
228 // Index the name predicate. We ensure it doesn't show up on export.
229 initTestExport(t, `
230 name: string @index(exact) .
231 age: int .
232 [0x2] name: string @index(exact) .
233 `)
234
235 bdir := t.TempDir()
236 time.Sleep(1 * time.Second)
237
238 // We have 4 friend type edges. FP("friends")%10 = 2.
239 x.WorkerConfig.ExportPath = bdir
240 readTs := timestamp()
241 // Do the following so export won't block forever for readTs.
242 posting.Oracle().ProcessDelta(&pb.OracleDelta{MaxAssigned: readTs})
243 files, err := export(context.Background(), &pb.ExportRequest{ReadTs: readTs, GroupId: 1,
244 Namespace: math.MaxUint64, Format: "rdf"})
245 require.NoError(t, err)
246
247 fileList, schemaFileList, gqlSchema := getExportFileList(t, bdir)
248 require.Equal(t, len(files), len(fileList)+len(schemaFileList)+len(gqlSchema))
249
250 file := fileList[0]
251 f, err := os.Open(file)
252 require.NoError(t, err)
253
254 r, err := gzip.NewReader(f)
255 require.NoError(t, err)
256
257 scanner := bufio.NewScanner(r)
258 count := 0
259
260 l := &lex.Lexer{}
261 for scanner.Scan() {
262 nq, err := chunker.ParseRDF(scanner.Text(), l)
263 require.NoError(t, err)
264 require.Contains(t, []string{"0x1", "0x2", "0x3", "0x4", "0x5", "0x6", "0x9"}, nq.Subject)
265 if nq.ObjectValue != nil {
266 switch nq.Subject {
267 case "0x1", "0x2":
268 require.Equal(t, &api.Value{Val: &api.Value_DefaultVal{DefaultVal: "pho\ton"}},
269 nq.ObjectValue)
270 case "0x3":
271 require.Equal(t, &api.Value{Val: &api.Value_DefaultVal{DefaultVal: "First Line\nSecondLine"}},
272 nq.ObjectValue)
273 case "0x4":
274 case "0x5":
275 require.Equal(t, `<0x5> <name> "" <0x0> .`, scanner.Text())
276 case "0x6":
277 require.Equal(t, `<0x6> <name> "Ding!\u0007Ding!\u0007Ding!\u0007" <0x0> .`,
278 scanner.Text())
279 case "0x9":
280 require.Equal(t, `<0x9> <name> "ns2" <0x2> .`, scanner.Text())
281 default:
282 t.Errorf("Unexpected subject: %v", nq.Subject)
283 }
284 if nq.Subject == "_:uid1" || nq.Subject == "0x2" {

Callers

nothing calls this directly

Calls 11

OracleFunction · 0.92
ParseRDFFunction · 0.92
initTestExportFunction · 0.85
exportFunction · 0.85
getExportFileListFunction · 0.85
checkExportSchemaFunction · 0.85
checkExportGqlSchemaFunction · 0.85
ProcessDeltaMethod · 0.80
timestampFunction · 0.70
OpenMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected