コード例 #1
0
ファイル: reqtrace_bucket.go プロジェクト: okdave/gcloud
func (b *reqtraceBucket) NewReader(
	ctx context.Context,
	req *ReadObjectRequest) (rc io.ReadCloser, err error) {
	var report reqtrace.ReportFunc

	// Start a span.
	desc := fmt.Sprintf("Read: %s", sanitizeObjectName(req.Name))
	ctx, report = reqtrace.StartSpan(ctx, desc)

	// Call the wrapped bucket.
	rc, err = b.Wrapped.NewReader(ctx, req)

	// If the bucket failed, we must report that now.
	if err != nil {
		report(err)
		return
	}

	// Snoop on the outcome.
	rc = &reportingReadCloser{
		Wrapped: rc,
		Report:  report,
	}

	return
}
コード例 #2
0
ファイル: common_op.go プロジェクト: BanzaiMan/gcsfuse
func (o *commonOp) init(
	ctx context.Context,
	op internalOp,
	bazilReq bazilfuse.Request,
	debugLog func(int, string, ...interface{}),
	errorLogger *log.Logger,
	finished func(error)) {
	// Initialize basic fields.
	o.ctx = ctx
	o.op = op
	o.bazilReq = bazilReq
	o.debugLog = debugLog
	o.errorLogger = errorLogger
	o.finished = finished

	// Set up a trace span for this op.
	var reportForTrace reqtrace.ReportFunc
	o.ctx, reportForTrace = reqtrace.StartSpan(o.ctx, o.op.ShortDesc())

	// When the op is finished, report to both reqtrace and the connection.
	prevFinish := o.finished
	o.finished = func(err error) {
		reportForTrace(err)
		prevFinish(err)
	}
}
コード例 #3
0
func registerTestSuite(
	makeDeps func(context.Context) BucketTestDeps,
	prototype bucketTestSetUpInterface) {
	suitePointerType := reflect.TypeOf(prototype)
	suiteType := suitePointerType.Elem()

	// We don't need anything fancy at the suite level.
	var ts ogletest.TestSuite
	ts.Name = getSuiteName(suiteType)

	// For each method, we create a test function.
	for _, method := range getTestMethods(suitePointerType) {
		var tf ogletest.TestFunction
		tf.Name = method.Name

		// Create an instance to be shared among SetUp and the test function itself.
		var instance reflect.Value = reflect.New(suiteType)

		// SetUp should create a bucket and then initialize the suite object,
		// remembering that the suite implements bucketTestSetUpInterface.
		var report reqtrace.ReportFunc
		tf.SetUp = func(*ogletest.TestInfo) {
			// Start tracing.
			var testCtx context.Context
			testCtx, report = reqtrace.Trace(context.Background(), "Overall test")

			// Set up the bucket and other dependencies.
			makeDepsCtx, makeDepsReport := reqtrace.StartSpan(testCtx, "Test setup")
			deps := makeDeps(makeDepsCtx)
			makeDepsReport(nil)

			// Hand off the dependencies and the context to the test.
			deps.ctx = testCtx
			instance.Interface().(bucketTestSetUpInterface).setUpBucketTest(deps)
		}

		// The test function itself should simply invoke the method.
		methodCopy := method
		tf.Run = func() {
			methodCopy.Func.Call([]reflect.Value{instance})
		}

		// Report the test result.
		tf.TearDown = func() {
			report(errors.New(
				"TODO(jacobsa): Plumb through the test failure status. " +
					"Or offer tracing in ogletest itself."))
		}

		// Save the test function.
		ts.TestFunctions = append(ts.TestFunctions, tf)
	}

	// Register the suite.
	ogletest.Register(ts)
}