VOL-1255: Fixed an issue with the proxy implementation
- Had to change the model slightly to mimic a polymorphic behaviour
Change-Id: I12017cdfedf5c0ed05243245aa2a811556222e0f
diff --git a/db/model/proxy_test.go b/db/model/proxy_test.go
index bf80bb7..a96aa28 100644
--- a/db/model/proxy_test.go
+++ b/db/model/proxy_test.go
@@ -29,7 +29,7 @@
)
type proxyTest struct {
- Root *Root
+ Root *root
Backend *Backend
Proxy *Proxy
DbPrefix string
@@ -66,7 +66,7 @@
GetProfiling().Report()
- pt.Proxy = pt.Root.Node.GetProxy("/", false)
+ pt.Proxy = pt.Root.GetProxy("/", false)
}
func Test_Proxy_1_GetDevices(t *testing.T) {
@@ -121,6 +121,61 @@
t.Logf("Found device: count: %s", djson)
}
}
+func Test_Proxy_3_1_RegisterProxy(t *testing.T) {
+ // Get a device proxy and update a specific port
+ devProxy := pt.Root.GetProxy("/devices/"+devId, false)
+ port123 := devProxy.Get("/ports/123", 0, false, "")
+ t.Logf("got ports: %+v", port123)
+
+ devProxy.RegisterCallback(POST_UPDATE, deviceCallback, nil)
+
+ port123.(*voltha.Port).OperStatus = common.OperStatus_DISCOVERED
+
+ devProxy.Update("/ports/123", port123, false, "")
+ updated := devProxy.Get("/ports", 0, false, "")
+ t.Logf("got updated ports: %+v", updated)
+
+ //
+ // Get a device proxy and update all its ports
+ //
+
+ //devProxy := pt.Root.GetProxy("/devices/"+devId, false)
+ //ports := devProxy.Get("/ports", 0, false, "")
+ //t.Logf("got ports: %+v", ports)
+ //devProxy.RegisterCallback(POST_UPDATE, deviceCallback, nil)
+ //
+ //ports.([]interface{})[0].(*voltha.Port).OperStatus = common.OperStatus_DISCOVERED
+ //
+ //devProxy.Update("/ports", ports, false, "")
+ //updated := devProxy.Get("/ports", 0, false, "")
+ //t.Logf("got updated ports: %+v", updated)
+
+
+ //
+ // Get a device proxy, retrieve all the ports and update a specific one
+ //
+
+ //devProxy := pt.Root.GetProxy("/devices/"+devId, false)
+ //ports := devProxy.Get("/ports", 0, false, "")
+ //t.Logf("got ports: %+v", ports)
+ //devProxy.RegisterCallback(POST_UPDATE, deviceCallback, nil)
+ //
+ //ports.([]interface{})[0].(*voltha.Port).OperStatus = common.OperStatus_DISCOVERED
+ //
+ //devProxy.Update("/ports/123", ports.([]interface{})[0], false, "")
+ //updated := devProxy.Get("/ports", 0, false, "")
+ //t.Logf("got updated ports: %+v", updated)
+}
+
+func Test_Proxy_3_2_GetDevice_PostRegister(t *testing.T) {
+ if d := pt.Proxy.Get("/devices/"+devId, 0, false, ""); !reflect.ValueOf(d).IsValid() {
+ t.Error("Failed to find updated registered device")
+ } else {
+ djson, _ := json.Marshal(d)
+
+ t.Logf("Found device: count: %s", djson)
+ }
+}
func Test_Proxy_4_UpdateDevice(t *testing.T) {
if retrieved := pt.Proxy.Get("/devices/"+targetDeviceId, 1, false, ""); retrieved == nil {
@@ -179,6 +234,10 @@
fmt.Printf("Running first callback - name: %s, id: %s\n", name, id)
return nil
}
+func deviceCallback(args ...interface{}) interface{} {
+ fmt.Printf("Running device callback\n")
+ return nil
+}
func secondCallback(args ...interface{}) interface{} {
name := args[0].(map[string]string)
id := args[1]