def test_get_cursor(self):
        project_name = "cursor_test_p"
        topic_name = "cursor_test_t%d_1" % int(time.time())

        record_schema = RecordSchema.from_lists([
            'bigint_field', 'string_field', 'double_field', 'bool_field',
            'event_time1'
        ], [
            FieldType.BIGINT, FieldType.STRING, FieldType.DOUBLE,
            FieldType.BOOLEAN, FieldType.TIMESTAMP
        ])

        try:
            dh.create_project(project_name, '')
        except ResourceExistException:
            pass

        # make sure project wil be deleted
        try:
            try:
                dh.create_tuple_topic(project_name, topic_name, 3, 7,
                                      record_schema, '1')
                dh.wait_shards_ready(project_name, topic_name)
            except ResourceExistException:
                pass

            # put tuple records
            record = TupleRecord(
                schema=record_schema,
                values=[1, 'yc1', 10.01, True, 1455869335000000])
            record.shard_id = '0'
            record.put_attribute('AK', '47')
            records = [record for i in range(0, 3)]
            put_record_result = dh.put_records(project_name, topic_name,
                                               records)
            print(put_record_result)

            assert put_record_result.failed_record_count == 0

            time.sleep(5)
            # ======================= get cursor =======================
            cursor_oldest = dh.get_cursor(project_name, topic_name, '0',
                                          CursorType.OLDEST)
            cursor_latest = dh.get_cursor(project_name, topic_name, '0',
                                          CursorType.LATEST)
            cursor_sequence_1 = dh.get_cursor(project_name, topic_name, '0',
                                              CursorType.SEQUENCE, 0)
            cursor_sequence_2 = dh.get_cursor(project_name, topic_name, '0',
                                              CursorType.SEQUENCE, 2)
            cursor_system_time = dh.get_cursor(project_name, topic_name, '0',
                                               CursorType.SYSTEM_TIME, 0)
            print(cursor_system_time)

            # assert cursor_oldest.cursor == cursor_sequence_1.cursor
            # assert cursor_latest.cursor == cursor_sequence_2.cursor
            # assert cursor_oldest.cursor == cursor_system_time.cursor
        finally:
            clean_topic(dh, project_name)
            dh.delete_project(project_name)
Beispiel #2
0
        sys.exit(-1)
    print("=======================================\n\n")

    shards_result = dh.list_shard(project_name, topic_name)
    shards = shards_result.shards
    for shard in shards:
        print(shard)
    print("=======================================\n\n")

    while True:
        records = []

        record0 = TupleRecord(schema=topic.record_schema,
                              values=[1, 'yc1', 10.01, True, 1455869335000000])
        record0.shard_id = shards[0].shard_id
        record0.put_attribute('AK', '47')
        records.append(record0)

        record1 = TupleRecord(schema=topic.record_schema)
        record1.values = [1, 'yc1', 10.01, True, 1455869335000000]
        record1.shard_id = shards[1].shard_id
        records.append(record1)

        record2 = TupleRecord(schema=topic.record_schema)
        record2.set_value(0, 3)
        record2.set_value(1, 'yc3')
        record2.set_value('double_field', 10.03)
        record2.set_value('bool_field', False)
        record2.set_value('time_field', 1455869335000013)
        record2.shard_id = shards[2].shard_id
        records.append(record2)