Exemplo n.º 1
0
 def setUp(self):
     self.rethinker = doublethink.Rethinker(
         db=random_db, servers=settings['RETHINKDB_HOSTS'])
     self.services = doublethink.ServiceRegistry(self.rethinker)
     self.registry = sync.HostRegistry(rethinker=self.rethinker,
                                       services=self.services)
     self.snakebite_client = mock.Mock()
     self.rethinker.table("services").delete().run()
Exemplo n.º 2
0
 def setUp(self):
     self.rethinker = doublethink.Rethinker(
         db=random_db, servers=settings['RETHINKDB_HOSTS'])
     self.services = doublethink.ServiceRegistry(self.rethinker)
     self.registry = sync.HostRegistry(rethinker=self.rethinker,
                                       services=self.services)
     sync.init(self.rethinker)
     self.rethinker.table("services").delete().run()
     self.rethinker.table("lock").delete().run()
     self.rethinker.table("assignment").delete().run()
Exemplo n.º 3
0
 def test_get_hosts(self):
     hostname = 'test.example.com'
     registry = sync.HostRegistry(rethinker=self.rethinker,
                                  services=self.services)
     registry.heartbeat(pool='trough-nodes',
                        service_id='trough:nodes:%s' % hostname,
                        node=hostname,
                        ttl=0.6)
     output = registry.get_hosts()
     self.assertEqual(output[0]['node'], "test.example.com")
Exemplo n.º 4
0
 def test_assign(self):
     registry = sync.HostRegistry(rethinker=self.rethinker,
                                  services=self.services)
     segment = sync.Segment('123456',
                            services=self.services,
                            rethinker=self.rethinker,
                            registry=registry,
                            size=1024)
     registry.assign('localhost', segment, '/fake/path')
     self.assertEqual(registry.assignment_queue._queue[0]['id'],
                      'localhost:123456')
     return (segment, registry)
Exemplo n.º 5
0
 def test_readable_copies(self):
     registry = sync.HostRegistry(rethinker=self.rethinker,
                                  services=self.services)
     segment = sync.Segment('test-segment',
                            services=self.services,
                            rethinker=self.rethinker,
                            registry=self.registry,
                            size=100)
     registry.heartbeat(pool='trough-read',
                        node=settings['HOSTNAME'],
                        ttl=0.4,
                        segment=segment.id)
     output = segment.readable_copies()
     output = list(output)
     self.assertEqual(output[0]['node'], settings['HOSTNAME'])
Exemplo n.º 6
0
 def test_all_copies(self):
     registry = sync.HostRegistry(rethinker=self.rethinker,
                                  services=self.services)
     segment = sync.Segment('test-segment',
                            services=self.services,
                            rethinker=self.rethinker,
                            registry=self.registry,
                            size=100)
     registry.assign(hostname='test-pool',
                     segment=segment,
                     remote_path="/fake/path")
     registry.commit_assignments()
     output = segment.all_copies()
     output = [item for item in output]
     self.assertEqual(output[0]['id'], 'test-pool:test-segment')
Exemplo n.º 7
0
 def test_heartbeat(self):
     '''This function unusually produces indeterminate output.'''
     hostname = 'test.example.com'
     registry = sync.HostRegistry(rethinker=self.rethinker,
                                  services=self.services)
     registry.heartbeat(pool='trough-nodes',
                        service_id='trough:nodes:%s' % hostname,
                        node=hostname,
                        ttl=0.3,
                        available_bytes=1024 * 1024)
     hosts = registry.get_hosts()
     self.assertEqual(hosts[0]["node"], hostname)
     time.sleep(0.4)
     hosts = registry.get_hosts()
     self.assertEqual(hosts, [])
Exemplo n.º 8
0
 def test_is_assigned_to_host(self):
     segment = sync.Segment('test-segment',
                            services=self.services,
                            rethinker=self.rethinker,
                            registry=self.registry,
                            size=100)
     registry = sync.HostRegistry(rethinker=self.rethinker,
                                  services=self.services)
     registry.assign(hostname='assigned',
                     segment=segment,
                     remote_path="/fake/path")
     registry.commit_assignments()
     output = segment.is_assigned_to_host('not-assigned')
     self.assertFalse(output)
     output = segment.is_assigned_to_host('assigned')
     self.assertTrue(output)
Exemplo n.º 9
0
 def test_segments_for_host(self):
     registry = sync.HostRegistry(rethinker=self.rethinker,
                                  services=self.services)
     segment = sync.Segment('123456',
                            services=self.services,
                            rethinker=self.rethinker,
                            registry=registry,
                            size=1024)
     asmt = registry.assign('localhost', segment, '/fake/path')
     registry.commit_assignments()
     output = registry.segments_for_host('localhost')
     self.assertEqual(output[0].id, '123456')
     registry.unassign(asmt)
     registry.commit_unassignments()
     output = registry.segments_for_host('localhost')
     self.assertEqual(output, [])