Merge lp:~chipaca/ubuntu-push/persistence into lp:ubuntu-push
- persistence
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | John Lenton |
Approved revision: | 67 |
Merged at revision: | 79 |
Proposed branch: | lp:~chipaca/ubuntu-push/persistence |
Merge into: | lp:ubuntu-push |
Prerequisite: | lp:~chipaca/ubuntu-push/sqlevelmap-in-session |
Diff against target: |
484 lines (+91/-51) 2 files modified
client/client.go (+28/-17) client/client_test.go (+63/-34) |
To merge this branch: | bzr merge lp:~chipaca/ubuntu-push/persistence |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Samuele Pedroni | Approve | ||
Review via email:
|
Commit message
and this gives the client the ability to persist its session's levelmap
Description of the change
With this, NewPushClient takes a second argument that is the path to
the sqlite db in which to persist its level map. If the path is "",
use the good ol' mapLevelMap instead.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
The attempt to merge lp:~chipaca/ubuntu-push/persistence into lp:ubuntu-push failed. Below is the output from the failed tests.
mkdir -p /mnt/tarmac/
mkdir -p /mnt/tarmac/
go get -u launchpad.
go get -d -u launchpad.
/mnt/tarmac/
"/mnt/tarmac/
go install launchpad.
go test launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
go test -race launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
Preview Diff
1 | === modified file 'client/client.go' | |||
2 | --- client/client.go 2014-02-21 16:17:28 +0000 | |||
3 | +++ client/client.go 2014-03-12 11:09:23 +0000 | |||
4 | @@ -50,8 +50,9 @@ | |||
5 | 50 | LogLevel string `json:"log_level"` | 50 | LogLevel string `json:"log_level"` |
6 | 51 | } | 51 | } |
7 | 52 | 52 | ||
10 | 53 | // pushClient is the Ubuntu Push Notifications client-side daemon. | 53 | // PushClient is the Ubuntu Push Notifications client-side daemon. |
11 | 54 | type pushClient struct { | 54 | type PushClient struct { |
12 | 55 | leveldbPath string | ||
13 | 55 | configPath string | 56 | configPath string |
14 | 56 | config ClientConfig | 57 | config ClientConfig |
15 | 57 | log logger.Logger | 58 | log logger.Logger |
16 | @@ -70,15 +71,16 @@ | |||
17 | 70 | 71 | ||
18 | 71 | // Creates a new Ubuntu Push Notifications client-side daemon that will use | 72 | // Creates a new Ubuntu Push Notifications client-side daemon that will use |
19 | 72 | // the given configuration file. | 73 | // the given configuration file. |
22 | 73 | func NewPushClient(configPath string) *pushClient { | 74 | func NewPushClient(configPath string, leveldbPath string) *PushClient { |
23 | 74 | client := new(pushClient) | 75 | client := new(PushClient) |
24 | 75 | client.configPath = configPath | 76 | client.configPath = configPath |
25 | 77 | client.leveldbPath = leveldbPath | ||
26 | 76 | 78 | ||
27 | 77 | return client | 79 | return client |
28 | 78 | } | 80 | } |
29 | 79 | 81 | ||
30 | 80 | // configure loads its configuration, and sets it up. | 82 | // configure loads its configuration, and sets it up. |
32 | 81 | func (client *pushClient) configure() error { | 83 | func (client *PushClient) configure() error { |
33 | 82 | f, err := os.Open(client.configPath) | 84 | f, err := os.Open(client.configPath) |
34 | 83 | if err != nil { | 85 | if err != nil { |
35 | 84 | return fmt.Errorf("opening config: %v", err) | 86 | return fmt.Errorf("opening config: %v", err) |
36 | @@ -115,7 +117,7 @@ | |||
37 | 115 | } | 117 | } |
38 | 116 | 118 | ||
39 | 117 | // getDeviceId gets the whoopsie identifier for the device | 119 | // getDeviceId gets the whoopsie identifier for the device |
41 | 118 | func (client *pushClient) getDeviceId() error { | 120 | func (client *PushClient) getDeviceId() error { |
42 | 119 | err := client.idder.Generate() | 121 | err := client.idder.Generate() |
43 | 120 | if err != nil { | 122 | if err != nil { |
44 | 121 | return err | 123 | return err |
45 | @@ -125,7 +127,7 @@ | |||
46 | 125 | } | 127 | } |
47 | 126 | 128 | ||
48 | 127 | // takeTheBus starts the connection(s) to D-Bus and sets up associated event channels | 129 | // takeTheBus starts the connection(s) to D-Bus and sets up associated event channels |
50 | 128 | func (client *pushClient) takeTheBus() error { | 130 | func (client *PushClient) takeTheBus() error { |
51 | 129 | go connectivity.ConnectedState(client.connectivityEndp, | 131 | go connectivity.ConnectedState(client.connectivityEndp, |
52 | 130 | client.config.ConnectivityConfig, client.log, client.connCh) | 132 | client.config.ConnectivityConfig, client.log, client.connCh) |
53 | 131 | iniCh := make(chan uint32) | 133 | iniCh := make(chan uint32) |
54 | @@ -140,10 +142,10 @@ | |||
55 | 140 | } | 142 | } |
56 | 141 | 143 | ||
57 | 142 | // initSession creates the session object | 144 | // initSession creates the session object |
59 | 143 | func (client *pushClient) initSession() error { | 145 | func (client *PushClient) initSession() error { |
60 | 144 | sess, err := session.NewSession(string(client.config.Addr), client.pem, | 146 | sess, err := session.NewSession(string(client.config.Addr), client.pem, |
61 | 145 | client.config.ExchangeTimeout.Duration, client.deviceId, | 147 | client.config.ExchangeTimeout.Duration, client.deviceId, |
63 | 146 | levelmap.NewLevelMap, client.log) | 148 | client.levelMapFactory, client.log) |
64 | 147 | if err != nil { | 149 | if err != nil { |
65 | 148 | return err | 150 | return err |
66 | 149 | } | 151 | } |
67 | @@ -151,8 +153,17 @@ | |||
68 | 151 | return nil | 153 | return nil |
69 | 152 | } | 154 | } |
70 | 153 | 155 | ||
71 | 156 | // levelmapFactory returns a levelMap for the session | ||
72 | 157 | func (client *PushClient) levelMapFactory() (levelmap.LevelMap, error) { | ||
73 | 158 | if client.leveldbPath == "" { | ||
74 | 159 | return levelmap.NewLevelMap() | ||
75 | 160 | } else { | ||
76 | 161 | return levelmap.NewSqliteLevelMap(client.leveldbPath) | ||
77 | 162 | } | ||
78 | 163 | } | ||
79 | 164 | |||
80 | 154 | // handleConnState deals with connectivity events | 165 | // handleConnState deals with connectivity events |
82 | 155 | func (client *pushClient) handleConnState(hasConnectivity bool) { | 166 | func (client *PushClient) handleConnState(hasConnectivity bool) { |
83 | 156 | if client.hasConnectivity == hasConnectivity { | 167 | if client.hasConnectivity == hasConnectivity { |
84 | 157 | // nothing to do! | 168 | // nothing to do! |
85 | 158 | return | 169 | return |
86 | @@ -166,7 +177,7 @@ | |||
87 | 166 | } | 177 | } |
88 | 167 | 178 | ||
89 | 168 | // handleErr deals with the session erroring out of its loop | 179 | // handleErr deals with the session erroring out of its loop |
91 | 169 | func (client *pushClient) handleErr(err error) { | 180 | func (client *PushClient) handleErr(err error) { |
92 | 170 | // if we're not connected, we don't really care | 181 | // if we're not connected, we don't really care |
93 | 171 | client.log.Errorf("session exited: %s", err) | 182 | client.log.Errorf("session exited: %s", err) |
94 | 172 | if client.hasConnectivity { | 183 | if client.hasConnectivity { |
95 | @@ -175,7 +186,7 @@ | |||
96 | 175 | } | 186 | } |
97 | 176 | 187 | ||
98 | 177 | // handleNotification deals with receiving a notification | 188 | // handleNotification deals with receiving a notification |
100 | 178 | func (client *pushClient) handleNotification() error { | 189 | func (client *PushClient) handleNotification() error { |
101 | 179 | action_id := "dummy_id" | 190 | action_id := "dummy_id" |
102 | 180 | a := []string{action_id, "Go get it!"} // action value not visible on the phone | 191 | a := []string{action_id, "Go get it!"} // action value not visible on the phone |
103 | 181 | h := map[string]*dbus.Variant{"x-canonical-switch-to-application": &dbus.Variant{true}} | 192 | h := map[string]*dbus.Variant{"x-canonical-switch-to-application": &dbus.Variant{true}} |
104 | @@ -199,14 +210,14 @@ | |||
105 | 199 | } | 210 | } |
106 | 200 | 211 | ||
107 | 201 | // handleClick deals with the user clicking a notification | 212 | // handleClick deals with the user clicking a notification |
109 | 202 | func (client *pushClient) handleClick() error { | 213 | func (client *PushClient) handleClick() error { |
110 | 203 | // it doesn't get much simpler... | 214 | // it doesn't get much simpler... |
111 | 204 | urld := urldispatcher.New(client.urlDispatcherEndp, client.log) | 215 | urld := urldispatcher.New(client.urlDispatcherEndp, client.log) |
112 | 205 | return urld.DispatchURL("settings:///system/system-update") | 216 | return urld.DispatchURL("settings:///system/system-update") |
113 | 206 | } | 217 | } |
114 | 207 | 218 | ||
115 | 208 | // doLoop connects events with their handlers | 219 | // doLoop connects events with their handlers |
117 | 209 | func (client *pushClient) doLoop(connhandler func(bool), clickhandler, notifhandler func() error, errhandler func(error)) { | 220 | func (client *PushClient) doLoop(connhandler func(bool), clickhandler, notifhandler func() error, errhandler func(error)) { |
118 | 210 | for { | 221 | for { |
119 | 211 | select { | 222 | select { |
120 | 212 | case state := <-client.connCh: | 223 | case state := <-client.connCh: |
121 | @@ -225,7 +236,7 @@ | |||
122 | 225 | 236 | ||
123 | 226 | // doStart calls each of its arguments in order, returning the first non-nil | 237 | // doStart calls each of its arguments in order, returning the first non-nil |
124 | 227 | // error (or nil at the end) | 238 | // error (or nil at the end) |
126 | 228 | func (client *pushClient) doStart(fs ...func() error) error { | 239 | func (client *PushClient) doStart(fs ...func() error) error { |
127 | 229 | for _, f := range fs { | 240 | for _, f := range fs { |
128 | 230 | if err := f(); err != nil { | 241 | if err := f(); err != nil { |
129 | 231 | return err | 242 | return err |
130 | @@ -235,13 +246,13 @@ | |||
131 | 235 | } | 246 | } |
132 | 236 | 247 | ||
133 | 237 | // Loop calls doLoop with the "real" handlers | 248 | // Loop calls doLoop with the "real" handlers |
135 | 238 | func (client *pushClient) Loop() { | 249 | func (client *PushClient) Loop() { |
136 | 239 | client.doLoop(client.handleConnState, client.handleClick, | 250 | client.doLoop(client.handleConnState, client.handleClick, |
137 | 240 | client.handleNotification, client.handleErr) | 251 | client.handleNotification, client.handleErr) |
138 | 241 | } | 252 | } |
139 | 242 | 253 | ||
140 | 243 | // Start calls doStart with the "real" starters | 254 | // Start calls doStart with the "real" starters |
142 | 244 | func (client *pushClient) Start() error { | 255 | func (client *PushClient) Start() error { |
143 | 245 | return client.doStart( | 256 | return client.doStart( |
144 | 246 | client.configure, | 257 | client.configure, |
145 | 247 | client.getDeviceId, | 258 | client.getDeviceId, |
146 | 248 | 259 | ||
147 | === modified file 'client/client_test.go' | |||
148 | --- client/client_test.go 2014-02-08 18:26:49 +0000 | |||
149 | +++ client/client_test.go 2014-03-12 11:09:23 +0000 | |||
150 | @@ -52,9 +52,10 @@ | |||
151 | 52 | } | 52 | } |
152 | 53 | 53 | ||
153 | 54 | type clientSuite struct { | 54 | type clientSuite struct { |
157 | 55 | timeouts []time.Duration | 55 | timeouts []time.Duration |
158 | 56 | configPath string | 56 | configPath string |
159 | 57 | log *helpers.TestLogger | 57 | leveldbPath string |
160 | 58 | log *helpers.TestLogger | ||
161 | 58 | } | 59 | } |
162 | 59 | 60 | ||
163 | 60 | var _ = Suite(&clientSuite{}) | 61 | var _ = Suite(&clientSuite{}) |
164 | @@ -74,6 +75,7 @@ | |||
165 | 74 | 75 | ||
166 | 75 | func (cs *clientSuite) SetUpSuite(c *C) { | 76 | func (cs *clientSuite) SetUpSuite(c *C) { |
167 | 76 | cs.timeouts = util.SwapTimeouts([]time.Duration{0}) | 77 | cs.timeouts = util.SwapTimeouts([]time.Duration{0}) |
168 | 78 | cs.leveldbPath = "" | ||
169 | 77 | } | 79 | } |
170 | 78 | 80 | ||
171 | 79 | func (cs *clientSuite) TearDownSuite(c *C) { | 81 | func (cs *clientSuite) TearDownSuite(c *C) { |
172 | @@ -99,12 +101,21 @@ | |||
173 | 99 | ioutil.WriteFile(cs.configPath, []byte(cfg), 0600) | 101 | ioutil.WriteFile(cs.configPath, []byte(cfg), 0600) |
174 | 100 | } | 102 | } |
175 | 101 | 103 | ||
176 | 104 | type sqlientSuite struct{ clientSuite } | ||
177 | 105 | |||
178 | 106 | func (s *sqlientSuite) SetUpSuite(c *C) { | ||
179 | 107 | s.clientSuite.SetUpSuite(c) | ||
180 | 108 | s.leveldbPath = ":memory:" | ||
181 | 109 | } | ||
182 | 110 | |||
183 | 111 | var _ = Suite(&sqlientSuite{}) | ||
184 | 112 | |||
185 | 102 | /***************************************************************** | 113 | /***************************************************************** |
186 | 103 | configure tests | 114 | configure tests |
187 | 104 | ******************************************************************/ | 115 | ******************************************************************/ |
188 | 105 | 116 | ||
189 | 106 | func (cs *clientSuite) TestConfigureWorks(c *C) { | 117 | func (cs *clientSuite) TestConfigureWorks(c *C) { |
191 | 107 | cli := NewPushClient(cs.configPath) | 118 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
192 | 108 | err := cli.configure() | 119 | err := cli.configure() |
193 | 109 | c.Assert(err, IsNil) | 120 | c.Assert(err, IsNil) |
194 | 110 | c.Assert(cli.config, NotNil) | 121 | c.Assert(cli.config, NotNil) |
195 | @@ -112,7 +123,7 @@ | |||
196 | 112 | } | 123 | } |
197 | 113 | 124 | ||
198 | 114 | func (cs *clientSuite) TestConfigureSetsUpLog(c *C) { | 125 | func (cs *clientSuite) TestConfigureSetsUpLog(c *C) { |
200 | 115 | cli := NewPushClient(cs.configPath) | 126 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
201 | 116 | c.Check(cli.log, IsNil) | 127 | c.Check(cli.log, IsNil) |
202 | 117 | err := cli.configure() | 128 | err := cli.configure() |
203 | 118 | c.Assert(err, IsNil) | 129 | c.Assert(err, IsNil) |
204 | @@ -120,7 +131,7 @@ | |||
205 | 120 | } | 131 | } |
206 | 121 | 132 | ||
207 | 122 | func (cs *clientSuite) TestConfigureSetsUpPEM(c *C) { | 133 | func (cs *clientSuite) TestConfigureSetsUpPEM(c *C) { |
209 | 123 | cli := NewPushClient(cs.configPath) | 134 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
210 | 124 | c.Check(cli.pem, IsNil) | 135 | c.Check(cli.pem, IsNil) |
211 | 125 | err := cli.configure() | 136 | err := cli.configure() |
212 | 126 | c.Assert(err, IsNil) | 137 | c.Assert(err, IsNil) |
213 | @@ -128,7 +139,7 @@ | |||
214 | 128 | } | 139 | } |
215 | 129 | 140 | ||
216 | 130 | func (cs *clientSuite) TestConfigureSetsUpIdder(c *C) { | 141 | func (cs *clientSuite) TestConfigureSetsUpIdder(c *C) { |
218 | 131 | cli := NewPushClient(cs.configPath) | 142 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
219 | 132 | c.Check(cli.idder, IsNil) | 143 | c.Check(cli.idder, IsNil) |
220 | 133 | err := cli.configure() | 144 | err := cli.configure() |
221 | 134 | c.Assert(err, IsNil) | 145 | c.Assert(err, IsNil) |
222 | @@ -136,7 +147,7 @@ | |||
223 | 136 | } | 147 | } |
224 | 137 | 148 | ||
225 | 138 | func (cs *clientSuite) TestConfigureSetsUpEndpoints(c *C) { | 149 | func (cs *clientSuite) TestConfigureSetsUpEndpoints(c *C) { |
227 | 139 | cli := NewPushClient(cs.configPath) | 150 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
228 | 140 | c.Check(cli.notificationsEndp, IsNil) | 151 | c.Check(cli.notificationsEndp, IsNil) |
229 | 141 | c.Check(cli.urlDispatcherEndp, IsNil) | 152 | c.Check(cli.urlDispatcherEndp, IsNil) |
230 | 142 | c.Check(cli.connectivityEndp, IsNil) | 153 | c.Check(cli.connectivityEndp, IsNil) |
231 | @@ -148,7 +159,7 @@ | |||
232 | 148 | } | 159 | } |
233 | 149 | 160 | ||
234 | 150 | func (cs *clientSuite) TestConfigureSetsUpConnCh(c *C) { | 161 | func (cs *clientSuite) TestConfigureSetsUpConnCh(c *C) { |
236 | 151 | cli := NewPushClient(cs.configPath) | 162 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
237 | 152 | c.Check(cli.connCh, IsNil) | 163 | c.Check(cli.connCh, IsNil) |
238 | 153 | err := cli.configure() | 164 | err := cli.configure() |
239 | 154 | c.Assert(err, IsNil) | 165 | c.Assert(err, IsNil) |
240 | @@ -156,13 +167,13 @@ | |||
241 | 156 | } | 167 | } |
242 | 157 | 168 | ||
243 | 158 | func (cs *clientSuite) TestConfigureBailsOnBadFilename(c *C) { | 169 | func (cs *clientSuite) TestConfigureBailsOnBadFilename(c *C) { |
245 | 159 | cli := NewPushClient("/does/not/exist") | 170 | cli := NewPushClient("/does/not/exist", cs.leveldbPath) |
246 | 160 | err := cli.configure() | 171 | err := cli.configure() |
247 | 161 | c.Assert(err, NotNil) | 172 | c.Assert(err, NotNil) |
248 | 162 | } | 173 | } |
249 | 163 | 174 | ||
250 | 164 | func (cs *clientSuite) TestConfigureBailsOnBadConfig(c *C) { | 175 | func (cs *clientSuite) TestConfigureBailsOnBadConfig(c *C) { |
252 | 165 | cli := NewPushClient("/etc/passwd") | 176 | cli := NewPushClient("/etc/passwd", cs.leveldbPath) |
253 | 166 | err := cli.configure() | 177 | err := cli.configure() |
254 | 167 | c.Assert(err, NotNil) | 178 | c.Assert(err, NotNil) |
255 | 168 | } | 179 | } |
256 | @@ -180,7 +191,7 @@ | |||
257 | 180 | "recheck_timeout": "3h" | 191 | "recheck_timeout": "3h" |
258 | 181 | }`), 0600) | 192 | }`), 0600) |
259 | 182 | 193 | ||
261 | 183 | cli := NewPushClient(cs.configPath) | 194 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
262 | 184 | err := cli.configure() | 195 | err := cli.configure() |
263 | 185 | c.Assert(err, ErrorMatches, "reading PEM file: .*") | 196 | c.Assert(err, ErrorMatches, "reading PEM file: .*") |
264 | 186 | } | 197 | } |
265 | @@ -198,7 +209,7 @@ | |||
266 | 198 | "recheck_timeout": "3h" | 209 | "recheck_timeout": "3h" |
267 | 199 | }`), 0600) | 210 | }`), 0600) |
268 | 200 | 211 | ||
270 | 201 | cli := NewPushClient(cs.configPath) | 212 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
271 | 202 | err := cli.configure() | 213 | err := cli.configure() |
272 | 203 | c.Assert(err, ErrorMatches, "no PEM found.*") | 214 | c.Assert(err, ErrorMatches, "no PEM found.*") |
273 | 204 | } | 215 | } |
274 | @@ -208,7 +219,7 @@ | |||
275 | 208 | ******************************************************************/ | 219 | ******************************************************************/ |
276 | 209 | 220 | ||
277 | 210 | func (cs *clientSuite) TestGetDeviceIdWorks(c *C) { | 221 | func (cs *clientSuite) TestGetDeviceIdWorks(c *C) { |
279 | 211 | cli := NewPushClient(cs.configPath) | 222 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
280 | 212 | cli.log = cs.log | 223 | cli.log = cs.log |
281 | 213 | cli.idder = identifier.New() | 224 | cli.idder = identifier.New() |
282 | 214 | c.Check(cli.deviceId, Equals, "") | 225 | c.Check(cli.deviceId, Equals, "") |
283 | @@ -217,7 +228,7 @@ | |||
284 | 217 | } | 228 | } |
285 | 218 | 229 | ||
286 | 219 | func (cs *clientSuite) TestGetDeviceIdCanFail(c *C) { | 230 | func (cs *clientSuite) TestGetDeviceIdCanFail(c *C) { |
288 | 220 | cli := NewPushClient(cs.configPath) | 231 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
289 | 221 | cli.log = cs.log | 232 | cli.log = cs.log |
290 | 222 | cli.idder = idtesting.Failing() | 233 | cli.idder = idtesting.Failing() |
291 | 223 | c.Check(cli.deviceId, Equals, "") | 234 | c.Check(cli.deviceId, Equals, "") |
292 | @@ -245,7 +256,7 @@ | |||
293 | 245 | ) | 256 | ) |
294 | 246 | testibus.SetWatchTicker(cEndp, make(chan bool)) | 257 | testibus.SetWatchTicker(cEndp, make(chan bool)) |
295 | 247 | // ok, create the thing | 258 | // ok, create the thing |
297 | 248 | cli := NewPushClient(cs.configPath) | 259 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
298 | 249 | cli.log = cs.log | 260 | cli.log = cs.log |
299 | 250 | err := cli.configure() | 261 | err := cli.configure() |
300 | 251 | c.Assert(err, IsNil) | 262 | c.Assert(err, IsNil) |
301 | @@ -273,7 +284,7 @@ | |||
302 | 273 | 284 | ||
303 | 274 | // takeTheBus can, in fact, fail | 285 | // takeTheBus can, in fact, fail |
304 | 275 | func (cs *clientSuite) TestTakeTheBusCanFail(c *C) { | 286 | func (cs *clientSuite) TestTakeTheBusCanFail(c *C) { |
306 | 276 | cli := NewPushClient(cs.configPath) | 287 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
307 | 277 | err := cli.configure() | 288 | err := cli.configure() |
308 | 278 | cli.log = cs.log | 289 | cli.log = cs.log |
309 | 279 | c.Assert(err, IsNil) | 290 | c.Assert(err, IsNil) |
310 | @@ -294,7 +305,7 @@ | |||
311 | 294 | ******************************************************************/ | 305 | ******************************************************************/ |
312 | 295 | 306 | ||
313 | 296 | func (cs *clientSuite) TestHandleErr(c *C) { | 307 | func (cs *clientSuite) TestHandleErr(c *C) { |
315 | 297 | cli := NewPushClient(cs.configPath) | 308 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
316 | 298 | cli.log = cs.log | 309 | cli.log = cs.log |
317 | 299 | c.Assert(cli.initSession(), IsNil) | 310 | c.Assert(cli.initSession(), IsNil) |
318 | 300 | cli.hasConnectivity = true | 311 | cli.hasConnectivity = true |
319 | @@ -303,11 +314,29 @@ | |||
320 | 303 | } | 314 | } |
321 | 304 | 315 | ||
322 | 305 | /***************************************************************** | 316 | /***************************************************************** |
323 | 317 | levelmapFactory tests | ||
324 | 318 | ******************************************************************/ | ||
325 | 319 | |||
326 | 320 | func (cs *clientSuite) TestLevelMapFactoryNoDbPath(c *C) { | ||
327 | 321 | cli := NewPushClient(cs.configPath, "") | ||
328 | 322 | ln, err := cli.levelMapFactory() | ||
329 | 323 | c.Assert(err, IsNil) | ||
330 | 324 | c.Check(fmt.Sprintf("%T", ln), Equals, "*levelmap.mapLevelMap") | ||
331 | 325 | } | ||
332 | 326 | |||
333 | 327 | func (cs *clientSuite) TestLevelMapFactoryWithDbPath(c *C) { | ||
334 | 328 | cli := NewPushClient(cs.configPath, ":memory:") | ||
335 | 329 | ln, err := cli.levelMapFactory() | ||
336 | 330 | c.Assert(err, IsNil) | ||
337 | 331 | c.Check(fmt.Sprintf("%T", ln), Equals, "*levelmap.sqliteLevelMap") | ||
338 | 332 | } | ||
339 | 333 | |||
340 | 334 | /***************************************************************** | ||
341 | 306 | handleConnState tests | 335 | handleConnState tests |
342 | 307 | ******************************************************************/ | 336 | ******************************************************************/ |
343 | 308 | 337 | ||
344 | 309 | func (cs *clientSuite) TestHandleConnStateD2C(c *C) { | 338 | func (cs *clientSuite) TestHandleConnStateD2C(c *C) { |
346 | 310 | cli := NewPushClient(cs.configPath) | 339 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
347 | 311 | cli.log = cs.log | 340 | cli.log = cs.log |
348 | 312 | c.Assert(cli.initSession(), IsNil) | 341 | c.Assert(cli.initSession(), IsNil) |
349 | 313 | 342 | ||
350 | @@ -318,7 +347,7 @@ | |||
351 | 318 | } | 347 | } |
352 | 319 | 348 | ||
353 | 320 | func (cs *clientSuite) TestHandleConnStateSame(c *C) { | 349 | func (cs *clientSuite) TestHandleConnStateSame(c *C) { |
355 | 321 | cli := NewPushClient(cs.configPath) | 350 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
356 | 322 | cli.log = cs.log | 351 | cli.log = cs.log |
357 | 323 | // here we want to check that we don't do anything | 352 | // here we want to check that we don't do anything |
358 | 324 | c.Assert(cli.session, IsNil) | 353 | c.Assert(cli.session, IsNil) |
359 | @@ -332,7 +361,7 @@ | |||
360 | 332 | } | 361 | } |
361 | 333 | 362 | ||
362 | 334 | func (cs *clientSuite) TestHandleConnStateC2D(c *C) { | 363 | func (cs *clientSuite) TestHandleConnStateC2D(c *C) { |
364 | 335 | cli := NewPushClient(cs.configPath) | 364 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
365 | 336 | cli.log = cs.log | 365 | cli.log = cs.log |
366 | 337 | cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, levelmap.NewLevelMap, cs.log) | 366 | cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, levelmap.NewLevelMap, cs.log) |
367 | 338 | cli.session.Dial() | 367 | cli.session.Dial() |
368 | @@ -345,7 +374,7 @@ | |||
369 | 345 | } | 374 | } |
370 | 346 | 375 | ||
371 | 347 | func (cs *clientSuite) TestHandleConnStateC2DPending(c *C) { | 376 | func (cs *clientSuite) TestHandleConnStateC2DPending(c *C) { |
373 | 348 | cli := NewPushClient(cs.configPath) | 377 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
374 | 349 | cli.log = cs.log | 378 | cli.log = cs.log |
375 | 350 | cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, levelmap.NewLevelMap, cs.log) | 379 | cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, levelmap.NewLevelMap, cs.log) |
376 | 351 | cli.hasConnectivity = true | 380 | cli.hasConnectivity = true |
377 | @@ -359,7 +388,7 @@ | |||
378 | 359 | ******************************************************************/ | 388 | ******************************************************************/ |
379 | 360 | 389 | ||
380 | 361 | func (cs *clientSuite) TestHandleNotification(c *C) { | 390 | func (cs *clientSuite) TestHandleNotification(c *C) { |
382 | 362 | cli := NewPushClient(cs.configPath) | 391 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
383 | 363 | endp := testibus.NewTestingEndpoint(nil, condition.Work(true), uint32(1)) | 392 | endp := testibus.NewTestingEndpoint(nil, condition.Work(true), uint32(1)) |
384 | 364 | cli.notificationsEndp = endp | 393 | cli.notificationsEndp = endp |
385 | 365 | cli.log = cs.log | 394 | cli.log = cs.log |
386 | @@ -372,7 +401,7 @@ | |||
387 | 372 | } | 401 | } |
388 | 373 | 402 | ||
389 | 374 | func (cs *clientSuite) TestHandleNotificationFail(c *C) { | 403 | func (cs *clientSuite) TestHandleNotificationFail(c *C) { |
391 | 375 | cli := NewPushClient(cs.configPath) | 404 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
392 | 376 | cli.log = cs.log | 405 | cli.log = cs.log |
393 | 377 | endp := testibus.NewTestingEndpoint(nil, condition.Work(false)) | 406 | endp := testibus.NewTestingEndpoint(nil, condition.Work(false)) |
394 | 378 | cli.notificationsEndp = endp | 407 | cli.notificationsEndp = endp |
395 | @@ -384,7 +413,7 @@ | |||
396 | 384 | ******************************************************************/ | 413 | ******************************************************************/ |
397 | 385 | 414 | ||
398 | 386 | func (cs *clientSuite) TestHandleClick(c *C) { | 415 | func (cs *clientSuite) TestHandleClick(c *C) { |
400 | 387 | cli := NewPushClient(cs.configPath) | 416 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
401 | 388 | cli.log = cs.log | 417 | cli.log = cs.log |
402 | 389 | endp := testibus.NewTestingEndpoint(nil, condition.Work(true), nil) | 418 | endp := testibus.NewTestingEndpoint(nil, condition.Work(true), nil) |
403 | 390 | cli.urlDispatcherEndp = endp | 419 | cli.urlDispatcherEndp = endp |
404 | @@ -401,7 +430,7 @@ | |||
405 | 401 | ******************************************************************/ | 430 | ******************************************************************/ |
406 | 402 | 431 | ||
407 | 403 | func (cs *clientSuite) TestDoLoopConn(c *C) { | 432 | func (cs *clientSuite) TestDoLoopConn(c *C) { |
409 | 404 | cli := NewPushClient(cs.configPath) | 433 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
410 | 405 | cli.log = cs.log | 434 | cli.log = cs.log |
411 | 406 | cli.connCh = make(chan bool, 1) | 435 | cli.connCh = make(chan bool, 1) |
412 | 407 | cli.connCh <- true | 436 | cli.connCh <- true |
413 | @@ -413,7 +442,7 @@ | |||
414 | 413 | } | 442 | } |
415 | 414 | 443 | ||
416 | 415 | func (cs *clientSuite) TestDoLoopClick(c *C) { | 444 | func (cs *clientSuite) TestDoLoopClick(c *C) { |
418 | 416 | cli := NewPushClient(cs.configPath) | 445 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
419 | 417 | cli.log = cs.log | 446 | cli.log = cs.log |
420 | 418 | c.Assert(cli.initSession(), IsNil) | 447 | c.Assert(cli.initSession(), IsNil) |
421 | 419 | aCh := make(chan notifications.RawActionReply, 1) | 448 | aCh := make(chan notifications.RawActionReply, 1) |
422 | @@ -426,7 +455,7 @@ | |||
423 | 426 | } | 455 | } |
424 | 427 | 456 | ||
425 | 428 | func (cs *clientSuite) TestDoLoopNotif(c *C) { | 457 | func (cs *clientSuite) TestDoLoopNotif(c *C) { |
427 | 429 | cli := NewPushClient(cs.configPath) | 458 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
428 | 430 | cli.log = cs.log | 459 | cli.log = cs.log |
429 | 431 | c.Assert(cli.initSession(), IsNil) | 460 | c.Assert(cli.initSession(), IsNil) |
430 | 432 | cli.session.MsgCh = make(chan *session.Notification, 1) | 461 | cli.session.MsgCh = make(chan *session.Notification, 1) |
431 | @@ -438,7 +467,7 @@ | |||
432 | 438 | } | 467 | } |
433 | 439 | 468 | ||
434 | 440 | func (cs *clientSuite) TestDoLoopErr(c *C) { | 469 | func (cs *clientSuite) TestDoLoopErr(c *C) { |
436 | 441 | cli := NewPushClient(cs.configPath) | 470 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
437 | 442 | cli.log = cs.log | 471 | cli.log = cs.log |
438 | 443 | c.Assert(cli.initSession(), IsNil) | 472 | c.Assert(cli.initSession(), IsNil) |
439 | 444 | cli.session.ErrCh = make(chan error, 1) | 473 | cli.session.ErrCh = make(chan error, 1) |
440 | @@ -454,7 +483,7 @@ | |||
441 | 454 | ******************************************************************/ | 483 | ******************************************************************/ |
442 | 455 | 484 | ||
443 | 456 | func (cs *clientSuite) TestDoStartWorks(c *C) { | 485 | func (cs *clientSuite) TestDoStartWorks(c *C) { |
445 | 457 | cli := NewPushClient(cs.configPath) | 486 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
446 | 458 | one_called := false | 487 | one_called := false |
447 | 459 | two_called := false | 488 | two_called := false |
448 | 460 | one := func() error { one_called = true; return nil } | 489 | one := func() error { one_called = true; return nil } |
449 | @@ -465,7 +494,7 @@ | |||
450 | 465 | } | 494 | } |
451 | 466 | 495 | ||
452 | 467 | func (cs *clientSuite) TestDoStartFailsAsExpected(c *C) { | 496 | func (cs *clientSuite) TestDoStartFailsAsExpected(c *C) { |
454 | 468 | cli := NewPushClient(cs.configPath) | 497 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
455 | 469 | one_called := false | 498 | one_called := false |
456 | 470 | two_called := false | 499 | two_called := false |
457 | 471 | failure := errors.New("Failure") | 500 | failure := errors.New("Failure") |
458 | @@ -481,7 +510,7 @@ | |||
459 | 481 | ******************************************************************/ | 510 | ******************************************************************/ |
460 | 482 | 511 | ||
461 | 483 | func (cs *clientSuite) TestLoop(c *C) { | 512 | func (cs *clientSuite) TestLoop(c *C) { |
463 | 484 | cli := NewPushClient(cs.configPath) | 513 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
464 | 485 | cli.connCh = make(chan bool) | 514 | cli.connCh = make(chan bool) |
465 | 486 | cli.sessionConnectedCh = make(chan uint32) | 515 | cli.sessionConnectedCh = make(chan uint32) |
466 | 487 | aCh := make(chan notifications.RawActionReply, 1) | 516 | aCh := make(chan notifications.RawActionReply, 1) |
467 | @@ -559,7 +588,7 @@ | |||
468 | 559 | c.Skip("no dbus") | 588 | c.Skip("no dbus") |
469 | 560 | } | 589 | } |
470 | 561 | 590 | ||
472 | 562 | cli := NewPushClient(cs.configPath) | 591 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
473 | 563 | // before start, everything sucks: | 592 | // before start, everything sucks: |
474 | 564 | // no config, | 593 | // no config, |
475 | 565 | c.Check(string(cli.config.Addr), Equals, "") | 594 | c.Check(string(cli.config.Addr), Equals, "") |
476 | @@ -588,7 +617,7 @@ | |||
477 | 588 | } | 617 | } |
478 | 589 | 618 | ||
479 | 590 | func (cs *clientSuite) TestStartCanFail(c *C) { | 619 | func (cs *clientSuite) TestStartCanFail(c *C) { |
481 | 591 | cli := NewPushClient("/does/not/exist") | 620 | cli := NewPushClient("/does/not/exist", cs.leveldbPath) |
482 | 592 | // easiest way for it to fail is to feed it a bad config | 621 | // easiest way for it to fail is to feed it a bad config |
483 | 593 | err := cli.Start() | 622 | err := cli.Start() |
484 | 594 | // and it works. Err. Doesn't. | 623 | // and it works. Err. Doesn't. |
good time to do: pushClient => PushClient ?
c.Check( fmt.Sprintf( "%T", ln), Equals, "*levelmap. sqliteLevelMap" )
maybe giving LevelMap again a String() ?