Пример #1
0
func testSimplePut(t btesting.T) {
	var bucketId typing.BucketId
	// Create a bucket
	CreateBucket(t, typing.TypeId_Store, &bucketId)
	Put(t, bucketId, typing.KeyFromStringPanic("hello/key"),
		typing.ValueFromInterfacePanic([][]byte{[]byte("Value One"), []byte("Value Two")}))
	Get(t, bucketId, typing.KeyFromStringPanic("hello/key"), true)
}
Пример #2
0
func benchmarkSimplePut(t btesting.T, n int, b *testing.B) {
	var bucketId typing.BucketId
	// Create a bucket
	CreateBucket(t, typing.TypeId_Store, &bucketId)
	// Reset timer, since we only want to measure the PUTs
	b.ResetTimer()
	for i := 0; i < n; i++ {
		Put(t, bucketId, typing.KeyFromStringPanic(fmt.Sprintf("hello/:uvarint:%v", i)),
			typing.ValueFromInterfacePanic([][]byte{[]byte("Value One"), []byte("Value Two")}))
	}
}
Пример #3
0
func SetPutReceiver(t btesting.T, bucketId typing.BucketId, receivers ...typing.BucketId) {

	// Now configure bucket "one" to forward the puts to bucket "two"
	putReceivers := make([][]byte, len(receivers))
	for index, receiver := range receivers {
		putReceivers[index] = []byte(receiver)
	}
	newPutReceiversEncoded, err := encoding.Cbor().Encode(putReceivers)
	if err != nil {
		t.Errorf("%v", err)
		return
	}
	Put(t, bucketId.ToMetadataBucketId(),
		typing.KeyFromStringPanic("system.put_receivers"),
		typing.ValueFromInterfacePanic([][]byte{newPutReceiversEncoded}))

}
Пример #4
0
// One of the interesting features of buran is that you can connect two buckets.
// In this case we use the 'put forwarding' mechanism to connect two buckets.
func testPutForwardingWithTwoStorages(t btesting.T) {
	var storageOneBucketId typing.BucketId
	var storageTwoBucketId typing.BucketId

	// Create two buckets
	// Bucket "one"
	CreateBucket(t, typing.TypeId_Store, &storageOneBucketId)
	if t.Failed() {
		return
	}
	// Bucket "two"
	CreateBucket(t, typing.TypeId_Store, &storageTwoBucketId)
	if t.Failed() {
		return
	}

	// Now configure bucket "one" to forward the puts to bucket "two"
	SetPutReceiver(t, storageOneBucketId, storageTwoBucketId)
	if t.Failed() {
		return
	}

	// Now put something to storage "one"
	Put(t, storageOneBucketId, typing.KeyFromStringPanic("daKey"),
		typing.ValueFromInterfacePanic([][]byte{[]byte("daValue")}))
	if t.Failed() {
		return
	}

	// So, noting new here, of course the puted value is found in bucket one
	valueFromBucketOne := Get(t,
		storageOneBucketId, typing.KeyFromStringPanic("daKey"), true)
	if t.Failed() {
		return
	}
	if len(valueFromBucketOne) != 1 {
		t.Errorf("Expect one value")
		return
	}
	if bytes.Compare(valueFromBucketOne[0], []byte("daValue")) != 0 {
		t.Errorf("Value in bucket one is wrong")
		return
	}

	// Now the interesting part: The same value can also be found in bucket two, since
	// the system forwarded the PUT operation to bucket two.
	valueFromBucketTwo := Get(t,
		storageOneBucketId, typing.KeyFromStringPanic("daKey"), true)
	if t.Failed() {
		return
	}
	if len(valueFromBucketTwo) != 1 {
		t.Errorf("Expect one value in bucket two too")
		return
	}
	if bytes.Compare(valueFromBucketTwo[0], []byte("daValue")) != 0 {
		t.Errorf("Value in bucket two is wrong")
		return
	}

}