コード例 #1
0
ファイル: integration_test.go プロジェクト: mbookman/gcsfuse
func (t *IntegrationTest) AppendThenSync() {
	// Create.
	o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", "taco")
	AssertEq(nil, err)

	t.create(o)

	// Append some data.
	n, err := t.mc.WriteAt(t.ctx, []byte("burrito"), 4)

	AssertEq(nil, err)
	ExpectEq(len("burrito"), n)

	// Sync should save out the new generation.
	rl, newObj, err := t.sync(o)
	AssertEq(nil, err)

	ExpectNe(o.Generation, newObj.Generation)
	ExpectEq(t.objectGeneration("foo"), newObj.Generation)

	// Read via the bucket.
	contents, err := gcsutil.ReadObject(t.ctx, t.bucket, "foo")
	AssertEq(nil, err)
	ExpectEq("tacoburrito", string(contents))

	// Read via the lease.
	_, err = rl.Seek(0, 0)
	AssertEq(nil, err)

	contents, err = ioutil.ReadAll(rl)
	AssertEq(nil, err)
	ExpectEq("tacoburrito", string(contents))

	// There should be no junk left over in the bucket besides the object of
	// interest.
	objects, runs, err := gcsutil.ListAll(
		t.ctx,
		t.bucket,
		&gcs.ListObjectsRequest{})

	AssertEq(nil, err)
	AssertEq(1, len(objects))
	AssertEq(0, len(runs))

	ExpectEq("foo", objects[0].Name)
}
コード例 #2
0
ファイル: integration_test.go プロジェクト: horzadome/gcsfuse
func (t *IntegrationTest) AppendThenSync() {
	// Create.
	o, err := gcsutil.CreateObject(t.ctx, t.bucket, "foo", []byte("taco"))
	AssertEq(nil, err)

	t.create(o)

	// Append some data.
	t.clock.AdvanceTime(time.Second)
	writeTime := t.clock.Now()
	n, err := t.tf.WriteAt([]byte("burrito"), 4)
	t.clock.AdvanceTime(time.Second)

	AssertEq(nil, err)
	ExpectEq(len("burrito"), n)

	// Sync should save out the new generation.
	newObj, err := t.sync(o)
	AssertEq(nil, err)

	ExpectNe(o.Generation, newObj.Generation)
	ExpectEq(t.objectGeneration("foo"), newObj.Generation)
	ExpectEq(
		writeTime.UTC().Format(time.RFC3339Nano),
		newObj.Metadata["gcsfuse_mtime"])

	// Read via the bucket.
	contents, err := gcsutil.ReadObject(t.ctx, t.bucket, "foo")
	AssertEq(nil, err)
	ExpectEq("tacoburrito", string(contents))

	// There should be no junk left over in the bucket besides the object of
	// interest.
	objects, runs, err := gcsutil.ListAll(
		t.ctx,
		t.bucket,
		&gcs.ListObjectsRequest{})

	AssertEq(nil, err)
	AssertEq(1, len(objects))
	AssertEq(0, len(runs))

	ExpectEq("foo", objects[0].Name)
}