Beispiel #1
1
func (delegate *TestClientDelegate) Initialize(ctx application.Context) {
	log.Printf("TestClientDelegate.Initialize...")

	// Set the necessary flags using the mojo args.
	args := ctx.Args()
	mojoFlag = flag.NewFlagSet(args[0], flag.ExitOnError)
	mojoRun := mojoFlag.String("test.run", "", "")
	mojoBench := mojoFlag.String("test.bench", "", "")
	endpointFlag = mojoFlag.String("endpoint", "", "")
	v23TcpAddr := mojoFlag.String("v23.tcp.address", "", "")
	mojoFlag.Parse(args[1:])
	flag.Set("test.run", *mojoRun)
	flag.Set("test.bench", *mojoBench)
	flag.Set("v23.tcp.address", *v23TcpAddr)

	tests := []func(*testing.T, application.Context){
		TestSimple, TestMultiArgs, TestReuseProxy, TestNoOutArgs,
	}
	benchmarks := []func(*testing.B, application.Context){
		BenchmarkSimpleRpc,
	}

	matchAllTests := func(pat, str string) (bool, error) { return true, nil }
	exitCode := testing.MainStart(matchAllTests, convertTests(tests, ctx), convertBenchmarks(benchmarks, ctx), nil).Run()
	if exitCode == 0 {
		fmt.Printf("%s\n", expected.SuccessMessage)
	} else {
		fmt.Printf("%s\n", expected.FailureMessage)
	}

	ctx.Close()
	os.Exit(exitCode)
}
Beispiel #2
0
// When running echo_client, ctx.Args() should contain:
// 0: mojo app name
// 1: remote endpoint
// 2+: string to echo
func (delegate *RemoteEchoClientDelegate) Initialize(ctx application.Context) {
	log.Printf("RemoteEchoClientDelegate.Initialize...")

	// Parse arguments. Note: May panic if not enough args are given.
	remoteEndpoint := ctx.Args()[1]
	echoString := "Hello, Go world!"
	if len(ctx.Args()) > 2 {
		echoString = strings.Join(ctx.Args()[2:], " ")
	}

	r, p := echo.CreateMessagePipeForRemoteEcho()

	v23.ConnectToRemoteService(ctx, &r, remoteEndpoint)
	echoProxy := echo.NewRemoteEchoProxy(p, bindings.GetAsyncWaiter())

	log.Printf("RemoteEchoClientDelegate.Initialize calling EchoString...")
	response, err := echoProxy.EchoString(echoString)
	if err == nil {
		fmt.Printf("client: %s\n", response)
	} else {
		fmt.Printf("error: %v\n", err)
	}

	log.Printf("RemoteEchoClientDelegate.Initialize calling EchoX...")
	response2, err := echoProxy.EchoX([]bool{true, false, false, true}, echo.AInArg{"A String"})
	if err == nil {
		fmt.Printf("client: %v\n", response2)
	} else {
		log.Println("Error: ", err)
	}

	fmt.Printf("(done)\n")
	echoProxy.Close_Proxy()
	ctx.Close()
}
// When running fortune_client, ctx.Args() should contain:
// 0: mojo app name
// 1: remote endpoint
// 2+: (optional) fortune to add
// If the fortune to add is omitted, then the fortune_client will Get a fortune.
// Otherwise, it will Add the given fortune.
func (delegate *FortuneClientDelegate) Initialize(ctx application.Context) {
	// Parse the arguments.
	remoteEndpoint := ctx.Args()[1]
	addFortune := strings.Join(ctx.Args()[2:], " ")

	log.Printf("FortuneClientDelegate.Initialize... %s", remoteEndpoint)
	fortuneRequest, fortunePointer := fortune.CreateMessagePipeForFortune()
	v23.ConnectToRemoteService(ctx, &fortuneRequest, remoteEndpoint)
	fortuneProxy := fortune.NewFortuneProxy(fortunePointer, bindings.GetAsyncWaiter())

	if addFortune != "" {
		log.Printf("FortuneClientDelegate.Initialize calling Add...")

		if err := fortuneProxy.Add(addFortune); err != nil {
			log.Println(err)
		} else {
			fmt.Printf("client added: %s\n", addFortune)
		}
	} else {
		log.Printf("FortuneClientDelegate.Initialize calling Get...")
		response, err := fortuneProxy.Get()
		if response != "" {
			fmt.Printf("client (get): %s\n", response)
		} else {
			log.Println(err)
		}
	}

	fortuneProxy.Close_Proxy()
	ctx.Close()
}
Beispiel #4
0
func (delegate *EchoClientDelegate) Initialize(ctx application.Context) {
	echoRequest, echoPointer := echo.CreateMessagePipeForEcho()
	ctx.ConnectToApplication("mojo:go_echo_server").ConnectToService(&echoRequest)
	echoProxy := echo.NewEchoProxy(echoPointer, bindings.GetAsyncWaiter())
	response, err := echoProxy.EchoString(bindings.StringPointer("Hello, Go world!"))
	if response != nil {
		fmt.Printf("client: %s\n", *response)
	} else {
		log.Println(err)
	}
	echoProxy.Close_Proxy()
	ctx.Close()
}