Esempio n. 1
0
 def wait_for_consistency(self, sm=None):
     if sm is None:
         sm = SystemManager(self._chosen_server)
     start_consistency_delay = time.time()
     consistency_delay = 0
     while len(sm.describe_schema_versions()) > 1 and \
             consistency_delay < self.max_consistency_delay:
         consistency_delay = time.time() - start_consistency_delay
         if consistency_delay > 20:
             logger.warn('waited %.1f seconds for cluster-wide consistency %r' % (
                     consistency_delay, sm.describe_schema_versions()))
         time.sleep(0.2)
     logger.info('number of schemas in cluster: %d' % len(sm.describe_schema_versions()))
def test_composite_column_names(client):
    '''
    examine the unique nature of cassandras "wide sorted rows";

    Basically, C* is good at storing large OrderedDict objects and
    less good at the simpler kind of key=value storage that we were
    doing earlier.
    '''
    config = client._config
    namespace = client._app_namespace
    chosen_server = client._chosen_server
    sm = SystemManager(chosen_server)
    sm.create_keyspace(namespace, SIMPLE_STRATEGY, {'replication_factor': '1'})

    family = 'test'
    sm.create_column_family(
        namespace, family, super=False,
        key_validation_class = ASCII_TYPE,
        default_validation_class = BYTES_TYPE,
        comparator_type=CompositeType(UUIDType(), UUIDType()),
        #column_name_class = LEXICAL_UUID_TYPE
        )

    logger.info( sm.describe_schema_versions() )

    pool = ConnectionPool(namespace, config['storage_addresses'],
                          max_retries=1000, pool_timeout=10, pool_size=2, timeout=120)

    cf = pycassa.ColumnFamily(pool, family)
    u1, u2, u3, u4 = uuid.uuid1(), uuid.uuid1(), uuid.uuid1(), uuid.uuid1()

    ## insert four
    cf.insert('inbound', {(u1, u2): b''})
    cf.insert('inbound', {(u1, u3): b''})
    cf.insert('inbound', {(u1, u4): b''})
    cf.insert('inbound', {(u1, u1): b'45'})

    ## insert three with duplicates
    cf.insert('inbound', {(u3, u3): b'42'})
    cf.insert('inbound', {(u3, u3): b'43'})
    cf.insert('inbound', {(u3, u2): b''})
    cf.insert('inbound', {(u3, u4): b''})

    ## insert two
    cf.insert('inbound', {(u2, u3): b''})
    cf.insert('inbound', {(u2, u4): b''})

    ## verify start/finish parameters work as expected
    assert 4 == len(cf.get('inbound', column_start=(u1,), column_finish=(u1,)))
    assert 2 == len(cf.get('inbound', column_start=(u2,), column_finish=(u2,)))
    assert 3 == len(cf.get('inbound', column_start=(u3,), column_finish=(u3,)))

    ## check delete of a single column
    cf.remove('inbound', columns=[(u2, u3)])
    assert 1 == len(cf.get('inbound', column_start=(u2,), column_finish=(u2,)))

    ## check that the last inserted value appears at the expected
    ## location in the OrderedDict
    assert '43' == cf.get('inbound', column_start=(u3,), column_finish=(u3,)).items()[1][1]

    rec1 = cf.get('inbound', column_start=(u3,u3), column_finish=(u3,u3)).items()
    assert len(rec1) == 1

    start  = uuid.UUID(int=0)
    finish = uuid.UUID(int=2**128-1)
    assert start < u1 < u2 < u3 < u4 < finish
    assert 8 == len(cf.get('inbound', column_start=(start,), column_finish=(finish,)).items())

    ## test range searching
    start  = uuid.UUID(int=u3.int - 1)
    finish = uuid.UUID(int=u3.int + 1)
    assert start.int < u3.int < finish.int
    rec2 = cf.get('inbound', column_start=(start,), column_finish=(finish,)).items()
    assert rec2[1][0] == rec1[0][0]
    assert rec2[1][1] == rec1[0][1] == '43'

    cf.insert('inbound', {(u3,u3): b''.join(map(lambda u: u.bytes, (u1,u2,u3,u4)))})
    data = cf.get('inbound', column_start=(u3,u3), column_finish=(u3,u3)).items()[0][1]

    assert [u1,u2,u3,u4] == map(lambda b: uuid.UUID(bytes=b), grouper(data, 16))

    sm.close()