| 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 |
// Package testing contains simple test implementations of some broker interfaces. |
| 18 |
package testing |
| 19 |
|
| 20 |
import ( |
| 21 |
"gitlab.com/ubports/development/core/lomiri-push-service/protocol" |
| 22 |
"gitlab.com/ubports/development/core/lomiri-push-service/server/broker" |
| 23 |
"gitlab.com/ubports/development/core/lomiri-push-service/server/store" |
| 24 |
) |
| 25 |
|
| 26 |
// Test implementation of BrokerSession. |
| 27 |
type TestBrokerSession struct { |
| 28 |
DeviceId string |
| 29 |
Model string |
| 30 |
ImageChannel string |
| 31 |
Exchanges chan broker.Exchange |
| 32 |
LevelsMap broker.LevelsMap |
| 33 |
exchgScratch broker.ExchangesScratchArea |
| 34 |
// hooks |
| 35 |
DoGet func(store.InternalChannelId, bool) (int64, []protocol.Notification, error) |
| 36 |
DoDropByMsgId func(store.InternalChannelId, []protocol.Notification) error |
| 37 |
} |
| 38 |
|
| 39 |
func (tbs *TestBrokerSession) DeviceIdentifier() string { |
| 40 |
return tbs.DeviceId |
| 41 |
} |
| 42 |
|
| 43 |
func (tbs *TestBrokerSession) DeviceImageModel() string { |
| 44 |
return tbs.Model |
| 45 |
} |
| 46 |
|
| 47 |
func (tbs *TestBrokerSession) DeviceImageChannel() string { |
| 48 |
return tbs.ImageChannel |
| 49 |
} |
| 50 |
|
| 51 |
func (tbs *TestBrokerSession) SessionChannel() <-chan broker.Exchange { |
| 52 |
return tbs.Exchanges |
| 53 |
} |
| 54 |
|
| 55 |
func (tbs *TestBrokerSession) Levels() broker.LevelsMap { |
| 56 |
return tbs.LevelsMap |
| 57 |
} |
| 58 |
|
| 59 |
func (tbs *TestBrokerSession) ExchangeScratchArea() *broker.ExchangesScratchArea { |
| 60 |
return &tbs.exchgScratch |
| 61 |
} |
| 62 |
|
| 63 |
func (tbs *TestBrokerSession) Get(chanId store.InternalChannelId, cachedOk bool) (int64, []protocol.Notification, error) { |
| 64 |
return tbs.DoGet(chanId, cachedOk) |
| 65 |
} |
| 66 |
|
| 67 |
func (tbs *TestBrokerSession) DropByMsgId(chanId store.InternalChannelId, targets []protocol.Notification) error { |
| 68 |
return tbs.DoDropByMsgId(chanId, targets) |
| 69 |
} |
| 70 |
|
| 71 |
func (tbs *TestBrokerSession) Feed(exchg broker.Exchange) { |
| 72 |
tbs.Exchanges <- exchg |
| 73 |
} |
| 74 |
|
| 75 |
func (tbs *TestBrokerSession) InternalChannelId() store.InternalChannelId { |
| 76 |
return store.UnicastInternalChannelId(tbs.DeviceId, tbs.DeviceId) |
| 77 |
} |
| 78 |
|
| 79 |
// Test implementation of BrokerConfig. |
| 80 |
type TestBrokerConfig struct { |
| 81 |
ConfigSessionQueueSize uint |
| 82 |
ConfigBrokerQueueSize uint |
| 83 |
} |
| 84 |
|
| 85 |
func (tbc *TestBrokerConfig) SessionQueueSize() uint { |
| 86 |
return tbc.ConfigSessionQueueSize |
| 87 |
} |
| 88 |
|
| 89 |
func (tbc *TestBrokerConfig) BrokerQueueSize() uint { |
| 90 |
return tbc.ConfigBrokerQueueSize |
| 91 |
} |