2024-06-24 10:34:12 +08:00
|
|
|
package registry
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2024-06-27 15:11:05 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/mocks/streaming/mock_walimpls"
|
2024-06-24 10:34:12 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRegister(t *testing.T) {
|
|
|
|
name := "mock"
|
|
|
|
b := mock_walimpls.NewMockOpenerBuilderImpls(t)
|
|
|
|
b.EXPECT().Name().Return(name)
|
|
|
|
|
|
|
|
RegisterBuilder(b)
|
|
|
|
b2 := MustGetBuilder(name)
|
|
|
|
assert.Equal(t, b.Name(), b2.Name())
|
|
|
|
|
|
|
|
// Panic if register twice.
|
|
|
|
assert.Panics(t, func() {
|
|
|
|
RegisterBuilder(b)
|
|
|
|
})
|
|
|
|
|
|
|
|
// Panic if get not exist builder.
|
|
|
|
assert.Panics(t, func() {
|
|
|
|
MustGetBuilder("not exist")
|
|
|
|
})
|
|
|
|
|
|
|
|
// Test concurrent.
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
count := 10
|
|
|
|
wg.Add(count)
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
go func(i int) {
|
|
|
|
defer wg.Done()
|
|
|
|
name := fmt.Sprintf("mock_%d", i)
|
|
|
|
b := mock_walimpls.NewMockOpenerBuilderImpls(t)
|
|
|
|
b.EXPECT().Name().Return(name)
|
|
|
|
RegisterBuilder(b)
|
|
|
|
b2 := MustGetBuilder(name)
|
|
|
|
assert.Equal(t, b.Name(), b2.Name())
|
|
|
|
}(i)
|
|
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
}
|