Skip to content
Snippets Groups Projects
Select Git revision
  • main default protected
  • java-operator-sdk
  • rework-state-handling
  • quarkus-36
  • bump-kotlinlogging-to-5.0.2
  • improve-patcher-documentation
  • use-internal-registry protected
  • v0.9 protected
  • kafka-nodeport-config-windows
  • v0.8 protected
  • test-k3d protected
  • simpleuc4 protected
  • reduce-code-duplication
  • test-coverage
  • code-cleanup
  • cleanup-commit-interval protected
  • delete-action-for-other-namespace
  • master protected
  • add-helm-test-debug2
  • add-helm-test-debug
  • v0.9.0 protected
  • v0.8.6 protected
  • v0.8.5 protected
  • v0.8.4 protected
  • v0.8.3 protected
  • v0.8.2 protected
  • v0.8.1 protected
  • v0.8.0 protected
  • v0.7.0 protected
  • v0.5.2 protected
  • v0.6.4 protected
  • v0.6.3 protected
  • v0.6.2 protected
  • v0.6.1 protected
  • v0.6.0 protected
  • v0.5.1 protected
  • v0.5.0 protected
  • v0.4.0 protected
  • v0.3.0 protected
  • v0.2.0 protected
40 results

test_binary_search_strategy.py

Blame
  • user avatar
    Simon Ehrenstein authored
    86597127
    History
    test_binary_search_strategy.py 3.05 KiB
    import pprint
    
    from strategies.config import ExperimentConfig
    import strategies.strategies.binary_search_strategy as binary_search_strategy
    from strategies.experiment_execution import ExperimentExecutor
    import strategies.subexperiment_execution.subexperiment_executor as subexperiment_executor
    
    class Object(object):
        pass
    
    pp = pprint.PrettyPrinter(indent=4)
    
    dim_values = [0, 1, 2, 3, 4, 5, 6]
    replicas = [0, 1, 2, 3, 4, 5, 6]
    
    # True means the experiment was successful
    # the experiments are indexed row (representing dimension values) and column (representing number of replicas) wise as usual arrays from 0 - 6 respectively.
    # this means the first row starts with (0,0), the second row with (1, 0) etc.
    successful = [
           [ True , True , True , True , True , True , True  ],
           [ False, False, True , True , True , True , True  ],
           [ False, False, True , True , True , True , True  ],
           [ False, False, False, True , True , True , True  ],
           [ False, False, False, False, True , True , True  ],
           [ False, False, False, False, False, False, True  ],
           [ False, False, False, False, False, False, False ] 
        ]
    
    expected_order = [
            (3,0), # interval (0, 6)
            (1,0), 
            (0,0),
            (3,1), # interval (0, 6)
            (1,1),
            (3,2), # interval (0, 6)
            (1,2),
            (2,2),
            (4,3), # interval (3, 6)
            (3,3),
            (5,4), # interval (4, 6)
            (4,4),
            (5,5), # interval (5,6)
            (5,6), # interval (5,6)
            (6,6)
        ]
    
    last_experiment = (0, 0)
    experiment_counter = -1
    subexperiment_executor = Object()
    
    def subexperiment_executor_executor(config):
        global experiment_counter, last_experiment, pp
        print("Simulate subexperiment with config:")
        pp.pprint(config)
        last_experiment = (config.dim_value, config.replicas)
        experiment_counter += 1
        print("Simulation complete")
    
    subexperiment_executor.execute = subexperiment_executor_executor
    
    
    # returns True if the experiment was successful
    
    subexperiment_evaluator = Object()
    
    def subexperiment_evaluator_execute():
        print("Evaluating last experiment. Index was:")
        global expected_order, experiment_counter, last_experiment, successful
        pp.pprint(last_experiment)
        print("Index was expected to be:")
        pp.pprint(expected_order[experiment_counter])
        assert expected_order[experiment_counter] == last_experiment
        print("Index was as expected. Evaluation finished.")
        return 1 if successful[last_experiment[0]][last_experiment[1]] else 0
    
    subexperiment_evaluator.execute = subexperiment_evaluator_execute
    
    def test_binary_search_strategy():
        # declare parameters
        uc="test-uc"
        partitions=40
        cpu_limit="1000m"
        memory_limit="4Gi"
        kafka_streams_commit_interval_ms=100
        execution_minutes=5
    
        # execute
        experiment_config = ExperimentConfig(uc, dim_values, replicas, partitions, cpu_limit, memory_limit, kafka_streams_commit_interval_ms, execution_minutes, binary_search_strategy, subexperiment_executor, subexperiment_evaluator)
        executor = ExperimentExecutor(experiment_config)
        executor.execute()