Пример #1
0
 def test_fail_if_supports_runtime_stats(self):
     stats = Stats()
     stats.measure(103.2)
     stats.measure(205.2)
     timed_stats = TimedStats(1, 2, stats)
     result = Result({}, 'select name', timed_stats, 1)
     with self.assertRaises(FailIf):
         eval_fail_if("{runtime_stats.max} > 30", result)
Пример #2
0
def timeit(hosts=None,
           stmt=None,
           warmup=30,
           repeat=None,
           duration=None,
           concurrency=1,
           output_fmt=None,
           fail_if=None,
           sample_mode='reservoir'):
    """Run the given statement a number of times and return the runtime stats

    Args:
        fail-if: An expression that causes cr8 to exit with a failure if it
            evaluates to true.
            The expression can contain formatting expressions for:
                - runtime_stats
                - statement
                - meta
                - concurrency
                - bulk_size
            For example:
                --fail-if "{runtime_stats.mean} > 1.34"
    """
    num_lines = 0
    log = Logger(output_fmt)
    with Runner(hosts, concurrency, sample_mode) as runner:
        try:
            version_info = aio.run(runner.client.get_server_version)
        except Exception:
            result = aio.run(runner.client.execute, 'select version()')
            version_info = {'hash': None, 'number': result['rows'][0][0]}
        for line in as_statements(lines_from_stdin(stmt)):
            runner.warmup(line, warmup)
            timed_stats = runner.run(line,
                                     iterations=repeat,
                                     duration=duration)
            r = Result(version_info=version_info,
                       statement=line,
                       timed_stats=timed_stats,
                       concurrency=concurrency)
            log.result(r)
            if fail_if:
                eval_fail_if(fail_if, r)
        num_lines += 1
    if num_lines == 0:
        raise SystemExit(
            'No SQL statements provided. Use --stmt or provide statements via stdin'
        )
Пример #3
0
 def test_fail_if_fails(self):
     timed_stats = TimedStats(1, 2, Stats())
     result = Result({}, 'select name', timed_stats, 1)
     with self.assertRaises(FailIf):
         eval_fail_if("'{statement}' == 'select name'", result)
Пример #4
0
 def test_fail_if_supports_bulk_size(self):
     stats = Stats()
     timed_stats = TimedStats(1, 2, stats)
     result = Result({}, 'select name', timed_stats, 1, bulk_size=200)
     eval_fail_if("{bulk_size} < 200", result)
Пример #5
0
 def test_fail_if_supports_concurrency(self):
     stats = Stats()
     timed_stats = TimedStats(1, 2, stats)
     result = Result({}, 'select name', timed_stats, 1)
     with self.assertRaises(FailIf):
         eval_fail_if("{concurrency} == 1", result)