예제 #1
0
  def setUp(self):
    super(TestCacheSetup, self).setUp()

    self.resolver = Mock(spec=Resolver)
    self.resolver.resolve = Mock(return_value=[self.REMOTE_URI_1, self.REMOTE_URI_2])
    self.log = MockLogger()
    self.pinger = MockPinger({'host1': 5, 'host2:666': 3, 'host3': 7})
    options = Mock()
    options.pinger_timeout = .5
    options.pinger_tries = 2
    options.read_from = [self.EMPTY_URI]
    options.write_to = [self.EMPTY_URI]
    options.compression_level = 1
    self.cache_factory = CacheFactory(options=options, log=MockLogger(),
                                 stable_name='test', resolver=self.resolver)
예제 #2
0
  def setUp(self):
    super(TestCacheSetup, self).setUp()

    self.resolver = Mock(spec=Resolver)
    self.resolver.resolve = Mock(return_value=[self.REMOTE_URI_1, self.REMOTE_URI_2])
    self.log = MockLogger()
    self.pinger = MockPinger({'host1': 5, 'host2:666': 3, 'host3': 7})
예제 #3
0
 def mk_cache(spec):
     return create_artifact_cache(MockLogger(),
                                  artifact_root,
                                  spec,
                                  'TestTask',
                                  compression=1,
                                  action='testing')
예제 #4
0
 def test_select_best_url(self):
     spec = 'http://host1|https://host2:666/path/to|http://host3/path/'
     best = select_best_url(
         spec, MockPinger({
             'host1': 5,
             'host2:666': 3,
             'host3': 7
         }), MockLogger())
     self.assertEquals('https://host2:666/path/to', best)
예제 #5
0
 def test_select_best_url(self):
     log = MockLogger()
     pinger = MockPinger({'host1': 5, 'host2:666': 3, 'host3': 7})
     cache_factory = CacheFactory(options={},
                                  log=log,
                                  stable_name='test',
                                  pinger=pinger)
     spec = 'http://host1|https://host2:666/path/to|http://host3/path/'
     best = cache_factory.select_best_url(spec)
     self.assertEquals('https://host2:666/path/to', best)
예제 #6
0
 def cache_factory(self, **options):
   cache_options = {
     'pinger_timeout': .5,
     'pinger_tries': 2,
     'ignore': False,
     'read': False,
     'read_from': [self.EMPTY_URI],
     'write_to': [self.EMPTY_URI],
     'write': False,
     'compression_level': 1,
     'max_entries_per_target': 1,
     'write_permissions': None,
     'dereference_symlinks': True,
     # Usually read from global scope.
     'pants_workdir': self.pants_workdir
   }
   cache_options.update(**options)
   return CacheFactory(create_options(options={'test': cache_options}).for_scope('test'),
                       MockLogger(),
                       self.create_task(),
                       resolver=self.resolver)
예제 #7
0
 def test_restful_cache(self):
     httpd = None
     httpd_thread = None
     try:
         with temporary_dir() as cache_root:
             with pushd(
                     cache_root):  # SimpleRESTHandler serves from the cwd.
                 httpd = SocketServer.TCPServer(('localhost', 0),
                                                SimpleRESTHandler)
                 port = httpd.server_address[1]
                 httpd_thread = Thread(target=httpd.serve_forever)
                 httpd_thread.start()
                 with temporary_dir() as artifact_root:
                     artifact_cache = RESTfulArtifactCache(
                         MockLogger(), artifact_root,
                         'http://localhost:%d' % port)
                     self.do_test_artifact_cache(artifact_cache)
     finally:
         if httpd:
             httpd.shutdown()
         if httpd_thread:
             httpd_thread.join()
예제 #8
0
class DummyContext(object):
    log = MockLogger()
예제 #9
0
def make_dag(nodes):
    return DoubleDag(nodes, lambda t: t.dependencies, MockLogger(Report.INFO))
예제 #10
0
 def check(expected_type, spec):
     cache = create_artifact_cache(MockLogger(), artifact_root, spec,
                                   'TestTask', 'testing')
     self.assertTrue(isinstance(cache, expected_type))
     self.assertEquals(cache.artifact_root, artifact_root)