func populateDB(tb testing.TB, kvSize int, totalKeys int, keyPrefix string) { dbWrapper := db.NewTestDBWrapper() dbWrapper.CreateFreshDB(tb) batch := gorocksdb.NewWriteBatch() for i := 0; i < totalKeys; i++ { key := []byte(keyPrefix + strconv.Itoa(i)) value := testutil.ConstructRandomBytes(tb, kvSize-len(key)) batch.Put(key, value) if i%1000 == 0 { dbWrapper.WriteToDB(tb, batch) batch = gorocksdb.NewWriteBatch() } } dbWrapper.CloseDB(tb) }
func BenchmarkDB(b *testing.B) { b.Logf("testParams:%q", testParams) flags := flag.NewFlagSet("testParams", flag.ExitOnError) kvSize := flags.Int("KVSize", 1000, "size of the key-value") toPopulateDB := flags.Bool("PopulateDB", false, "Run in populate DB mode") maxKeySuffix := flags.Int("MaxKeySuffix", 1, "the keys are appended with _1, _2,.. upto MaxKeySuffix") keyPrefix := flags.String("KeyPrefix", "Key_", "The generated workload will have keys such as KeyPrefix_1, KeyPrefix_2, and so on") flags.Parse(testParams) if *toPopulateDB { b.ResetTimer() populateDB(b, *kvSize, *maxKeySuffix, *keyPrefix) return } dbWrapper := db.NewTestDBWrapper() randNumGen := testutil.NewTestRandomNumberGenerator(*maxKeySuffix) b.ResetTimer() for i := 0; i < b.N; i++ { key := []byte(*keyPrefix + strconv.Itoa(randNumGen.Next())) value := dbWrapper.GetFromDB(b, key) b.SetBytes(int64(len(value))) } }
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package ledger import ( "github.com/openblockchain/obc-peer/openchain/db" "github.com/openblockchain/obc-peer/openchain/ledger/testutil" "testing" ) var testDBWrapper = db.NewTestDBWrapper() func InitTestLedger(t *testing.T) *Ledger { testDBWrapper.CreateFreshDB(t) _, err := GetLedger() testutil.AssertNoError(t, err, "Error while constructing ledger") newLedger, err := newLedger() testutil.AssertNoError(t, err, "Error while constructing ledger") ledger = newLedger return newLedger }