Пример #1
0
 def get_msg(self, n=None, direction=None, session_id=None, host_ids=None,
             ptn_ids=None, ts0=None, ts1=None):
     # query object is session_id
     # need to simulate get/fetch behavior similar to over-the-network
     # operation.
     if session_id:
         self._msgq = session_id
         if direction == "bwd":
             firststep = bquery.bmq_prev_entry
         else:
             firststep = bquery.bmq_next_entry
     else:
         self._msgq = bquery.bmsgquery_create(
                                     self.bstore,
                                     list2csv(host_ids),
                                     list2csv(ptn_ids),
                                     strnone(ts0),
                                     strnone(ts1),
                                     0,
                                     None,
                                     None
                                 )
         if direction == "bwd":
             firststep = bquery.bmq_last_entry
         else:
             firststep = bquery.bmq_first_entry
     self._msgn = n
     self._msgi = 0
     self._msgd = direction
     if direction == "bwd":
         self._msgstep = bquery.bmq_prev_entry
     else:
         self._msgstep = bquery.bmq_next_entry
     self._msgrc = firststep(self._msgq)
Пример #2
0
def msg_iter(node_range, ptn_range, ts0, ts1, exp_msg_per_ts, exp_msg):
    msgs = []
    if ts0:
        ts0 = str(ts0)
    else:
        ts0 = None
    if ts1:
        ts1 = str(ts1)
    else:
        ts1 = None
    print "Checking MSG iter | node_range: '%s', ptn_range: '%s', " \
            "ts0: '%s', ts1: '%s'" % (node_range, ptn_range, ts0, ts1)
    bmq = bquery.bmsgquery_create(bstore, node_range, ptn_range, ts0, ts1, 0,
                                  ' ', None)
    assert bmq
    bq = bquery.bmq_to_bq(bmq)

    n = 0
    rc = bquery.bq_first_entry(bq)
    prev_sec = 0
    while rc == 0 and n < 10:
        sec = bquery.bq_entry_get_sec(bq)
        usec = bquery.bq_entry_get_sec(bq)
        comp_id = bquery.bq_entry_get_comp_id(bq)
        msg_str = bquery.bq_entry_get_msg_str(bq)
        s = "%d %d %d %s" % (sec, usec, comp_id, msg_str)
        msgs.append(s)
        n = n + 1
        # print "%d.%d (%d) %s" % (sec, usec, comp_id, msg_str)
        rc = bquery.bq_next_entry(bq)

    while n:
        rc = bquery.bq_prev_entry(bq)
        assert (rc == 0)
        sec = bquery.bq_entry_get_sec(bq)
        usec = bquery.bq_entry_get_sec(bq)
        comp_id = bquery.bq_entry_get_comp_id(bq)
        msg_str = bquery.bq_entry_get_msg_str(bq)
        s = "%d %d %d %s" % (sec, usec, comp_id, msg_str)
        _s = msgs.pop()
        if (_s != s):
            print "strings not matched"
            print "    _s:", _s
            print "     s:", s
        assert (_s == s)

        n = n - 1
Пример #3
0
def msg_query(node_range, ptn_range, ts0, ts1, exp_msg_per_ts, exp_msg):
    if ts0:
        ts0 = str(ts0)
    else:
        ts0 = None
    if ts1:
        ts1 = str(ts1)
    else:
        ts1 = None
    print "Checking MSG query | node_range: '%s', ptn_range: '%s', " \
            "ts0: '%s', ts1: '%s'" % (node_range, ptn_range, ts0, ts1)
    bmq = bquery.bmsgquery_create(bstore, node_range, ptn_range,
                                        ts0, ts1, 0, ' ', None)
    assert bmq
    bq = bquery.bmq_to_bq(bmq)

    bq_count = 0
    n = 0
    rc = bquery.bq_first_entry(bq)
    prev_sec = 0
    while rc == 0:
        bq_count = bq_count + 1

        sec = bquery.bq_entry_get_sec(bq)
        usec = bquery.bq_entry_get_sec(bq)
        comp_id = bquery.bq_entry_get_comp_id(bq)
        msg_str = bquery.bq_entry_get_msg_str(bq)
        if sec != prev_sec:
            assert (prev_sec == 0 or (sec - prev_sec) == BTEST_TS_INC)
            if n and n != exp_msg_per_ts:
                print "query ts: %d has only %d messages, expecting %d messages" % \
                    (prev_sec, n, BTEST_NODE_LEN)
                exit(-1)
            n = 0
        n = n + 1
        prev_sec = sec
        # print "%d.%d (%d) %s" % (sec, usec, comp_id, msg_str)
        rc = bquery.bq_next_entry(bq)
    if exp_msg != bq_count:
        print "Expecting %d, bq_count: %d" % (exp_msg, bq_count)
        exit(-1)
Пример #4
0
    def get_msg2(self, n=None, direction=None, pos=None,host_ids=None,
                 ptn_ids=None, ts0=None, ts1=None, curr=None):
        self._msgq_reset()
        self._msgq = bquery.bmsgquery_create(
                                    self.bstore,
                                    list2csv(host_ids),
                                    list2csv(ptn_ids),
                                    strnone(ts0),
                                    strnone(ts1),
                                    0,
                                    None,
                                    None
                                )
        assert(self._msgq != None)
        self._msgd = direction
        if self._msgd == "bwd":
            firststep = bquery.bmq_last_entry
        else:
            firststep = bquery.bmq_first_entry
        if pos:
            # recover position
            rc = bquery.bmq_set_pos(self._msgq, str(pos))
            if rc:
                raise Exception("bmq_set_pos() failed, rc: %d" % rc)
            if self._msgd == "bwd":
                firststep = bquery.bmq_prev_entry
            else:
                firststep = bquery.bmq_next_entry
        self._msgi = 0
        self._msgn = n
        if self._msgd == "bwd":
            self._msgstep = bquery.bmq_prev_entry
        else:
            self._msgstep = bquery.bmq_next_entry

        if pos and curr:
            self._msgrc = 0
        else:
            self._msgrc = firststep(self._msgq)