MCPcopy
hub / github.com/NVIDIA/aistore / Example_obj

Function Example_obj

transport/obj_test.go:197–229  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

195}
196
197func Example_obj() {
198 receive := func(hdr transport.ObjHdr, objReader io.Reader, err error) error {
199 cos.Assert(err == nil)
200 object, err := io.ReadAll(objReader)
201 if err != nil {
202 panic(err)
203 }
204 if int64(len(object)) != hdr.ObjAttrs.Size {
205 panic(fmt.Sprintf("size %d != %d", len(object), hdr.ObjAttrs.Size))
206 }
207 fmt.Printf("%s...\n", string(object[:16]))
208 return nil
209 }
210 ts := httptest.NewServer(objmux)
211 defer ts.Close()
212 trname := "dummy-obj"
213 err := transport.HandleObjStream(trname, receive)
214 if err != nil {
215 fmt.Println(err)
216 return
217 }
218 httpclient := transport.NewIntraDataClient()
219 stream := transport.NewObjStream(httpclient, ts.URL+transport.ObjURLPath(trname), cos.GenTie(), nil)
220 sendText(stream, lorem, duis)
221 sendText(stream, et, temporibus)
222 stream.Fin()
223
224 // Output:
225 // Lorem ipsum dolo...
226 // Duis aute irure ...
227 // Et harum quidem ...
228 // Temporibus autem...
229}
230
231// test random streaming
232func Test_OneStream(t *testing.T) {

Callers

nothing calls this directly

Calls 10

AssertFunction · 0.92
HandleObjStreamFunction · 0.92
NewIntraDataClientFunction · 0.92
NewObjStreamFunction · 0.92
ObjURLPathFunction · 0.92
GenTieFunction · 0.92
sendTextFunction · 0.85
ReadAllMethod · 0.80
CloseMethod · 0.65
FinMethod · 0.45

Tested by

no test coverage detected