func TestRandN(t *testing.T) { var seed uint32 = uint32(1) dlog.Printf("seed %v\n", seed) for i := 0; i < 1000; i++ { x := RandN(&seed, 10) // No idea how to test a random number generator, just look at the results for now. dlog.Println(x, seed) _ = x } }
// TODO: Check and see if I need more tx.MaybeWrite()s func StoreBidTxn(t Query, tx ETransaction) (*Result, error) { var r *Result = nil user := t.U1 item := t.U2 price := int32(t.U3) if price < 0 { log.Fatalf("price %v %v", price, t.U3) } // insert bid n := tx.UID('b') bid_key := BidKey(n) bid := &Bid{ ID: uint64(n), Item: item, Bidder: user, Price: price, } tx.Write(bid_key, bid, WRITE) // update # bids per item err := tx.WriteInt32(NumBidsKey(item), 1, SUM) if err != nil { tx.RelinquishKey(n, 'b') tx.Abort() dlog.Printf("StoreBidTxn(): Couldn't write numbids for item %v; %v\n", item, err) return nil, err } // update max bid? high := MaxBidKey(item) tx.MaybeWrite(high) err = tx.WriteInt32(high, price, MAX) if err != nil { tx.RelinquishKey(n, 'b') dlog.Println("Aborting because of max") tx.Abort() dlog.Printf("StoreBidTxn(): Couldn't write maxbid for item %v; %v\n", item, err) return nil, err } bidder := MaxBidBidderKey(item) err = tx.WriteOO(bidder, price, user, OOWRITE) if err != nil { tx.RelinquishKey(n, 'b') dlog.Println("Aborting because of max oowrite") tx.Abort() dlog.Printf("StoreBidTxn(): Couldn't write maxbidder for item %v; %v\n", item, err) return nil, err } // add to item's bid list e := Entry{int(bid.Price), bid_key, 0} err = tx.WriteList(BidsPerItemKey(item), e, LIST) if err != nil { tx.RelinquishKey(n, 'b') tx.Abort() dlog.Printf("StoreBidTxn(): Error adding to bids per item key %v! %v\n", item, err) return nil, err } if tx.Commit() == 0 { tx.RelinquishKey(n, 'b') dlog.Printf("StoreBidTxn(): Abort item %v\n", item) return r, EABORT } if *Allocate { r = &Result{uint64(n)} // dlog.Printf("User %v Bid on item %v for %v dollars\n", user, item, price) } return r, nil }