veyron/runtimes/google/rt: Make tests use veyron2.Init.
Change-Id: Ibd50614be6f5de2734bbcca8226ef4cda035bf96
diff --git a/profiles/chrome/chromeinit.go b/profiles/chrome/chromeinit.go
index b18108d..6ec957d 100644
--- a/profiles/chrome/chromeinit.go
+++ b/profiles/chrome/chromeinit.go
@@ -15,7 +15,7 @@
}
func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
- runtime, ctx, shutdown, err := grt.Init(ctx, nil)
+ runtime, ctx, shutdown, err := grt.Init(ctx, nil, nil, nil, nil)
if err != nil {
return nil, nil, shutdown, err
}
diff --git a/profiles/gce/initx.go b/profiles/gce/initx.go
index 4aa63c8..45d9b23 100644
--- a/profiles/gce/initx.go
+++ b/profiles/gce/initx.go
@@ -8,10 +8,12 @@
"flag"
"fmt"
"net"
+ "os"
"v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
+ "v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/appcycle"
"v.io/core/veyron/lib/flags"
@@ -33,16 +35,14 @@
}
func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
+ vlog.Log.VI(1).Infof("Initializing GCE profile.")
if !gce.RunningOnGCE() {
return nil, nil, nil, fmt.Errorf("GCE profile used on a non-GCE system")
}
- runtime, ctx, shutdown, err := grt.Init(ctx, nil)
- if err != nil {
- return nil, nil, shutdown, err
- }
- runtime.GetLogger(ctx).VI(1).Infof("Initializing GCE profile.")
+ ac := appcycle.New()
+ commonFlags.Parse(os.Args[1:], nil)
lf := commonFlags.ListenFlags()
listenSpec := ipc.ListenSpec{
Addrs: ipc.ListenAddrs(lf.Addrs),
@@ -50,20 +50,21 @@
}
if ip, err := gce.ExternalIPAddress(); err != nil {
- return nil, nil, shutdown, err
+ return nil, nil, nil, err
} else {
listenSpec.AddressChooser = func(network string, addrs []ipc.Address) ([]ipc.Address, error) {
return []ipc.Address{&netstate.AddrIfc{&net.IPAddr{IP: ip}, "gce-nat", nil}}, nil
}
}
- ctx = runtime.SetListenSpec(ctx, listenSpec)
- ac := appcycle.New()
- ctx = runtime.SetAppCycle(ctx, ac)
+ runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, nil)
+ if err != nil {
+ return nil, nil, shutdown, err
+ }
profileShutdown := func() {
- shutdown()
ac.Shutdown()
+ shutdown()
}
return runtime, ctx, profileShutdown, nil
diff --git a/profiles/genericinit.go b/profiles/genericinit.go
index cbd7312..257974a 100644
--- a/profiles/genericinit.go
+++ b/profiles/genericinit.go
@@ -3,8 +3,10 @@
import (
"v.io/core/veyron2"
"v.io/core/veyron2/context"
+ "v.io/core/veyron2/ipc"
"v.io/core/veyron/lib/appcycle"
+ "v.io/core/veyron/profiles/internal"
_ "v.io/core/veyron/runtimes/google/ipc/protocols/tcp"
_ "v.io/core/veyron/runtimes/google/ipc/protocols/ws"
_ "v.io/core/veyron/runtimes/google/ipc/protocols/wsh"
@@ -16,18 +18,24 @@
}
func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
- runtime, ctx, shutdown, err := grt.Init(ctx, nil)
+ ac := appcycle.New()
+
+ runtime, ctx, shutdown, err := grt.Init(ctx,
+ ac,
+ nil,
+ &ipc.ListenSpec{
+ Addrs: ipc.ListenAddrs{{"tcp", "127.0.0.1:0"}},
+ AddressChooser: internal.IPAddressChooser,
+ },
+ nil)
if err != nil {
return nil, nil, nil, err
}
runtime.GetLogger(ctx).VI(1).Infof("Initializing generic profile.")
- ac := appcycle.New()
- ctx = runtime.SetAppCycle(ctx, ac)
-
profileShutdown := func() {
- shutdown()
ac.Shutdown()
+ shutdown()
}
return runtime, ctx, profileShutdown, nil
}
diff --git a/profiles/roaming/roaminginit.go b/profiles/roaming/roaminginit.go
index 533cabb..8dbe076 100644
--- a/profiles/roaming/roaminginit.go
+++ b/profiles/roaming/roaminginit.go
@@ -12,11 +12,13 @@
import (
"flag"
+ "os"
"v.io/core/veyron2"
"v.io/core/veyron2/config"
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
+ "v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/appcycle"
"v.io/core/veyron/lib/flags"
@@ -47,14 +49,10 @@
}
func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
- runtime, ctx, shutdown, err := grt.Init(ctx, nil)
- if err != nil {
- return nil, nil, shutdown, err
- }
- log := runtime.GetLogger(ctx)
+ log := vlog.Log
+ reservedDispatcher := debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie())
- ctx = runtime.SetReservedNameDispatcher(ctx, debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie()))
-
+ commonFlags.Parse(os.Args[1:], nil)
lf := commonFlags.ListenFlags()
listenSpec := ipc.ListenSpec{
Addrs: ipc.ListenAddrs(lf.Addrs),
@@ -62,7 +60,6 @@
}
ac := appcycle.New()
- ctx = runtime.SetAppCycle(ctx, ac)
// Our address is private, so we test for running on GCE and for its
// 1:1 NAT configuration.
@@ -71,36 +68,40 @@
listenSpec.AddressChooser = func(string, []ipc.Address) ([]ipc.Address, error) {
return []ipc.Address{&netstate.AddrIfc{addr, "nat", nil}}, nil
}
- ctx = runtime.SetListenSpec(ctx, listenSpec)
- return runtime, ctx, shutdown, nil
+ runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, reservedDispatcher)
+ if err != nil {
+ return nil, nil, shutdown, err
+ }
+ profileShutdown := func() {
+ ac.Shutdown()
+ shutdown()
+ }
+ return runtime, ctx, profileShutdown, nil
}
}
- publisher := runtime.GetPublisher(ctx)
+ publisher := config.NewPublisher()
// Create stream in Init function to avoid a race between any
// goroutines started here and consumers started after Init returns.
ch := make(chan config.Setting)
stop, err := publisher.CreateStream(SettingsStreamName, SettingsStreamName, ch)
if err != nil {
- log.Errorf("failed to create publisher: %s", err)
ac.Shutdown()
- return nil, nil, shutdown, err
+ return nil, nil, nil, err
}
prev, err := netstate.GetAccessibleIPs()
if err != nil {
- log.VI(2).Infof("failed to determine network state")
ac.Shutdown()
- return nil, nil, shutdown, err
+ return nil, nil, nil, err
}
// Start the dhcp watcher.
watcher, err := netconfig.NewNetConfigWatcher()
if err != nil {
- log.VI(2).Infof("Failed to get new config watcher: %s", err)
ac.Shutdown()
- return nil, nil, shutdown, err
+ return nil, nil, nil, err
}
cleanupCh := make(chan struct{})
@@ -110,13 +111,16 @@
listenSpec.StreamName = SettingsStreamName
listenSpec.AddressChooser = internal.IPAddressChooser
- ctx = runtime.SetListenSpec(ctx, listenSpec)
+ runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, reservedDispatcher)
+ if err != nil {
+ return nil, nil, shutdown, err
+ }
go monitorNetworkSettingsX(runtime, ctx, watcher, prev, stop, cleanupCh, watcherCh, ch)
profileShutdown := func() {
close(cleanupCh)
- shutdown()
ac.Shutdown()
+ shutdown()
<-watcherCh
}
return runtime, ctx, profileShutdown, nil
diff --git a/profiles/static/staticinit.go b/profiles/static/staticinit.go
index 4def643..4f84141 100644
--- a/profiles/static/staticinit.go
+++ b/profiles/static/staticinit.go
@@ -2,10 +2,12 @@
import (
"flag"
+ "os"
"v.io/core/veyron2"
"v.io/core/veyron2/context"
"v.io/core/veyron2/ipc"
+ "v.io/core/veyron2/vlog"
"v.io/core/veyron/lib/appcycle"
"v.io/core/veyron/lib/flags"
@@ -31,14 +33,11 @@
}
func Init(ctx *context.T) (veyron2.RuntimeX, *context.T, veyron2.Shutdown, error) {
- runtime, ctx, shutdown, err := grt.Init(ctx, nil)
- if err != nil {
- return nil, nil, nil, err
- }
- log := runtime.GetLogger(ctx)
+ log := vlog.Log
- ctx = runtime.SetReservedNameDispatcher(ctx, debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie()))
+ reservedDispatcher := debug.NewDispatcher(log.LogDir(), sflag.NewAuthorizerOrDie())
+ commonFlags.Parse(os.Args[1:], nil)
lf := commonFlags.ListenFlags()
listenSpec := ipc.ListenSpec{
Addrs: ipc.ListenAddrs(lf.Addrs),
@@ -46,7 +45,6 @@
}
ac := appcycle.New()
- ctx = runtime.SetAppCycle(ctx, ac)
// Our address is private, so we test for running on GCE and for its 1:1 NAT
// configuration. GCEPublicAddress returns a non-nil addr if we are running on GCE.
@@ -55,15 +53,23 @@
listenSpec.AddressChooser = func(string, []ipc.Address) ([]ipc.Address, error) {
return []ipc.Address{&netstate.AddrIfc{addr, "nat", nil}}, nil
}
+ runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, reservedDispatcher)
+ if err != nil {
+ return nil, nil, nil, err
+ }
return runtime, ctx, shutdown, nil
}
}
listenSpec.AddressChooser = internal.IPAddressChooser
- ctx = runtime.SetListenSpec(ctx, listenSpec)
+
+ runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, &listenSpec, reservedDispatcher)
+ if err != nil {
+ return nil, nil, shutdown, err
+ }
profileShutdown := func() {
- shutdown()
ac.Shutdown()
+ shutdown()
}
return runtime, ctx, profileShutdown, nil
}