Example #1
0
func TestReflectionDescriberErrors(t *testing.T) {
	_, err := tick.NewReflectionDescriber(nil, nil)
	if err == nil {
		t.Error("expected err got nil")
	}

	o := struct{}{}
	_, err = tick.NewReflectionDescriber(o, nil)
	if err == nil {
		t.Error("expected err got nil")
	}

	var c *C
	_, err = tick.NewReflectionDescriber(c, nil)
	if err == nil {
		t.Error("expected err got nil")
	}

	c = new(C)
	_, err = tick.NewReflectionDescriber(c, nil)
	if err == nil {
		t.Error("expected err got nil")
	}

	i := new(int)
	*i = 42
	_, err = tick.NewReflectionDescriber(i, nil)
	if err == nil {
		t.Error("expected err got nil")
	}

}
Example #2
0
func NewUDF(
	parent Node,
	name string,
	wants,
	provides udf.EdgeType,
	options map[string]*udf.OptionInfo,
) *UDFNode {
	var pwants, pprovides EdgeType
	switch wants {
	case udf.EdgeType_STREAM:
		pwants = StreamEdge
	case udf.EdgeType_BATCH:
		pwants = BatchEdge
	}
	switch provides {
	case udf.EdgeType_STREAM:
		pprovides = StreamEdge
	case udf.EdgeType_BATCH:
		pprovides = BatchEdge
	}
	udf := &UDFNode{
		chainnode: newBasicChainNode(name, pwants, pprovides),
		UDFName:   name,
		options:   options,
	}
	udf.describer, _ = tick.NewReflectionDescriber(udf, nil)
	parent.linkChild(udf)
	return udf
}
Example #3
0
func NewUDF(
	parent Node,
	name string,
	commander command.Commander,
	timeout time.Duration,
	wants,
	provides EdgeType,
	options map[string]*udf.OptionInfo,
) *UDFNode {
	udf := &UDFNode{
		chainnode: newBasicChainNode(name, wants, provides),
		desc:      name,
		Commander: commander,
		Timeout:   timeout,
		options:   options,
	}
	udf.describer = tick.NewReflectionDescriber(udf)
	parent.linkChild(udf)
	return udf
}
Example #4
0
func TestReflectionDescriber(t *testing.T) {
	//----------------
	// Test A type
	//
	a := new(A)
	rdA, err := tick.NewReflectionDescriber(a, nil)
	if err != nil {
		t.Fatal(err)
	}

	// Test A.privateMethod
	if exp, got := false, rdA.HasProperty("privateMethod"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}

	// Test A.AProperty
	if exp, got := true, rdA.HasProperty("aProperty"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdA.HasChainMethod("aProperty"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	_, err = rdA.SetProperty("aProperty", "test")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := "test", a.AProperty; exp != got {
		t.Fatalf("unexpected a.AProperty got: %v exp: %v", got, exp)
	}

	// Test A.PropertyMethodA
	if exp, got := true, rdA.HasProperty("propertyMethodA"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdA.HasChainMethod("propertyMethodA"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdA.HasProperty("aFlag"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdA.SetProperty("propertyMethodA")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := true, a.AFlag; exp != got {
		t.Fatalf("unexpected a.AFlag got: %v exp: %v", got, exp)
	}
	if exp, got := 1, a.propertyMethodCallCount; exp != got {
		t.Fatalf("unexpected a.propertyMethodCallCount got: %v exp: %v", got, exp)
	}

	// Test A.HiddenPropertyMethod
	if exp, got := true, rdA.HasProperty("hiddenPropertyMethod"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdA.HasChainMethod("hiddenPropertyMethod"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdA.HasProperty("aHiddenPMFlag"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdA.SetProperty("hiddenPropertyMethod")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := true, a.AHiddenPMFlag; exp != got {
		t.Fatalf("unexpected a.AHiddenPMFlag got: %v exp: %v", got, exp)
	}

	// Test A.ChainMethodA
	if exp, got := true, rdA.HasChainMethod("chainMethodA"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdA.HasProperty("chainMethodA"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdA.CallChainMethod("chainMethodA")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := 1, a.chainMethodCallCount; exp != got {
		t.Fatalf("unexpected a.chainMethodCallCount got: %v exp: %v", got, exp)
	}

	// Test A.HiddenChainMethod
	if exp, got := true, rdA.HasChainMethod("hiddenChainMethod"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdA.HasProperty("hiddenChainMethod"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdA.CallChainMethod("hiddenChainMethod")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := 1, a.hcmCallCount; exp != got {
		t.Fatalf("unexpected a.hcmCallCount got: %v exp: %v", got, exp)
	}

	//----------------
	// Test B type
	//
	b := new(B)
	rdB, err := tick.NewReflectionDescriber(b, map[string]reflect.Value{
		"HiddenPropertyMethod": reflect.ValueOf(b.HiddenPropertyMethod),
		"HiddenChainMethod":    reflect.ValueOf(b.A.HiddenChainMethod),
	})
	if err != nil {
		t.Fatal(err)
	}

	// Test B.AProperty as property
	if exp, got := true, rdB.HasProperty("aProperty"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdB.SetProperty("aProperty", "test")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := "test", b.A.AProperty; exp != got {
		t.Fatalf("unexpected b.A.AProperty got: %v exp: %v", got, exp)
	}

	// Test B.AProperty as chain
	if exp, got := true, rdB.HasChainMethod("aProperty"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	_, err = rdB.CallChainMethod("aProperty")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := 1, b.apCallCount; exp != got {
		t.Fatalf("unexpected b.apCallCount got: %v exp: %v", got, exp)
	}

	// Test B.PropertyMethodA
	if exp, got := true, rdB.HasProperty("propertyMethodA"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdB.HasChainMethod("propertyMethodA"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdB.HasProperty("aFlag"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdB.SetProperty("propertyMethodA")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := true, b.AFlag; exp != got {
		t.Fatalf("unexpected b.AFlag got: %v exp: %v", got, exp)
	}
	if exp, got := 1, b.A.propertyMethodCallCount; exp != got {
		t.Fatalf("unexpected b.A.propertyMethodCallCount got: %v exp: %v", got, exp)
	}

	// Test B.HiddenPropertyMethod as chain
	if exp, got := true, rdB.HasChainMethod("hiddenPropertyMethod"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	_, err = rdB.CallChainMethod("hiddenPropertyMethod")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := 1, b.hpmCallCount; exp != got {
		t.Fatalf("unexpected b.hpmCallCount got: %v exp: %v", got, exp)
	}

	// Test B.HiddenPropertyMethod as property
	if exp, got := true, rdB.HasProperty("hiddenPropertyMethod"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdB.SetProperty("hiddenPropertyMethod")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := true, b.AHiddenPMFlag; exp != got {
		t.Fatalf("unexpected b.AHiddenPMFlag got: %v exp: %v", got, exp)
	}

	// Test B.HiddenChainMethod as chain
	if exp, got := true, rdB.HasChainMethod("hiddenChainMethod"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	_, err = rdB.CallChainMethod("hiddenChainMethod")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := 1, b.A.hcmCallCount; exp != got {
		t.Fatalf("unexpected b.A.hcmCallCount got: %v exp: %v", got, exp)
	}

	// Test B.HiddenPropertyMethod as property
	if exp, got := true, rdB.HasProperty("hiddenChainMethod"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdB.SetProperty("hiddenChainMethod", "test")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := "test", b.BOverriddingProp; exp != got {
		t.Fatalf("unexpected b.BOverriddingProp got: %v exp: %v", got, exp)
	}

	// Test B.ChainMethodA as chain
	if exp, got := true, rdB.HasChainMethod("chainMethodA"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	_, err = rdB.CallChainMethod("chainMethodA")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := 1, b.A.chainMethodCallCount; exp != got {
		t.Fatalf("unexpected b.A.chainMethodCallCount got: %v exp: %v", got, exp)
	}

	// Test B.ChainMethodA as property
	if exp, got := true, rdB.HasProperty("chainMethodA"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdB.SetProperty("chainMethodA", "test")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := "test", b.ChainMethodA; exp != got {
		t.Fatalf("unexpected b.ChainMethodA got: %v exp: %v", got, exp)
	}

	// Test B.BProperty
	if exp, got := true, rdB.HasProperty("bProperty"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdB.HasChainMethod("bProperty"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	_, err = rdB.SetProperty("bProperty", "test")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := "test", b.BProperty; exp != got {
		t.Fatalf("unexpected b.BProperty got: %v exp: %v", got, exp)
	}

	// Test B.PropertyMethodB
	if exp, got := true, rdB.HasProperty("propertyMethodB"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdB.HasChainMethod("propertyMethodB"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	_, err = rdB.SetProperty("propertyMethodB")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := true, b.BFlag; exp != got {
		t.Fatalf("unexpected b.BFlag got: %v exp: %v", got, exp)
	}
	if exp, got := 1, b.propertyMethodCallCount; exp != got {
		t.Fatalf("unexpected b.propertyMethodCallCount got: %v exp: %v", got, exp)
	}

	// Test B.ChainMethodB
	if exp, got := true, rdB.HasChainMethod("chainMethodB"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdB.HasProperty("chainMethodB"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdB.CallChainMethod("chainMethodB")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := 1, b.chainMethodCallCount; exp != got {
		t.Fatalf("unexpected b.chainMethodCallCount got: %v exp: %v", got, exp)
	}

	//----------------
	// Test C type
	//
	c := &C{
		A: new(A),
	}
	rdC, err := tick.NewReflectionDescriber(c, map[string]reflect.Value{
		"HiddenPropertyMethod": reflect.ValueOf(c.HiddenPropertyMethod),
		"HiddenChainMethod":    reflect.ValueOf(c.A.HiddenChainMethod),
	})
	if err != nil {
		t.Fatal(err)
	}

	// Test C.AProperty as property
	if exp, got := true, rdC.HasProperty("aProperty"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdC.SetProperty("aProperty", "test")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := "test", c.A.AProperty; exp != got {
		t.Fatalf("unexpected c.A.AProperty got: %v exp: %v", got, exp)
	}

	// Test C.AProperty as chain
	if exp, got := true, rdC.HasChainMethod("aProperty"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	_, err = rdC.CallChainMethod("aProperty")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := 1, c.apCallCount; exp != got {
		t.Fatalf("unexpected c.apCallCount got: %v exp: %v", got, exp)
	}

	// Test C.PropertyMethodA
	if exp, got := true, rdC.HasProperty("propertyMethodA"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdC.HasChainMethod("propertyMethodA"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdC.HasProperty("aFlag"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdC.SetProperty("propertyMethodA")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := true, c.AFlag; exp != got {
		t.Fatalf("unexpected c.AFlag got: %v exp: %v", got, exp)
	}
	if exp, got := 1, c.A.propertyMethodCallCount; exp != got {
		t.Fatalf("unexpected c.A.propertyMethodCallCount got: %v exp: %v", got, exp)
	}

	// Test C.HiddenPropertyMethod as chain
	if exp, got := true, rdC.HasChainMethod("hiddenPropertyMethod"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	_, err = rdC.CallChainMethod("hiddenPropertyMethod")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := 1, c.hpmCallCount; exp != got {
		t.Fatalf("unexpected c.hpmCallCount got: %v exp: %v", got, exp)
	}

	// Test C.HiddenPropertyMethod as property
	if exp, got := true, rdC.HasProperty("hiddenPropertyMethod"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdC.SetProperty("hiddenPropertyMethod")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := true, c.AHiddenPMFlag; exp != got {
		t.Fatalf("unexpected c.AHiddenPMFlag got: %v exp: %v", got, exp)
	}

	// Test C.HiddenChainMethod as chain
	if exp, got := true, rdC.HasChainMethod("hiddenChainMethod"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	_, err = rdC.CallChainMethod("hiddenChainMethod")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := 1, c.A.hcmCallCount; exp != got {
		t.Fatalf("unexpected c.A.hcmCallCount got: %v exp: %v", got, exp)
	}

	// Test C.HiddenPropertyMethod as property
	if exp, got := true, rdC.HasProperty("hiddenChainMethod"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdC.SetProperty("hiddenChainMethod", "test")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := "test", c.COverriddingProp; exp != got {
		t.Fatalf("unexpected c.COverriddingProp got: %v exp: %v", got, exp)
	}

	// Test C.ChainMethodA as chain
	if exp, got := true, rdC.HasChainMethod("chainMethodA"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	_, err = rdC.CallChainMethod("chainMethodA")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := 1, c.A.chainMethodCallCount; exp != got {
		t.Fatalf("unexpected c.A.chainMethodCallCount got: %v exp: %v", got, exp)
	}

	// Test C.ChainMethodA as property
	if exp, got := true, rdC.HasProperty("chainMethodA"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdC.SetProperty("chainMethodA", "test")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := "test", c.ChainMethodA; exp != got {
		t.Fatalf("unexpected c.ChainMethodA got: %v exp: %v", got, exp)
	}

	// Test C.CProperty
	if exp, got := true, rdC.HasProperty("cProperty"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdC.HasChainMethod("cProperty"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	_, err = rdC.SetProperty("cProperty", "test")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := "test", c.CProperty; exp != got {
		t.Fatalf("unexpected c.CProperty got: %v exp: %v", got, exp)
	}

	// Test C.PropertyMethodC
	if exp, got := true, rdC.HasProperty("propertyMethodC"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdC.HasChainMethod("propertyMethodC"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	_, err = rdC.SetProperty("propertyMethodC")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := true, c.CFlag; exp != got {
		t.Fatalf("unexpected c.CFlag got: %v exp: %v", got, exp)
	}
	if exp, got := 1, c.propertyMethodCallCount; exp != got {
		t.Fatalf("unexpected c.propertyMethodCallCount got: %v exp: %v", got, exp)
	}

	// Test C.ChainMethodC
	if exp, got := true, rdC.HasChainMethod("chainMethodC"); exp != got {
		t.Fatalf("unexpected HasChainMethod got: %v exp: %v", got, exp)
	}
	if exp, got := false, rdC.HasProperty("chainMethodC"); exp != got {
		t.Fatalf("unexpected HasProperty got: %v exp: %v", got, exp)
	}
	_, err = rdC.CallChainMethod("chainMethodC")
	if err != nil {
		t.Fatal(err)
	}
	if exp, got := 1, c.chainMethodCallCount; exp != got {
		t.Fatalf("unexpected c.chainMethodCallCount got: %v exp: %v", got, exp)
	}
}