Beispiel #1
0
func newJob(app fwk.App, props P) *Job {
	if app == nil {
		app = fwk.NewApp()
	}

	job := &Job{
		stmts: []Stmt{
			{
				Type: StmtNewApp,
				Data: C{
					Name:  app.Name(),
					Type:  app.Type(),
					Props: props,
				},
			},
		},
		app: app,
	}
	for k, v := range props {
		job.setProp(app, k, v)
	}
	return job
}
Beispiel #2
0
func TestJSONEncode(t *testing.T) {
	appcfg := C{
		Name: "app",
		Type: "github.com/go-hep/fwk.appmgr",
		Props: P{
			"EvtMax": int64(10),
			"NProcs": 42,
		},
	}

	cfg0 := C{
		Type: "github.com/go-hep/fwk/testdata.task1",
		Name: "t0",
		Props: P{
			"Ints1": "t0-ints1",
			"Ints2": "t0-ints2",
		},
	}

	cfg1 := C{
		Type: "github.com/go-hep/fwk/testdata.task1",
		Name: "t1",
		Props: P{
			"Ints1": "t1-ints1",
			"Ints2": "t1-ints2",
		},
	}

	cfg2 := C{
		Type: "github.com/go-hep/fwk/testdata.svc1",
		Name: "svc1",
		Props: P{
			"Int":    testdata.MyInt(12),
			"Struct": testdata.MyStruct{12},
		},
	}

	job := NewJob(
		fwk.NewApp(),
		appcfg.Props,
	)

	if job == nil {
		t.Fatalf("got nil job.Job")
	}

	job.Create(cfg0)

	comp1 := job.Create(cfg1)
	prop11 := P{
		"Ints1": "t1-ints1-modified",
	}
	job.SetProp(comp1, "Ints1", prop11["Ints1"])

	job.Create(cfg2)

	exp := []Stmt{
		{
			Type: StmtNewApp,
			Data: appcfg,
		},
		{
			Type: StmtCreate,
			Data: cfg0,
		},
		{
			Type: StmtCreate,
			Data: cfg1,
		},
		{
			Type: StmtSetProp,
			Data: C{
				Type:  comp1.Type(),
				Name:  comp1.Name(),
				Props: prop11,
			},
		},
		{
			Type: StmtCreate,
			Data: cfg2,
		},
	}

	stmts := job.Stmts()

	if !reflect.DeepEqual(exp, stmts) {
		t.Fatalf("unexpected statments:\nexp=%#v\ngot=%#v\n", exp, stmts)
	}

	buf := new(bytes.Buffer)
	enc := NewJSONEncoder(buf)
	err := enc.Encode(stmts)
	if err != nil {
		t.Fatalf("error json-encoding: %v\n", err)
	}

	dec := NewJSONDecoder(buf)
	stmts = make([]Stmt, 0)
	err = dec.Decode(&stmts)
	if err != nil {
		t.Fatalf("error json-decoding: %v\n", err)
	}

	// FIXME(sbinet)
	//  issue is that JSON won't deserialize 'MyStruct' into testdata.MyStruct...
	//  same for 'MyInt' and testdata.MyInt
	//
	// if !reflect.DeepEqual(exp, stmts) {
	// 	t.Fatalf("unexpected statments:\nexp=%#v\ngot=%#v\n", exp, stmts)
	// }
}
Beispiel #3
0
func TestGoEncode(t *testing.T) {
	appcfg := C{
		Name: "app",
		Type: "github.com/go-hep/fwk.appmgr",
		Props: P{
			"EvtMax": int64(10),
			"NProcs": 42,
		},
	}

	cfg0 := C{
		Type: "github.com/go-hep/fwk/testdata.task1",
		Name: "t0",
		Props: P{
			"Ints1": "t0-ints1",
			"Ints2": "t0-ints2",
		},
	}

	cfg1 := C{
		Type: "github.com/go-hep/fwk/testdata.task1",
		Name: "t1",
		Props: P{
			"Ints1": "t1-ints1",
			"Ints2": "t1-ints2",
		},
	}

	cfg2 := C{
		Type: "github.com/go-hep/fwk/testdata.svc1",
		Name: "svc1",
		Props: P{
			"Int":    testdata.MyInt(12),
			"Struct": testdata.MyStruct{12},
		},
	}

	job := NewJob(
		fwk.NewApp(),
		appcfg.Props,
	)

	if job == nil {
		t.Fatalf("got nil job.Job")
	}

	job.Create(cfg0)

	comp1 := job.Create(cfg1)
	prop11 := P{
		"Ints1": "t1-ints1-modified",
	}
	job.SetProp(comp1, "Ints1", prop11["Ints1"])

	job.Create(cfg2)

	exp := []Stmt{
		{
			Type: StmtNewApp,
			Data: appcfg,
		},
		{
			Type: StmtCreate,
			Data: cfg0,
		},
		{
			Type: StmtCreate,
			Data: cfg1,
		},
		{
			Type: StmtSetProp,
			Data: C{
				Type:  comp1.Type(),
				Name:  comp1.Name(),
				Props: prop11,
			},
		},
		{
			Type: StmtCreate,
			Data: cfg2,
		},
	}

	stmts := job.Stmts()

	if !reflect.DeepEqual(exp, stmts) {
		t.Fatalf("unexpected statments:\nexp=%#v\ngot=%#v\n", exp, stmts)
	}

	buf := new(bytes.Buffer)
	enc := NewGoEncoder(buf)
	err := enc.Encode(stmts)
	if err != nil {
		t.Fatalf("error go-encoding: %v\n", err)
	}
}
Beispiel #4
0
func TestStmtWithProps(t *testing.T) {

	appcfg := C{
		Name: "app",
		Type: "github.com/go-hep/fwk.appmgr",
		Props: P{
			"EvtMax": int64(10),
			"NProcs": 42,
		},
	}

	cfg0 := C{
		Type: "github.com/go-hep/fwk/testdata.task1",
		Name: "t0",
		Props: P{
			"Ints1": "t0-ints1",
			"Ints2": "t0-ints2",
		},
	}

	cfg1 := C{
		Type: "github.com/go-hep/fwk/testdata.task1",
		Name: "t1",
		Props: P{
			"Ints1": "t1-ints1",
			"Ints2": "t1-ints2",
		},
	}

	job := NewJob(
		fwk.NewApp(),
		appcfg.Props,
	)

	if job == nil {
		t.Fatalf("got nil job.Job")
	}

	comp0 := job.Create(cfg0)
	prop01 := P{
		"Ints1": "t0-ints1-modified",
	}
	prop02 := P{
		"Ints2": "t0-ints2-modified",
	}

	job.SetProp(comp0, "Ints1", prop01["Ints1"])
	job.SetProp(comp0, "Ints2", prop02["Ints2"])

	comp1 := job.Create(cfg1)

	prop11 := P{
		"Ints1": "t1-ints1-modified",
	}
	prop12 := P{
		"Ints2": "t1-ints2-modified",
	}

	job.SetProp(comp1, "Ints1", prop11["Ints1"])
	job.SetProp(comp1, "Ints2", prop12["Ints2"])

	exp := []Stmt{
		{
			Type: StmtNewApp,
			Data: appcfg,
		},
		{
			Type: StmtCreate,
			Data: cfg0,
		},
		{
			Type: StmtSetProp,
			Data: C{
				Type:  comp0.Type(),
				Name:  comp0.Name(),
				Props: prop01,
			},
		},
		{
			Type: StmtSetProp,
			Data: C{
				Type:  comp0.Type(),
				Name:  comp0.Name(),
				Props: prop02,
			},
		},
		{
			Type: StmtCreate,
			Data: cfg1,
		},
		{
			Type: StmtSetProp,
			Data: C{
				Type:  comp1.Type(),
				Name:  comp1.Name(),
				Props: prop11,
			},
		},
		{
			Type: StmtSetProp,
			Data: C{
				Type:  comp1.Type(),
				Name:  comp1.Name(),
				Props: prop12,
			},
		},
	}

	stmts := job.Stmts()

	if !reflect.DeepEqual(exp, stmts) {
		t.Fatalf("unexpected statments:\nexp=%#v\ngot=%#v\n", exp, stmts)
	}
}
Beispiel #5
0
func TestStmt(t *testing.T) {

	appcfg := C{
		Name: "app",
		Type: "github.com/go-hep/fwk.appmgr",
		Props: P{
			"EvtMax": int64(10),
			"NProcs": 42,
		},
	}

	cfg0 := C{
		Type: "github.com/go-hep/fwk/testdata.task1",
		Name: "t0",
		Props: P{
			"Ints1": "t0-ints1",
			"Ints2": "t0-ints2",
		},
	}

	cfg1 := C{
		Type: "github.com/go-hep/fwk/testdata.task1",
		Name: "t1",
		Props: P{
			"Ints1": "t1-ints1",
			"Ints2": "t1-ints2",
		},
	}

	job := NewJob(
		fwk.NewApp(),
		appcfg.Props,
	)

	if job == nil {
		t.Fatalf("got nil job.Job")
	}

	job.Create(cfg0)
	job.Create(cfg1)

	exp := []Stmt{
		{
			Type: StmtNewApp,
			Data: appcfg,
		},
		{
			Type: StmtCreate,
			Data: cfg0,
		},
		{
			Type: StmtCreate,
			Data: cfg1,
		},
	}

	stmts := job.Stmts()

	if !reflect.DeepEqual(exp, stmts) {
		t.Fatalf("unexpected statments:\nexp=%#v\ngot=%#v\n", exp, stmts)
	}
}