Пример #1
0
 def test_proxy_backend_provider(self):
   try:
     config, scope = build_proxy_configuration(add_share_adjusters=True)
     update_fn = scope.signal_update_fn
     ProxyBackendProvider.register(TstProxyBackend)
     backend = ProxyBackendProvider.get_backend(name=TstProxyBackend.NAME,
                                                configuration=config,
                                                signal_update_fn=update_fn)
     self.tst_proxy_backend(backend, scope)
   finally:
     ProxyBackendProvider.unregister(TstProxyBackend)
Пример #2
0
  def test_proxy_updater(self):
    arg_sets = []
    for add_s_a in [True, False]:
      config, scope = build_proxy_configuration(include_route_server=True,
                                                include_stream_server=False,
                                                include_route_share_adjusters=add_s_a,
                                                include_stream_share_adjusters=False)
      arg_sets.append((config, scope, add_s_a))

    try:
      ProxyBackendProvider.register(TstProxyBackend)
      for config, scope, add_share_adjusters in arg_sets:
        config, scope = build_proxy_configuration(include_route_server=True,
                                                  include_stream_server=False,
                                                  include_route_share_adjusters=True,
                                                  include_stream_share_adjusters=False)
        now = datetime.now()

        proxy_updater = ProxyUpdater(backend=TstProxyBackend.NAME,
                                     config=config,
                                     update_period=0,
                                     max_update_frequency=0)
        # Newly initialized proxy updater should need to update
        self.assertTrue(proxy_updater._should_update(now))
        proxy_updater._try_update(now)
        self.assertFalse(proxy_updater._should_update(now))

        # Newly started proxy updater should need to update
        proxy_updater.start(weight_adjustment_delay_seconds=0)
        self.assertTrue(proxy_updater._should_update(now))
        proxy_updater._try_update(now)
        self.assertFalse(proxy_updater._should_update(now))

        # Proxy updater that has been signaled by a source should need to
        # update
        scope.route_source.add(SourceEndpoint('127.0.0.1', 8080))
        self.assertTrue(proxy_updater._should_update(now))
        proxy_updater._try_update(now)
        self.assertFalse(proxy_updater._should_update(now))

        if add_share_adjusters:
          # Proxy updater that has been signaled by a share_adjuster should
          # need to update
          scope.route_share_adjuster.set_share(.5)
          self.assertTrue(proxy_updater._should_update(now))
          proxy_updater._try_update(now)
          self.assertFalse(proxy_updater._should_update(now))
    finally:
      ProxyBackendProvider.unregister(TstProxyBackend)
Пример #3
0
 def test_proxy_backend_provider(self):
     try:
         config, scope = build_proxy_configuration(
             include_route_server=True,
             include_stream_server=False,
             include_route_share_adjusters=True,
             include_stream_share_adjusters=False)
         update_fn = scope.signal_update_fn
         ProxyBackendProvider.register(TstProxyBackend)
         backend = ProxyBackendProvider.get_backend(
             name=TstProxyBackend.NAME,
             configuration=config,
             signal_update_fn=update_fn)
         self.tst_proxy_backend(backend, scope)
     finally:
         ProxyBackendProvider.unregister(TstProxyBackend)
Пример #4
0
 def __init__(self, backend, config, update_period, max_update_frequency):
     self._backend = ProxyBackendProvider.get_backend(
         backend, config, self._on_update)
     self._update_period = int(update_period)
     self._max_update_frequency = int(max_update_frequency)
     self._needs_update = True
     self._last_updated = datetime(1970, 1, 1)
     self._updating = False
Пример #5
0
 def __init__(self, backend, config, update_period, max_update_frequency):
   self._backend = ProxyBackendProvider.get_backend(backend,
                                                    config,
                                                    self._on_update)
   self._update_period = int(update_period)
   self._max_update_frequency = int(max_update_frequency)
   self._needs_update = True
   self._last_updated = datetime(1970, 1, 1)
   self._updating = False