def run_generator():
     generate_search_blocks.main(
         db_factory(),
         search_strategy=SuperabundantSearchStrategy(),
         # this ensures there are many blocks that are quick
         # to process, maximizing the likelihood of a
         # conflict. For example, this test will fail if the
         # 'FOR UPDATE' is removed from the subquery in
         # claim_next_search_block
         args=FakeArgs(refresh_count=10000, block_size=2))
示例#2
0
def test_superabundant_exactly_landing_on_level_boundary():
    search = SuperabundantSearchStrategy().starting_from(
        SuperabundantEnumerationIndex(level=4, index_in_level=1))
    '''
    The parititions of 4 are 

    [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]

    So if the index in the level is 1, a batch size of 4 should land
    exactly on the boundary of the level.
    '''
    blocks = search.generate_search_blocks(count=2, batch_size=4)
    assert blocks[0].starting_search_index == SuperabundantEnumerationIndex(
        level=4, index_in_level=1)
    assert blocks[0].ending_search_index == SuperabundantEnumerationIndex(
        level=4, index_in_level=4)
    assert blocks[1].starting_search_index == SuperabundantEnumerationIndex(
        level=5, index_in_level=0)
    assert blocks[1].ending_search_index == SuperabundantEnumerationIndex(
        level=5, index_in_level=3)
from riemann.search_strategy import SuperabundantSearchStrategy
from riemann.types import SuperabundantEnumerationIndex
import tracemalloc

tracemalloc.start()

search_strategy = SuperabundantSearchStrategy().starting_from(
    SuperabundantEnumerationIndex(71, 196047))
batch = search_strategy.next_batch(250000)

snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno')

print("[ Top 10 ]")
for stat in top_stats[:10]:
    print(stat)
 def run_processor():
     process_search_blocks.main(
         db_factory(), search_strategy=SuperabundantSearchStrategy())
 def run_generator():
     generate_search_blocks.main(
         db_factory(),
         search_strategy=SuperabundantSearchStrategy(),
         args=FakeArgs())
 def index_name(self) -> str:
     return SuperabundantSearchStrategy().index_name()