2022-05-06 17:43:51 +08:00
|
|
|
package planparserv2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/antlr/antlr4/runtime/Go/antlr"
|
2023-05-16 16:19:22 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-09-21 09:45:27 +08:00
|
|
|
|
|
|
|
antlrparser "github.com/milvus-io/milvus/internal/parser/planparserv2/generated"
|
2022-05-06 17:43:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func genNaiveInputStream() *antlr.InputStream {
|
|
|
|
return antlr.NewInputStream("a > 2")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_getLexer(t *testing.T) {
|
|
|
|
var lexer *antlrparser.PlanLexer
|
2024-05-11 10:51:31 +08:00
|
|
|
resetLexerPool()
|
2024-07-28 21:50:20 +08:00
|
|
|
lexer = getLexer(genNaiveInputStream(), &errorListenerImpl{})
|
2022-05-06 17:43:51 +08:00
|
|
|
assert.NotNil(t, lexer)
|
|
|
|
|
2024-07-28 21:50:20 +08:00
|
|
|
lexer = getLexer(genNaiveInputStream(), &errorListenerImpl{})
|
2022-05-06 17:43:51 +08:00
|
|
|
assert.NotNil(t, lexer)
|
2024-05-11 10:51:31 +08:00
|
|
|
|
|
|
|
pool := getLexerPool()
|
|
|
|
assert.Equal(t, pool.GetNumActive(), 2)
|
|
|
|
assert.Equal(t, pool.GetNumIdle(), 0)
|
|
|
|
|
|
|
|
putLexer(lexer)
|
|
|
|
assert.Equal(t, pool.GetNumActive(), 1)
|
|
|
|
assert.Equal(t, pool.GetNumIdle(), 1)
|
2022-05-06 17:43:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func Test_getParser(t *testing.T) {
|
2022-05-20 18:47:57 +08:00
|
|
|
var lexer *antlrparser.PlanLexer
|
2022-05-06 17:43:51 +08:00
|
|
|
var parser *antlrparser.PlanParser
|
|
|
|
|
2024-05-11 10:51:31 +08:00
|
|
|
resetParserPool()
|
2024-07-28 21:50:20 +08:00
|
|
|
lexer = getLexer(genNaiveInputStream(), &errorListenerImpl{})
|
2022-05-20 18:47:57 +08:00
|
|
|
assert.NotNil(t, lexer)
|
|
|
|
|
2024-07-28 21:50:20 +08:00
|
|
|
parser = getParser(lexer, &errorListenerImpl{})
|
2022-05-06 17:43:51 +08:00
|
|
|
assert.NotNil(t, parser)
|
|
|
|
|
2024-07-28 21:50:20 +08:00
|
|
|
parser = getParser(lexer, &errorListenerImpl{})
|
2022-05-06 17:43:51 +08:00
|
|
|
assert.NotNil(t, parser)
|
2024-05-11 10:51:31 +08:00
|
|
|
|
|
|
|
pool := getParserPool()
|
|
|
|
assert.Equal(t, pool.GetNumActive(), 2)
|
|
|
|
assert.Equal(t, pool.GetNumIdle(), 0)
|
|
|
|
|
|
|
|
putParser(parser)
|
|
|
|
assert.Equal(t, pool.GetNumActive(), 1)
|
|
|
|
assert.Equal(t, pool.GetNumIdle(), 1)
|
2022-05-06 17:43:51 +08:00
|
|
|
}
|