tempo/pkg/tempopb/prealloc_test.go

43 lines
858 B
Go
Raw Permalink Normal View History

package tempopb
import (
crand "crypto/rand"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestUnmarshal(t *testing.T) {
dummyData := make([]byte, 10)
_, err := crand.Read(dummyData)
require.NoError(t, err)
Reduce Ingester Allocations (#694) * wip: convert to passing premarshalled traces Signed-off-by: Joe Elliott <number101010@gmail.com> * restored tests Signed-off-by: Joe Elliott <number101010@gmail.com> * receive Batches in ingester Signed-off-by: Joe Elliott <number101010@gmail.com> * ingester tests Signed-off-by: Joe Elliott <number101010@gmail.com> * removed unused struct field Signed-off-by: Joe Elliott <number101010@gmail.com> * added ids to push request Signed-off-by: Joe Elliott <number101010@gmail.com> * first pass v1 dataEncoding Signed-off-by: Joe Elliott <number101010@gmail.com> * perf improvements Signed-off-by: Joe Elliott <number101010@gmail.com> * made some assumptions Signed-off-by: Joe Elliott <number101010@gmail.com> * jpes Signed-off-by: Joe Elliott <number101010@gmail.com> * hid marshal Signed-off-by: Joe Elliott <number101010@gmail.com> * batches => traces Signed-off-by: Joe Elliott <number101010@gmail.com> * Added sorting and tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Added tess Signed-off-by: Joe Elliott <number101010@gmail.com> * Added cross encoding combine tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Additional tests/fixes Signed-off-by: Joe Elliott <number101010@gmail.com> * improved instance tests Signed-off-by: Joe Elliott <number101010@gmail.com> * instance tests Signed-off-by: Joe Elliott <number101010@gmail.com> * improved err msgs Signed-off-by: Joe Elliott <number101010@gmail.com> * fix slice reuse Signed-off-by: Joe Elliott <number101010@gmail.com> * improved test Signed-off-by: Joe Elliott <number101010@gmail.com> * improved query testing Signed-off-by: Joe Elliott <number101010@gmail.com> * lint/context fix Signed-off-by: Joe Elliott <number101010@gmail.com> * Logs/tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Stop reusing trace ids! Signed-off-by: Joe Elliott <number101010@gmail.com> * Removed id from trace Signed-off-by: Joe Elliott <number101010@gmail.com> * improved comment Signed-off-by: Joe Elliott <number101010@gmail.com> * changelog Signed-off-by: Joe Elliott <number101010@gmail.com> * go.mod Signed-off-by: Joe Elliott <number101010@gmail.com> * simplified SortTraceBytes Signed-off-by: Joe Elliott <number101010@gmail.com>
2021-05-12 16:08:01 -04:00
preallocReq := &PreallocBytes{}
err = preallocReq.Unmarshal(dummyData)
assert.NoError(t, err)
Reduce Ingester Allocations (#694) * wip: convert to passing premarshalled traces Signed-off-by: Joe Elliott <number101010@gmail.com> * restored tests Signed-off-by: Joe Elliott <number101010@gmail.com> * receive Batches in ingester Signed-off-by: Joe Elliott <number101010@gmail.com> * ingester tests Signed-off-by: Joe Elliott <number101010@gmail.com> * removed unused struct field Signed-off-by: Joe Elliott <number101010@gmail.com> * added ids to push request Signed-off-by: Joe Elliott <number101010@gmail.com> * first pass v1 dataEncoding Signed-off-by: Joe Elliott <number101010@gmail.com> * perf improvements Signed-off-by: Joe Elliott <number101010@gmail.com> * made some assumptions Signed-off-by: Joe Elliott <number101010@gmail.com> * jpes Signed-off-by: Joe Elliott <number101010@gmail.com> * hid marshal Signed-off-by: Joe Elliott <number101010@gmail.com> * batches => traces Signed-off-by: Joe Elliott <number101010@gmail.com> * Added sorting and tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Added tess Signed-off-by: Joe Elliott <number101010@gmail.com> * Added cross encoding combine tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Additional tests/fixes Signed-off-by: Joe Elliott <number101010@gmail.com> * improved instance tests Signed-off-by: Joe Elliott <number101010@gmail.com> * instance tests Signed-off-by: Joe Elliott <number101010@gmail.com> * improved err msgs Signed-off-by: Joe Elliott <number101010@gmail.com> * fix slice reuse Signed-off-by: Joe Elliott <number101010@gmail.com> * improved test Signed-off-by: Joe Elliott <number101010@gmail.com> * improved query testing Signed-off-by: Joe Elliott <number101010@gmail.com> * lint/context fix Signed-off-by: Joe Elliott <number101010@gmail.com> * Logs/tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Stop reusing trace ids! Signed-off-by: Joe Elliott <number101010@gmail.com> * Removed id from trace Signed-off-by: Joe Elliott <number101010@gmail.com> * improved comment Signed-off-by: Joe Elliott <number101010@gmail.com> * changelog Signed-off-by: Joe Elliott <number101010@gmail.com> * go.mod Signed-off-by: Joe Elliott <number101010@gmail.com> * simplified SortTraceBytes Signed-off-by: Joe Elliott <number101010@gmail.com>
2021-05-12 16:08:01 -04:00
assert.Equal(t, dummyData, preallocReq.Slice)
}
func TestMarshal(t *testing.T) {
Reduce Ingester Allocations (#694) * wip: convert to passing premarshalled traces Signed-off-by: Joe Elliott <number101010@gmail.com> * restored tests Signed-off-by: Joe Elliott <number101010@gmail.com> * receive Batches in ingester Signed-off-by: Joe Elliott <number101010@gmail.com> * ingester tests Signed-off-by: Joe Elliott <number101010@gmail.com> * removed unused struct field Signed-off-by: Joe Elliott <number101010@gmail.com> * added ids to push request Signed-off-by: Joe Elliott <number101010@gmail.com> * first pass v1 dataEncoding Signed-off-by: Joe Elliott <number101010@gmail.com> * perf improvements Signed-off-by: Joe Elliott <number101010@gmail.com> * made some assumptions Signed-off-by: Joe Elliott <number101010@gmail.com> * jpes Signed-off-by: Joe Elliott <number101010@gmail.com> * hid marshal Signed-off-by: Joe Elliott <number101010@gmail.com> * batches => traces Signed-off-by: Joe Elliott <number101010@gmail.com> * Added sorting and tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Added tess Signed-off-by: Joe Elliott <number101010@gmail.com> * Added cross encoding combine tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Additional tests/fixes Signed-off-by: Joe Elliott <number101010@gmail.com> * improved instance tests Signed-off-by: Joe Elliott <number101010@gmail.com> * instance tests Signed-off-by: Joe Elliott <number101010@gmail.com> * improved err msgs Signed-off-by: Joe Elliott <number101010@gmail.com> * fix slice reuse Signed-off-by: Joe Elliott <number101010@gmail.com> * improved test Signed-off-by: Joe Elliott <number101010@gmail.com> * improved query testing Signed-off-by: Joe Elliott <number101010@gmail.com> * lint/context fix Signed-off-by: Joe Elliott <number101010@gmail.com> * Logs/tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Stop reusing trace ids! Signed-off-by: Joe Elliott <number101010@gmail.com> * Removed id from trace Signed-off-by: Joe Elliott <number101010@gmail.com> * improved comment Signed-off-by: Joe Elliott <number101010@gmail.com> * changelog Signed-off-by: Joe Elliott <number101010@gmail.com> * go.mod Signed-off-by: Joe Elliott <number101010@gmail.com> * simplified SortTraceBytes Signed-off-by: Joe Elliott <number101010@gmail.com>
2021-05-12 16:08:01 -04:00
preallocReq := &PreallocBytes{
Slice: make([]byte, 10),
}
_, err := crand.Read(preallocReq.Slice)
require.NoError(t, err)
dummyData := make([]byte, 10)
_, err = preallocReq.MarshalTo(dummyData)
assert.NoError(t, err)
Reduce Ingester Allocations (#694) * wip: convert to passing premarshalled traces Signed-off-by: Joe Elliott <number101010@gmail.com> * restored tests Signed-off-by: Joe Elliott <number101010@gmail.com> * receive Batches in ingester Signed-off-by: Joe Elliott <number101010@gmail.com> * ingester tests Signed-off-by: Joe Elliott <number101010@gmail.com> * removed unused struct field Signed-off-by: Joe Elliott <number101010@gmail.com> * added ids to push request Signed-off-by: Joe Elliott <number101010@gmail.com> * first pass v1 dataEncoding Signed-off-by: Joe Elliott <number101010@gmail.com> * perf improvements Signed-off-by: Joe Elliott <number101010@gmail.com> * made some assumptions Signed-off-by: Joe Elliott <number101010@gmail.com> * jpes Signed-off-by: Joe Elliott <number101010@gmail.com> * hid marshal Signed-off-by: Joe Elliott <number101010@gmail.com> * batches => traces Signed-off-by: Joe Elliott <number101010@gmail.com> * Added sorting and tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Added tess Signed-off-by: Joe Elliott <number101010@gmail.com> * Added cross encoding combine tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Additional tests/fixes Signed-off-by: Joe Elliott <number101010@gmail.com> * improved instance tests Signed-off-by: Joe Elliott <number101010@gmail.com> * instance tests Signed-off-by: Joe Elliott <number101010@gmail.com> * improved err msgs Signed-off-by: Joe Elliott <number101010@gmail.com> * fix slice reuse Signed-off-by: Joe Elliott <number101010@gmail.com> * improved test Signed-off-by: Joe Elliott <number101010@gmail.com> * improved query testing Signed-off-by: Joe Elliott <number101010@gmail.com> * lint/context fix Signed-off-by: Joe Elliott <number101010@gmail.com> * Logs/tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Stop reusing trace ids! Signed-off-by: Joe Elliott <number101010@gmail.com> * Removed id from trace Signed-off-by: Joe Elliott <number101010@gmail.com> * improved comment Signed-off-by: Joe Elliott <number101010@gmail.com> * changelog Signed-off-by: Joe Elliott <number101010@gmail.com> * go.mod Signed-off-by: Joe Elliott <number101010@gmail.com> * simplified SortTraceBytes Signed-off-by: Joe Elliott <number101010@gmail.com>
2021-05-12 16:08:01 -04:00
assert.Equal(t, preallocReq.Slice, dummyData)
}
func TestSize(t *testing.T) {
Reduce Ingester Allocations (#694) * wip: convert to passing premarshalled traces Signed-off-by: Joe Elliott <number101010@gmail.com> * restored tests Signed-off-by: Joe Elliott <number101010@gmail.com> * receive Batches in ingester Signed-off-by: Joe Elliott <number101010@gmail.com> * ingester tests Signed-off-by: Joe Elliott <number101010@gmail.com> * removed unused struct field Signed-off-by: Joe Elliott <number101010@gmail.com> * added ids to push request Signed-off-by: Joe Elliott <number101010@gmail.com> * first pass v1 dataEncoding Signed-off-by: Joe Elliott <number101010@gmail.com> * perf improvements Signed-off-by: Joe Elliott <number101010@gmail.com> * made some assumptions Signed-off-by: Joe Elliott <number101010@gmail.com> * jpes Signed-off-by: Joe Elliott <number101010@gmail.com> * hid marshal Signed-off-by: Joe Elliott <number101010@gmail.com> * batches => traces Signed-off-by: Joe Elliott <number101010@gmail.com> * Added sorting and tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Added tess Signed-off-by: Joe Elliott <number101010@gmail.com> * Added cross encoding combine tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Additional tests/fixes Signed-off-by: Joe Elliott <number101010@gmail.com> * improved instance tests Signed-off-by: Joe Elliott <number101010@gmail.com> * instance tests Signed-off-by: Joe Elliott <number101010@gmail.com> * improved err msgs Signed-off-by: Joe Elliott <number101010@gmail.com> * fix slice reuse Signed-off-by: Joe Elliott <number101010@gmail.com> * improved test Signed-off-by: Joe Elliott <number101010@gmail.com> * improved query testing Signed-off-by: Joe Elliott <number101010@gmail.com> * lint/context fix Signed-off-by: Joe Elliott <number101010@gmail.com> * Logs/tests Signed-off-by: Joe Elliott <number101010@gmail.com> * Stop reusing trace ids! Signed-off-by: Joe Elliott <number101010@gmail.com> * Removed id from trace Signed-off-by: Joe Elliott <number101010@gmail.com> * improved comment Signed-off-by: Joe Elliott <number101010@gmail.com> * changelog Signed-off-by: Joe Elliott <number101010@gmail.com> * go.mod Signed-off-by: Joe Elliott <number101010@gmail.com> * simplified SortTraceBytes Signed-off-by: Joe Elliott <number101010@gmail.com>
2021-05-12 16:08:01 -04:00
preallocReq := &PreallocBytes{
Slice: make([]byte, 10),
}
assert.Equal(t, 10, preallocReq.Size())
}