Пример #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 benchmarkSimplePutGet(t btesting.T, n int, b *testing.B) {
	var bucketId typing.BucketId
	// Create a bucket
	CreateBucket(t, typing.TypeId_Store, &bucketId)

	fillToIndex := n / 2
	for i := 0; i < fillToIndex; i++ {
		Put(t, bucketId, typing.KeyFromStringPanic(fmt.Sprintf("hello/:uvarint:%v", i)),
			typing.ValueFromInterfacePanic([][]byte{[]byte("Value One"), []byte("Value Two")}))
	}

	// Reset timer, since we only want to measure the GETs
	b.ResetTimer()

	for i := 0; i < n; i++ {
		shouldBeFound := i < fillToIndex
		Get(t, bucketId, typing.KeyFromStringPanic(fmt.Sprintf("hello/:uvarint:%v", i)), shouldBeFound)
	}
}
Пример #3
0
func testScanPutCornerCase1(t btesting.T) {
	// Create a bucket
	var bucketId typing.BucketId
	CreateBucket(t, typing.TypeId_Store, &bucketId)

	// Now perform some scans
	// Match the entire 26-range, nothing more
	ScanPutMatch(t, bucketId, &ScanSettings{
		FromKey:          ":uvarint:26",
		ToKeyOptional:    ":uvarint:27", // To the 27-range, but it's set to 'exlusive'
		ToExclusive:      true,
		Limit:            10,
		Skip:             0,
		ExpectToHaveMore: false,
	}, []ScanEntry{
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:25"),
			Match: false,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:25/:hex:00"),
			Match: false,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:26/:hex:00"),
			Match: true,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:26/alpha"),
			Match: true,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:26/beta"),
			Match: true,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:26/gamma"),
			Match: true,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:27"),
			Match: false,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:27/:hex:00"),
			Match: false,
		},
	})

}
Пример #4
0
func testScanPutToEndOfBucket(t btesting.T) {
	// Create a bucket
	var bucketId typing.BucketId
	CreateBucket(t, typing.TypeId_Store, &bucketId)

	// Now perform some scans
	// Match from the beginning of the 26 range
	// Note: 'ToExclusive' is missing, so scan to the end of the bucket
	ScanPutMatch(t, bucketId, &ScanSettings{
		FromKey:          ":uvarint:26",
		ToExclusive:      true,
		Limit:            10,
		Skip:             0,
		ExpectToHaveMore: false,
	}, []ScanEntry{
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:25"),
			Match: false,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:25/:hex:00"),
			Match: false,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:26/:hex:00"),
			Match: true,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:26/alpha"),
			Match: true,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:26/beta"),
			Match: true,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:26/gamma"),
			Match: true,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:27"),
			Match: true,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(":uvarint:27/:hex:00"),
			Match: true,
		},
	})

}
Пример #5
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}))

}
Пример #6
0
func testScanPutSimple(t btesting.T) {
	// Create a bucket
	var bucketId typing.BucketId
	CreateBucket(t, typing.TypeId_Store, &bucketId)

	// Now perform some scans
	ScanPutMatch(t, bucketId, &ScanSettings{
		FromKey:          "ceta",
		ToKeyOptional:    "frido",
		Limit:            10,
		Skip:             0,
		ExpectToHaveMore: false,
	}, []ScanEntry{
		ScanEntry{
			Key:   typing.KeyFromStringPanic("dumbo"),
			Match: true,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic("alpha"),
			Match: false,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic(""),
			Match: false,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic("ceta"),
			Match: true,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic("frido"),
			Match: true,
		},
		ScanEntry{
			Key:   typing.KeyFromStringPanic("zebra"),
			Match: false,
		},
	})

}
Пример #7
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
	}

}