Merge lp:~chipaca/ubuntu-push/levelmap into lp:ubuntu-push

Proposed by John Lenton
Status: Merged
Approved by: John Lenton
Approved revision: 34
Merged at revision: 33
Proposed branch: lp:~chipaca/ubuntu-push/levelmap
Merge into: lp:ubuntu-push
Prerequisite: lp:~chipaca/ubuntu-push/watchticker
Diff against target: 130 lines (+90/-3)
3 files modified
client/session/levelmap/levelmap.go (+46/-0)
client/session/levelmap/levelmap_test.go (+41/-0)
server/session/tracker_test.go (+3/-3)
To merge this branch: bzr merge lp:~chipaca/ubuntu-push/levelmap
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+203914@code.launchpad.net

Commit message

The client session level map. Interesting as an interface and not much more, right now.

Description of the change

The client session level map. Interesting as an interface and not much more, right now.

To post a comment you must log in.
lp:~chipaca/ubuntu-push/levelmap updated
34. By John Lenton

s/sessionSuite/trackerSuite/ in server/session/tracker_test.go

Revision history for this message
Samuele Pedroni (pedronis) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'client'
=== added directory 'client/session'
=== added directory 'client/session/levelmap'
=== added file 'client/session/levelmap/levelmap.go'
--- client/session/levelmap/levelmap.go 1970-01-01 00:00:00 +0000
+++ client/session/levelmap/levelmap.go 2014-01-30 12:56:19 +0000
@@ -0,0 +1,46 @@
1/*
2 Copyright 2013-2014 Canonical Ltd.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published
6 by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranties of
10 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program. If not, see <http://www.gnu.org/licenses/>.
15*/
16
17// levelmap holds an implementation of the LevelMap that the client
18// session uses to keep track of what messages it has seen.
19package levelmap
20
21// This implementation is memory-based and does not save state. There
22// is another one that stores the levels in sqlite that is missing a
23// few dependencies still.
24
25type LevelMap interface {
26 // Set() (re)sets the given level to the given value.
27 Set(level string, top int64)
28 // GetAll() returns a "simple" map of the current levels.
29 GetAll() map[string]int64
30}
31
32type mapLevelMap map[string]int64
33
34func (m *mapLevelMap) Set(level string, top int64) {
35 (*m)[level] = top
36}
37func (m *mapLevelMap) GetAll() map[string]int64 {
38 return map[string]int64(*m)
39}
40
41var _ LevelMap = &mapLevelMap{}
42
43// default constructor
44func NewLevelMap() LevelMap {
45 return &mapLevelMap{}
46}
047
=== added file 'client/session/levelmap/levelmap_test.go'
--- client/session/levelmap/levelmap_test.go 1970-01-01 00:00:00 +0000
+++ client/session/levelmap/levelmap_test.go 2014-01-30 12:56:19 +0000
@@ -0,0 +1,41 @@
1/*
2 Copyright 2013-2014 Canonical Ltd.
3
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published
6 by the Free Software Foundation.
7
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranties of
10 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along
14 with this program. If not, see <http://www.gnu.org/licenses/>.
15*/
16
17package levelmap
18
19import (
20 . "launchpad.net/gocheck"
21 "testing"
22)
23
24func TestLevelMap(t *testing.T) { TestingT(t) }
25
26type lmSuite struct{}
27
28var _ = Suite(&lmSuite{})
29
30func (cs *lmSuite) TestAllTheThings(c *C) {
31 // checks NewLevelMap returns a LevelMap
32 var lm LevelMap = NewLevelMap()
33 // setting a couple of things, sets them
34 lm.Set("this", 12)
35 lm.Set("that", 42)
36 c.Check(lm.GetAll(), DeepEquals, map[string]int64{"this": 12, "that": 42})
37 // re-setting one of them, resets it
38 lm.Set("this", 999)
39 c.Check(lm.GetAll(), DeepEquals, map[string]int64{"this": 999, "that": 42})
40 // huzzah
41}
042
=== modified file 'server/session/tracker_test.go'
--- server/session/tracker_test.go 2014-01-23 20:13:22 +0000
+++ server/session/tracker_test.go 2014-01-30 12:56:19 +0000
@@ -36,7 +36,7 @@
36 return &net.TCPAddr{net.IPv4(127, 0, 0, 1), 9999, ""}36 return &net.TCPAddr{net.IPv4(127, 0, 0, 1), 9999, ""}
37}37}
3838
39func (s *sessionSuite) TestSessionTrackStart(c *C) {39func (s *trackerSuite) TestSessionTrackStart(c *C) {
40 buf := &bytes.Buffer{}40 buf := &bytes.Buffer{}
41 logger := logger.NewSimpleLogger(buf, "debug")41 logger := logger.NewSimpleLogger(buf, "debug")
42 track := NewTracker(logger)42 track := NewTracker(logger)
@@ -46,7 +46,7 @@
46 c.Check(buf.String(), Matches, regExpected)46 c.Check(buf.String(), Matches, regExpected)
47}47}
4848
49func (s *sessionSuite) TestSessionTrackRegistered(c *C) {49func (s *trackerSuite) TestSessionTrackRegistered(c *C) {
50 buf := &bytes.Buffer{}50 buf := &bytes.Buffer{}
51 logger := logger.NewSimpleLogger(buf, "debug")51 logger := logger.NewSimpleLogger(buf, "debug")
52 track := NewTracker(logger)52 track := NewTracker(logger)
@@ -56,7 +56,7 @@
56 c.Check(buf.String(), Matches, regExpected)56 c.Check(buf.String(), Matches, regExpected)
57}57}
5858
59func (s *sessionSuite) TestSessionTrackEnd(c *C) {59func (s *trackerSuite) TestSessionTrackEnd(c *C) {
60 buf := &bytes.Buffer{}60 buf := &bytes.Buffer{}
61 logger := logger.NewSimpleLogger(buf, "debug")61 logger := logger.NewSimpleLogger(buf, "debug")
62 track := NewTracker(logger)62 track := NewTracker(logger)

Subscribers

People subscribed via source and target branches