def test_returns_singleton_list_for_zero_clients(self):
   unplaced_factory = executor_stacks.UnplacedExecutorFactory(use_caching=True)
   federating_factory = executor_stacks.FederatingExecutorFactory(
       clients_per_thread=1, unplaced_ex_factory=unplaced_factory)
   flat_stack_fn = executor_stacks.create_minimal_length_flat_stack_fn(
       3, federating_factory)
   executor_list = flat_stack_fn({placement_literals.CLIENTS: 0})
   self.assertLen(executor_list, 1)
 def test_callable_raises_negative_clients(self):
   unplaced_factory = executor_stacks.UnplacedExecutorFactory(use_caching=True)
   federating_factory = executor_stacks.FederatingExecutorFactory(
       clients_per_thread=1, unplaced_ex_factory=unplaced_factory)
   flat_stack_fn = executor_stacks.create_minimal_length_flat_stack_fn(
       2, federating_factory)
   with self.assertRaises(ValueError):
     flat_stack_fn({placement_literals.CLIENTS: -1})
 def test_constructs_correct_length_list(self, max_clients_per_stack,
                                         num_clients):
   unplaced_factory = executor_stacks.UnplacedExecutorFactory(use_caching=True)
   federating_factory = executor_stacks.FederatingExecutorFactory(
       clients_per_thread=1, unplaced_ex_factory=unplaced_factory)
   flat_stack_fn = executor_stacks.create_minimal_length_flat_stack_fn(
       max_clients_per_stack, federating_factory)
   executor_list = flat_stack_fn({placement_literals.CLIENTS: num_clients})
   self.assertLen(executor_list,
                  math.ceil(num_clients / max_clients_per_stack))
 def test_construction_raises_with_max_fanout_one(self):
   unplaced_factory = executor_stacks.UnplacedExecutorFactory(use_caching=True)
   federating_factory = executor_stacks.FederatingExecutorFactory(
       clients_per_thread=1, unplaced_ex_factory=unplaced_factory)
   flat_stack_fn = executor_stacks.create_minimal_length_flat_stack_fn(
       2, federating_factory)
   with self.assertRaises(ValueError):
     executor_stacks.ComposingExecutorFactory(
         max_fanout=1,
         unplaced_ex_factory=unplaced_factory,
         flat_stack_fn=flat_stack_fn)
 def test_creates_executor_with_small_fanout(self):
   unplaced_factory = executor_stacks.UnplacedExecutorFactory(use_caching=True)
   federating_factory = executor_stacks.FederatingExecutorFactory(
       clients_per_thread=1, unplaced_ex_factory=unplaced_factory)
   flat_stack_fn = executor_stacks.create_minimal_length_flat_stack_fn(
       2, federating_factory)
   composing_ex_factory = executor_stacks.ComposingExecutorFactory(
       max_fanout=2,
       unplaced_ex_factory=unplaced_factory,
       flat_stack_fn=flat_stack_fn)
   ex = composing_ex_factory.create_executor({placement_literals.CLIENTS: 10})
   self.assertIsInstance(ex, executor_base.Executor)
 def test_constructs_executor_factory_with_federated_factory(self):
   unplaced_factory = executor_stacks.UnplacedExecutorFactory(use_caching=True)
   federating_factory = executor_stacks.FederatingExecutorFactory(
       clients_per_thread=1, unplaced_ex_factory=unplaced_factory)
   flat_stack_fn = executor_stacks.create_minimal_length_flat_stack_fn(
       2, federating_factory)
   composing_ex_factory = executor_stacks.ComposingExecutorFactory(
       max_fanout=2,
       unplaced_ex_factory=unplaced_factory,
       flat_stack_fn=flat_stack_fn)
   self.assertIsInstance(composing_ex_factory,
                         executor_factory.ExecutorFactory)
Esempio n. 7
0
 def test_executor_with_small_fanout_calls_correct_number_of_composing_strategies(
         self, composing_strategy_mock):
     num_clients = 10
     max_fanout = 2
     clients_per_thread = 1
     unplaced_factory = executor_stacks.UnplacedExecutorFactory(
         use_caching=True)
     federating_factory = executor_stacks.FederatingExecutorFactory(
         clients_per_thread=clients_per_thread,
         unplaced_ex_factory=unplaced_factory)
     flat_stack_fn = executor_stacks.create_minimal_length_flat_stack_fn(
         2, federating_factory)
     composing_ex_factory = executor_stacks.ComposingExecutorFactory(
         max_fanout=max_fanout,
         unplaced_ex_factory=unplaced_factory,
         flat_stack_fn=flat_stack_fn)
     composing_ex_factory.create_executor({placements.CLIENTS: num_clients})
     args_list = composing_strategy_mock.call_args_list
     # 5 at the first layer, 1 at the second
     self.assertLen(args_list, 6)