예제 #1
0
 def test_add_all(self):
     batch = BatchStatement()
     statements = ['%s'] * 10
     parameters = [(i,) for i in range(10)]
     batch.add_all(statements, parameters)
     bound_statements = [t[1] for t in batch._statements_and_parameters]
     str_parameters = [str(i) for i in range(10)]
     self.assertEqual(bound_statements, str_parameters)
    def test_too_many_statements(self):
        # The actual max # of statements is 0xFFFF, but this can occasionally cause a server write timeout.
        large_batch = 0xFFF
        max_statements = 0xFFFF
        ss = SimpleStatement("INSERT INTO test3rf.test (k, v) VALUES (0, 0)")
        b = BatchStatement(batch_type=BatchType.UNLOGGED, consistency_level=ConsistencyLevel.ONE)

        # large number works works
        b.add_all([ss] * large_batch, [None] * large_batch)
        self.session.execute(b, timeout=30.0)

        b = BatchStatement(batch_type=BatchType.UNLOGGED, consistency_level=ConsistencyLevel.ONE)
        # max + 1 raises
        b.add_all([ss] * max_statements, [None] * max_statements)
        self.assertRaises(ValueError, b.add, ss)

        # also would have bombed trying to encode
        b._statements_and_parameters.append((False, ss.query_string, ()))
        self.assertRaises(NoHostAvailable, self.session.execute, b)
예제 #3
0
 def test_len(self):
     for n in 0, 10, 100:
         batch = BatchStatement()
         batch.add_all(statements=['%s'] * n,
                       parameters=[(i,) for i in range(n)])
         self.assertEqual(len(batch), n)