diff --git a/lib/carbon/routers.py b/lib/carbon/routers.py index 9b8d8ef1..72d93cfa 100644 --- a/lib/carbon/routers.py +++ b/lib/carbon/routers.py @@ -31,6 +31,29 @@ def getDestinations(self, key): raise NotImplementedError() +class ConstantRouter(DatapointRouter): + plugin_name = 'constant' + + def __init__(self, settings): + self.destinations = set() + + def addDestination(self, destination): + self.destinations.add(destination) + + def removeDestination(self, destination): + self.destinations.discard(destination) + + def hasDestination(self, destination): + return destination in self.destinations + + def countDestinations(self): + return len(self.destinations) + + def getDestinations(self, key): + for destination in self.destinations: + yield destination + + class RelayRulesRouter(DatapointRouter): plugin_name = 'rules' diff --git a/lib/carbon/tests/test_routers.py b/lib/carbon/tests/test_routers.py index f6309e8f..8cc3e476 100644 --- a/lib/carbon/tests/test_routers.py +++ b/lib/carbon/tests/test_routers.py @@ -54,5 +54,5 @@ def testBasic(self): router.addDestination(parseDestination(destination)) self.assertEqual( len(list(router.getDestinations('foo.bar'))), - settings['REPLICATION_FACTOR'] + len(DESTINATIONS) if plugin == 'constant' else settings['REPLICATION_FACTOR'] )