コード例 #1
0
ファイル: dingo_local_test.go プロジェクト: MogeiWang/dingo
func (me *localSingleAppTestSuite) SetupTest() {
	// reset the 'virtual wire' for every test
	me.wireBroker, me.wireBackend = make(chan []byte, 10), make(chan *dingo.ReportEnvelope, 10)

	me.GenApp = func() (app *dingo.App, err error) {
		app, err = dingo.NewApp("remote", nil)
		if err != nil {
			return
		}

		brk, err := dingo.NewLocalBroker(dingo.DefaultConfig(), me.wireBroker)
		if err != nil {
			return
		}
		_, _, err = app.Use(brk, dingo.ObjT.Default)
		if err != nil {
			return
		}

		bkd, err := dingo.NewLocalBackend(dingo.DefaultConfig(), me.wireBackend)
		if err != nil {
			return
		}
		_, _, err = app.Use(bkd, dingo.ObjT.Default)
		if err != nil {
			return
		}

		return
	}

	me.DingoSingleAppTestSuite.SetupTest()
}
コード例 #2
0
ファイル: backend_local_test.go プロジェクト: MogeiWang/dingo
func TestLocalBackendSuite(t *testing.T) {
	suite.Run(t, &localBackendTestSuite{
		dingo.BackendTestSuite{
			Gen: func() (b dingo.Backend, err error) {
				b, err = dingo.NewLocalBackend(dingo.DefaultConfig(), nil)
				if err == nil {
					err = b.(dingo.Object).Expect(dingo.ObjT.Reporter | dingo.ObjT.Store)
				}
				return
			},
		},
	})
}
コード例 #3
0
ファイル: backend_local_test.go プロジェクト: MogeiWang/dingo
func TestLocalReporter(t *testing.T) {
	ass := assert.New(t)

	var reporter dingo.Reporter
	reporter, err := dingo.NewLocalBackend(dingo.DefaultConfig(), nil)

	// test case for Report/Unbind
	reports := make(chan *dingo.ReportEnvelope, 10)
	_, err = reporter.Report("TestLocalReporter", reports)
	ass.Nil(err)

	// teardown
	reporter.(dingo.Object).Close()
}
コード例 #4
0
ファイル: dingo_local_test.go プロジェクト: MogeiWang/dingo
func (me *localMultiAppTestSuite) SetupTest() {
	// reset the 'virtual wire' for every test
	me.wireBroker, me.wireBackend = make(chan []byte, 10), make(chan *dingo.ReportEnvelope, 10)

	me.GenCaller = func() (app *dingo.App, err error) {
		app, err = dingo.NewApp("remote", nil)
		me.Nil(err)
		if err != nil {
			return
		}

		brk, err := dingo.NewLocalBroker(dingo.DefaultConfig(), me.wireBroker)
		me.Nil(err)
		if err != nil {
			return
		}
		_, _, err = app.Use(brk, dingo.ObjT.Producer)
		me.Nil(err)
		if err != nil {
			return
		}

		bkd, err := dingo.NewLocalBackend(dingo.DefaultConfig(), me.wireBackend)
		me.Nil(err)
		if err != nil {
			return
		}
		_, _, err = app.Use(bkd, dingo.ObjT.Store)
		me.Nil(err)
		if err != nil {
			return
		}

		return
	}

	me.GenWorker = func() (app *dingo.App, err error) {
		app, err = dingo.NewApp("remote", nil)
		me.Nil(err)
		if err != nil {
			return
		}

		brk, err := dingo.NewLocalBroker(dingo.DefaultConfig(), me.wireBroker)
		me.Nil(err)
		if err != nil {
			return
		}
		_, _, err = app.Use(brk, dingo.ObjT.Consumer)
		me.Nil(err)
		if err != nil {
			return
		}

		bkd, err := dingo.NewLocalBackend(dingo.DefaultConfig(), me.wireBackend)
		me.Nil(err)
		if err != nil {
			return
		}
		_, _, err = app.Use(bkd, dingo.ObjT.Reporter)
		me.Nil(err)
		if err != nil {
			return
		}

		return
	}

	me.DingoMultiAppTestSuite.SetupTest()
}
コード例 #5
0
ファイル: example_test.go プロジェクト: MogeiWang/dingo
func ExampleCustomMarshaller() {
	/*
		import (
			"encoding/json"
			"fmt"

			"github.com/mission-liao/dingo"
		)
	*/
	// this example demonstrate the usage of using a
	// customized marshaller by encoding every parameter
	// in JSON.
	// And invoke it with customized invoker
	var err error
	defer func() {
		if err != nil {
			fmt.Printf("%v\n", err)
		}
	}()

	// an App in remote mode, with local backend/broker
	app, err := dingo.NewApp("remote", nil)
	if err != nil {
		return
	}

	// attach a local broker.
	broker, err := dingo.NewLocalBroker(dingo.DefaultConfig(), nil)
	if err != nil {
		return
	}
	_, _, err = app.Use(broker, dingo.ObjT.Default)
	// attach a local backend
	backend, err := dingo.NewLocalBackend(dingo.DefaultConfig(), nil)
	if err != nil {
		return
	}
	_, _, err = app.Use(backend, dingo.ObjT.Default)
	if err != nil {
		return
	}

	// register customize marshaller & invoker
	err = app.AddMarshaller(101, &struct {
		testMyInvoker3
		dingo.CustomMarshaller
	}{
		testMyInvoker3{},
		dingo.CustomMarshaller{Codec: &testCustomMarshallerCodec{}},
	})
	if err != nil {
		return
	}

	// register worker function
	err = app.Register("concat", func(words []string) (ret string) {
		for _, v := range words {
			ret = ret + v
		}
		return
	})
	if err != nil {
		return
	}

	// change marshaller of worker function
	err = app.SetMarshaller("concat", 101, 101)
	if err != nil {
		return
	}

	// allocate workers
	_, err = app.Allocate("concat", 1, 1)
	if err != nil {
		return
	}

	// trigger the fire...
	result := dingo.NewResult(app.Call("concat", nil, []string{"Merry ", "X", "'mas"}))
	err = result.Wait(0)
	if err != nil {
		return
	}
	result.OnOK(func(ret string) {
		fmt.Printf("%v\n", ret)
	})

	err = app.Close()
	if err != nil {
		return
	}
}