Exemplo n.º 1
0
    def test_select_from_timeout(self):
        from relstorage.tests import mock
        from relstorage.adapters.interfaces import AggregateOperationTimeoutError
        cursor = MockCursor()
        cursor.sort_sequence_params = True
        cursor.many_results = [[(1, 1)], [(2, 1)], [(3, 1)], []]
        batcher = self.getClass()(cursor)
        batcher.bind_limit = 1
        batcher.perf_counter = mock.Mock()
        # These will be the time values returned from perf_counter()
        batcher.perf_counter.side_effect = (
            12345,  # Begin
            12346,  # First batch
            12347,  # Second batch
        )

        gener = batcher.select_from((
            'zoid',
            'tid',
        ),
                                    'object_state',
                                    timeout=2,
                                    oids=[1, 2, 3, 4, 5])
        rows = []
        with self.assertRaises(AggregateOperationTimeoutError):
            for row in gener:
                rows.append(row)

        # We ran exactly twice before the perf_counter exceeded the timeout.
        self.assertEqual(rows, [
            (1, 1),
            (2, 1),
        ])
Exemplo n.º 2
0
    def test_select_multiple_many_batch(self):
        cursor = MockCursor()
        cursor.many_results = [
            [(1, 1)],
            [(3, 1)],
            []
        ]
        batcher = self.getClass()(cursor)
        batcher.row_limit = 2
        rows = batcher.select_from(('zoid', 'tid'), 'object_state',
                                   oids=(1, 2, 3, 4, 5))
        rows = list(rows)
        self.assertEqual(cursor.executed, [
            ('SELECT zoid,tid FROM object_state WHERE oids = ANY (%s)',
             ([1, 2,],)),
            ('SELECT zoid,tid FROM object_state WHERE oids = ANY (%s)',
             ([3, 4,],)),
            ('SELECT zoid,tid FROM object_state WHERE oids = ANY (%s)',
             ([5,],)),
        ])

        self.assertEqual(rows, [
            (1, 1),
            (3, 1)
        ])
Exemplo n.º 3
0
    def test_select_multiple_many_batch(self, batch_limit_attr='row_limit'):
        cursor = MockCursor()
        cursor.sort_sequence_params = True
        cursor.many_results = [[(1, 1)], [(3, 1)], []]
        batcher = self.getClass()(cursor)
        setattr(batcher, batch_limit_attr, 2)
        rows = batcher.select_from(('zoid', 'tid'),
                                   'object_state',
                                   oids=iter((1, 2, 3, 4, 5)))
        rows = list(rows)

        self.assertEqual(cursor.executed, [
            (self.select_multiple_many_batch, self._in(1, 2)),
            (self.select_multiple_many_batch, self._in(3, 4)),
            (self.select_one, self._in(5)),
        ])

        self.assertEqual(rows, [(1, 1), (3, 1)])