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
1=== added directory 'client'
2=== added directory 'client/session'
3=== added directory 'client/session/levelmap'
4=== added file 'client/session/levelmap/levelmap.go'
5--- client/session/levelmap/levelmap.go 1970-01-01 00:00:00 +0000
6+++ client/session/levelmap/levelmap.go 2014-01-30 12:56:19 +0000
7@@ -0,0 +1,46 @@
8+/*
9+ Copyright 2013-2014 Canonical Ltd.
10+
11+ This program is free software: you can redistribute it and/or modify it
12+ under the terms of the GNU General Public License version 3, as published
13+ by the Free Software Foundation.
14+
15+ This program is distributed in the hope that it will be useful, but
16+ WITHOUT ANY WARRANTY; without even the implied warranties of
17+ MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
18+ PURPOSE. See the GNU General Public License for more details.
19+
20+ You should have received a copy of the GNU General Public License along
21+ with this program. If not, see <http://www.gnu.org/licenses/>.
22+*/
23+
24+// levelmap holds an implementation of the LevelMap that the client
25+// session uses to keep track of what messages it has seen.
26+package levelmap
27+
28+// This implementation is memory-based and does not save state. There
29+// is another one that stores the levels in sqlite that is missing a
30+// few dependencies still.
31+
32+type LevelMap interface {
33+ // Set() (re)sets the given level to the given value.
34+ Set(level string, top int64)
35+ // GetAll() returns a "simple" map of the current levels.
36+ GetAll() map[string]int64
37+}
38+
39+type mapLevelMap map[string]int64
40+
41+func (m *mapLevelMap) Set(level string, top int64) {
42+ (*m)[level] = top
43+}
44+func (m *mapLevelMap) GetAll() map[string]int64 {
45+ return map[string]int64(*m)
46+}
47+
48+var _ LevelMap = &mapLevelMap{}
49+
50+// default constructor
51+func NewLevelMap() LevelMap {
52+ return &mapLevelMap{}
53+}
54
55=== added file 'client/session/levelmap/levelmap_test.go'
56--- client/session/levelmap/levelmap_test.go 1970-01-01 00:00:00 +0000
57+++ client/session/levelmap/levelmap_test.go 2014-01-30 12:56:19 +0000
58@@ -0,0 +1,41 @@
59+/*
60+ Copyright 2013-2014 Canonical Ltd.
61+
62+ This program is free software: you can redistribute it and/or modify it
63+ under the terms of the GNU General Public License version 3, as published
64+ by the Free Software Foundation.
65+
66+ This program is distributed in the hope that it will be useful, but
67+ WITHOUT ANY WARRANTY; without even the implied warranties of
68+ MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
69+ PURPOSE. See the GNU General Public License for more details.
70+
71+ You should have received a copy of the GNU General Public License along
72+ with this program. If not, see <http://www.gnu.org/licenses/>.
73+*/
74+
75+package levelmap
76+
77+import (
78+ . "launchpad.net/gocheck"
79+ "testing"
80+)
81+
82+func TestLevelMap(t *testing.T) { TestingT(t) }
83+
84+type lmSuite struct{}
85+
86+var _ = Suite(&lmSuite{})
87+
88+func (cs *lmSuite) TestAllTheThings(c *C) {
89+ // checks NewLevelMap returns a LevelMap
90+ var lm LevelMap = NewLevelMap()
91+ // setting a couple of things, sets them
92+ lm.Set("this", 12)
93+ lm.Set("that", 42)
94+ c.Check(lm.GetAll(), DeepEquals, map[string]int64{"this": 12, "that": 42})
95+ // re-setting one of them, resets it
96+ lm.Set("this", 999)
97+ c.Check(lm.GetAll(), DeepEquals, map[string]int64{"this": 999, "that": 42})
98+ // huzzah
99+}
100
101=== modified file 'server/session/tracker_test.go'
102--- server/session/tracker_test.go 2014-01-23 20:13:22 +0000
103+++ server/session/tracker_test.go 2014-01-30 12:56:19 +0000
104@@ -36,7 +36,7 @@
105 return &net.TCPAddr{net.IPv4(127, 0, 0, 1), 9999, ""}
106 }
107
108-func (s *sessionSuite) TestSessionTrackStart(c *C) {
109+func (s *trackerSuite) TestSessionTrackStart(c *C) {
110 buf := &bytes.Buffer{}
111 logger := logger.NewSimpleLogger(buf, "debug")
112 track := NewTracker(logger)
113@@ -46,7 +46,7 @@
114 c.Check(buf.String(), Matches, regExpected)
115 }
116
117-func (s *sessionSuite) TestSessionTrackRegistered(c *C) {
118+func (s *trackerSuite) TestSessionTrackRegistered(c *C) {
119 buf := &bytes.Buffer{}
120 logger := logger.NewSimpleLogger(buf, "debug")
121 track := NewTracker(logger)
122@@ -56,7 +56,7 @@
123 c.Check(buf.String(), Matches, regExpected)
124 }
125
126-func (s *sessionSuite) TestSessionTrackEnd(c *C) {
127+func (s *trackerSuite) TestSessionTrackEnd(c *C) {
128 buf := &bytes.Buffer{}
129 logger := logger.NewSimpleLogger(buf, "debug")
130 track := NewTracker(logger)

Subscribers

People subscribed via source and target branches