Merge "nsb: Test output nit fix"
diff --git a/Makefile b/Makefile
index 84ad5ee..c45154b 100644
--- a/Makefile
+++ b/Makefile
@@ -107,13 +107,8 @@
touch bower_components
go/bin: directories
- v23 go install -a -tags wspr v.io/x/ref/cmd/servicerunner
v23 go install v.io/x/ref/services/mounttable/mounttabled
- v23 go install v.io/x/ref/cmd/principal
- v23 go install v.io/x/browser/sample/sampled
v23 go install v.io/x/browser/runner
- v23 go install v.io/x/ref/cmd/principal
- v23 go install v.io/x/ref/services/agent/agentd
# PHONY targets:
@@ -126,7 +121,7 @@
# Run unit and integration tests.
test: all
:;jshint test # lint all test JavaScript files.
- :;./go/bin/runner -v=3 -log_dir=$(V23_ROOT)/release/projects/browser/tmp/log -runSample=true -runTests=true -alsologtostderr=false
+ :;./go/bin/runner -v=3 -log_dir=$(V23_ROOT)/release/projects/browser/tmp/log -alsologtostderr=false
# Continuously watch for changes to .js, .html or .css files.
# Rebundles the appropriate bundles when local files change.
@@ -135,7 +130,7 @@
# Continuously reruns the tests as they change.
watch-test: go/bin
- NOMINIFY=true ./go/bin/runner -v=3 -log_dir=$(V23_ROOT)/release/projects/browser/tmp/log -runSample=true -runTests=true -runTestsWatch=true -alsologtostderr=false
+ NOMINIFY=true ./go/bin/runner -v=3 -log_dir=$(V23_ROOT)/release/projects/browser/tmp/log -runTestsWatch=true -alsologtostderr=false
# Serves the needed daemons and starts a server at http://localhost:9000
# CTRL-C to stop
diff --git a/go/src/v.io/x/browser/runner/main.go b/go/src/v.io/x/browser/runner/main.go
index dc16f70..18fcba0 100644
--- a/go/src/v.io/x/browser/runner/main.go
+++ b/go/src/v.io/x/browser/runner/main.go
@@ -10,8 +10,6 @@
"flag"
"fmt"
"io"
- "net"
- "net/http"
"os"
"os/exec"
"os/signal"
@@ -32,36 +30,21 @@
"v.io/x/ref/services/mounttable/mounttablelib"
"v.io/x/ref/test/expect"
"v.io/x/ref/test/modules"
-
- "v.io/x/browser/sample/sampleworld"
)
const (
- SampleWorldCommand = "sampleWorld" // The modules library command.
- RunMTCommand = "runMT"
- stdoutLog = "tmp/runner.stdout.log" // Used as stdout drain when shutting down.
- stderrLog = "tmp/runner.stderr.log" // Used as stderr drain when shutting down.
+ RunMTCommand = "runMT"
+ stdoutLog = "tmp/runner.stdout.log" // Used as stdout drain when shutting down.
+ stderrLog = "tmp/runner.stderr.log" // Used as stderr drain when shutting down.
)
var (
- // Flags used as input to this program.
- runSample bool
- serveHTTP bool
- portHTTP string
- rootHTTP string
- runTests bool
runTestsWatch bool
)
func init() {
- modules.RegisterChild(SampleWorldCommand, "desc", sampleWorld)
modules.RegisterChild(RunMTCommand, "", runMT)
- flag.BoolVar(&runSample, "runSample", false, "if true, runs sample services")
- flag.BoolVar(&serveHTTP, "serveHTTP", false, "if true, serves HTTP")
- flag.StringVar(&portHTTP, "portHTTP", "9001", "default 9001, the port to serve HTTP on")
- flag.StringVar(&rootHTTP, "rootHTTP", ".", "default '.', the root HTTP folder path")
- flag.BoolVar(&runTests, "runTests", false, "if true, runs the namespace browser tests")
- flag.BoolVar(&runTestsWatch, "runTestsWatch", false, "if true && runTests, runs the tests in watch mode")
+ flag.BoolVar(&runTestsWatch, "runTestsWatch", false, "if true runs the tests in watch mode")
}
func runMT(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
@@ -131,18 +114,6 @@
return nil
}
-// The module command for running the sample world.
-func sampleWorld(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- ctx, shutdown := v23.Init()
- defer shutdown()
-
- sampleworld.RunSampleWorld(ctx, func() {
- modules.WaitForEOF(stdin)
- })
-
- return nil
-}
-
func main() {
if modules.IsModulesChildProcess() {
exitOnError(modules.Dispatch(), "Failed to dispatch module")
@@ -166,36 +137,6 @@
}
}
-// Returns the first ipv4 address found or an error
-func getFirstIPv4Address() (string, error) {
- ifaces, err := net.Interfaces()
- if err != nil {
- return "", fmt.Errorf("No net interfaces found")
- }
- for _, i := range ifaces {
- addrs, err := i.Addrs()
- if err != nil {
- continue
- }
-
- for _, addr := range addrs {
- var ip net.IP
- if v, ok := addr.(*net.IPNet); ok {
- ip = v.IP
- }
- if ip == nil || ip.IsLoopback() {
- continue
- }
- ip = ip.To4()
- if ip == nil {
- continue // not an ipv4 address
- }
- return ip.String(), nil
- }
- }
- return "", fmt.Errorf("no ipv4 addresses were found")
-}
-
// Runs the services and cleans up afterwards.
// Returns true if the run was successful.
func run() bool {
@@ -207,13 +148,6 @@
cottagePort := 8885
housePort := 8886
host := "localhost"
- if !runTests {
- // Get the IP address to serve at, since this is external-facing.
- sampleHost, err := getFirstIPv4Address()
- exitOnError(err, "Could not get host IP address")
- fmt.Printf("Using host %s\n", sampleHost)
- host = sampleHost
- }
// Start a new shell module.
vars := map[string]string{}
@@ -233,96 +167,61 @@
defer errFile.Close()
defer sh.Cleanup(outFile, errFile)
- // ns.dev.v.io Mounttable only allows one to publish under users/<name>
- // for a user that poses the blessing /dev.v.io/root/users/<name>
- // therefore to find a <name> we can publish under, we remove /dev.v.io/root/users/
- // from the default blessing name.
- blessing := string(security.DefaultBlessingPatterns(v23.GetPrincipal(ctx))[0])
- name := strings.TrimPrefix(blessing, "dev.v.io/root/users/")
- nsPrefix := fmt.Sprintf("/ns.dev.v.io:8101/users/%s", name)
- exitOnError(err, "Failed to obtain hostname")
+ // Run a mounttable for tests
+ hRoot, err := sh.Start(RunMTCommand, nil, "--v23.tcp.protocol=wsh", fmt.Sprintf("--v23.tcp.address=%s:%d", host, port), "root")
+ exitOnError(err, "Failed to start root mount table")
+ exitOnError(updateVars(hRoot, vars, "MT_NAME"), "Failed to get MT_NAME")
+ defer hRoot.Shutdown(outFile, errFile)
- rootName := fmt.Sprintf("%s/sample-world", nsPrefix)
- fmt.Printf("Publishing under %s\n", rootName)
- if runTests {
- // Run a mounttable for tests
- hRoot, err := sh.Start(RunMTCommand, nil, "--v23.tcp.protocol=wsh", fmt.Sprintf("--v23.tcp.address=%s:%d", host, port), "root")
- exitOnError(err, "Failed to start root mount table")
- exitOnError(updateVars(hRoot, vars, "MT_NAME"), "Failed to get MT_NAME")
- defer hRoot.Shutdown(outFile, errFile)
+ // Set envvar.NamespacePrefix env var, consumed downstream.
+ sh.SetVar(envvar.NamespacePrefix, vars["MT_NAME"])
+ v23.GetNamespace(ctx).SetRoots(vars["MT_NAME"])
- // Set envvar.NamespacePrefix env var, consumed downstream.
- sh.SetVar(envvar.NamespacePrefix, vars["MT_NAME"])
- v23.GetNamespace(ctx).SetRoots(vars["MT_NAME"])
+ // Run the cottage mounttable at host/cottage.
+ hCottage, err := sh.Start(RunMTCommand, nil, "--v23.tcp.protocol=wsh", fmt.Sprintf("--v23.tcp.address=%s:%d", host, cottagePort), "cottage")
+ exitOnError(err, "Failed to start cottage mount table")
+ expect.NewSession(nil, hCottage.Stdout(), 30*time.Second)
+ defer hCottage.Shutdown(outFile, errFile)
- // Run the cottage mounttable at host/cottage.
- hCottage, err := sh.Start(RunMTCommand, nil, "--v23.tcp.protocol=wsh", fmt.Sprintf("--v23.tcp.address=%s:%d", host, cottagePort), "cottage")
- exitOnError(err, "Failed to start cottage mount table")
- expect.NewSession(nil, hCottage.Stdout(), 30*time.Second)
- defer hCottage.Shutdown(outFile, errFile)
-
- // run the house mounttable at host/house.
- hHouse, err := sh.Start(RunMTCommand, nil, "--v23.tcp.protocol=wsh", fmt.Sprintf("--v23.tcp.address=%s:%d", host, housePort), "house")
- exitOnError(err, "Failed to start house mount table")
- expect.NewSession(nil, hHouse.Stdout(), 30*time.Second)
- defer hHouse.Shutdown(outFile, errFile)
- } else {
- sh.SetVar(envvar.NamespacePrefix, rootName)
- v23.GetNamespace(ctx).SetRoots(rootName)
- }
-
- // Possibly run the sample world.
- if runSample {
- authorize := security.DefaultBlessingPatterns(v23.GetPrincipal(ctx))[0]
- fmt.Println("Running Sample World")
- hSample, err := sh.Start(SampleWorldCommand, nil, "--v23.tcp.protocol=wsh", fmt.Sprintf("--v23.tcp.address=%s:0", host), fmt.Sprintf("--authorize=%s", authorize))
- exitOnError(err, "Failed to start sample world")
- expect.NewSession(nil, hSample.Stdout(), 30*time.Second)
- defer hSample.Shutdown(outFile, errFile)
- }
-
- // Possibly serve the public bundle at the portHTTP.
- if serveHTTP {
- fmt.Printf("Also serving HTTP at %s for %s\n", portHTTP, rootHTTP)
- http.ListenAndServe(":"+portHTTP, http.FileServer(http.Dir(rootHTTP)))
- }
+ // run the house mounttable at host/house.
+ hHouse, err := sh.Start(RunMTCommand, nil, "--v23.tcp.protocol=wsh", fmt.Sprintf("--v23.tcp.address=%s:%d", host, housePort), "house")
+ exitOnError(err, "Failed to start house mount table")
+ expect.NewSession(nil, hHouse.Stdout(), 30*time.Second)
+ defer hHouse.Shutdown(outFile, errFile)
// Just print out the collected variables. This is for debugging purposes.
bytes, err := json.Marshal(vars)
exitOnError(err, "Failed to marshal the collected variables")
fmt.Println(string(bytes))
- // Possibly run the tests in Prova.
- if runTests {
- // Also set HOUSE_MOUNTTABLE (used in the tests)
- os.Setenv("HOUSE_MOUNTTABLE", fmt.Sprintf("/%s:%d", host, housePort))
+ // Also set HOUSE_MOUNTTABLE (used in the tests)
+ os.Setenv("HOUSE_MOUNTTABLE", fmt.Sprintf("/%s:%d", host, housePort))
- lspec := v23.GetListenSpec(ctx)
- lspec.Addrs = rpc.ListenAddrs{{"wsh", ":0"}}
- // Allow all processes started by this runner to use the proxy.
- proxyACL := access.AccessList{In: security.DefaultBlessingPatterns(v23.GetPrincipal(ctx))}
- proxyShutdown, proxyEndpoint, err := profiles.NewProxy(ctx, lspec, proxyACL, "test/proxy")
- exitOnError(err, "Failed to start proxy")
- defer proxyShutdown()
- vars["PROXY_NAME"] = proxyEndpoint.Name()
+ lspec := v23.GetListenSpec(ctx)
+ lspec.Addrs = rpc.ListenAddrs{{"wsh", ":0"}}
+ // Allow all processes started by this runner to use the proxy.
+ proxyACL := access.AccessList{In: security.DefaultBlessingPatterns(v23.GetPrincipal(ctx))}
+ proxyShutdown, proxyEndpoint, err := profiles.NewProxy(ctx, lspec, proxyACL, "test/proxy")
+ exitOnError(err, "Failed to start proxy")
+ defer proxyShutdown()
+ vars["PROXY_NAME"] = proxyEndpoint.Name()
- hIdentityd, err := sh.Start(identitylib.TestIdentitydCommand, nil, "--v23.tcp.protocol=wsh", "--v23.tcp.address=:0", "--v23.proxy=test/proxy", "--http-addr=localhost:0")
- exitOnError(err, "Failed to start identityd")
- exitOnError(updateVars(hIdentityd, vars, "TEST_IDENTITYD_NAME", "TEST_IDENTITYD_HTTP_ADDR"), "Failed to obtain identityd address")
- defer hIdentityd.Shutdown(outFile, errFile)
+ hIdentityd, err := sh.Start(identitylib.TestIdentitydCommand, nil, "--v23.tcp.protocol=wsh", "--v23.tcp.address=:0", "--v23.proxy=test/proxy", "--http-addr=localhost:0")
+ exitOnError(err, "Failed to start identityd")
+ exitOnError(updateVars(hIdentityd, vars, "TEST_IDENTITYD_NAME", "TEST_IDENTITYD_HTTP_ADDR"), "Failed to obtain identityd address")
+ defer hIdentityd.Shutdown(outFile, errFile)
- // Setup a lot of environment variables; these are used for the tests and building the test extension.
- os.Setenv(envvar.NamespacePrefix, vars["MT_NAME"])
- os.Setenv("PROXY_ADDR", vars["PROXY_NAME"])
- os.Setenv("IDENTITYD", fmt.Sprintf("%s/google", vars["TEST_IDENTITYD_NAME"]))
- os.Setenv("IDENTITYD_BLESSING_URL", fmt.Sprintf("%s/auth/blessing-root", vars["TEST_IDENTITYD_HTTP_ADDR"]))
- os.Setenv("DEBUG", "false")
+ // Setup a lot of environment variables; these are used for the tests and building the test extension.
+ os.Setenv(envvar.NamespacePrefix, vars["MT_NAME"])
+ os.Setenv("PROXY_ADDR", vars["PROXY_NAME"])
+ os.Setenv("IDENTITYD", fmt.Sprintf("%s/google", vars["TEST_IDENTITYD_NAME"]))
+ os.Setenv("IDENTITYD_BLESSING_URL", fmt.Sprintf("%s/auth/blessing-root", vars["TEST_IDENTITYD_HTTP_ADDR"]))
+ os.Setenv("DEBUG", "false")
- testsOk := runProva()
+ testsOk := runProva()
- fmt.Println("Cleaning up launched services...")
- return testsOk
- }
+ fmt.Println("Cleaning up launched services...")
+ return testsOk
// Not in a test, so run until the program is killed.
<-signals.ShutdownOnSignals(ctx)
diff --git a/go/src/v.io/x/browser/sample/alarm.vdl b/go/src/v.io/x/browser/sample/alarm.vdl
deleted file mode 100644
index 74aae85..0000000
--- a/go/src/v.io/x/browser/sample/alarm.vdl
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package sample
-
-// Alarm allows clients to manipulate an alarm and query its status.
-type Alarm interface {
- // Status returns the current status of the Alarm (i.e., armed, unarmed, panicking).
- Status() (string | error)
- // Arm sets the Alarm to the armed state.
- Arm() error
- // DelayArm sets the Alarm to the armed state after the given delay in seconds.
- DelayArm(seconds float32) error
- // Unarm sets the Alarm to the unarmed state.
- Unarm() error
- // Panic sets the Alarm to the panicking state.
- Panic() error
-}
diff --git a/go/src/v.io/x/browser/sample/alarm.vdl.go b/go/src/v.io/x/browser/sample/alarm.vdl.go
deleted file mode 100644
index 1a8f451..0000000
--- a/go/src/v.io/x/browser/sample/alarm.vdl.go
+++ /dev/null
@@ -1,190 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file was auto-generated by the vanadium vdl tool.
-// Source: alarm.vdl
-
-package sample
-
-import (
- // VDL system imports
- "v.io/v23"
- "v.io/v23/context"
- "v.io/v23/rpc"
-)
-
-// AlarmClientMethods is the client interface
-// containing Alarm methods.
-//
-// Alarm allows clients to manipulate an alarm and query its status.
-type AlarmClientMethods interface {
- // Status returns the current status of the Alarm (i.e., armed, unarmed, panicking).
- Status(*context.T, ...rpc.CallOpt) (string, error)
- // Arm sets the Alarm to the armed state.
- Arm(*context.T, ...rpc.CallOpt) error
- // DelayArm sets the Alarm to the armed state after the given delay in seconds.
- DelayArm(ctx *context.T, seconds float32, opts ...rpc.CallOpt) error
- // Unarm sets the Alarm to the unarmed state.
- Unarm(*context.T, ...rpc.CallOpt) error
- // Panic sets the Alarm to the panicking state.
- Panic(*context.T, ...rpc.CallOpt) error
-}
-
-// AlarmClientStub adds universal methods to AlarmClientMethods.
-type AlarmClientStub interface {
- AlarmClientMethods
- rpc.UniversalServiceMethods
-}
-
-// AlarmClient returns a client stub for Alarm.
-func AlarmClient(name string) AlarmClientStub {
- return implAlarmClientStub{name}
-}
-
-type implAlarmClientStub struct {
- name string
-}
-
-func (c implAlarmClientStub) Status(ctx *context.T, opts ...rpc.CallOpt) (o0 string, err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Status", nil, []interface{}{&o0}, opts...)
- return
-}
-
-func (c implAlarmClientStub) Arm(ctx *context.T, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Arm", nil, nil, opts...)
- return
-}
-
-func (c implAlarmClientStub) DelayArm(ctx *context.T, i0 float32, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "DelayArm", []interface{}{i0}, nil, opts...)
- return
-}
-
-func (c implAlarmClientStub) Unarm(ctx *context.T, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Unarm", nil, nil, opts...)
- return
-}
-
-func (c implAlarmClientStub) Panic(ctx *context.T, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Panic", nil, nil, opts...)
- return
-}
-
-// AlarmServerMethods is the interface a server writer
-// implements for Alarm.
-//
-// Alarm allows clients to manipulate an alarm and query its status.
-type AlarmServerMethods interface {
- // Status returns the current status of the Alarm (i.e., armed, unarmed, panicking).
- Status(*context.T, rpc.ServerCall) (string, error)
- // Arm sets the Alarm to the armed state.
- Arm(*context.T, rpc.ServerCall) error
- // DelayArm sets the Alarm to the armed state after the given delay in seconds.
- DelayArm(ctx *context.T, call rpc.ServerCall, seconds float32) error
- // Unarm sets the Alarm to the unarmed state.
- Unarm(*context.T, rpc.ServerCall) error
- // Panic sets the Alarm to the panicking state.
- Panic(*context.T, rpc.ServerCall) error
-}
-
-// AlarmServerStubMethods is the server interface containing
-// Alarm methods, as expected by rpc.Server.
-// There is no difference between this interface and AlarmServerMethods
-// since there are no streaming methods.
-type AlarmServerStubMethods AlarmServerMethods
-
-// AlarmServerStub adds universal methods to AlarmServerStubMethods.
-type AlarmServerStub interface {
- AlarmServerStubMethods
- // Describe the Alarm interfaces.
- Describe__() []rpc.InterfaceDesc
-}
-
-// AlarmServer returns a server stub for Alarm.
-// It converts an implementation of AlarmServerMethods into
-// an object that may be used by rpc.Server.
-func AlarmServer(impl AlarmServerMethods) AlarmServerStub {
- stub := implAlarmServerStub{
- impl: impl,
- }
- // Initialize GlobState; always check the stub itself first, to handle the
- // case where the user has the Glob method defined in their VDL source.
- if gs := rpc.NewGlobState(stub); gs != nil {
- stub.gs = gs
- } else if gs := rpc.NewGlobState(impl); gs != nil {
- stub.gs = gs
- }
- return stub
-}
-
-type implAlarmServerStub struct {
- impl AlarmServerMethods
- gs *rpc.GlobState
-}
-
-func (s implAlarmServerStub) Status(ctx *context.T, call rpc.ServerCall) (string, error) {
- return s.impl.Status(ctx, call)
-}
-
-func (s implAlarmServerStub) Arm(ctx *context.T, call rpc.ServerCall) error {
- return s.impl.Arm(ctx, call)
-}
-
-func (s implAlarmServerStub) DelayArm(ctx *context.T, call rpc.ServerCall, i0 float32) error {
- return s.impl.DelayArm(ctx, call, i0)
-}
-
-func (s implAlarmServerStub) Unarm(ctx *context.T, call rpc.ServerCall) error {
- return s.impl.Unarm(ctx, call)
-}
-
-func (s implAlarmServerStub) Panic(ctx *context.T, call rpc.ServerCall) error {
- return s.impl.Panic(ctx, call)
-}
-
-func (s implAlarmServerStub) Globber() *rpc.GlobState {
- return s.gs
-}
-
-func (s implAlarmServerStub) Describe__() []rpc.InterfaceDesc {
- return []rpc.InterfaceDesc{AlarmDesc}
-}
-
-// AlarmDesc describes the Alarm interface.
-var AlarmDesc rpc.InterfaceDesc = descAlarm
-
-// descAlarm hides the desc to keep godoc clean.
-var descAlarm = rpc.InterfaceDesc{
- Name: "Alarm",
- PkgPath: "v.io/x/browser/sample",
- Doc: "// Alarm allows clients to manipulate an alarm and query its status.",
- Methods: []rpc.MethodDesc{
- {
- Name: "Status",
- Doc: "// Status returns the current status of the Alarm (i.e., armed, unarmed, panicking).",
- OutArgs: []rpc.ArgDesc{
- {"", ``}, // string
- },
- },
- {
- Name: "Arm",
- Doc: "// Arm sets the Alarm to the armed state.",
- },
- {
- Name: "DelayArm",
- Doc: "// DelayArm sets the Alarm to the armed state after the given delay in seconds.",
- InArgs: []rpc.ArgDesc{
- {"seconds", ``}, // float32
- },
- },
- {
- Name: "Unarm",
- Doc: "// Unarm sets the Alarm to the unarmed state.",
- },
- {
- Name: "Panic",
- Doc: "// Panic sets the Alarm to the panicking state.",
- },
- },
-}
diff --git a/go/src/v.io/x/browser/sample/lightswitch.vdl b/go/src/v.io/x/browser/sample/lightswitch.vdl
deleted file mode 100644
index d7ad29b..0000000
--- a/go/src/v.io/x/browser/sample/lightswitch.vdl
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package sample
-
-// LightSwitch allows clients to manipulate a virtual light switch.
-type LightSwitch interface {
- // Status indicates whether the light is on or off.
- Status() (string | error)
- // FlipSwitch sets the light to on or off, depending on the input.
- FlipSwitch(toOn bool) error
-}
diff --git a/go/src/v.io/x/browser/sample/lightswitch.vdl.go b/go/src/v.io/x/browser/sample/lightswitch.vdl.go
deleted file mode 100644
index 8c8602e..0000000
--- a/go/src/v.io/x/browser/sample/lightswitch.vdl.go
+++ /dev/null
@@ -1,139 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file was auto-generated by the vanadium vdl tool.
-// Source: lightswitch.vdl
-
-package sample
-
-import (
- // VDL system imports
- "v.io/v23"
- "v.io/v23/context"
- "v.io/v23/rpc"
-)
-
-// LightSwitchClientMethods is the client interface
-// containing LightSwitch methods.
-//
-// LightSwitch allows clients to manipulate a virtual light switch.
-type LightSwitchClientMethods interface {
- // Status indicates whether the light is on or off.
- Status(*context.T, ...rpc.CallOpt) (string, error)
- // FlipSwitch sets the light to on or off, depending on the input.
- FlipSwitch(ctx *context.T, toOn bool, opts ...rpc.CallOpt) error
-}
-
-// LightSwitchClientStub adds universal methods to LightSwitchClientMethods.
-type LightSwitchClientStub interface {
- LightSwitchClientMethods
- rpc.UniversalServiceMethods
-}
-
-// LightSwitchClient returns a client stub for LightSwitch.
-func LightSwitchClient(name string) LightSwitchClientStub {
- return implLightSwitchClientStub{name}
-}
-
-type implLightSwitchClientStub struct {
- name string
-}
-
-func (c implLightSwitchClientStub) Status(ctx *context.T, opts ...rpc.CallOpt) (o0 string, err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Status", nil, []interface{}{&o0}, opts...)
- return
-}
-
-func (c implLightSwitchClientStub) FlipSwitch(ctx *context.T, i0 bool, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "FlipSwitch", []interface{}{i0}, nil, opts...)
- return
-}
-
-// LightSwitchServerMethods is the interface a server writer
-// implements for LightSwitch.
-//
-// LightSwitch allows clients to manipulate a virtual light switch.
-type LightSwitchServerMethods interface {
- // Status indicates whether the light is on or off.
- Status(*context.T, rpc.ServerCall) (string, error)
- // FlipSwitch sets the light to on or off, depending on the input.
- FlipSwitch(ctx *context.T, call rpc.ServerCall, toOn bool) error
-}
-
-// LightSwitchServerStubMethods is the server interface containing
-// LightSwitch methods, as expected by rpc.Server.
-// There is no difference between this interface and LightSwitchServerMethods
-// since there are no streaming methods.
-type LightSwitchServerStubMethods LightSwitchServerMethods
-
-// LightSwitchServerStub adds universal methods to LightSwitchServerStubMethods.
-type LightSwitchServerStub interface {
- LightSwitchServerStubMethods
- // Describe the LightSwitch interfaces.
- Describe__() []rpc.InterfaceDesc
-}
-
-// LightSwitchServer returns a server stub for LightSwitch.
-// It converts an implementation of LightSwitchServerMethods into
-// an object that may be used by rpc.Server.
-func LightSwitchServer(impl LightSwitchServerMethods) LightSwitchServerStub {
- stub := implLightSwitchServerStub{
- impl: impl,
- }
- // Initialize GlobState; always check the stub itself first, to handle the
- // case where the user has the Glob method defined in their VDL source.
- if gs := rpc.NewGlobState(stub); gs != nil {
- stub.gs = gs
- } else if gs := rpc.NewGlobState(impl); gs != nil {
- stub.gs = gs
- }
- return stub
-}
-
-type implLightSwitchServerStub struct {
- impl LightSwitchServerMethods
- gs *rpc.GlobState
-}
-
-func (s implLightSwitchServerStub) Status(ctx *context.T, call rpc.ServerCall) (string, error) {
- return s.impl.Status(ctx, call)
-}
-
-func (s implLightSwitchServerStub) FlipSwitch(ctx *context.T, call rpc.ServerCall, i0 bool) error {
- return s.impl.FlipSwitch(ctx, call, i0)
-}
-
-func (s implLightSwitchServerStub) Globber() *rpc.GlobState {
- return s.gs
-}
-
-func (s implLightSwitchServerStub) Describe__() []rpc.InterfaceDesc {
- return []rpc.InterfaceDesc{LightSwitchDesc}
-}
-
-// LightSwitchDesc describes the LightSwitch interface.
-var LightSwitchDesc rpc.InterfaceDesc = descLightSwitch
-
-// descLightSwitch hides the desc to keep godoc clean.
-var descLightSwitch = rpc.InterfaceDesc{
- Name: "LightSwitch",
- PkgPath: "v.io/x/browser/sample",
- Doc: "// LightSwitch allows clients to manipulate a virtual light switch.",
- Methods: []rpc.MethodDesc{
- {
- Name: "Status",
- Doc: "// Status indicates whether the light is on or off.",
- OutArgs: []rpc.ArgDesc{
- {"", ``}, // string
- },
- },
- {
- Name: "FlipSwitch",
- Doc: "// FlipSwitch sets the light to on or off, depending on the input.",
- InArgs: []rpc.ArgDesc{
- {"toOn", ``}, // bool
- },
- },
- },
-}
diff --git a/go/src/v.io/x/browser/sample/mocks/alarm.go b/go/src/v.io/x/browser/sample/mocks/alarm.go
deleted file mode 100644
index 78a770b..0000000
--- a/go/src/v.io/x/browser/sample/mocks/alarm.go
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package mocks
-
-import (
- "time"
-
- "v.io/v23/context"
- "v.io/v23/rpc"
-)
-
-const (
- // Alarm status constants
- alarmPanicking = "panicking"
- alarmArmed = "armed"
- alarmUnarmed = "unarmed"
-)
-
-// Alarm allows clients to manipulate an alarm and query its status.
-type alarm struct {
- status string
-}
-
-// Status returns the current status of the Alarm (i.e., armed, unarmed, panicking).
-func (a *alarm) Status(*context.T, rpc.ServerCall) (string, error) {
- return a.status, nil
-}
-
-// Arm sets the Alarm to the armed state
-func (a *alarm) Arm(*context.T, rpc.ServerCall) error {
- a.status = alarmArmed
- return nil
-}
-
-// DelayArm sets the Alarm to the armed state after the given delay in seconds.
-func (a *alarm) DelayArm(_ *context.T, _ rpc.ServerCall, delay float32) error {
- time.AfterFunc(
- time.Duration(delay)*time.Second,
- func() {
- a.status = alarmArmed
- },
- )
- return nil
-}
-
-// Unarm sets the Alarm to the unarmed state.
-func (a *alarm) Unarm(*context.T, rpc.ServerCall) error {
- a.status = alarmUnarmed
- return nil
-}
-
-// Panic sets the Alarm to the panicking state.
-func (a *alarm) Panic(*context.T, rpc.ServerCall) error {
- a.status = alarmPanicking
- return nil
-}
-
-// NewAlarm creates a new alarm stub.
-func NewAlarm() *alarm {
- return &alarm{status: alarmUnarmed}
-}
diff --git a/go/src/v.io/x/browser/sample/mocks/lightswitch.go b/go/src/v.io/x/browser/sample/mocks/lightswitch.go
deleted file mode 100644
index c0742fa..0000000
--- a/go/src/v.io/x/browser/sample/mocks/lightswitch.go
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package mocks
-
-import (
- "v.io/v23/context"
- "v.io/v23/rpc"
-)
-
-const (
- // Light Switch status constants
- lightSwitchOn = "on"
- lightSwitchOff = "off"
-)
-
-// LightSwitch allows clients to manipulate a virtual light switch.
-type lightSwitch struct {
- status string
-}
-
-// Status indicates whether the light is on or off.
-func (l *lightSwitch) Status(*context.T, rpc.ServerCall) (string, error) {
- return l.status, nil
-}
-
-// FlipSwitch sets the light to on or off, depending on the input.
-func (l *lightSwitch) FlipSwitch(_ *context.T, _ rpc.ServerCall, toOn bool) error {
- if toOn {
- l.status = lightSwitchOn
- } else {
- l.status = lightSwitchOff
- }
- return nil
-}
-
-// NewLightSwitch creates a new light switch stub.
-func NewLightSwitch() *lightSwitch {
- return &lightSwitch{
- status: lightSwitchOff,
- }
-}
diff --git a/go/src/v.io/x/browser/sample/mocks/petfeeder.go b/go/src/v.io/x/browser/sample/mocks/petfeeder.go
deleted file mode 100644
index 180d3e0..0000000
--- a/go/src/v.io/x/browser/sample/mocks/petfeeder.go
+++ /dev/null
@@ -1,251 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package mocks
-
-import (
- "fmt"
- "math"
- "math/rand"
- "strings"
- "time"
-
- "v.io/v23/context"
- "v.io/v23/rpc"
- "v.io/x/browser/sample"
-)
-
-const (
- // Pet Feeder limits
- MIN_FILL = 0.0
- MAX_FILL = 1.0
-
- HUNGER_DELAY = 60000 // hunger worsens every 60s
-
- MOOD_DELAY_BASE = 40000 // mood worsens every 40s to 85s
- MOOD_DELAY_SCALING = 7500
-
- EAT_DELAY = 500 // dog eating progress updates every 0.5s
- EAT_SPEED = 0.02 // eats 0.02 of the dog bowl every interval
- HUNGER_BAND = 0.2 // upon eating 0.2 of the dog bowl, hunger improves
-
- PLAY_MINIMUM = 3 // playtime lasts at least 3s for mood to improve
-
- MIN_MOOD = 0
- START_MOOD = 2
- MAX_MOOD = 4
-
- MIN_HUNGER = 0
- START_HUNGER = 3
- MAX_HUNGER = 6
-)
-
-var (
- // Dog mood strings
- moods = [][]string{
- {"angry", "sullen", "depressed"},
- {"bored", "tired", "unhappy"},
- {"content", "at-ease", "lazy"},
- {"happy", "friendly", "playful"},
- {"exuberant", "loving", "excited"},
- }
- responses = [][]string{
- {"*whine*", "*whimper*", "*growl*"},
- {"<ignores you>", "*bark*", "<turns away>"},
- {"<yawns>", "<pants>", "<looks at you>"},
- {"*playful bark*", "<lick>", "<wags tail>"},
- {"*<tackle hug>*", "<brushes up>", "*woof! woof!*"},
- }
- // Dog hunger strings
- hungers = []string{
- "starving", "famished", "hungry", "not hungry", "satiated", "full", "bloated",
- }
-)
-
-// PetFeeder allows clients to remotely feed their pets.
-type PetFeeder struct {
- status float64
-}
-
-// NewPetFeeder creates a new PetFeeder stub.
-func NewPetFeeder() *PetFeeder {
- return &PetFeeder{status: MIN_FILL}
-}
-
-// Status returns the current status of the Pet Feeder
-func (p *PetFeeder) Status(*context.T, rpc.ServerCall) (float64, error) {
- return p.status, nil
-}
-
-// Fill fills the pet feeder bowl with food. Errors if the bowl will overflow.
-func (p *PetFeeder) Fill(_ *context.T, _ rpc.ServerCall, amount float64) error {
- if p.status+amount > MAX_FILL {
- p.status = MAX_FILL
- return fmt.Errorf("pet feeder overflowed")
- }
- p.status += amount
- return nil
-}
-
-// Empty removes all food from the pet feeder bowl.
-func (p *PetFeeder) Empty(*context.T, rpc.ServerCall) error {
- p.status = MIN_FILL
- return nil
-}
-
-// RoboDog allows clients to play with a virtual robotic dog.
-type RoboDog struct {
- name string // the dog's current name
- mood int // mood improves when played with and not hungry
- hunger int // hunger worsens over time. Improves while eating.
- eating bool // the dog is busy while eating.
- feeder *PetFeeder // The PetFeeder that this dog is linked to.
-}
-
-// NewRoboDog creates a new RoboDog stub.
-func NewRoboDog(p *PetFeeder) *RoboDog {
- r := &RoboDog{
- name: "VDog",
- mood: START_MOOD,
- hunger: START_HUNGER,
- eating: false,
- feeder: p,
- }
-
- // Make the dog hungrier and hungrier.
- // Worsen the dog's mood over time. Faster when dog is hungrier.
- // If available, slowly eat from the feeder and improve hunger.
- // But I need a way to signal that these things should stop...
- // defer could catch this during cleanup, but is it even really necessary?
- // Also, I don't care about race conditions.
- go r.hungerCycle()
- go r.moodCycle()
- go r.eatCycle()
-
- return r
-}
-
-// Helper goroutine to emulate the dog's hunger cycle.
-func (r *RoboDog) hungerCycle() {
- for {
- // Delay for a while... hunger worsens!
- time.Sleep(HUNGER_DELAY * time.Millisecond)
- r.changeHunger(-1)
- }
-}
-
-// Helper goroutine to emulate the dog's mood cycle.
-func (r *RoboDog) moodCycle() {
- for {
- // Delay for a while... mood worsens!
- // Delay is longer when the dog is less hungry.
- delay := MOOD_DELAY_BASE + MOOD_DELAY_SCALING*r.hunger
- time.Sleep(time.Duration(delay) * time.Millisecond)
- r.changeMood(-1)
- }
-}
-
-// Helper goroutine to emulate the dog's eating cycle.
-func (r *RoboDog) eatCycle() {
- var eaten float64
- for {
- // Check in on the dog at intervals.
- time.Sleep(EAT_DELAY * time.Millisecond)
-
- // If the dog is eating, empty the feeder by the same amount.
- if r.eating {
- eat := math.Min(r.feeder.status, EAT_SPEED)
- r.feeder.status -= eat
- eaten += eat
- if eaten >= HUNGER_BAND {
- eaten -= HUNGER_BAND
- r.changeHunger(1)
- }
- }
-
- // Eat if there's any food and hunger is not at max.
- r.eating = (r.feeder.status != MIN_FILL && r.hunger != MAX_HUNGER)
- }
-}
-
-// Status returns the state of the robotic dog.
-func (r *RoboDog) Status(*context.T, rpc.ServerCall) (sample.RoboDogStatus, error) {
- dogMoods := moods[r.mood]
- dogMood := dogMoods[rand.Intn(len(dogMoods))] // pick a random mood
- dogHunger := hungers[r.hunger]
- return sample.RoboDogStatus{
- r.name,
- dogMood,
- dogHunger,
- r.eating,
- }, nil
-}
-
-// Speak allows a client to speak with the robotic dog.
-func (r *RoboDog) Speak(_ *context.T, _ rpc.ServerCall, words string) (string, error) {
- // If dog is eating, the dog cannot listen or respond.
- if r.eating {
- return "*munch* *munch*", nil
- }
-
- // Secret: If dog's name was spoken. Mood up!
- if strings.Contains(strings.ToLower(words), strings.ToLower(r.name)) {
- r.changeMood(1)
- }
-
- // The dog's response depends on mood.
- return r.respond(), nil
-}
-
-// Play allows a client to play with the robotic dog.
-// Errors if the dog does not want to play.
-func (r *RoboDog) Play(_ *context.T, _ rpc.ServerCall, duration uint32) error {
- if r.eating {
- return fmt.Errorf("%s is busy eating now", r.name)
- } else if r.mood == MIN_MOOD {
- return fmt.Errorf("%s is in a bad mood", r.name)
- }
-
- // Delay for a while... mood improves!
- time.Sleep(time.Duration(duration) * time.Second)
- if duration >= PLAY_MINIMUM {
- r.changeMood(1)
- }
-
- return nil
-}
-
-// SetName allows a client to set the robotic dog's name.
-func (r *RoboDog) SetName(_ *context.T, _ rpc.ServerCall, name string) error {
- r.name = name
- return nil
-}
-
-// Helper to pick a random response based on the dog's mood.
-func (r *RoboDog) respond() string {
- responseList := responses[r.mood]
- return responseList[rand.Intn(len(responseList))] // pick a random response
-}
-
-// Helper to change the dog's mood.
-func (r *RoboDog) changeMood(amount int) {
- r.mood += amount
- // Do not overflow on mood.
- if r.mood > MAX_MOOD {
- r.mood = MAX_MOOD
- } else if r.mood < MIN_MOOD {
- r.mood = MIN_MOOD
- }
-}
-
-// Helper to change the dog's hunger.
-func (r *RoboDog) changeHunger(amount int) {
- r.hunger += amount
- // Do not overflow on hunger.
- if r.hunger > MAX_HUNGER {
- r.hunger = MAX_HUNGER
- } else if r.hunger < MIN_HUNGER {
- r.hunger = MIN_HUNGER
- }
-}
diff --git a/go/src/v.io/x/browser/sample/mocks/poolheater.go b/go/src/v.io/x/browser/sample/mocks/poolheater.go
deleted file mode 100644
index 23dee20..0000000
--- a/go/src/v.io/x/browser/sample/mocks/poolheater.go
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package mocks
-
-import (
- "time"
-
- "v.io/v23/context"
- "v.io/v23/rpc"
-)
-
-const (
- // Pool heater status constants
- poolHeaterActive = "active"
- poolHeaterIdle = "idle"
-
- poolHeaterDefaultTemperature = 60
-)
-
-// PoolHeater allows clients to control when the pool is being heated.
-type poolHeater struct {
- status string
- currTemperature uint64
-}
-
-// Status retrieves the PoolHeater's status (i.e., active, idle) and temperature.
-func (p *poolHeater) Status(*context.T, rpc.ServerCall) (status string, temperature uint64, err error) {
- return p.status, p.currTemperature, nil
-}
-
-// Start informs the PoolHeater to heat the pool to the given temperature until the duration expires.
-func (p *poolHeater) Start(_ *context.T, _ rpc.ServerCall, temperature uint64, duration uint64) error {
- // Begin heating.
- p.status = poolHeaterActive
- p.currTemperature = temperature
-
- // After duration, stop heating.
- time.AfterFunc(
- time.Duration(duration)*time.Second,
- func() {
- p.status = poolHeaterIdle
- p.currTemperature = poolHeaterDefaultTemperature
- },
- )
- return nil
-}
-
-// Stop informs the PoolHeater to cease heating the pool.
-func (p *poolHeater) Stop(*context.T, rpc.ServerCall) error {
- p.status = poolHeaterIdle
- p.currTemperature = poolHeaterDefaultTemperature
- return nil
-}
-
-// NewPoolHeater creates a new poolHeater stub.
-func NewPoolHeater() *poolHeater {
- return &poolHeater{
- status: poolHeaterIdle,
- currTemperature: poolHeaterDefaultTemperature,
- }
-}
diff --git a/go/src/v.io/x/browser/sample/mocks/smokedetector.go b/go/src/v.io/x/browser/sample/mocks/smokedetector.go
deleted file mode 100644
index 55a9272..0000000
--- a/go/src/v.io/x/browser/sample/mocks/smokedetector.go
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package mocks
-
-import (
- "time"
-
- "v.io/v23/context"
- "v.io/v23/rpc"
-)
-
-const (
- // Smoke detector status constants
- smokeDetectorDetecting = "smoky"
- smokeDetectorNotDetecting = "normal"
-
- smokeDetectorDefaultSensitivity = int16(10)
-)
-
-// SmokeDetector allows clients to monitor and adjust a smoke detector.
-type smokeDetector struct {
- status string
- sensitivity int16
-}
-
-// Status retrieves the current status and sensitivity of the SmokeDetector.
-func (s *smokeDetector) Status(*context.T, rpc.ServerCall) (status string, sensitivity int16, err error) {
- return s.status, s.sensitivity, nil
-}
-
-// Test the SmokeDetector to check if it is working.
-func (s *smokeDetector) Test(*context.T, rpc.ServerCall) (bool, error) {
- time.Sleep(1500 * time.Millisecond) // simulate testing for 1.5 seconds
- success := s.sensitivity > 0 // succeed only if sensitivity is positive
- return success, nil
-}
-
-// Sensitivity adjusts the SmokeDetector's sensitivity to smoke.
-func (s *smokeDetector) Sensitivity(_ *context.T, _ rpc.ServerCall, sensitivity int16) error {
- s.sensitivity = sensitivity
- return nil
-}
-
-// NewSmokeDetector creates a new smoke detector stub.
-func NewSmokeDetector() *smokeDetector {
- return &smokeDetector{
- status: smokeDetectorNotDetecting,
- sensitivity: smokeDetectorDefaultSensitivity,
- }
-}
diff --git a/go/src/v.io/x/browser/sample/mocks/speaker.go b/go/src/v.io/x/browser/sample/mocks/speaker.go
deleted file mode 100644
index 6204250..0000000
--- a/go/src/v.io/x/browser/sample/mocks/speaker.go
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package mocks
-
-import (
- "errors"
- "fmt"
-
- "v.io/v23/context"
- "v.io/v23/rpc"
- "v.io/x/browser/sample"
-)
-
-const speakerDefaultVolume = uint16(10)
-
-// Speaker allows clients to control the music being played.
-type speaker struct {
- currentSong string
- playing bool
- volume uint16
- speakerLibrary map[string]bool
-}
-
-// Play starts or continues the current song.
-func (s *speaker) Play(*context.T, rpc.ServerCall) error {
- if s.currentSong == "" {
- return errors.New("no current song")
- }
- s.playing = true
- return nil
-}
-
-// PlaySong plays back the given song title, if possible.
-func (s *speaker) PlaySong(_ *context.T, _ rpc.ServerCall, title string) error {
- if !s.speakerLibrary[title] {
- return errors.New(fmt.Sprintf("%q does not exist", title))
- }
- s.currentSong = title
- s.playing = true
- return nil
-}
-
-// PlayStream plays the given stream of music data.
-func (s *speaker) PlayStream(*context.T, sample.SpeakerPlayStreamServerCall) error {
- s.currentSong = ""
- s.playing = true
- return nil
-}
-
-// GetSong retrieves the title of the Speaker's current song, if any.
-func (s *speaker) GetSong(*context.T, rpc.ServerCall) (string, error) {
- return s.currentSong, nil
-}
-
-// Pause playback of the Speaker's current song.
-func (s *speaker) Pause(*context.T, rpc.ServerCall) error {
- s.playing = false
- return nil
-}
-
-// Stop playback of the Speaker's current song.
-func (s *speaker) Stop(*context.T, rpc.ServerCall) error {
- s.currentSong = ""
- s.playing = false
- return nil
-}
-
-// Volume adjusts the Speaker's volume.
-func (s *speaker) Volume(_ *context.T, _ rpc.ServerCall, volume uint16) error {
- s.volume = volume
- return nil
-}
-
-// GetVolume retrieves the Speaker's volume.
-func (s *speaker) GetVolume(*context.T, rpc.ServerCall) (uint16, error) {
- return s.volume, nil
-}
-
-// AddSongs adds the list of given songs to the song library.
-func (s *speaker) AddSongs(_ *context.T, _ rpc.ServerCall, songs []string) error {
- for _, song := range songs {
- s.speakerLibrary[song] = true // No-op if the song is there.
- }
- return nil
-}
-
-// Delete removes the list of given songs from the song library.
-func (s *speaker) Delete(_ *context.T, _ rpc.ServerCall, songs []string) error {
- for _, song := range songs {
- delete(s.speakerLibrary, song) // No-op if the song isn't there.
- if s.currentSong == song { // Stop playing the current song if it was removed.
- s.currentSong = ""
- s.playing = false
- }
- }
- return nil
-}
-
-// NewSpeaker creates a new speaker stub.
-func NewSpeaker() *speaker {
- return &speaker{
- playing: false,
- volume: speakerDefaultVolume,
- speakerLibrary: map[string]bool{ // Start with some default songs.
- "Happy Birthday": true,
- "Never Gonna Give You Up": true,
- },
- }
-}
diff --git a/go/src/v.io/x/browser/sample/mocks/sprinkler.go b/go/src/v.io/x/browser/sample/mocks/sprinkler.go
deleted file mode 100644
index 58eddef..0000000
--- a/go/src/v.io/x/browser/sample/mocks/sprinkler.go
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package mocks
-
-import (
- "time"
-
- "v.io/v23/context"
- "v.io/v23/rpc"
-)
-
-const (
- // Sprinkler status constants
- sprinklerActive = "active"
- sprinklerIdle = "idle"
-)
-
-// Sprinkler allows clients to control the virtual sprinkler.
-type sprinkler struct {
- status string
-}
-
-// Status retrieves the Sprinkler's status (i.e., active, idle)
-func (s *sprinkler) Status(*context.T, rpc.ServerCall) (string, error) {
- return s.status, nil
-}
-
-// Start causes the Sprinkler to emit water for the given duration (in seconds).
-func (s *sprinkler) Start(_ *context.T, _ rpc.ServerCall, duration uint16) error {
- s.status = sprinklerActive
- time.AfterFunc(
- time.Duration(duration)*time.Second,
- func() { s.status = sprinklerIdle },
- )
- return nil
-}
-
-// Stop causes the Sprinkler to cease watering.
-func (s *sprinkler) Stop(*context.T, rpc.ServerCall) error {
- s.status = sprinklerIdle
- return nil
-}
-
-// NewSprinkler creates a new sprinkler stub.
-func NewSprinkler() *sprinkler {
- return &sprinkler{
- status: sprinklerIdle,
- }
-}
diff --git a/go/src/v.io/x/browser/sample/petfeeder.vdl b/go/src/v.io/x/browser/sample/petfeeder.vdl
deleted file mode 100644
index 80438dc..0000000
--- a/go/src/v.io/x/browser/sample/petfeeder.vdl
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package sample
-
-// PetFeeder allows clients to remotely feed their pets.
-type PetFeeder interface {
- // Status returns the current status of the PetFeeder (how full the bowl is).
- Status() (float64 | error)
- // Fill fills the pet feeder bowl with food. Errors if the bowl will overflow.
- Fill(amount float64) error
- // Empty removes all food from the pet feeder bowl.
- Empty() error
-}
-
-// RoboDogStatus represents the status of a robotic dog.
-type RoboDogStatus struct{
- Name string // the dog's current name
- Mood string // mood improves when played with and not hungry
- Hunger string // hunger worsens over time. Improves while eating.
- Eating bool // the dog is busy while eating.
-}
-
-// RoboDog allows clients to play with a virtual robotic dog.
-type RoboDog interface {
- // Status returns the state of the robotic dog.
- Status() (RoboDogStatus | error)
- // Speak allows a client to speak with the robotic dog.
- Speak(words string) (string | error)
- // Play allows a client to play with the robotic dog.
- // Errors if the dog does not want to play.
- Play(duration uint32) error
- // SetName allows a client to set the robotic dog's name.
- SetName(name string) error
-}
\ No newline at end of file
diff --git a/go/src/v.io/x/browser/sample/petfeeder.vdl.go b/go/src/v.io/x/browser/sample/petfeeder.vdl.go
deleted file mode 100644
index 0e02f18..0000000
--- a/go/src/v.io/x/browser/sample/petfeeder.vdl.go
+++ /dev/null
@@ -1,343 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file was auto-generated by the vanadium vdl tool.
-// Source: petfeeder.vdl
-
-package sample
-
-import (
- // VDL system imports
- "v.io/v23"
- "v.io/v23/context"
- "v.io/v23/rpc"
- "v.io/v23/vdl"
-)
-
-// RoboDogStatus represents the status of a robotic dog.
-type RoboDogStatus struct {
- Name string // the dog's current name
- Mood string // mood improves when played with and not hungry
- Hunger string // hunger worsens over time. Improves while eating.
- Eating bool // the dog is busy while eating.
-}
-
-func (RoboDogStatus) __VDLReflect(struct {
- Name string "v.io/x/browser/sample.RoboDogStatus"
-}) {
-}
-
-func init() {
- vdl.Register((*RoboDogStatus)(nil))
-}
-
-// PetFeederClientMethods is the client interface
-// containing PetFeeder methods.
-//
-// PetFeeder allows clients to remotely feed their pets.
-type PetFeederClientMethods interface {
- // Status returns the current status of the PetFeeder (how full the bowl is).
- Status(*context.T, ...rpc.CallOpt) (float64, error)
- // Fill fills the pet feeder bowl with food. Errors if the bowl will overflow.
- Fill(ctx *context.T, amount float64, opts ...rpc.CallOpt) error
- // Empty removes all food from the pet feeder bowl.
- Empty(*context.T, ...rpc.CallOpt) error
-}
-
-// PetFeederClientStub adds universal methods to PetFeederClientMethods.
-type PetFeederClientStub interface {
- PetFeederClientMethods
- rpc.UniversalServiceMethods
-}
-
-// PetFeederClient returns a client stub for PetFeeder.
-func PetFeederClient(name string) PetFeederClientStub {
- return implPetFeederClientStub{name}
-}
-
-type implPetFeederClientStub struct {
- name string
-}
-
-func (c implPetFeederClientStub) Status(ctx *context.T, opts ...rpc.CallOpt) (o0 float64, err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Status", nil, []interface{}{&o0}, opts...)
- return
-}
-
-func (c implPetFeederClientStub) Fill(ctx *context.T, i0 float64, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Fill", []interface{}{i0}, nil, opts...)
- return
-}
-
-func (c implPetFeederClientStub) Empty(ctx *context.T, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Empty", nil, nil, opts...)
- return
-}
-
-// PetFeederServerMethods is the interface a server writer
-// implements for PetFeeder.
-//
-// PetFeeder allows clients to remotely feed their pets.
-type PetFeederServerMethods interface {
- // Status returns the current status of the PetFeeder (how full the bowl is).
- Status(*context.T, rpc.ServerCall) (float64, error)
- // Fill fills the pet feeder bowl with food. Errors if the bowl will overflow.
- Fill(ctx *context.T, call rpc.ServerCall, amount float64) error
- // Empty removes all food from the pet feeder bowl.
- Empty(*context.T, rpc.ServerCall) error
-}
-
-// PetFeederServerStubMethods is the server interface containing
-// PetFeeder methods, as expected by rpc.Server.
-// There is no difference between this interface and PetFeederServerMethods
-// since there are no streaming methods.
-type PetFeederServerStubMethods PetFeederServerMethods
-
-// PetFeederServerStub adds universal methods to PetFeederServerStubMethods.
-type PetFeederServerStub interface {
- PetFeederServerStubMethods
- // Describe the PetFeeder interfaces.
- Describe__() []rpc.InterfaceDesc
-}
-
-// PetFeederServer returns a server stub for PetFeeder.
-// It converts an implementation of PetFeederServerMethods into
-// an object that may be used by rpc.Server.
-func PetFeederServer(impl PetFeederServerMethods) PetFeederServerStub {
- stub := implPetFeederServerStub{
- impl: impl,
- }
- // Initialize GlobState; always check the stub itself first, to handle the
- // case where the user has the Glob method defined in their VDL source.
- if gs := rpc.NewGlobState(stub); gs != nil {
- stub.gs = gs
- } else if gs := rpc.NewGlobState(impl); gs != nil {
- stub.gs = gs
- }
- return stub
-}
-
-type implPetFeederServerStub struct {
- impl PetFeederServerMethods
- gs *rpc.GlobState
-}
-
-func (s implPetFeederServerStub) Status(ctx *context.T, call rpc.ServerCall) (float64, error) {
- return s.impl.Status(ctx, call)
-}
-
-func (s implPetFeederServerStub) Fill(ctx *context.T, call rpc.ServerCall, i0 float64) error {
- return s.impl.Fill(ctx, call, i0)
-}
-
-func (s implPetFeederServerStub) Empty(ctx *context.T, call rpc.ServerCall) error {
- return s.impl.Empty(ctx, call)
-}
-
-func (s implPetFeederServerStub) Globber() *rpc.GlobState {
- return s.gs
-}
-
-func (s implPetFeederServerStub) Describe__() []rpc.InterfaceDesc {
- return []rpc.InterfaceDesc{PetFeederDesc}
-}
-
-// PetFeederDesc describes the PetFeeder interface.
-var PetFeederDesc rpc.InterfaceDesc = descPetFeeder
-
-// descPetFeeder hides the desc to keep godoc clean.
-var descPetFeeder = rpc.InterfaceDesc{
- Name: "PetFeeder",
- PkgPath: "v.io/x/browser/sample",
- Doc: "// PetFeeder allows clients to remotely feed their pets.",
- Methods: []rpc.MethodDesc{
- {
- Name: "Status",
- Doc: "// Status returns the current status of the PetFeeder (how full the bowl is).",
- OutArgs: []rpc.ArgDesc{
- {"", ``}, // float64
- },
- },
- {
- Name: "Fill",
- Doc: "// Fill fills the pet feeder bowl with food. Errors if the bowl will overflow.",
- InArgs: []rpc.ArgDesc{
- {"amount", ``}, // float64
- },
- },
- {
- Name: "Empty",
- Doc: "// Empty removes all food from the pet feeder bowl.",
- },
- },
-}
-
-// RoboDogClientMethods is the client interface
-// containing RoboDog methods.
-//
-// RoboDog allows clients to play with a virtual robotic dog.
-type RoboDogClientMethods interface {
- // Status returns the state of the robotic dog.
- Status(*context.T, ...rpc.CallOpt) (RoboDogStatus, error)
- // Speak allows a client to speak with the robotic dog.
- Speak(ctx *context.T, words string, opts ...rpc.CallOpt) (string, error)
- // Play allows a client to play with the robotic dog.
- // Errors if the dog does not want to play.
- Play(ctx *context.T, duration uint32, opts ...rpc.CallOpt) error
- // SetName allows a client to set the robotic dog's name.
- SetName(ctx *context.T, name string, opts ...rpc.CallOpt) error
-}
-
-// RoboDogClientStub adds universal methods to RoboDogClientMethods.
-type RoboDogClientStub interface {
- RoboDogClientMethods
- rpc.UniversalServiceMethods
-}
-
-// RoboDogClient returns a client stub for RoboDog.
-func RoboDogClient(name string) RoboDogClientStub {
- return implRoboDogClientStub{name}
-}
-
-type implRoboDogClientStub struct {
- name string
-}
-
-func (c implRoboDogClientStub) Status(ctx *context.T, opts ...rpc.CallOpt) (o0 RoboDogStatus, err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Status", nil, []interface{}{&o0}, opts...)
- return
-}
-
-func (c implRoboDogClientStub) Speak(ctx *context.T, i0 string, opts ...rpc.CallOpt) (o0 string, err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Speak", []interface{}{i0}, []interface{}{&o0}, opts...)
- return
-}
-
-func (c implRoboDogClientStub) Play(ctx *context.T, i0 uint32, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Play", []interface{}{i0}, nil, opts...)
- return
-}
-
-func (c implRoboDogClientStub) SetName(ctx *context.T, i0 string, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "SetName", []interface{}{i0}, nil, opts...)
- return
-}
-
-// RoboDogServerMethods is the interface a server writer
-// implements for RoboDog.
-//
-// RoboDog allows clients to play with a virtual robotic dog.
-type RoboDogServerMethods interface {
- // Status returns the state of the robotic dog.
- Status(*context.T, rpc.ServerCall) (RoboDogStatus, error)
- // Speak allows a client to speak with the robotic dog.
- Speak(ctx *context.T, call rpc.ServerCall, words string) (string, error)
- // Play allows a client to play with the robotic dog.
- // Errors if the dog does not want to play.
- Play(ctx *context.T, call rpc.ServerCall, duration uint32) error
- // SetName allows a client to set the robotic dog's name.
- SetName(ctx *context.T, call rpc.ServerCall, name string) error
-}
-
-// RoboDogServerStubMethods is the server interface containing
-// RoboDog methods, as expected by rpc.Server.
-// There is no difference between this interface and RoboDogServerMethods
-// since there are no streaming methods.
-type RoboDogServerStubMethods RoboDogServerMethods
-
-// RoboDogServerStub adds universal methods to RoboDogServerStubMethods.
-type RoboDogServerStub interface {
- RoboDogServerStubMethods
- // Describe the RoboDog interfaces.
- Describe__() []rpc.InterfaceDesc
-}
-
-// RoboDogServer returns a server stub for RoboDog.
-// It converts an implementation of RoboDogServerMethods into
-// an object that may be used by rpc.Server.
-func RoboDogServer(impl RoboDogServerMethods) RoboDogServerStub {
- stub := implRoboDogServerStub{
- impl: impl,
- }
- // Initialize GlobState; always check the stub itself first, to handle the
- // case where the user has the Glob method defined in their VDL source.
- if gs := rpc.NewGlobState(stub); gs != nil {
- stub.gs = gs
- } else if gs := rpc.NewGlobState(impl); gs != nil {
- stub.gs = gs
- }
- return stub
-}
-
-type implRoboDogServerStub struct {
- impl RoboDogServerMethods
- gs *rpc.GlobState
-}
-
-func (s implRoboDogServerStub) Status(ctx *context.T, call rpc.ServerCall) (RoboDogStatus, error) {
- return s.impl.Status(ctx, call)
-}
-
-func (s implRoboDogServerStub) Speak(ctx *context.T, call rpc.ServerCall, i0 string) (string, error) {
- return s.impl.Speak(ctx, call, i0)
-}
-
-func (s implRoboDogServerStub) Play(ctx *context.T, call rpc.ServerCall, i0 uint32) error {
- return s.impl.Play(ctx, call, i0)
-}
-
-func (s implRoboDogServerStub) SetName(ctx *context.T, call rpc.ServerCall, i0 string) error {
- return s.impl.SetName(ctx, call, i0)
-}
-
-func (s implRoboDogServerStub) Globber() *rpc.GlobState {
- return s.gs
-}
-
-func (s implRoboDogServerStub) Describe__() []rpc.InterfaceDesc {
- return []rpc.InterfaceDesc{RoboDogDesc}
-}
-
-// RoboDogDesc describes the RoboDog interface.
-var RoboDogDesc rpc.InterfaceDesc = descRoboDog
-
-// descRoboDog hides the desc to keep godoc clean.
-var descRoboDog = rpc.InterfaceDesc{
- Name: "RoboDog",
- PkgPath: "v.io/x/browser/sample",
- Doc: "// RoboDog allows clients to play with a virtual robotic dog.",
- Methods: []rpc.MethodDesc{
- {
- Name: "Status",
- Doc: "// Status returns the state of the robotic dog.",
- OutArgs: []rpc.ArgDesc{
- {"", ``}, // RoboDogStatus
- },
- },
- {
- Name: "Speak",
- Doc: "// Speak allows a client to speak with the robotic dog.",
- InArgs: []rpc.ArgDesc{
- {"words", ``}, // string
- },
- OutArgs: []rpc.ArgDesc{
- {"", ``}, // string
- },
- },
- {
- Name: "Play",
- Doc: "// Play allows a client to play with the robotic dog.\n// Errors if the dog does not want to play.",
- InArgs: []rpc.ArgDesc{
- {"duration", ``}, // uint32
- },
- },
- {
- Name: "SetName",
- Doc: "// SetName allows a client to set the robotic dog's name.",
- InArgs: []rpc.ArgDesc{
- {"name", ``}, // string
- },
- },
- },
-}
diff --git a/go/src/v.io/x/browser/sample/poolheater.vdl b/go/src/v.io/x/browser/sample/poolheater.vdl
deleted file mode 100644
index 41cd666..0000000
--- a/go/src/v.io/x/browser/sample/poolheater.vdl
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package sample
-
-// PoolHeater allows clients to control when the pool is being heated.
-type PoolHeater interface {
- // Status retrieves the PoolHeater's status (i.e., active, idle) and temperature.
- Status() (running string, temperature uint64 | error)
- // Start informs the PoolHeater to heat the pool to the given temperature until the duration expires.
- Start(temperature uint64, duration uint64) error
- // Stop informs the PoolHeater to cease heating the pool.
- Stop() error
-}
diff --git a/go/src/v.io/x/browser/sample/poolheater.vdl.go b/go/src/v.io/x/browser/sample/poolheater.vdl.go
deleted file mode 100644
index 75691e3..0000000
--- a/go/src/v.io/x/browser/sample/poolheater.vdl.go
+++ /dev/null
@@ -1,158 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file was auto-generated by the vanadium vdl tool.
-// Source: poolheater.vdl
-
-package sample
-
-import (
- // VDL system imports
- "v.io/v23"
- "v.io/v23/context"
- "v.io/v23/rpc"
-)
-
-// PoolHeaterClientMethods is the client interface
-// containing PoolHeater methods.
-//
-// PoolHeater allows clients to control when the pool is being heated.
-type PoolHeaterClientMethods interface {
- // Status retrieves the PoolHeater's status (i.e., active, idle) and temperature.
- Status(*context.T, ...rpc.CallOpt) (running string, temperature uint64, err error)
- // Start informs the PoolHeater to heat the pool to the given temperature until the duration expires.
- Start(ctx *context.T, temperature uint64, duration uint64, opts ...rpc.CallOpt) error
- // Stop informs the PoolHeater to cease heating the pool.
- Stop(*context.T, ...rpc.CallOpt) error
-}
-
-// PoolHeaterClientStub adds universal methods to PoolHeaterClientMethods.
-type PoolHeaterClientStub interface {
- PoolHeaterClientMethods
- rpc.UniversalServiceMethods
-}
-
-// PoolHeaterClient returns a client stub for PoolHeater.
-func PoolHeaterClient(name string) PoolHeaterClientStub {
- return implPoolHeaterClientStub{name}
-}
-
-type implPoolHeaterClientStub struct {
- name string
-}
-
-func (c implPoolHeaterClientStub) Status(ctx *context.T, opts ...rpc.CallOpt) (o0 string, o1 uint64, err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Status", nil, []interface{}{&o0, &o1}, opts...)
- return
-}
-
-func (c implPoolHeaterClientStub) Start(ctx *context.T, i0 uint64, i1 uint64, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Start", []interface{}{i0, i1}, nil, opts...)
- return
-}
-
-func (c implPoolHeaterClientStub) Stop(ctx *context.T, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Stop", nil, nil, opts...)
- return
-}
-
-// PoolHeaterServerMethods is the interface a server writer
-// implements for PoolHeater.
-//
-// PoolHeater allows clients to control when the pool is being heated.
-type PoolHeaterServerMethods interface {
- // Status retrieves the PoolHeater's status (i.e., active, idle) and temperature.
- Status(*context.T, rpc.ServerCall) (running string, temperature uint64, err error)
- // Start informs the PoolHeater to heat the pool to the given temperature until the duration expires.
- Start(ctx *context.T, call rpc.ServerCall, temperature uint64, duration uint64) error
- // Stop informs the PoolHeater to cease heating the pool.
- Stop(*context.T, rpc.ServerCall) error
-}
-
-// PoolHeaterServerStubMethods is the server interface containing
-// PoolHeater methods, as expected by rpc.Server.
-// There is no difference between this interface and PoolHeaterServerMethods
-// since there are no streaming methods.
-type PoolHeaterServerStubMethods PoolHeaterServerMethods
-
-// PoolHeaterServerStub adds universal methods to PoolHeaterServerStubMethods.
-type PoolHeaterServerStub interface {
- PoolHeaterServerStubMethods
- // Describe the PoolHeater interfaces.
- Describe__() []rpc.InterfaceDesc
-}
-
-// PoolHeaterServer returns a server stub for PoolHeater.
-// It converts an implementation of PoolHeaterServerMethods into
-// an object that may be used by rpc.Server.
-func PoolHeaterServer(impl PoolHeaterServerMethods) PoolHeaterServerStub {
- stub := implPoolHeaterServerStub{
- impl: impl,
- }
- // Initialize GlobState; always check the stub itself first, to handle the
- // case where the user has the Glob method defined in their VDL source.
- if gs := rpc.NewGlobState(stub); gs != nil {
- stub.gs = gs
- } else if gs := rpc.NewGlobState(impl); gs != nil {
- stub.gs = gs
- }
- return stub
-}
-
-type implPoolHeaterServerStub struct {
- impl PoolHeaterServerMethods
- gs *rpc.GlobState
-}
-
-func (s implPoolHeaterServerStub) Status(ctx *context.T, call rpc.ServerCall) (string, uint64, error) {
- return s.impl.Status(ctx, call)
-}
-
-func (s implPoolHeaterServerStub) Start(ctx *context.T, call rpc.ServerCall, i0 uint64, i1 uint64) error {
- return s.impl.Start(ctx, call, i0, i1)
-}
-
-func (s implPoolHeaterServerStub) Stop(ctx *context.T, call rpc.ServerCall) error {
- return s.impl.Stop(ctx, call)
-}
-
-func (s implPoolHeaterServerStub) Globber() *rpc.GlobState {
- return s.gs
-}
-
-func (s implPoolHeaterServerStub) Describe__() []rpc.InterfaceDesc {
- return []rpc.InterfaceDesc{PoolHeaterDesc}
-}
-
-// PoolHeaterDesc describes the PoolHeater interface.
-var PoolHeaterDesc rpc.InterfaceDesc = descPoolHeater
-
-// descPoolHeater hides the desc to keep godoc clean.
-var descPoolHeater = rpc.InterfaceDesc{
- Name: "PoolHeater",
- PkgPath: "v.io/x/browser/sample",
- Doc: "// PoolHeater allows clients to control when the pool is being heated.",
- Methods: []rpc.MethodDesc{
- {
- Name: "Status",
- Doc: "// Status retrieves the PoolHeater's status (i.e., active, idle) and temperature.",
- OutArgs: []rpc.ArgDesc{
- {"running", ``}, // string
- {"temperature", ``}, // uint64
- },
- },
- {
- Name: "Start",
- Doc: "// Start informs the PoolHeater to heat the pool to the given temperature until the duration expires.",
- InArgs: []rpc.ArgDesc{
- {"temperature", ``}, // uint64
- {"duration", ``}, // uint64
- },
- },
- {
- Name: "Stop",
- Doc: "// Stop informs the PoolHeater to cease heating the pool.",
- },
- },
-}
diff --git a/go/src/v.io/x/browser/sample/sampled/main.go b/go/src/v.io/x/browser/sample/sampled/main.go
deleted file mode 100644
index 80bf854..0000000
--- a/go/src/v.io/x/browser/sample/sampled/main.go
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main
-
-import (
- "v.io/v23"
- "v.io/x/browser/sample/sampleworld"
- "v.io/x/ref/lib/signals"
- _ "v.io/x/ref/profiles/static"
-)
-
-func main() {
- ctx, shutdown := v23.Init()
- defer shutdown()
-
- sampleworld.RunSampleWorld(ctx, func() {
- <-signals.ShutdownOnSignals(ctx)
- })
-}
diff --git a/go/src/v.io/x/browser/sample/sampleworld/sampleworld.go b/go/src/v.io/x/browser/sample/sampleworld/sampleworld.go
deleted file mode 100644
index b922048..0000000
--- a/go/src/v.io/x/browser/sample/sampleworld/sampleworld.go
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package sampleworld
-
-import (
- "flag"
- "fmt"
- "log"
-
- "v.io/v23"
- "v.io/v23/context"
- "v.io/v23/naming"
- "v.io/v23/security"
- "v.io/v23/security/access"
- "v.io/x/browser/sample"
- "v.io/x/browser/sample/mocks"
-)
-
-func makeServerAlarm() interface{} {
- return sample.AlarmServer(mocks.NewAlarm())
-}
-func makeServerLightSwitch() interface{} {
- return sample.LightSwitchServer(mocks.NewLightSwitch())
-}
-func makeServerPoolHeater() interface{} {
- return sample.PoolHeaterServer(mocks.NewPoolHeater())
-}
-func makeServerSmokeDetector() interface{} {
- return sample.SmokeDetectorServer(mocks.NewSmokeDetector())
-}
-func makeServerSpeaker() interface{} {
- return sample.SpeakerServer(mocks.NewSpeaker())
-}
-func makeServerSprinkler() interface{} {
- return sample.SprinklerServer(mocks.NewSprinkler())
-}
-func makePetFeederAndRoboDog() (interface{}, interface{}) {
- p := mocks.NewPetFeeder()
- r := mocks.NewRoboDog(p)
- return sample.PetFeederServer(p), sample.RoboDogServer(r)
-}
-
-var (
- authorizedBlessingPattern = flag.String("authorize", string(security.AllPrincipals), "Blessing pattern that matches authorized users. By default all principals are authorized.")
- namePrefix = flag.String("name", "", "Name prefix used to publish the sample world under.")
-)
-
-func RunSampleWorld(ctx *context.T, wait func()) {
-
- // Create new server and publish the given server under the given name
- var listenAndServe = func(name string, server interface{}) func() {
-
- // Create a new server instance.
- s, err := v23.NewServer(ctx)
- if err != nil {
- log.Fatal("failure creating server: ", err)
- }
-
- // Create an endpoint and begin listening.
- if endpoint, err := s.Listen(v23.GetListenSpec(ctx)); err == nil {
- fmt.Printf("Listening at: %v\n", endpoint)
- } else {
- log.Fatal("error listening to service: ", err)
- }
-
- acl := access.AccessList{
- In: []security.BlessingPattern{
- security.BlessingPattern(*authorizedBlessingPattern),
- },
- }
-
- fullName := naming.Join(*namePrefix, name)
-
- // Serve these services at the given name.
- if err := s.Serve(fullName, server, acl); err != nil {
- log.Fatal("error serving service: ", err)
- }
-
- return func() {
- s.Stop()
- }
- }
-
- // Serve bunch of mock services under different names
- defer listenAndServe("house/alarm", makeServerAlarm())()
- defer listenAndServe("house/living-room/lights", makeServerLightSwitch())()
- defer listenAndServe("house/living-room/smoke-detector", makeServerSmokeDetector())()
- defer listenAndServe("house/living-room/blast-speaker", makeServerSpeaker())()
- defer listenAndServe("house/living-room/soundbar", makeServerSpeaker())()
- defer listenAndServe("house/master-bedroom/desk-lamp", makeServerLightSwitch())()
- defer listenAndServe("house/master-bedroom/lights", makeServerLightSwitch())()
- defer listenAndServe("house/master-bedroom/smoke-detector", makeServerSmokeDetector())()
- defer listenAndServe("house/master-bedroom/speaker", makeServerSpeaker())()
- defer listenAndServe("house/kitchen/lights", makeServerLightSwitch())()
- defer listenAndServe("house/kitchen/smoke-detector", makeServerSmokeDetector())()
-
- petfeeder, robodog := makePetFeederAndRoboDog()
- defer listenAndServe("house/pet-feeder", petfeeder)()
- defer listenAndServe("house/robo-dog", robodog)()
-
- defer listenAndServe("cottage/smoke-detector", makeServerSmokeDetector())()
- defer listenAndServe("cottage/alarm", makeServerAlarm())()
- defer listenAndServe("cottage/lights", makeServerLightSwitch())()
- defer listenAndServe("cottage/pool/heater", makeServerPoolHeater())()
- defer listenAndServe("cottage/pool/speaker", makeServerSpeaker())()
- defer listenAndServe("cottage/pool/pool-lights", makeServerLightSwitch())()
- defer listenAndServe("cottage/lawn/front/sprinkler", makeServerSprinkler())()
- defer listenAndServe("cottage/lawn/back/sprinkler", makeServerSprinkler())()
- defer listenAndServe("cottage/lawn/master-sprinkler", makeServerSprinkler())()
-
- var onlyMe = []security.BlessingPattern{"dev.v.io/root/users/me@example.com"}
- var everybody = []security.BlessingPattern{"..."}
- var nobodyCanList = access.Permissions{
- "Resolve": access.AccessList{
- In: onlyMe,
- },
- "Read": access.AccessList{
- In: everybody,
- },
- "Admin": access.AccessList{
- In: onlyMe,
- },
- "Create": access.AccessList{
- In: onlyMe,
- },
- "Mount": access.AccessList{
- In: onlyMe,
- },
- }
- ns := v23.GetNamespace(ctx)
- ns.SetPermissions(ctx, "house/kitchen/secret-pantry", nobodyCanList, "")
-
- wait()
-}
diff --git a/go/src/v.io/x/browser/sample/smokedetector.vdl b/go/src/v.io/x/browser/sample/smokedetector.vdl
deleted file mode 100644
index 6b317aa..0000000
--- a/go/src/v.io/x/browser/sample/smokedetector.vdl
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package sample
-
-// SmokeDetector allows clients to monitor and adjust a smoke detector.
-type SmokeDetector interface {
- // Status retrieves the current status and sensitivity of the SmokeDetector.
- Status() (status string, sensitivity int16 | error)
- // Test the SmokeDetector to check if it is working.
- Test() (bool | error)
- // Sensitivity adjusts the SmokeDetector's sensitivity to smoke.
- Sensitivity(sens int16) error
-}
diff --git a/go/src/v.io/x/browser/sample/smokedetector.vdl.go b/go/src/v.io/x/browser/sample/smokedetector.vdl.go
deleted file mode 100644
index 040c604..0000000
--- a/go/src/v.io/x/browser/sample/smokedetector.vdl.go
+++ /dev/null
@@ -1,160 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file was auto-generated by the vanadium vdl tool.
-// Source: smokedetector.vdl
-
-package sample
-
-import (
- // VDL system imports
- "v.io/v23"
- "v.io/v23/context"
- "v.io/v23/rpc"
-)
-
-// SmokeDetectorClientMethods is the client interface
-// containing SmokeDetector methods.
-//
-// SmokeDetector allows clients to monitor and adjust a smoke detector.
-type SmokeDetectorClientMethods interface {
- // Status retrieves the current status and sensitivity of the SmokeDetector.
- Status(*context.T, ...rpc.CallOpt) (status string, sensitivity int16, err error)
- // Test the SmokeDetector to check if it is working.
- Test(*context.T, ...rpc.CallOpt) (bool, error)
- // Sensitivity adjusts the SmokeDetector's sensitivity to smoke.
- Sensitivity(ctx *context.T, sens int16, opts ...rpc.CallOpt) error
-}
-
-// SmokeDetectorClientStub adds universal methods to SmokeDetectorClientMethods.
-type SmokeDetectorClientStub interface {
- SmokeDetectorClientMethods
- rpc.UniversalServiceMethods
-}
-
-// SmokeDetectorClient returns a client stub for SmokeDetector.
-func SmokeDetectorClient(name string) SmokeDetectorClientStub {
- return implSmokeDetectorClientStub{name}
-}
-
-type implSmokeDetectorClientStub struct {
- name string
-}
-
-func (c implSmokeDetectorClientStub) Status(ctx *context.T, opts ...rpc.CallOpt) (o0 string, o1 int16, err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Status", nil, []interface{}{&o0, &o1}, opts...)
- return
-}
-
-func (c implSmokeDetectorClientStub) Test(ctx *context.T, opts ...rpc.CallOpt) (o0 bool, err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Test", nil, []interface{}{&o0}, opts...)
- return
-}
-
-func (c implSmokeDetectorClientStub) Sensitivity(ctx *context.T, i0 int16, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Sensitivity", []interface{}{i0}, nil, opts...)
- return
-}
-
-// SmokeDetectorServerMethods is the interface a server writer
-// implements for SmokeDetector.
-//
-// SmokeDetector allows clients to monitor and adjust a smoke detector.
-type SmokeDetectorServerMethods interface {
- // Status retrieves the current status and sensitivity of the SmokeDetector.
- Status(*context.T, rpc.ServerCall) (status string, sensitivity int16, err error)
- // Test the SmokeDetector to check if it is working.
- Test(*context.T, rpc.ServerCall) (bool, error)
- // Sensitivity adjusts the SmokeDetector's sensitivity to smoke.
- Sensitivity(ctx *context.T, call rpc.ServerCall, sens int16) error
-}
-
-// SmokeDetectorServerStubMethods is the server interface containing
-// SmokeDetector methods, as expected by rpc.Server.
-// There is no difference between this interface and SmokeDetectorServerMethods
-// since there are no streaming methods.
-type SmokeDetectorServerStubMethods SmokeDetectorServerMethods
-
-// SmokeDetectorServerStub adds universal methods to SmokeDetectorServerStubMethods.
-type SmokeDetectorServerStub interface {
- SmokeDetectorServerStubMethods
- // Describe the SmokeDetector interfaces.
- Describe__() []rpc.InterfaceDesc
-}
-
-// SmokeDetectorServer returns a server stub for SmokeDetector.
-// It converts an implementation of SmokeDetectorServerMethods into
-// an object that may be used by rpc.Server.
-func SmokeDetectorServer(impl SmokeDetectorServerMethods) SmokeDetectorServerStub {
- stub := implSmokeDetectorServerStub{
- impl: impl,
- }
- // Initialize GlobState; always check the stub itself first, to handle the
- // case where the user has the Glob method defined in their VDL source.
- if gs := rpc.NewGlobState(stub); gs != nil {
- stub.gs = gs
- } else if gs := rpc.NewGlobState(impl); gs != nil {
- stub.gs = gs
- }
- return stub
-}
-
-type implSmokeDetectorServerStub struct {
- impl SmokeDetectorServerMethods
- gs *rpc.GlobState
-}
-
-func (s implSmokeDetectorServerStub) Status(ctx *context.T, call rpc.ServerCall) (string, int16, error) {
- return s.impl.Status(ctx, call)
-}
-
-func (s implSmokeDetectorServerStub) Test(ctx *context.T, call rpc.ServerCall) (bool, error) {
- return s.impl.Test(ctx, call)
-}
-
-func (s implSmokeDetectorServerStub) Sensitivity(ctx *context.T, call rpc.ServerCall, i0 int16) error {
- return s.impl.Sensitivity(ctx, call, i0)
-}
-
-func (s implSmokeDetectorServerStub) Globber() *rpc.GlobState {
- return s.gs
-}
-
-func (s implSmokeDetectorServerStub) Describe__() []rpc.InterfaceDesc {
- return []rpc.InterfaceDesc{SmokeDetectorDesc}
-}
-
-// SmokeDetectorDesc describes the SmokeDetector interface.
-var SmokeDetectorDesc rpc.InterfaceDesc = descSmokeDetector
-
-// descSmokeDetector hides the desc to keep godoc clean.
-var descSmokeDetector = rpc.InterfaceDesc{
- Name: "SmokeDetector",
- PkgPath: "v.io/x/browser/sample",
- Doc: "// SmokeDetector allows clients to monitor and adjust a smoke detector.",
- Methods: []rpc.MethodDesc{
- {
- Name: "Status",
- Doc: "// Status retrieves the current status and sensitivity of the SmokeDetector. ",
- OutArgs: []rpc.ArgDesc{
- {"status", ``}, // string
- {"sensitivity", ``}, // int16
- },
- },
- {
- Name: "Test",
- Doc: "// Test the SmokeDetector to check if it is working.",
- OutArgs: []rpc.ArgDesc{
- {"", ``}, // bool
- },
- },
- {
- Name: "Sensitivity",
- Doc: "// Sensitivity adjusts the SmokeDetector's sensitivity to smoke.",
- InArgs: []rpc.ArgDesc{
- {"sens", ``}, // int16
- },
- },
- },
-}
diff --git a/go/src/v.io/x/browser/sample/speaker.vdl b/go/src/v.io/x/browser/sample/speaker.vdl
deleted file mode 100644
index fe1f87a..0000000
--- a/go/src/v.io/x/browser/sample/speaker.vdl
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package sample
-
-// Speaker allows clients to control the music being played.
-type Speaker interface {
- // Play starts or continues the current song.
- Play() error
- // PlaySong plays back the given song title, if possible.
- PlaySong(songName string) error
- // PlayStream plays the given stream of music data.
- PlayStream() stream<[]byte, _> error
- // GetSong retrieves the title of the Speaker's current song, if any.
- GetSong() (string | error)
- // Pause playback of the Speaker's current song.
- Pause() error
- // Stop playback of the Speaker's current song.
- Stop() error
- // Volume adjusts the Speaker's volume.
- Volume(volumeLevel uint16) error
- // GetVolume retrieves the Speaker's volume.
- GetVolume() (uint16 | error)
- // AddSongs adds the list of given songs to the song library.
- AddSongs(songs []string) error
- // Delete removes the list of given songs from the song library.
- Delete(songs []string) error
-}
diff --git a/go/src/v.io/x/browser/sample/speaker.vdl.go b/go/src/v.io/x/browser/sample/speaker.vdl.go
deleted file mode 100644
index 28ec39c..0000000
--- a/go/src/v.io/x/browser/sample/speaker.vdl.go
+++ /dev/null
@@ -1,438 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file was auto-generated by the vanadium vdl tool.
-// Source: speaker.vdl
-
-package sample
-
-import (
- // VDL system imports
- "io"
- "v.io/v23"
- "v.io/v23/context"
- "v.io/v23/rpc"
-)
-
-// SpeakerClientMethods is the client interface
-// containing Speaker methods.
-//
-// Speaker allows clients to control the music being played.
-type SpeakerClientMethods interface {
- // Play starts or continues the current song.
- Play(*context.T, ...rpc.CallOpt) error
- // PlaySong plays back the given song title, if possible.
- PlaySong(ctx *context.T, songName string, opts ...rpc.CallOpt) error
- // PlayStream plays the given stream of music data.
- PlayStream(*context.T, ...rpc.CallOpt) (SpeakerPlayStreamClientCall, error)
- // GetSong retrieves the title of the Speaker's current song, if any.
- GetSong(*context.T, ...rpc.CallOpt) (string, error)
- // Pause playback of the Speaker's current song.
- Pause(*context.T, ...rpc.CallOpt) error
- // Stop playback of the Speaker's current song.
- Stop(*context.T, ...rpc.CallOpt) error
- // Volume adjusts the Speaker's volume.
- Volume(ctx *context.T, volumeLevel uint16, opts ...rpc.CallOpt) error
- // GetVolume retrieves the Speaker's volume.
- GetVolume(*context.T, ...rpc.CallOpt) (uint16, error)
- // AddSongs adds the list of given songs to the song library.
- AddSongs(ctx *context.T, songs []string, opts ...rpc.CallOpt) error
- // Delete removes the list of given songs from the song library.
- Delete(ctx *context.T, songs []string, opts ...rpc.CallOpt) error
-}
-
-// SpeakerClientStub adds universal methods to SpeakerClientMethods.
-type SpeakerClientStub interface {
- SpeakerClientMethods
- rpc.UniversalServiceMethods
-}
-
-// SpeakerClient returns a client stub for Speaker.
-func SpeakerClient(name string) SpeakerClientStub {
- return implSpeakerClientStub{name}
-}
-
-type implSpeakerClientStub struct {
- name string
-}
-
-func (c implSpeakerClientStub) Play(ctx *context.T, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Play", nil, nil, opts...)
- return
-}
-
-func (c implSpeakerClientStub) PlaySong(ctx *context.T, i0 string, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "PlaySong", []interface{}{i0}, nil, opts...)
- return
-}
-
-func (c implSpeakerClientStub) PlayStream(ctx *context.T, opts ...rpc.CallOpt) (ocall SpeakerPlayStreamClientCall, err error) {
- var call rpc.ClientCall
- if call, err = v23.GetClient(ctx).StartCall(ctx, c.name, "PlayStream", nil, opts...); err != nil {
- return
- }
- ocall = &implSpeakerPlayStreamClientCall{ClientCall: call}
- return
-}
-
-func (c implSpeakerClientStub) GetSong(ctx *context.T, opts ...rpc.CallOpt) (o0 string, err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "GetSong", nil, []interface{}{&o0}, opts...)
- return
-}
-
-func (c implSpeakerClientStub) Pause(ctx *context.T, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Pause", nil, nil, opts...)
- return
-}
-
-func (c implSpeakerClientStub) Stop(ctx *context.T, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Stop", nil, nil, opts...)
- return
-}
-
-func (c implSpeakerClientStub) Volume(ctx *context.T, i0 uint16, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Volume", []interface{}{i0}, nil, opts...)
- return
-}
-
-func (c implSpeakerClientStub) GetVolume(ctx *context.T, opts ...rpc.CallOpt) (o0 uint16, err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "GetVolume", nil, []interface{}{&o0}, opts...)
- return
-}
-
-func (c implSpeakerClientStub) AddSongs(ctx *context.T, i0 []string, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "AddSongs", []interface{}{i0}, nil, opts...)
- return
-}
-
-func (c implSpeakerClientStub) Delete(ctx *context.T, i0 []string, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Delete", []interface{}{i0}, nil, opts...)
- return
-}
-
-// SpeakerPlayStreamClientStream is the client stream for Speaker.PlayStream.
-type SpeakerPlayStreamClientStream interface {
- // SendStream returns the send side of the Speaker.PlayStream client stream.
- SendStream() interface {
- // Send places the item onto the output stream. Returns errors
- // encountered while sending, or if Send is called after Close or
- // the stream has been canceled. Blocks if there is no buffer
- // space; will unblock when buffer space is available or after
- // the stream has been canceled.
- Send(item []byte) error
- // Close indicates to the server that no more items will be sent;
- // server Recv calls will receive io.EOF after all sent items.
- // This is an optional call - e.g. a client might call Close if it
- // needs to continue receiving items from the server after it's
- // done sending. Returns errors encountered while closing, or if
- // Close is called after the stream has been canceled. Like Send,
- // blocks if there is no buffer space available.
- Close() error
- }
-}
-
-// SpeakerPlayStreamClientCall represents the call returned from Speaker.PlayStream.
-type SpeakerPlayStreamClientCall interface {
- SpeakerPlayStreamClientStream
- // Finish performs the equivalent of SendStream().Close, then blocks until
- // the server is done, and returns the positional return values for the call.
- //
- // Finish returns immediately if the call has been canceled; depending on the
- // timing the output could either be an error signaling cancelation, or the
- // valid positional return values from the server.
- //
- // Calling Finish is mandatory for releasing stream resources, unless the call
- // has been canceled or any of the other methods return an error. Finish should
- // be called at most once.
- Finish() error
-}
-
-type implSpeakerPlayStreamClientCall struct {
- rpc.ClientCall
-}
-
-func (c *implSpeakerPlayStreamClientCall) SendStream() interface {
- Send(item []byte) error
- Close() error
-} {
- return implSpeakerPlayStreamClientCallSend{c}
-}
-
-type implSpeakerPlayStreamClientCallSend struct {
- c *implSpeakerPlayStreamClientCall
-}
-
-func (c implSpeakerPlayStreamClientCallSend) Send(item []byte) error {
- return c.c.Send(item)
-}
-func (c implSpeakerPlayStreamClientCallSend) Close() error {
- return c.c.CloseSend()
-}
-func (c *implSpeakerPlayStreamClientCall) Finish() (err error) {
- err = c.ClientCall.Finish()
- return
-}
-
-// SpeakerServerMethods is the interface a server writer
-// implements for Speaker.
-//
-// Speaker allows clients to control the music being played.
-type SpeakerServerMethods interface {
- // Play starts or continues the current song.
- Play(*context.T, rpc.ServerCall) error
- // PlaySong plays back the given song title, if possible.
- PlaySong(ctx *context.T, call rpc.ServerCall, songName string) error
- // PlayStream plays the given stream of music data.
- PlayStream(*context.T, SpeakerPlayStreamServerCall) error
- // GetSong retrieves the title of the Speaker's current song, if any.
- GetSong(*context.T, rpc.ServerCall) (string, error)
- // Pause playback of the Speaker's current song.
- Pause(*context.T, rpc.ServerCall) error
- // Stop playback of the Speaker's current song.
- Stop(*context.T, rpc.ServerCall) error
- // Volume adjusts the Speaker's volume.
- Volume(ctx *context.T, call rpc.ServerCall, volumeLevel uint16) error
- // GetVolume retrieves the Speaker's volume.
- GetVolume(*context.T, rpc.ServerCall) (uint16, error)
- // AddSongs adds the list of given songs to the song library.
- AddSongs(ctx *context.T, call rpc.ServerCall, songs []string) error
- // Delete removes the list of given songs from the song library.
- Delete(ctx *context.T, call rpc.ServerCall, songs []string) error
-}
-
-// SpeakerServerStubMethods is the server interface containing
-// Speaker methods, as expected by rpc.Server.
-// The only difference between this interface and SpeakerServerMethods
-// is the streaming methods.
-type SpeakerServerStubMethods interface {
- // Play starts or continues the current song.
- Play(*context.T, rpc.ServerCall) error
- // PlaySong plays back the given song title, if possible.
- PlaySong(ctx *context.T, call rpc.ServerCall, songName string) error
- // PlayStream plays the given stream of music data.
- PlayStream(*context.T, *SpeakerPlayStreamServerCallStub) error
- // GetSong retrieves the title of the Speaker's current song, if any.
- GetSong(*context.T, rpc.ServerCall) (string, error)
- // Pause playback of the Speaker's current song.
- Pause(*context.T, rpc.ServerCall) error
- // Stop playback of the Speaker's current song.
- Stop(*context.T, rpc.ServerCall) error
- // Volume adjusts the Speaker's volume.
- Volume(ctx *context.T, call rpc.ServerCall, volumeLevel uint16) error
- // GetVolume retrieves the Speaker's volume.
- GetVolume(*context.T, rpc.ServerCall) (uint16, error)
- // AddSongs adds the list of given songs to the song library.
- AddSongs(ctx *context.T, call rpc.ServerCall, songs []string) error
- // Delete removes the list of given songs from the song library.
- Delete(ctx *context.T, call rpc.ServerCall, songs []string) error
-}
-
-// SpeakerServerStub adds universal methods to SpeakerServerStubMethods.
-type SpeakerServerStub interface {
- SpeakerServerStubMethods
- // Describe the Speaker interfaces.
- Describe__() []rpc.InterfaceDesc
-}
-
-// SpeakerServer returns a server stub for Speaker.
-// It converts an implementation of SpeakerServerMethods into
-// an object that may be used by rpc.Server.
-func SpeakerServer(impl SpeakerServerMethods) SpeakerServerStub {
- stub := implSpeakerServerStub{
- impl: impl,
- }
- // Initialize GlobState; always check the stub itself first, to handle the
- // case where the user has the Glob method defined in their VDL source.
- if gs := rpc.NewGlobState(stub); gs != nil {
- stub.gs = gs
- } else if gs := rpc.NewGlobState(impl); gs != nil {
- stub.gs = gs
- }
- return stub
-}
-
-type implSpeakerServerStub struct {
- impl SpeakerServerMethods
- gs *rpc.GlobState
-}
-
-func (s implSpeakerServerStub) Play(ctx *context.T, call rpc.ServerCall) error {
- return s.impl.Play(ctx, call)
-}
-
-func (s implSpeakerServerStub) PlaySong(ctx *context.T, call rpc.ServerCall, i0 string) error {
- return s.impl.PlaySong(ctx, call, i0)
-}
-
-func (s implSpeakerServerStub) PlayStream(ctx *context.T, call *SpeakerPlayStreamServerCallStub) error {
- return s.impl.PlayStream(ctx, call)
-}
-
-func (s implSpeakerServerStub) GetSong(ctx *context.T, call rpc.ServerCall) (string, error) {
- return s.impl.GetSong(ctx, call)
-}
-
-func (s implSpeakerServerStub) Pause(ctx *context.T, call rpc.ServerCall) error {
- return s.impl.Pause(ctx, call)
-}
-
-func (s implSpeakerServerStub) Stop(ctx *context.T, call rpc.ServerCall) error {
- return s.impl.Stop(ctx, call)
-}
-
-func (s implSpeakerServerStub) Volume(ctx *context.T, call rpc.ServerCall, i0 uint16) error {
- return s.impl.Volume(ctx, call, i0)
-}
-
-func (s implSpeakerServerStub) GetVolume(ctx *context.T, call rpc.ServerCall) (uint16, error) {
- return s.impl.GetVolume(ctx, call)
-}
-
-func (s implSpeakerServerStub) AddSongs(ctx *context.T, call rpc.ServerCall, i0 []string) error {
- return s.impl.AddSongs(ctx, call, i0)
-}
-
-func (s implSpeakerServerStub) Delete(ctx *context.T, call rpc.ServerCall, i0 []string) error {
- return s.impl.Delete(ctx, call, i0)
-}
-
-func (s implSpeakerServerStub) Globber() *rpc.GlobState {
- return s.gs
-}
-
-func (s implSpeakerServerStub) Describe__() []rpc.InterfaceDesc {
- return []rpc.InterfaceDesc{SpeakerDesc}
-}
-
-// SpeakerDesc describes the Speaker interface.
-var SpeakerDesc rpc.InterfaceDesc = descSpeaker
-
-// descSpeaker hides the desc to keep godoc clean.
-var descSpeaker = rpc.InterfaceDesc{
- Name: "Speaker",
- PkgPath: "v.io/x/browser/sample",
- Doc: "// Speaker allows clients to control the music being played.",
- Methods: []rpc.MethodDesc{
- {
- Name: "Play",
- Doc: "// Play starts or continues the current song.",
- },
- {
- Name: "PlaySong",
- Doc: "// PlaySong plays back the given song title, if possible.",
- InArgs: []rpc.ArgDesc{
- {"songName", ``}, // string
- },
- },
- {
- Name: "PlayStream",
- Doc: "// PlayStream plays the given stream of music data.",
- },
- {
- Name: "GetSong",
- Doc: "// GetSong retrieves the title of the Speaker's current song, if any.",
- OutArgs: []rpc.ArgDesc{
- {"", ``}, // string
- },
- },
- {
- Name: "Pause",
- Doc: "// Pause playback of the Speaker's current song.",
- },
- {
- Name: "Stop",
- Doc: "// Stop playback of the Speaker's current song.",
- },
- {
- Name: "Volume",
- Doc: "// Volume adjusts the Speaker's volume.",
- InArgs: []rpc.ArgDesc{
- {"volumeLevel", ``}, // uint16
- },
- },
- {
- Name: "GetVolume",
- Doc: "// GetVolume retrieves the Speaker's volume.",
- OutArgs: []rpc.ArgDesc{
- {"", ``}, // uint16
- },
- },
- {
- Name: "AddSongs",
- Doc: "// AddSongs adds the list of given songs to the song library.",
- InArgs: []rpc.ArgDesc{
- {"songs", ``}, // []string
- },
- },
- {
- Name: "Delete",
- Doc: "// Delete removes the list of given songs from the song library.",
- InArgs: []rpc.ArgDesc{
- {"songs", ``}, // []string
- },
- },
- },
-}
-
-// SpeakerPlayStreamServerStream is the server stream for Speaker.PlayStream.
-type SpeakerPlayStreamServerStream interface {
- // RecvStream returns the receiver side of the Speaker.PlayStream server stream.
- RecvStream() interface {
- // Advance stages an item so that it may be retrieved via Value. Returns
- // true iff there is an item to retrieve. Advance must be called before
- // Value is called. May block if an item is not available.
- Advance() bool
- // Value returns the item that was staged by Advance. May panic if Advance
- // returned false or was not called. Never blocks.
- Value() []byte
- // Err returns any error encountered by Advance. Never blocks.
- Err() error
- }
-}
-
-// SpeakerPlayStreamServerCall represents the context passed to Speaker.PlayStream.
-type SpeakerPlayStreamServerCall interface {
- rpc.ServerCall
- SpeakerPlayStreamServerStream
-}
-
-// SpeakerPlayStreamServerCallStub is a wrapper that converts rpc.StreamServerCall into
-// a typesafe stub that implements SpeakerPlayStreamServerCall.
-type SpeakerPlayStreamServerCallStub struct {
- rpc.StreamServerCall
- valRecv []byte
- errRecv error
-}
-
-// Init initializes SpeakerPlayStreamServerCallStub from rpc.StreamServerCall.
-func (s *SpeakerPlayStreamServerCallStub) Init(call rpc.StreamServerCall) {
- s.StreamServerCall = call
-}
-
-// RecvStream returns the receiver side of the Speaker.PlayStream server stream.
-func (s *SpeakerPlayStreamServerCallStub) RecvStream() interface {
- Advance() bool
- Value() []byte
- Err() error
-} {
- return implSpeakerPlayStreamServerCallRecv{s}
-}
-
-type implSpeakerPlayStreamServerCallRecv struct {
- s *SpeakerPlayStreamServerCallStub
-}
-
-func (s implSpeakerPlayStreamServerCallRecv) Advance() bool {
- s.s.errRecv = s.s.Recv(&s.s.valRecv)
- return s.s.errRecv == nil
-}
-func (s implSpeakerPlayStreamServerCallRecv) Value() []byte {
- return s.s.valRecv
-}
-func (s implSpeakerPlayStreamServerCallRecv) Err() error {
- if s.s.errRecv == io.EOF {
- return nil
- }
- return s.s.errRecv
-}
diff --git a/go/src/v.io/x/browser/sample/sprinkler.vdl b/go/src/v.io/x/browser/sample/sprinkler.vdl
deleted file mode 100644
index 3adc96f..0000000
--- a/go/src/v.io/x/browser/sample/sprinkler.vdl
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package sample
-
-// Sprinkler allows clients to control the virtual sprinkler.
-type Sprinkler interface {
- // Status retrieves the Sprinkler's status (i.e., active, idle)
- Status() (string | error)
- // Start causes the Sprinkler to emit water for the given duration (in seconds).
- Start(duration uint16) error
- // Stop causes the Sprinkler to cease watering.
- Stop() error
-}
diff --git a/go/src/v.io/x/browser/sample/sprinkler.vdl.go b/go/src/v.io/x/browser/sample/sprinkler.vdl.go
deleted file mode 100644
index 25a2ef9..0000000
--- a/go/src/v.io/x/browser/sample/sprinkler.vdl.go
+++ /dev/null
@@ -1,156 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// This file was auto-generated by the vanadium vdl tool.
-// Source: sprinkler.vdl
-
-package sample
-
-import (
- // VDL system imports
- "v.io/v23"
- "v.io/v23/context"
- "v.io/v23/rpc"
-)
-
-// SprinklerClientMethods is the client interface
-// containing Sprinkler methods.
-//
-// Sprinkler allows clients to control the virtual sprinkler.
-type SprinklerClientMethods interface {
- // Status retrieves the Sprinkler's status (i.e., active, idle)
- Status(*context.T, ...rpc.CallOpt) (string, error)
- // Start causes the Sprinkler to emit water for the given duration (in seconds).
- Start(ctx *context.T, duration uint16, opts ...rpc.CallOpt) error
- // Stop causes the Sprinkler to cease watering.
- Stop(*context.T, ...rpc.CallOpt) error
-}
-
-// SprinklerClientStub adds universal methods to SprinklerClientMethods.
-type SprinklerClientStub interface {
- SprinklerClientMethods
- rpc.UniversalServiceMethods
-}
-
-// SprinklerClient returns a client stub for Sprinkler.
-func SprinklerClient(name string) SprinklerClientStub {
- return implSprinklerClientStub{name}
-}
-
-type implSprinklerClientStub struct {
- name string
-}
-
-func (c implSprinklerClientStub) Status(ctx *context.T, opts ...rpc.CallOpt) (o0 string, err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Status", nil, []interface{}{&o0}, opts...)
- return
-}
-
-func (c implSprinklerClientStub) Start(ctx *context.T, i0 uint16, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Start", []interface{}{i0}, nil, opts...)
- return
-}
-
-func (c implSprinklerClientStub) Stop(ctx *context.T, opts ...rpc.CallOpt) (err error) {
- err = v23.GetClient(ctx).Call(ctx, c.name, "Stop", nil, nil, opts...)
- return
-}
-
-// SprinklerServerMethods is the interface a server writer
-// implements for Sprinkler.
-//
-// Sprinkler allows clients to control the virtual sprinkler.
-type SprinklerServerMethods interface {
- // Status retrieves the Sprinkler's status (i.e., active, idle)
- Status(*context.T, rpc.ServerCall) (string, error)
- // Start causes the Sprinkler to emit water for the given duration (in seconds).
- Start(ctx *context.T, call rpc.ServerCall, duration uint16) error
- // Stop causes the Sprinkler to cease watering.
- Stop(*context.T, rpc.ServerCall) error
-}
-
-// SprinklerServerStubMethods is the server interface containing
-// Sprinkler methods, as expected by rpc.Server.
-// There is no difference between this interface and SprinklerServerMethods
-// since there are no streaming methods.
-type SprinklerServerStubMethods SprinklerServerMethods
-
-// SprinklerServerStub adds universal methods to SprinklerServerStubMethods.
-type SprinklerServerStub interface {
- SprinklerServerStubMethods
- // Describe the Sprinkler interfaces.
- Describe__() []rpc.InterfaceDesc
-}
-
-// SprinklerServer returns a server stub for Sprinkler.
-// It converts an implementation of SprinklerServerMethods into
-// an object that may be used by rpc.Server.
-func SprinklerServer(impl SprinklerServerMethods) SprinklerServerStub {
- stub := implSprinklerServerStub{
- impl: impl,
- }
- // Initialize GlobState; always check the stub itself first, to handle the
- // case where the user has the Glob method defined in their VDL source.
- if gs := rpc.NewGlobState(stub); gs != nil {
- stub.gs = gs
- } else if gs := rpc.NewGlobState(impl); gs != nil {
- stub.gs = gs
- }
- return stub
-}
-
-type implSprinklerServerStub struct {
- impl SprinklerServerMethods
- gs *rpc.GlobState
-}
-
-func (s implSprinklerServerStub) Status(ctx *context.T, call rpc.ServerCall) (string, error) {
- return s.impl.Status(ctx, call)
-}
-
-func (s implSprinklerServerStub) Start(ctx *context.T, call rpc.ServerCall, i0 uint16) error {
- return s.impl.Start(ctx, call, i0)
-}
-
-func (s implSprinklerServerStub) Stop(ctx *context.T, call rpc.ServerCall) error {
- return s.impl.Stop(ctx, call)
-}
-
-func (s implSprinklerServerStub) Globber() *rpc.GlobState {
- return s.gs
-}
-
-func (s implSprinklerServerStub) Describe__() []rpc.InterfaceDesc {
- return []rpc.InterfaceDesc{SprinklerDesc}
-}
-
-// SprinklerDesc describes the Sprinkler interface.
-var SprinklerDesc rpc.InterfaceDesc = descSprinkler
-
-// descSprinkler hides the desc to keep godoc clean.
-var descSprinkler = rpc.InterfaceDesc{
- Name: "Sprinkler",
- PkgPath: "v.io/x/browser/sample",
- Doc: "// Sprinkler allows clients to control the virtual sprinkler.",
- Methods: []rpc.MethodDesc{
- {
- Name: "Status",
- Doc: "// Status retrieves the Sprinkler's status (i.e., active, idle)",
- OutArgs: []rpc.ArgDesc{
- {"", ``}, // string
- },
- },
- {
- Name: "Start",
- Doc: "// Start causes the Sprinkler to emit water for the given duration (in seconds).",
- InArgs: []rpc.ArgDesc{
- {"duration", ``}, // uint16
- },
- },
- {
- Name: "Stop",
- Doc: "// Stop causes the Sprinkler to cease watering.",
- },
- },
-}
diff --git a/package.json b/package.json
index ab8b63a..ebe17d8 100644
--- a/package.json
+++ b/package.json
@@ -34,7 +34,6 @@
"routes": "^1.2.0",
"d3": "~3.5.5",
"lodash": "~3.0.0",
- "extend": "~2.0.0",
- "bluebird": "~2.3.2"
+ "extend": "~2.0.0"
}
}
diff --git a/src/services/sample-world/index.js b/src/services/sample-world/index.js
index 0d6f6e3..87e7383 100644
--- a/src/services/sample-world/index.js
+++ b/src/services/sample-world/index.js
@@ -83,10 +83,10 @@
}
// Helper function that waits until name is published or unpublished,
-// it checks every 1000ms for a total of 20 tries before failing.
+// it checks every 1000ms for a total of 30 tries before failing.
function waitUntilPublished(name, runtime) {
var WAIT_TIME = 1000;
- var MAX_TRIES = 20;
+ var MAX_TRIES = 30;
return new Promise(function(resolve, reject) {
var ns = runtime.namespace();
var count = 0;
diff --git a/src/services/sample-world/poolheater.js b/src/services/sample-world/poolheater.js
index 5ade868..b51e9a4 100644
--- a/src/services/sample-world/poolheater.js
+++ b/src/services/sample-world/poolheater.js
@@ -33,7 +33,7 @@
clearTimeout(this.handle); // Clear timeout handle, if any.
// Begin heating.
- this.status = ACTIVE;
+ this.state = ACTIVE;
this.currTemperature = temperature;
// After duration, stop heating.
diff --git a/src/services/sample-world/speaker.js b/src/services/sample-world/speaker.js
index 1eb711f..d8c0f03 100644
--- a/src/services/sample-world/speaker.js
+++ b/src/services/sample-world/speaker.js
@@ -73,7 +73,7 @@
Speaker.prototype.addSongs = function(context, serverCall, songs) {
songs.forEach(function(song) {
this.speakerLibrary.add(song); // No-op if the song is already there.
- });
+ }, this);
};
// Delete removes the list of given songs from the song library.
@@ -84,5 +84,5 @@
this.currentSong = null;
this.playing = false;
}
- });
+ }, this);
};
\ No newline at end of file
diff --git a/test/integration/services/namespace/service.js b/test/integration/services/namespace/service.js
index 6560603..28541a4 100644
--- a/test/integration/services/namespace/service.js
+++ b/test/integration/services/namespace/service.js
@@ -7,6 +7,9 @@
var _ = require('lodash');
var proxyquire = require('proxyquireify')(require);
var mockLRUCache = require('./mocks/lru-cache');
+var sampleWorld = require('../../../../src/services/sample-world');
+
+test.timeout(60 * 1000);
// @noCallThru ensures this completely overrdies the original config
// instead of inheriting the properties that are not defined here from
@@ -29,118 +32,140 @@
}
});
-test('getChildren of default namespace root', function(t) {
- namespaceService.getChildren().
- then(function assertResult(result) {
- assertIsImmutable(t, result);
- // Wait until we finish, we expect 2 top level items: cottage, house
- result.events.on('end', function validate() {
- mercury.watch(result, function(children) {
- assertCottage(children[0]);
- assertHouse(children[1]);
- t.end();
- });
- });
- result.events.on('globError', function(error) {
- t.notOk(error, 'did not expect any globs errors');
- t.end();
- });
- }).catch(t.end);
+var sw;
- function assertCottage(item) {
- assertServer(t, item, {
- name: 'cottage',
- objectName: 'cottage',
- isLeaf: false,
- isMounttable: true
- });
+function initSampleWorld(t) {
+ if (!sw) {
+ var prefix = '';
+ sw = sampleWorld.create(prefix);
}
- function assertHouse(item) {
- assertServer(t, item, {
- name: 'house',
- objectName: 'house',
- isLeaf: false,
- isMounttable: true
- });
+ return sw.catch(function(err) {
+ t.fail(err);
+ t.end();
+ // Throw again so the promise is not resolved and test does not continue
+ // to run.
+ throw err;
+ });
+}
+
+test('getChildren of default namespace root', function(t) {
+ initSampleWorld(t).then(run);
+
+ function run() {
+ namespaceService.getChildren().
+ then(function assertResult(result) {
+ assertIsImmutable(t, result);
+ // Wait until we finish, we expect 2 top level items: cottage, house
+ result.events.on('end', function validate() {
+ mercury.watch(result, function(children) {
+ assertCottage(children[0]);
+ assertHouse(children[1]);
+ t.end();
+ });
+ });
+ result.events.on('globError', function(error) {
+ t.notOk(error, 'did not expect any globs errors');
+ t.end();
+ });
+ }).catch(t.end);
+
+ function assertCottage(item) {
+ assertServer(t, item, {
+ name: 'cottage',
+ objectName: 'cottage',
+ isLeaf: false,
+ isMounttable: true
+ });
+ }
+
+ function assertHouse(item) {
+ assertServer(t, item, {
+ name: 'house',
+ objectName: 'house',
+ isLeaf: false,
+ isMounttable: true
+ });
+ }
}
});
test('getChildren of cottage/lawn', function(t) {
- namespaceService.getChildren('cottage/lawn').
- then(function assertResult(result) {
- assertIsImmutable(t, result);
- // Wait until we finish, we expect 3 items back, front and master-sprinkler
- result.events.on('end', function validate() {
- mercury.watch(result, function(children) {
- assertBack(children[0]);
- assertSprinkler(children[2]);
+ initSampleWorld(t).then(run);
+
+ function run() {
+ namespaceService.getChildren('cottage/lawn').
+ then(function assertResult(result) {
+ assertIsImmutable(t, result);
+ // Wait until we finish, we expect 3 items back, front and
+ // master-sprinkler
+ result.events.on('end', function validate() {
+ mercury.watch(result, function(children) {
+ assertBack(children[0]);
+ assertSprinkler(children[2]);
+ t.end();
+ });
+ });
+ result.events.on('globError', function(error) {
+ t.notOk(error, 'did not expect any globs errors');
t.end();
});
- });
- result.events.on('globError', function(error) {
- t.notOk(error, 'did not expect any globs errors');
- t.end();
- });
- }).catch(t.end);
+ }).catch(t.end);
- function assertSprinkler(item) {
- assertServer(t, item, {
- name: 'master-sprinkler',
- objectName: 'cottage/lawn/master-sprinkler',
- isLeaf: true
- });
- }
+ function assertSprinkler(item) {
+ assertServer(t, item, {
+ name: 'master-sprinkler',
+ objectName: 'cottage/lawn/master-sprinkler',
+ isLeaf: true
+ });
+ }
- function assertBack(item) {
- assertSubtableName(t, item, {
- name: 'back',
- objectName: 'cottage/lawn/back'
- });
+ function assertBack(item) {
+ assertSubtableName(t, item, {
+ name: 'back',
+ objectName: 'cottage/lawn/back'
+ });
+ }
}
});
test('getChildren of rooted ' + globalRoot + '/house/kitchen', function(t) {
- namespaceService.getChildren(globalRoot + '/house/kitchen').
- then(function assertResult(result) {
- assertIsImmutable(t, result);
- // Wait until we finish, we expect 3 items, lights, secret-pantry
- // and smoke-detector
- result.events.on('end', function validate() {
- mercury.watch(result, function(children) {
- assertLightSwitch(children[0]);
- assertSecretPantry(children[1]);
- assertSmokeDetector(children[2]);
+ initSampleWorld(t).then(run);
+
+ function run() {
+ namespaceService.getChildren(globalRoot + '/house/kitchen').
+ then(function assertResult(result) {
+ assertIsImmutable(t, result);
+ // Wait until we finish, we expect 2 items, lights
+ // and smoke-detector
+ result.events.on('end', function validate() {
+ mercury.watch(result, function(children) {
+ assertLightSwitch(children[0]);
+ assertSmokeDetector(children[1]);
+ t.end();
+ });
+ });
+ result.events.on('globError', function(error) {
+ t.notOk(error, 'did not expect any globs errors');
t.end();
});
- });
- result.events.on('globError', function(error) {
- t.notOk(error, 'did not expect any globs errors');
- t.end();
- });
- }).catch(t.end);
+ }).catch(t.end);
- function assertLightSwitch(item) {
- assertServer(t, item, {
- name: 'lights',
- objectName: globalRoot + '/house/kitchen/lights',
- isLeaf: true
- });
- }
+ function assertLightSwitch(item) {
+ assertServer(t, item, {
+ name: 'lights',
+ objectName: globalRoot + '/house/kitchen/lights',
+ isLeaf: true
+ });
+ }
- function assertSecretPantry(item) {
- assertSubtableName(t, item, {
- name: 'secret-pantry',
- objectName: globalRoot + '/house/kitchen/secret-pantry'
- });
- }
-
- function assertSmokeDetector(item) {
- assertServer(t, item, {
- name: 'smoke-detector',
- objectName: globalRoot + '/house/kitchen/smoke-detector',
- isLeaf: true
- });
+ function assertSmokeDetector(item) {
+ assertServer(t, item, {
+ name: 'smoke-detector',
+ objectName: globalRoot + '/house/kitchen/smoke-detector',
+ isLeaf: true
+ });
+ }
}
});
@@ -150,152 +175,172 @@
var hostPortRoot = process.env.HOUSE_MOUNTTABLE;
test('getChildren of rooted ' + hostPortRoot + '/kitchen', function(t) {
- namespaceService.getChildren(hostPortRoot + '/kitchen').
- then(function assertResult(result) {
- assertIsImmutable(t, result);
- // Wait until we finish, we expect 3 items, lights, secret-pantry
- // and smoke-detector
- result.events.on('end', function validate() {
- mercury.watch(result, function(children) {
- assertLightSwitch(children[0]);
- assertSecretPantry(children[1]);
- assertSmokeDetector(children[2]);
+ initSampleWorld(t).then(run);
+
+ function run() {
+ namespaceService.getChildren(hostPortRoot + '/kitchen').
+ then(function assertResult(result) {
+ assertIsImmutable(t, result);
+ // Wait until we finish, we expect 2 items, lights
+ // and smoke-detector
+ result.events.on('end', function validate() {
+ mercury.watch(result, function(children) {
+ assertLightSwitch(children[0]);
+ assertSmokeDetector(children[1]);
+ t.end();
+ });
+ });
+ result.events.on('globError', function(error) {
+ t.notOk(error, 'did not expect any globs errors');
t.end();
});
- });
- result.events.on('globError', function(error) {
- t.notOk(error, 'did not expect any globs errors');
- t.end();
- });
- }).catch(t.end);
+ }).catch(t.end);
- function assertLightSwitch(item) {
- assertServer(t, item, {
- name: 'lights',
- objectName: hostPortRoot + '/kitchen/lights',
- isLeaf: true
- });
- }
+ function assertLightSwitch(item) {
+ assertServer(t, item, {
+ name: 'lights',
+ objectName: hostPortRoot + '/kitchen/lights',
+ isLeaf: true
+ });
+ }
- function assertSecretPantry(item) {
- assertSubtableName(t, item, {
- name: 'secret-pantry',
- objectName: hostPortRoot + '/kitchen/secret-pantry'
- });
- }
-
- function assertSmokeDetector(item) {
- assertServer(t, item, {
- name: 'smoke-detector',
- objectName: hostPortRoot + '/kitchen/smoke-detector',
- isLeaf: true
- });
+ function assertSmokeDetector(item) {
+ assertServer(t, item, {
+ name: 'smoke-detector',
+ objectName: hostPortRoot + '/kitchen/smoke-detector',
+ isLeaf: true
+ });
+ }
}
});
test('getChildren of non-existing mounttable', function(t) {
- // TODO(aghassemi) why does namespace library return empty results instead of
- // error when globbing rooted names that don't exist?
- namespaceService.getChildren('/DoesNotExist:666/What/Ever').
- then(function assertResult(result) {
- result.events.on('end', function validate() {
- // Expect empty results
- mercury.watch(result, function(children) {
- t.deepEqual(children, []);
- t.end();
+ initSampleWorld(t).then(run);
+
+ function run() {
+ // TODO(aghassemi) why does namespace library return empty results instead
+ // of error when globbing rooted names that don't exist?
+ namespaceService.getChildren('/DoesNotExist:666/What/Ever').
+ then(function assertResult(result) {
+ result.events.on('end', function validate() {
+ // Expect empty results
+ mercury.watch(result, function(children) {
+ t.deepEqual(children, []);
+ t.end();
+ });
});
- });
- result.events.on('globError', function(error) {
- // we do actually expect a glob error in this case
- t.ok(error);
- });
- }).catch(t.end);
+ result.events.on('globError', function(error) {
+ // we do actually expect a glob error in this case
+ t.ok(error);
+ });
+ }).catch(t.end);
+ }
});
test('getNamespaceItem of leaf server', function(t) {
- namespaceService.getNamespaceItem('cottage/lawn/master-sprinkler').
- then(function assertItem(itemObs) {
- assertIsImmutable(t, itemObs);
- var item = itemObs();
- assertServer(t, item, {
- name: 'master-sprinkler',
- objectName: 'cottage/lawn/master-sprinkler',
- isLeaf: true
- });
- t.end();
- }).catch(t.end);
+ initSampleWorld(t).then(run);
+
+ function run() {
+ namespaceService.getNamespaceItem('cottage/lawn/master-sprinkler').
+ then(function assertItem(itemObs) {
+ assertIsImmutable(t, itemObs);
+ var item = itemObs();
+ assertServer(t, item, {
+ name: 'master-sprinkler',
+ objectName: 'cottage/lawn/master-sprinkler',
+ isLeaf: true
+ });
+ t.end();
+ }).catch(t.end);
+ }
});
test('getNamespaceItem of subtable', function(t) {
- namespaceService.getNamespaceItem('cottage/lawn/back').
- then(function assertItem(itemObs) {
- assertIsImmutable(t, itemObs);
- var item = itemObs();
- assertSubtableName(t, item, {
- name: 'back',
- objectName: 'cottage/lawn/back'
- });
- t.end();
- }).catch(t.end);
+ initSampleWorld(t).then(run);
+
+ function run() {
+ namespaceService.getNamespaceItem('cottage/lawn/back').
+ then(function assertItem(itemObs) {
+ assertIsImmutable(t, itemObs);
+ var item = itemObs();
+ assertSubtableName(t, item, {
+ name: 'back',
+ objectName: 'cottage/lawn/back'
+ });
+ t.end();
+ }).catch(t.end);
+ }
});
test('getNamespaceItem of mounttable leaf server', function(t) {
- namespaceService.getNamespaceItem('cottage').
- then(function assertItem(itemObs) {
- assertIsImmutable(t, itemObs);
- var item = itemObs();
- assertServer(t, item, {
- name: 'cottage',
- objectName: 'cottage',
- isLeaf: false,
- isMounttable: true
- });
- t.end();
- }).catch(t.end);
+ initSampleWorld(t).then(run);
+
+ function run() {
+ namespaceService.getNamespaceItem('cottage').
+ then(function assertItem(itemObs) {
+ assertIsImmutable(t, itemObs);
+ var item = itemObs();
+ assertServer(t, item, {
+ name: 'cottage',
+ objectName: 'cottage',
+ isLeaf: false,
+ isMounttable: true
+ });
+ t.end();
+ }).catch(t.end);
+ }
});
test('search uses caching', function(t) {
- mockLRUCache.reset();
+ initSampleWorld(t).then(run);
- namespaceService.search('house', '*').
- then(function assertNoCacheHit() {
- t.notOk(mockLRUCache.wasCacheHit('glob|house/*'),
- 'first glob call is not a cache hit');
+ function run() {
+ mockLRUCache.reset();
- // Call second time, there should have been a cache hit
- return namespaceService.search('house', '*');
- }).then(function assertCacheHit() {
- t.ok(mockLRUCache.wasCacheHit('glob|house/*'),
- 'second glob call is a cache hit');
+ namespaceService.search('house', '*').
+ then(function assertNoCacheHit() {
+ t.notOk(mockLRUCache.wasCacheHit('glob|house/*'),
+ 'first glob call is not a cache hit');
- // Call glob with same name, different query
- return namespaceService.search('house', 'foo*');
- }).then(function assertNoCacheHit() {
- t.notOk(mockLRUCache.wasCacheHit('glob|house/foo*'),
- 'third glob call with different query is not a cache hit');
- t.end();
- }).catch(t.end);
+ // Call second time, there should have been a cache hit
+ return namespaceService.search('house', '*');
+ }).then(function assertCacheHit() {
+ t.ok(mockLRUCache.wasCacheHit('glob|house/*'),
+ 'second glob call is a cache hit');
+
+ // Call glob with same name, different query
+ return namespaceService.search('house', 'foo*');
+ }).then(function assertNoCacheHit() {
+ t.notOk(mockLRUCache.wasCacheHit('glob|house/foo*'),
+ 'third glob call with different query is not a cache hit');
+ t.end();
+ }).catch(t.end);
+ }
});
test('getSignature uses caching', function(t) {
- mockLRUCache.reset();
+ initSampleWorld(t).then(run);
- namespaceService.getSignature('house/alarm').then(function() {
- t.notOk(mockLRUCache.wasCacheHit('getSignature|house/alarm'),
- 'first getSignature call is not a cache hit');
- // Call a second time
- return namespaceService.getSignature('house/alarm');
- }).then(function() {
- t.ok(mockLRUCache.wasCacheHit('getSignature|house/alarm'),
- 'second getSignature call is a cache hit');
- // Call a different name
- return namespaceService.getSignature('house/kitchen/smoke-detector');
- }).then(function() {
- t.notOk(mockLRUCache.wasCacheHit(
- 'getSignature|house/kitchen/smoke-detector'
- ), 'third getSignature call to a different name is not a cache hit');
- t.end();
- }).catch(t.end);
+ function run() {
+ mockLRUCache.reset();
+
+ namespaceService.getSignature('house/alarm').then(function() {
+ t.notOk(mockLRUCache.wasCacheHit('getSignature|house/alarm'),
+ 'first getSignature call is not a cache hit');
+ // Call a second time
+ return namespaceService.getSignature('house/alarm');
+ }).then(function() {
+ t.ok(mockLRUCache.wasCacheHit('getSignature|house/alarm'),
+ 'second getSignature call is a cache hit');
+ // Call a different name
+ return namespaceService.getSignature('house/kitchen/smoke-detector');
+ }).then(function() {
+ t.notOk(mockLRUCache.wasCacheHit(
+ 'getSignature|house/kitchen/smoke-detector'
+ ), 'third getSignature call to a different name is not a cache hit');
+ t.end();
+ }).catch(t.end);
+ }
});
// Make RPC: good inputs => no error
@@ -338,33 +383,71 @@
// Make RPC: outputs have the expected # of outputs
test('makeRPC returns output properly', function(t) {
- namespaceService.makeRPC('cottage/alarm', 'panic', []).then(
- function got0Outputs(res) { // 0 outputs: has no result.
- t.ok(res === undefined, '0 outputs => is undefined');
+ initSampleWorld(t).then(run);
- return namespaceService.makeRPC('house/alarm', 'status', []);
- }
- ).then( // 1 output: (Non-array/slice output) is not an Array.
- function got1Output(res) {
- t.notOk(res instanceof Array, '1 output => not an Array');
+ function run() {
+ namespaceService.makeRPC('cottage/alarm', 'panic', []).then(
+ function got0Outputs(res) { // 0 outputs: has no result.
+ t.ok(res === undefined, '0 outputs => is undefined');
- return namespaceService.makeRPC('cottage/smoke-detector', 'test', []);
- }
- ).then( // 1 output: Delayed return. Also not an array.
- function got1OutputDelayed(res) {
- t.notOk(res instanceof Array, '1 output => not an Array');
+ return namespaceService.makeRPC('house/alarm', 'status', []);
+ }
+ ).then( // 1 output: (Non-array/slice output) is not an Array.
+ function got1Output(res) {
+ t.notOk(res instanceof Array, '1 output => not an Array');
- return namespaceService.makeRPC('cottage/pool/heater', 'status', []);
- }
- ).then( // 2 outputs: Is an Array of the correct length.
- function got2Outputs(res) {
- var ok = res instanceof Array && res.length === 2;
- t.ok(ok, '2 outputs => length 2 Array');
- t.end();
- }
- ).catch(t.end);
+ return namespaceService.makeRPC('cottage/smoke-detector', 'test', []);
+ }
+ ).then( // 1 output: Delayed return. Also not an array.
+ function got1OutputDelayed(res) {
+ t.notOk(res instanceof Array, '1 output => not an Array');
+
+ return namespaceService.makeRPC('cottage/pool/heater', 'status', []);
+ }
+ ).then( // 2 outputs: Is an Array of the correct length.
+ function got2Outputs(res) {
+ var ok = res instanceof Array && res.length === 2;
+ t.ok(ok, '2 outputs => length 2 Array');
+ t.end();
+ }
+ ).catch(t.end);
+ }
});
+
+/*
+ * Runs a test to ensure the makeRPC call terminates without error.
+ */
+function testMakeRPCNoError(args, t) {
+ initSampleWorld(t).then(run);
+
+ function run() {
+ namespaceService.makeRPC.apply(null, args).then(function(result) {
+ t.pass('completed without error');
+ t.end();
+ }).catch(function(err) {
+ t.end(err);
+ });
+ }
+}
+
+/*
+ * Runs a test to ensure the makeRPC call terminates with an error.
+ */
+function testMakeRPCHasError(args, t) {
+ initSampleWorld(t).then(run);
+
+ function run() {
+ namespaceService.makeRPC.apply(null, args).then(function(result) {
+ t.fail('should not have completed without error');
+ t.end();
+ }).catch(function(err) {
+ t.pass('correctly returned an error');
+ t.end();
+ });
+ }
+}
+
/*
* Test helpers
*/
@@ -415,31 +498,6 @@
t.ok(observable.set === undefined, 'is immutable');
}
-/*
- * Runs a test to ensure the makeRPC call terminates without error.
- */
-function testMakeRPCNoError(args, t) {
- namespaceService.makeRPC.apply(null, args).then(function(result) {
- t.pass('completed without error');
- t.end();
- }).catch(function(err) {
- t.end(err);
- });
-}
-
-/*
- * Runs a test to ensure the makeRPC call terminates with an error.
- */
-function testMakeRPCHasError(args, t) {
- namespaceService.makeRPC.apply(null, args).then(function(result) {
- t.fail('should not have completed without error');
- t.end();
- }).catch(function(err) {
- t.pass('correctly returned an error');
- t.end();
- });
-}
-
//TODO(aghassemi)
//Tests for:
// Recursive glob