virtual int read_pkt(p_pkt_buffer& buf)
    {
        ASSERT_LTE(buf->len, tx_symbol_size-sizeof(T_zeropad));

        T_zeropad zeros = buf->zero_pad_to(tx_symbol_size-sizeof(T_zeropad));
        set_packet_zeros(buf, zeros);

#if defined(VERBOSE) || defined(KODO_VERBOSE)
        printf("Adding %hu bytes of zeropadding\n", zeros);
#endif

#if defined(VERBOSE) || defined(KODO_VERBOSE)
        uint32_t rank_before = encoder->rank();
#endif
        encoder->set_symbol(encoder->rank(), {buf->head, (uint32_t)buf->len});
#if defined(VERBOSE) || defined(KODO_VERBOSE)
        printf("Adding pkt of %lu bytes to encoder, rank before: %u, rank after: %u\n", buf->len, rank_before, encoder->rank());
#endif

        buf->clear();

        if (encoder->rank() * tx_redundancy > tx_delivered_pkts)
        {
            uint32_t amount_of_pkts = (encoder->rank() * tx_redundancy) - tx_delivered_pkts;
            if (encoder->rank() == tx_gen_size)
            {
                amount_of_pkts = std::ceil(encoder->rank() * tx_redundancy) - tx_delivered_pkts;
            }
#if defined(VERBOSE) || defined(KODO_VERBOSE)
            printf("Sending TX generation, gen=%u, pkts=%u\n", tx_gen, amount_of_pkts);
#endif
            tx_delivered_pkts += amount_of_pkts;
            for (uint32_t i = 0; i < amount_of_pkts; ++i)
            {
                size_t len = encoder->encode(buf->head);
                buf->data_push(len);

#if defined(VERBOSE) || defined(KODO_VERBOSE)
                printf("Size of KODO (encoded) symbol %lu bytes, gen=%u\n", len, tx_gen);
#endif

                set_packet_symbol_size(buf, tx_symbol_size);
                set_packet_gen_size(buf, tx_gen_size);
                set_packet_gen(buf, tx_gen);

                super::read_pkt(buf);
                buf->clear();
            }

            if (encoder->rank() == tx_gen_size)
            {
                tx_new_generation();
            }

            return tx_symbol_size;
        }

        return 0;
    }
Exemplo n.º 2
0
/**
 * Test that nextCanonicalDouble() always returns values between 0 and 1.
 */
TEST(RandomTest, NextCanonicalWithinRange) {
    PseudoRandom prng(10);
    for (int i = 0; i < 100; i++) {
        double next = prng.nextCanonicalDouble();
        ASSERT_LTE(0.0, next);
        ASSERT_LT(next, 1.0);
    }
}
    void rx_new_generation(uint32_t gen, uint32_t gen_size, uint32_t symbol_size)
    {
        ASSERT_LTE(gen_size, rx_max_gen_size);
        ASSERT_LTE(symbol_size, rx_max_symbol_size);
        ASSERT_NEQ(gen_size, 0);
        ASSERT_NEQ(symbol_size, 0);

        decoder_factory.set_symbols(gen_size);
        decoder_factory.set_symbol_size(symbol_size);
        decoder = decoder_factory.build();
        rx_gen = gen;
        rx_gen_size = gen_size;
        rx_symbol_size = symbol_size;
        rx_delivered_symbols = 0;
#if defined(VERBOSE) || defined(KODO_VERBOSE)
        printf("New RX generation, gen=%u, gen_size=%u, symbols_size=%u\n", rx_gen, rx_gen_size, rx_symbol_size);
#endif
    }
Exemplo n.º 4
0
TEST(KVEngineTestHarness, AllCommittedTimestamp) {
    unique_ptr<KVHarnessHelper> helper(KVHarnessHelper::create());
    KVEngine* engine = helper->getEngine();
    if (!engine->supportsDocLocking())
        return;

    unique_ptr<RecordStore> rs;
    {
        MyOperationContext opCtx(engine);
        WriteUnitOfWork uow(&opCtx);
        CollectionOptions options;
        options.capped = true;
        options.cappedSize = 10240;
        options.cappedMaxDocs = -1;

        NamespaceString oplogNss("local.oplog.rs");
        ASSERT_OK(engine->createRecordStore(&opCtx, oplogNss.ns(), "ident", options));
        rs = engine->getRecordStore(&opCtx, oplogNss.ns(), "ident", options);
        ASSERT(rs);
    }
    {
        Timestamp t11(1, 1);
        Timestamp t12(1, 2);
        Timestamp t21(2, 1);

        auto t11Doc = BSON("ts" << t11);
        auto t12Doc = BSON("ts" << t12);
        auto t21Doc = BSON("ts" << t21);

        Timestamp allCommitted = engine->getAllCommittedTimestamp();
        MyOperationContext opCtx1(engine);
        WriteUnitOfWork uow1(&opCtx1);
        ASSERT_EQ(invariant(rs->insertRecord(
                      &opCtx1, t11Doc.objdata(), t11Doc.objsize(), Timestamp::min())),
                  RecordId(1, 1));

        Timestamp lastAllCommitted = allCommitted;
        allCommitted = engine->getAllCommittedTimestamp();
        ASSERT_GTE(allCommitted, lastAllCommitted);
        ASSERT_LT(allCommitted, t11);

        MyOperationContext opCtx2(engine);
        WriteUnitOfWork uow2(&opCtx2);
        ASSERT_EQ(invariant(rs->insertRecord(
                      &opCtx2, t21Doc.objdata(), t21Doc.objsize(), Timestamp::min())),
                  RecordId(2, 1));
        uow2.commit();

        lastAllCommitted = allCommitted;
        allCommitted = engine->getAllCommittedTimestamp();
        ASSERT_GTE(allCommitted, lastAllCommitted);
        ASSERT_LT(allCommitted, t11);

        ASSERT_EQ(invariant(rs->insertRecord(
                      &opCtx1, t12Doc.objdata(), t12Doc.objsize(), Timestamp::min())),
                  RecordId(1, 2));

        lastAllCommitted = allCommitted;
        allCommitted = engine->getAllCommittedTimestamp();
        ASSERT_GTE(allCommitted, lastAllCommitted);
        ASSERT_LT(allCommitted, t11);

        uow1.commit();

        lastAllCommitted = allCommitted;
        allCommitted = engine->getAllCommittedTimestamp();
        ASSERT_GTE(allCommitted, lastAllCommitted);
        ASSERT_LTE(allCommitted, t21);
    }
}