2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-12-09 09:55:31 -05:00
|
|
|
|
|
|
|
package json
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2021-06-01 17:59:40 -04:00
|
|
|
"github.com/minio/minio/internal/s3select/sql"
|
2019-12-09 09:55:31 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewPReader(t *testing.T) {
|
2022-09-19 14:05:16 -04:00
|
|
|
files, err := os.ReadDir("testdata")
|
2019-12-09 09:55:31 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
for _, file := range files {
|
|
|
|
t.Run(file.Name(), func(t *testing.T) {
|
|
|
|
f, err := os.Open(filepath.Join("testdata", file.Name()))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
r := NewPReader(f, &ReaderArgs{})
|
|
|
|
var record sql.Record
|
|
|
|
for {
|
|
|
|
record, err = r.Read(record)
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r.Close()
|
|
|
|
if err != io.EOF {
|
|
|
|
t.Fatalf("Reading failed with %s, %s", err, file.Name())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run(file.Name()+"-close", func(t *testing.T) {
|
|
|
|
f, err := os.Open(filepath.Join("testdata", file.Name()))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
r := NewPReader(f, &ReaderArgs{})
|
|
|
|
r.Close()
|
|
|
|
var record sql.Record
|
|
|
|
for {
|
|
|
|
record, err = r.Read(record)
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != io.EOF {
|
|
|
|
t.Fatalf("Reading failed with %s, %s", err, file.Name())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPReader(b *testing.B) {
|
2022-09-19 14:05:16 -04:00
|
|
|
files, err := os.ReadDir("testdata")
|
2019-12-09 09:55:31 -05:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
for _, file := range files {
|
|
|
|
b.Run(file.Name(), func(b *testing.B) {
|
2022-09-19 14:05:16 -04:00
|
|
|
f, err := os.ReadFile(filepath.Join("testdata", file.Name()))
|
2019-12-09 09:55:31 -05:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
b.SetBytes(int64(len(f)))
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.ResetTimer()
|
|
|
|
var record sql.Record
|
|
|
|
for i := 0; i < b.N; i++ {
|
2022-09-19 14:05:16 -04:00
|
|
|
r := NewPReader(io.NopCloser(bytes.NewBuffer(f)), &ReaderArgs{})
|
2019-12-09 09:55:31 -05:00
|
|
|
for {
|
|
|
|
record, err = r.Read(record)
|
|
|
|
if err != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r.Close()
|
|
|
|
if err != io.EOF {
|
|
|
|
b.Fatalf("Reading failed with %s, %s", err, file.Name())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|