def test_cannot_load_last_sent_pre_preapre_key_if_pp_seq_not_int(
        txnPoolNodeSet, view_no_set, setup):
    node = txnPoolNodeSet[0]
    node.nodeStatusDB.put(LAST_SENT_PRE_PREPARE,
                          node_status_db_serializer.serialize({'1': [2, 5.0]}))

    with pytest.raises(TypeError):
        pp_key = node.last_sent_pp_store_helper._load_last_sent_pp_key()
Exemple #2
0
def test_fail_update_instance_changes_from_db(instance_change_provider, tconf,
                                              node_status_db, time_provider,
                                              logsearch):
    # test updating cache with view without votes
    node_status_db.iterator = lambda include_value=True: {
        "3": node_status_db_serializer.serialize(None)
    }.items()
    provider = InstanceChangeProvider(
        tconf.OUTDATED_INSTANCE_CHANGES_CHECK_INTERVAL, node_status_db,
        time_provider)
    assert not provider.has_view(3)

    # test updating cache with Vote with incorrect timestamp format
    node_status_db.iterator = lambda include_value=True: {
        "3": node_status_db_serializer.serialize({"voter": ["a", 10.4]})
    }.items()
    logs, _ = logsearch(msgs=[
        "InstanceChangeProvider: timestamp in Vote .* : .* - .* must "
        "be of float or int type"
    ])
    InstanceChangeProvider(tconf.OUTDATED_INSTANCE_CHANGES_CHECK_INTERVAL,
                           node_status_db, time_provider)
    assert logs

    # test updating cache with Vote with incorrect reason format
    node_status_db.iterator = lambda include_value=True: {
        "3": node_status_db_serializer.serialize({"voter": [5, 10.4]})
    }.items()
    logs, _ = logsearch(msgs=[
        "InstanceChangeProvider: reason in Vote .* : .* - .* must "
        "be of int type"
    ])
    InstanceChangeProvider(tconf.OUTDATED_INSTANCE_CHANGES_CHECK_INTERVAL,
                           node_status_db, time_provider)
    assert logs

    # test updating cache with incorrect view_no format
    node_status_db.iterator = lambda include_value=True: {
        "a": node_status_db_serializer.serialize({"voter": [5, 25]})
    }.items()
    logs, _ = logsearch(
        msgs=["InstanceChangeProvider: view_no='.*' "
              "must be of int type"])
    InstanceChangeProvider(tconf.OUTDATED_INSTANCE_CHANGES_CHECK_INTERVAL,
                           node_status_db, time_provider)
    assert logs
def test_can_load_valid_last_sent_pre_preapre_key_if_valid(
        txnPoolNodeSet, view_no_set, setup):
    node = txnPoolNodeSet[0]
    node.nodeStatusDB.put(LAST_SENT_PRE_PREPARE,
                          node_status_db_serializer.serialize({'1': [2, 5]}))

    pp_key = node.last_sent_pp_store_helper._load_last_sent_pp_key()

    assert pp_key == {'1': [2, 5]}
def test_cannot_load_last_sent_pre_preapre_key_if_not_valid_dict(
        txnPoolNodeSet, view_no_set, setup):
    node = txnPoolNodeSet[0]
    node.nodeStatusDB.put(
        LAST_SENT_PRE_PREPARE,
        node_status_db_serializer.serialize({1: [2, 5]})[:-1])

    with pytest.raises(JSONDecodeError):
        pp_key = node.last_sent_pp_store_helper._load_last_sent_pp_key()
def test_cannot_load_last_sent_pre_preapre_key_if_dict_has_no_entries(
        txnPoolNodeSet, view_no_set, setup):

    node = txnPoolNodeSet[0]
    node.nodeStatusDB.put(LAST_SENT_PRE_PREPARE,
                          node_status_db_serializer.serialize({}))

    with pytest.raises(TypeError):
        pp_key = node.last_sent_pp_store_helper._load_last_sent_pp_key()
def test_cannot_load_last_sent_pre_preapre_key_if_pp_seq_no_missed(
        txnPoolNodeSet, view_no_set, setup):

    node = txnPoolNodeSet[0]
    node.nodeStatusDB.put(LAST_SENT_PRE_PREPARE,
                          node_status_db_serializer.serialize({'inst_id': 1,
                                                               'view_no': 2}))

    with pytest.raises(TypeError):
        pp_key = node.last_sent_pp_store_helper._load_last_sent_pp_key()
def test_cannot_load_last_sent_pre_preapre_key_if_not_valid_dict(
        txnPoolNodeSet, view_no_set, setup):

    node = txnPoolNodeSet[0]
    node.nodeStatusDB.put(LAST_SENT_PRE_PREPARE,
                          node_status_db_serializer.serialize({'inst_id': 1,
                                                               'view_no': 2,
                                                               'pp_seq_no': 5})[:-1])

    with pytest.raises(JSONDecodeError):
        pp_key = node.last_sent_pp_store_helper._load_last_sent_pp_key()
def test_can_load_valid_last_sent_pre_preapre_key_if_valid(
        txnPoolNodeSet, view_no_set, setup):

    node = txnPoolNodeSet[0]
    node.nodeStatusDB.put(LAST_SENT_PRE_PREPARE,
                          node_status_db_serializer.serialize({'inst_id': 1,
                                                               'view_no': 2,
                                                               'pp_seq_no': 5}))

    pp_key = node.last_sent_pp_store_helper._load_last_sent_pp_key()

    assert pp_key == PrePrepareKey(inst_id=1, view_no=2, pp_seq_no=5)
def pack_pp_key(value: Dict) -> bytes:
    return node_status_db_serializer.serialize(value)
 def _save_last_stored(self, value: Dict):
     serialized_value = node_status_db_serializer.serialize(value)
     self.node.nodeStatusDB.put(LAST_SENT_PRE_PREPARE, serialized_value)
Exemple #11
0
 def _save_last_sent_pp_key(self, pp_key: PrePrepareKey):
     value_as_dict = pp_key._asdict()
     serialized_value = node_status_db_serializer.serialize(value_as_dict)
     self.node.nodeStatusDB.put(LAST_SENT_PRE_PREPARE, serialized_value)
 def _save_last_sent_pp_key(self, pp_key: PrePrepareKey):
     value_as_dict = pp_key._asdict()
     serialized_value = node_status_db_serializer.serialize(value_as_dict)
     self.node.nodeStatusDB.put(LAST_SENT_PRE_PREPARE, serialized_value)
def pack_pp_key(value: PrePrepareKey) -> bytes:
    return node_status_db_serializer.serialize(value._asdict())