Skip to content

Commit

Permalink
Add persistence for storing node table data.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwood committed Jun 14, 2024
1 parent dc796e8 commit a7b75e0
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 81 deletions.
5 changes: 3 additions & 2 deletions adapter_endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package zstack
import (
"context"
"github.com/shimmeringbee/bytecodec"
"github.com/shimmeringbee/persistence/impl/memory"
. "github.com/shimmeringbee/unpi"
unpiTest "github.com/shimmeringbee/unpi/testing"
"github.com/shimmeringbee/zigbee"
Expand All @@ -18,7 +19,7 @@ func Test_RegisterAdapterEndpoint(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
zstack.sem = semaphore.NewWeighted(8)
defer unpiMock.Stop()

Expand All @@ -44,7 +45,7 @@ func Test_RegisterAdapterEndpoint(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
zstack.sem = semaphore.NewWeighted(8)
defer unpiMock.Stop()

Expand Down
5 changes: 3 additions & 2 deletions adapter_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package zstack
import (
"context"
"github.com/shimmeringbee/bytecodec"
"github.com/shimmeringbee/persistence/impl/memory"
. "github.com/shimmeringbee/unpi"
unpiTest "github.com/shimmeringbee/unpi/testing"
"github.com/shimmeringbee/zigbee"
Expand All @@ -18,7 +19,7 @@ func Test_GetAdapterIEEEAddress(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
zstack.sem = semaphore.NewWeighted(8)
defer unpiMock.Stop()

Expand All @@ -43,7 +44,7 @@ func Test_GetAdapterNetworkAddress(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
zstack.sem = semaphore.NewWeighted(8)
defer unpiMock.Stop()

Expand Down
21 changes: 11 additions & 10 deletions adapter_initialise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package zstack
import (
"context"
"github.com/shimmeringbee/bytecodec"
"github.com/shimmeringbee/persistence/impl/memory"
. "github.com/shimmeringbee/unpi"
unpiTest "github.com/shimmeringbee/unpi/testing"
"github.com/shimmeringbee/zigbee"
Expand All @@ -17,7 +18,7 @@ func Test_Initialise(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
defer unpiMock.Stop()
defer zstack.Stop()

Expand Down Expand Up @@ -120,7 +121,7 @@ func Test_Initialise(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
defer unpiMock.Stop()
defer zstack.Stop()

Expand Down Expand Up @@ -248,7 +249,7 @@ func Test_Initialise(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
defer unpiMock.Stop()
defer zstack.Stop()

Expand Down Expand Up @@ -353,7 +354,7 @@ func Test_verifyAdapterNetworkConfig(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
defer unpiMock.Stop()
defer zstack.Stop()

Expand Down Expand Up @@ -404,7 +405,7 @@ func Test_verifyAdapterNetworkConfig(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
defer unpiMock.Stop()
defer zstack.Stop()

Expand Down Expand Up @@ -457,7 +458,7 @@ func Test_startZigbeeStack(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
defer unpiMock.Stop()

unpiMock.On(SREQ, ZDO, ZDOStartUpFromAppRequestId).Return(Frame{
Expand All @@ -478,7 +479,7 @@ func Test_startZigbeeStack(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
defer unpiMock.Stop()

unpiMock.On(SREQ, ZDO, ZDOStartUpFromAppRequestId).Return(Frame{
Expand Down Expand Up @@ -509,7 +510,7 @@ func Test_startZigbeeStack(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
defer unpiMock.Stop()

unpiMock.On(SREQ, ZDO, ZDOStartUpFromAppRequestId).Return(Frame{
Expand All @@ -532,7 +533,7 @@ func Test_waitForCoordinatorStart(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
defer unpiMock.Stop()

go func() {
Expand All @@ -556,7 +557,7 @@ func Test_waitForCoordinatorStart(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
defer unpiMock.Stop()

err := zstack.waitForCoordinatorStart(ctx)
Expand Down
3 changes: 2 additions & 1 deletion events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package zstack

import (
"context"
"github.com/shimmeringbee/persistence/impl/memory"
unpiTest "github.com/shimmeringbee/unpi/testing"
"github.com/stretchr/testify/assert"
"testing"
Expand All @@ -14,7 +15,7 @@ func Test_ReadEvent(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
defer unpiMock.Stop()
defer unpiMock.AssertCalls(t)

Expand Down
14 changes: 12 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
module github.com/shimmeringbee/zstack

go 1.14
go 1.22.0

toolchain go1.22.2

require (
github.com/shimmeringbee/bytecodec v0.0.0-20210228205504-1e9e0677347b
github.com/shimmeringbee/logwrap v0.1.3
github.com/shimmeringbee/persistence v0.0.0-20240521204303-bf4ab8a6b71b
github.com/shimmeringbee/retry v0.0.0-20221006193055-2ce01bf139c2
github.com/shimmeringbee/unpi v0.0.0-20210525151328-7ede275a1033
github.com/shimmeringbee/zigbee v0.0.0-20221016122511-6c2328db0d94
github.com/shimmeringbee/zigbee v0.0.0-20240614090423-d67fd427d102
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.7.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
27 changes: 5 additions & 22 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,35 @@ github.com/shimmeringbee/bytecodec v0.0.0-20200216120857-49d677293817/go.mod h1:
github.com/shimmeringbee/bytecodec v0.0.0-20210111165458-877359ca1003/go.mod h1:iqI5PkiqY+Xq6Hu22TNhepAY00iJCfk9jiXKBUrMSQQ=
github.com/shimmeringbee/bytecodec v0.0.0-20210228205504-1e9e0677347b h1:8q7X6JQwYKjnl+Absfv9m+LbDSBBllqTDDKzmtZ1ybY=
github.com/shimmeringbee/bytecodec v0.0.0-20210228205504-1e9e0677347b/go.mod h1:WYnxfxTJ45UQ+xeAuuTSIalcEepgP8Rb7T/OhCaDdgo=
github.com/shimmeringbee/logwrap v0.0.0-20210228205504-ec4498cd3a41 h1:ZyQT0LgUA8s7UyMRvi444yROU4TXFxvz3XIqpIvlgbs=
github.com/shimmeringbee/logwrap v0.0.0-20210228205504-ec4498cd3a41/go.mod h1:NBAcZCUl6aFOGnWTs8m67EUAmWFZXRhoRQf5nknY8W0=
github.com/shimmeringbee/logwrap v0.1.3 h1:1PqPGdgbeQxACQqc6RUWERn7EnpA1jbiHzXVYFa7q2A=
github.com/shimmeringbee/logwrap v0.1.3/go.mod h1:NBAcZCUl6aFOGnWTs8m67EUAmWFZXRhoRQf5nknY8W0=
github.com/shimmeringbee/retry v0.0.0-20210228205505-2704f9c1c8a2 h1:BAAlZ6gR1/mUbbTIVLz2fXQnfkERO1PJYu+r3L+EqxM=
github.com/shimmeringbee/retry v0.0.0-20210228205505-2704f9c1c8a2/go.mod h1:FFeFkkqdD9vdDFr2la9PkSTQr6qgU9aBiGU3QKn8ZKY=
github.com/shimmeringbee/persistence v0.0.0-20240521204303-bf4ab8a6b71b h1:hxMT4WUvcmJVzv4EgSGq4LvEoUZFdysWIznFTJoSRIU=
github.com/shimmeringbee/persistence v0.0.0-20240521204303-bf4ab8a6b71b/go.mod h1:Z5euPm65BHgTSRFgaWHByaXejU/J4oUqESV9k0VzQDU=
github.com/shimmeringbee/retry v0.0.0-20221006193055-2ce01bf139c2 h1:HxpPz7w7SxVf1GmcM5oTK1JK64TGpK1UflweYRSOwC4=
github.com/shimmeringbee/retry v0.0.0-20221006193055-2ce01bf139c2/go.mod h1:KYvVq5b7/BSSlWng+AKB5jwNGpc0D7eg8ySWrdPAlms=
github.com/shimmeringbee/unpi v0.0.0-20210111165207-f0210c6942fc/go.mod h1:iAt5R5HT+VC7B9U77uBmN5Z6+DJo4U0z6ag68NH2mMw=
github.com/shimmeringbee/unpi v0.0.0-20210525151328-7ede275a1033 h1:PQGdXelNwwcQH58S90MR0xA3GnikCnzt+xpDw0P4qxM=
github.com/shimmeringbee/unpi v0.0.0-20210525151328-7ede275a1033/go.mod h1:hOrncW6hd26Z18eayp99i7hNKj0aHtUx1SxXT49aEsk=
github.com/shimmeringbee/zigbee v0.0.0-20210427191220-76676a734066 h1:3ClT9MdUGZToPHXmLM+pC5csq5XptJ6thQTQbhjV6Dw=
github.com/shimmeringbee/zigbee v0.0.0-20210427191220-76676a734066/go.mod h1:GMA6rVpzvUK16cZwi8uW11JUTx8xUGOk5DbkXYWvm/8=
github.com/shimmeringbee/zigbee v0.0.0-20221016122511-6c2328db0d94 h1:WlfIY/YXIl+8DvmyAnA1PD8pJ6kxRfXrFzWERTSv7pY=
github.com/shimmeringbee/zigbee v0.0.0-20221016122511-6c2328db0d94/go.mod h1:GMA6rVpzvUK16cZwi8uW11JUTx8xUGOk5DbkXYWvm/8=
github.com/shimmeringbee/zigbee v0.0.0-20240614090423-d67fd427d102 h1:SNuznHuBvY1iEbkOEP0jbmIvn2p0GQGlCNQAUyDmcRQ=
github.com/shimmeringbee/zigbee v0.0.0-20240614090423-d67fd427d102/go.mod h1:k5LLUXiOWq3hlNvMecCZRqamocgH9Zp9ocadrAfyCpw=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
11 changes: 6 additions & 5 deletions joining_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package zstack
import (
"context"
"github.com/shimmeringbee/bytecodec"
"github.com/shimmeringbee/persistence/impl/memory"
. "github.com/shimmeringbee/unpi"
unpiTest "github.com/shimmeringbee/unpi/testing"
"github.com/shimmeringbee/zigbee"
Expand All @@ -18,7 +19,7 @@ func Test_PermitJoin(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
zstack.sem = semaphore.NewWeighted(8)
defer unpiMock.Stop()

Expand All @@ -43,7 +44,7 @@ func Test_PermitJoin(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
zstack.sem = semaphore.NewWeighted(8)
defer unpiMock.Stop()
zstack.NetworkProperties.NetworkAddress = zigbee.NetworkAddress(0x0102)
Expand All @@ -69,7 +70,7 @@ func Test_PermitJoin(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
zstack.sem = semaphore.NewWeighted(8)
defer unpiMock.Stop()

Expand All @@ -93,7 +94,7 @@ func Test_DenyJoin(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
zstack.sem = semaphore.NewWeighted(8)
defer unpiMock.Stop()

Expand All @@ -119,7 +120,7 @@ func Test_DenyJoin(t *testing.T) {
defer cancel()

unpiMock := unpiTest.NewMockAdapter()
zstack := New(unpiMock)
zstack := New(unpiMock, memory.New())
zstack.sem = semaphore.NewWeighted(8)
defer unpiMock.Stop()

Expand Down
Loading

0 comments on commit a7b75e0

Please sign in to comment.