Item_list Item_factory::create_random(int created_at, int quantity){ Item_list new_items; item new_item_base = create(random_id(), created_at); for(int ii=0;ii<quantity;++ii){ new_items.push_back(new_item_base.clone()); } return new_items; }
TEST_F(dht_routing_test, TestDhtRestart) { // insert some nodes for (int i = 0; i < 10; ++i) { DhtPeerID p; p.id = random_id(); p.addr = random_address(); DhtPeer* k = impl->Update(p, IDht::DHT_ORIGIN_INCOMING, true, 500); EXPECT_TRUE(k) << "a DHT node failed to be inserted"; } impl->Restart(); }
TEST_F(dht_routing_test, TestRoutingTable) { // insert 128 random IDs uniformly distributed // all RTTs are 500, later we'll test to make sure we can replace // them with lower RTT nodes for (int i = 0; i < 256; ++i) { DhtID id = random_id(); id.id[0] = (uint(i) << 24) | 0xffffff; DhtPeerID p; p.id = id; p.addr = random_address(); DhtPeer* k = impl->Update(p, IDht::DHT_ORIGIN_INCOMING, true, 500); EXPECT_TRUE(k) << "a DHT node failed to be inserted"; } EXPECT_EQ(256, impl->GetNumPeers()) << "the number of nodes is not the number we inserted"; EXPECT_EQ(32, impl->NumBuckets()) << "the number buckets is supposed to be 32 still"; // now, split the bucket DhtID id = random_id(); // copy just the 8 most significant bits from our ID uint mask = 0xffffffff >> 8; id.id[0] &= mask; id.id[0] |= my_id.id[0] & ~mask; DhtPeerID p; p.id = id; p.addr = random_address(); impl->Update(p, IDht::DHT_ORIGIN_INCOMING, true, 500); EXPECT_EQ(33, impl->NumBuckets()) << "the number buckets is supposed to be 33"; // TODO: somehow assert that there are 14 nodes in bucket 1 and 128 nodes // in bucket 0 }
void TpcbExample::populateHistory(Db *dbp, int nrecs, u_int32_t accounts, u_int32_t branches, u_int32_t tellers) { Histrec hrec; memset(&hrec.pad[0], 1, sizeof(hrec.pad)); hrec.amount = 10; db_recno_t key; Dbt kdbt(&key, sizeof(u_int32_t)); Dbt ddbt(&hrec, sizeof(hrec)); for (int i = 1; i <= nrecs; i++) { hrec.aid = random_id(ACCOUNT, accounts, branches, tellers); hrec.bid = random_id(BRANCH, accounts, branches, tellers); hrec.tid = random_id(TELLER, accounts, branches, tellers); int err; key = (db_recno_t)i; if ((err = dbp->put(NULL, &kdbt, &ddbt, DB_APPEND)) != 0) { errExit(err, "Failure initializing history file"); } } }
std::string ddp::subscribe(std::string const& name, nlohmann::json::array_t const& params, ready_signal::slot_type const& slot) throw(websocketpp::exception) { auto const i = random_id(); if(slot.slot_function()) { _ready_sig.connect_extended([=](boost::signals2::connection const& conn, std::string const& id) { if(id == i) { slot(i); conn.disconnect(); } }); } nlohmann::json payload; payload["msg"] = "sub"; payload["name"] = name; payload["id"] = i; payload["params"] = params; _conn->send(payload.dump(), websocketpp::frame::opcode::text); return i; }
item Item_factory::create_random(int created_at){ return create(random_id(), created_at); }
virtual void SetUp() override { dht_impl_test::SetUp(); my_id = random_id(); impl->SetId(my_id); impl->Enable(true, 0); }
// // XXX Figure out the appropriate way to pick out IDs. // int TpcbExample::txn(Db *adb, Db *bdb, Db *tdb, Db *hdb, int accounts, int branches, int tellers) { Dbc *acurs = NULL; Dbc *bcurs = NULL; Dbc *tcurs = NULL; DbTxn *t = NULL; db_recno_t key; Defrec rec; Histrec hrec; int account, branch, teller; Dbt d_dbt; Dbt d_histdbt; Dbt k_dbt; Dbt k_histdbt(&key, sizeof(key)); // // XXX We could move a lot of this into the driver to make this // faster. // account = random_id(ACCOUNT, accounts, branches, tellers); branch = random_id(BRANCH, accounts, branches, tellers); teller = random_id(TELLER, accounts, branches, tellers); k_dbt.set_size(sizeof(int)); d_dbt.set_flags(DB_DBT_USERMEM); d_dbt.set_data(&rec); d_dbt.set_ulen(sizeof(rec)); hrec.aid = account; hrec.bid = branch; hrec.tid = teller; hrec.amount = 10; // Request 0 bytes since we're just positioning. d_histdbt.set_flags(DB_DBT_PARTIAL); // START TIMING if (txn_begin(NULL, &t, 0) != 0) goto err; if (adb->cursor(t, &acurs, 0) != 0 || bdb->cursor(t, &bcurs, 0) != 0 || tdb->cursor(t, &tcurs, 0) != 0) goto err; // Account record k_dbt.set_data(&account); if (acurs->get(&k_dbt, &d_dbt, DB_SET) != 0) goto err; rec.balance += 10; if (acurs->put(&k_dbt, &d_dbt, DB_CURRENT) != 0) goto err; // Branch record k_dbt.set_data(&branch); if (bcurs->get(&k_dbt, &d_dbt, DB_SET) != 0) goto err; rec.balance += 10; if (bcurs->put(&k_dbt, &d_dbt, DB_CURRENT) != 0) goto err; // Teller record k_dbt.set_data(&teller); if (tcurs->get(&k_dbt, &d_dbt, DB_SET) != 0) goto err; rec.balance += 10; if (tcurs->put(&k_dbt, &d_dbt, DB_CURRENT) != 0) goto err; // History record d_histdbt.set_flags(0); d_histdbt.set_data(&hrec); d_histdbt.set_ulen(sizeof(hrec)); if (hdb->put(t, &k_histdbt, &d_histdbt, DB_APPEND) != 0) goto err; if (acurs->close() != 0 || bcurs->close() != 0 || tcurs->close() != 0) goto err; if (t->commit(0) != 0) goto err; // END TIMING return (0); err: if (acurs != NULL) (void)acurs->close(); if (bcurs != NULL) (void)bcurs->close(); if (tcurs != NULL) (void)tcurs->close(); if (t != NULL) (void)t->abort(); if (verbose) cout << "Transaction A=" << (long)account << " B=" << (long)branch << " T=" << (long)teller << " failed\n"; return (-1); }
static void create_digest_secret(void) { random_id((unsigned char *)digest_secret, 16); secret_created = 1; }