Skip to content

Commit

Permalink
the default id maker for local mode should be seq one
Browse files Browse the repository at this point in the history
  • Loading branch information
mission-liao committed Jan 5, 2016
1 parent 63c77d2 commit 8c07e0a
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion backend_test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type BackendTestSuite struct {
}

func (ts *BackendTestSuite) SetupSuite() {
ts.Trans = newFnMgr()
ts.Trans = newFnMgr("")
ts.NotNil(ts.Gen)
}

Expand Down
2 changes: 1 addition & 1 deletion bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type bridgeTestSuite struct {

func (ts *bridgeTestSuite) SetupSuite() {
ts.eventMux = newMux()
ts.trans = newFnMgr()
ts.trans = newFnMgr("")
}

func (ts *bridgeTestSuite) TearDownSuite() {
Expand Down
2 changes: 1 addition & 1 deletion broker_test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (ts *BrokerTestSuite) SetupTest() {
}

ts.ConsumerNames = []string{}
ts.Trans = newFnMgr()
ts.Trans = newFnMgr("")
}

func (ts *BrokerTestSuite) TearDownTest() {
Expand Down
8 changes: 4 additions & 4 deletions dingo.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,21 @@ type App struct {
workers *_workers
}

/*NewApp whose "nameOfBridge" refers to different modes of dingo:
/*NewApp whose "mode" refers to different modes of dingo:
- "local": an App works in local mode, which is similar to other background worker framework.
- "remote": an App works in remote(distributed) mode, brokers(ex. AMQP...) and backends(ex. redis..., if required) would be needed to work.
*/
func NewApp(nameOfBridge string, cfg *Config) (app *App, err error) {
func NewApp(mode string, cfg *Config) (app *App, err error) {
if cfg == nil {
cfg = DefaultConfig()
}
v := &App{
objs: make(map[int]*_object),
eventMux: newMux(),
trans: newFnMgr(),
trans: newFnMgr(mode),
cfg: *cfg,
}
v.b = newBridge(nameOfBridge, v.trans)
v.b = newBridge(mode, v.trans)

// refer to 'ReadMostly' example in sync/atomic
v.eventOut.Store(make(map[int]*_eventListener))
Expand Down
4 changes: 3 additions & 1 deletion id_maker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ var ID = struct {
Default int
// an ID maker implemented via uuid4
UUID int
// an ID maker implemented by atomic.AddInt64
SEQ int
}{
0, 1,
0, 1, 2,
}

/*IDMaker is an object that can generate a series of identiy, typed as string.
Expand Down
2 changes: 1 addition & 1 deletion mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type mapperTestSuite struct {

func TestMapperSuite(t *testing.T) {
suite.Run(t, &mapperTestSuite{
_trans: newFnMgr(),
_trans: newFnMgr(""),
_hooks: newLocalBridge().(exHooks),
_tasks: make(chan *Task, 5),
_countOfMappers: 3,
Expand Down
10 changes: 8 additions & 2 deletions mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type fnMgr struct {
fn2opt atomic.Value
}

func newFnMgr() (c *fnMgr) {
func newFnMgr(mode string) (c *fnMgr) {
c = &fnMgr{}

// init for marshaller's'
Expand Down Expand Up @@ -66,7 +66,13 @@ func newFnMgr() (c *fnMgr) {
defer c.imsLock.Unlock()

ims[ID.UUID] = &uuidMaker{}
ims[ID.Default] = ims[ID.UUID]
ims[ID.SEQ] = &SeqIDMaker{}
switch mode {
case "local":
ims[ID.Default] = ims[ID.SEQ]
default:
ims[ID.Default] = ims[ID.UUID]
}
c.ims.Store(ims)

// init map from name of function to options
Expand Down
10 changes: 5 additions & 5 deletions mgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestMgrMarshallers(t *testing.T) {
ass := assert.New(t)
trans := newFnMgr()
trans := newFnMgr("")
ass.Nil(trans.Register("TestMgrMarshallers", func() {}))
ass.Nil(trans.SetMarshaller("TestMgrMarshallers", Encode.JSON, Encode.GOB))
task, err := trans.ComposeTask("TestMgrMarshallers", nil, []interface{}{float64(1)})
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestMgrInvokers(t *testing.T) {
}

ass := assert.New(t)
trans := newFnMgr()
trans := newFnMgr("")
ass.Nil(trans.Register("TestMgrInvokers", fn))
ass.Nil(trans.SetMarshaller("TestMgrInvokers", Encode.JSON, Encode.JSON))

Expand All @@ -91,7 +91,7 @@ func TestMgrInvokers(t *testing.T) {

func TestMgrOption(t *testing.T) {
ass := assert.New(t)
trans := newFnMgr()
trans := newFnMgr("")

// name doesn't register
ass.NotNil(trans.SetOption("TestMgrOption", DefaultOption()))
Expand All @@ -118,7 +118,7 @@ func TestMgrOption(t *testing.T) {

func TestMgrRegister(t *testing.T) {
ass := assert.New(t)
trans := newFnMgr()
trans := newFnMgr("")

// register a function, with not-existed marshaller id.
ass.Nil(trans.Register("TestMgrResgister", func() {}))
Expand All @@ -141,7 +141,7 @@ func (idm *testAlwaysErrorIDMaker) NewID() (string, error) { return "", errors.N

func TestMgrIDMaker(t *testing.T) {
ass := assert.New(t)
trans := newFnMgr()
trans := newFnMgr("")

// register a function
ass.Nil(trans.Register("TestMgrIDMaker", func() {}))
Expand Down
2 changes: 1 addition & 1 deletion result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type resultTestSuite struct {

func TestResultSuite(t *testing.T) {
suite.Run(t, &resultTestSuite{
trans: newFnMgr(),
trans: newFnMgr(""),
})
}

Expand Down
2 changes: 1 addition & 1 deletion worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type workerTestSuite struct {

func TestWorkerSuite(t *testing.T) {
suite.Run(t, &workerTestSuite{
_trans: newFnMgr(),
_trans: newFnMgr(""),
_hooks: newLocalBridge().(exHooks),
})
}
Expand Down

0 comments on commit 8c07e0a

Please sign in to comment.