2023-04-10 11:43:13 +02:00
|
|
|
package etl_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
2023-04-10 14:52:05 +02:00
|
|
|
"os"
|
|
|
|
"runtime/trace"
|
2023-04-10 11:43:13 +02:00
|
|
|
"testing"
|
|
|
|
|
2023-04-10 14:52:05 +02:00
|
|
|
"gitea.urkob.com/urko/crono"
|
2023-04-10 11:43:13 +02:00
|
|
|
"gitea.urkob.com/urko/ess-etl-go/config"
|
|
|
|
"gitea.urkob.com/urko/ess-etl-go/internal/etl"
|
|
|
|
"gitea.urkob.com/urko/ess-etl-go/internal/request"
|
|
|
|
"gitea.urkob.com/urko/ess-etl-go/internal/xml_loader"
|
|
|
|
"gitea.urkob.com/urko/ess-etl-go/pkg/adapter/repository/mongodb/employee_wi"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
|
|
)
|
|
|
|
|
2023-04-10 14:52:05 +02:00
|
|
|
const traceFlag = false
|
|
|
|
|
|
|
|
func BenchmarkETLFanout(b *testing.B) {
|
|
|
|
if traceFlag {
|
|
|
|
trace.Start(os.Stdout)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if traceFlag {
|
|
|
|
trace.Stop()
|
|
|
|
}
|
|
|
|
}()
|
2023-04-10 11:43:13 +02:00
|
|
|
cfg := config.NewConfig(".env")
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
dbOpts := options.Client()
|
|
|
|
dbOpts.ApplyURI(cfg.DbAddress)
|
|
|
|
|
|
|
|
client, err := mongo.NewClient(dbOpts)
|
|
|
|
require.NoError(b, err, "mongo.NewClient")
|
|
|
|
|
|
|
|
require.NoError(b, client.Connect(ctx), "client.Connect")
|
|
|
|
|
2023-04-24 12:03:15 +02:00
|
|
|
employeeWICollection := client.Database(cfg.DbName).Collection(cfg.WorkInformationCollection)
|
2023-04-10 14:52:05 +02:00
|
|
|
require.NoError(b, employeeWICollection.Drop(ctx), "employeeWICollection.Drop")
|
|
|
|
repo := employee_wi.NewRepo(employeeWICollection)
|
|
|
|
|
|
|
|
r := request.NewRequestService(cfg.AmsApi, cfg.AmsApiKey)
|
|
|
|
|
|
|
|
ewiLoader := xml_loader.NewEmployeeWILoader(r)
|
|
|
|
from, to := "2023-01-01", "2023-01-31"
|
|
|
|
etlLoader := etl.New(ewiLoader, repo)
|
|
|
|
|
|
|
|
// err = etlLoader.Main(signalContext(ctx), cr, cfg.EmployeeIdList, from, to)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
require.NoError(b, etlLoader.FanOut(ctx, cfg.EmployeeIdList, from, to))
|
2023-04-10 11:43:13 +02:00
|
|
|
}
|
2023-04-10 14:52:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkETLFanout2(b *testing.B) {
|
|
|
|
if traceFlag {
|
|
|
|
trace.Start(os.Stdout)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if traceFlag {
|
|
|
|
trace.Stop()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
cfg := config.NewConfig(".env")
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
dbOpts := options.Client()
|
|
|
|
dbOpts.ApplyURI(cfg.DbAddress)
|
|
|
|
|
|
|
|
client, err := mongo.NewClient(dbOpts)
|
|
|
|
require.NoError(b, err, "mongo.NewClient")
|
|
|
|
|
|
|
|
require.NoError(b, client.Connect(ctx), "client.Connect")
|
|
|
|
|
2023-04-24 12:03:15 +02:00
|
|
|
employeeWICollection := client.Database(cfg.DbName).Collection(cfg.WorkInformationCollection)
|
2023-04-10 14:52:05 +02:00
|
|
|
require.NoError(b, employeeWICollection.Drop(ctx), "employeeWICollection.Drop")
|
2023-04-10 11:43:13 +02:00
|
|
|
repo := employee_wi.NewRepo(employeeWICollection)
|
|
|
|
|
|
|
|
r := request.NewRequestService(cfg.AmsApi, cfg.AmsApiKey)
|
|
|
|
|
|
|
|
ewiLoader := xml_loader.NewEmployeeWILoader(r)
|
|
|
|
from, to := "2023-01-01", "2023-01-31"
|
2023-04-10 14:52:05 +02:00
|
|
|
etlLoader := etl.New(ewiLoader, repo)
|
2023-04-10 11:43:13 +02:00
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2023-04-10 14:52:05 +02:00
|
|
|
require.NoError(b, etlLoader.FanOut2(ctx, cfg.EmployeeIdList, from, to))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkETLMain(b *testing.B) {
|
|
|
|
if traceFlag {
|
|
|
|
trace.Start(os.Stdout)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if traceFlag {
|
|
|
|
trace.Stop()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
cfg := config.NewConfig(".env")
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
dbOpts := options.Client()
|
|
|
|
dbOpts.ApplyURI(cfg.DbAddress)
|
|
|
|
|
|
|
|
client, err := mongo.NewClient(dbOpts)
|
|
|
|
require.NoError(b, err, "mongo.NewClient")
|
|
|
|
|
|
|
|
require.NoError(b, client.Connect(ctx), "client.Connect")
|
|
|
|
|
2023-04-24 12:03:15 +02:00
|
|
|
employeeWICollection := client.Database(cfg.DbName).Collection(cfg.WorkInformationCollection)
|
2023-04-10 14:52:05 +02:00
|
|
|
require.NoError(b, employeeWICollection.Drop(ctx), "employeeWICollection.Drop")
|
|
|
|
repo := employee_wi.NewRepo(employeeWICollection)
|
|
|
|
|
|
|
|
r := request.NewRequestService(cfg.AmsApi, cfg.AmsApiKey)
|
|
|
|
|
|
|
|
ewiLoader := xml_loader.NewEmployeeWILoader(r)
|
|
|
|
from, to := "2023-01-01", "2023-01-31"
|
|
|
|
etlLoader := etl.New(ewiLoader, repo)
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
require.NoError(b, etlLoader.Main(ctx, crono.New(), cfg.EmployeeIdList, from, to))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestETLFanout(t *testing.T) {
|
|
|
|
cr := crono.New()
|
|
|
|
if traceFlag {
|
|
|
|
trace.Start(os.Stdout)
|
|
|
|
} else {
|
|
|
|
defer cr.Table()
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if traceFlag {
|
|
|
|
trace.Stop()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
cfg := config.NewConfig(".env")
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
dbOpts := options.Client()
|
|
|
|
dbOpts.ApplyURI(cfg.DbAddress)
|
|
|
|
|
|
|
|
client, err := mongo.NewClient(dbOpts)
|
|
|
|
require.NoError(t, err, "mongo.NewClient")
|
|
|
|
|
|
|
|
require.NoError(t, client.Connect(ctx), "client.Connect")
|
|
|
|
|
2023-04-24 12:03:15 +02:00
|
|
|
employeeWICollection := client.Database(cfg.DbName).Collection(cfg.WorkInformationCollection)
|
2023-04-10 14:52:05 +02:00
|
|
|
require.NoError(t, employeeWICollection.Drop(ctx), "employeeWICollection.Drop")
|
|
|
|
repo := employee_wi.NewRepo(employeeWICollection)
|
|
|
|
|
|
|
|
r := request.NewRequestService(cfg.AmsApi, cfg.AmsApiKey)
|
|
|
|
|
|
|
|
ewiLoader := xml_loader.NewEmployeeWILoader(r)
|
|
|
|
from, to := "2023-01-01", "2023-01-31"
|
|
|
|
etlLoader := etl.New(ewiLoader, repo)
|
|
|
|
|
|
|
|
require.NoError(t, etlLoader.FanOut(ctx, cfg.EmployeeIdList, from, to))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestETLFanOut2(t *testing.T) {
|
|
|
|
cr := crono.New()
|
|
|
|
if traceFlag {
|
|
|
|
trace.Start(os.Stdout)
|
|
|
|
} else {
|
|
|
|
defer cr.Table()
|
2023-04-10 11:43:13 +02:00
|
|
|
}
|
2023-04-10 14:52:05 +02:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if traceFlag {
|
|
|
|
trace.Stop()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
cfg := config.NewConfig(".env")
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
dbOpts := options.Client()
|
|
|
|
dbOpts.ApplyURI(cfg.DbAddress)
|
|
|
|
|
|
|
|
client, err := mongo.NewClient(dbOpts)
|
|
|
|
require.NoError(t, err, "mongo.NewClient")
|
|
|
|
|
|
|
|
require.NoError(t, client.Connect(ctx), "client.Connect")
|
|
|
|
|
2023-04-24 12:03:15 +02:00
|
|
|
employeeWICollection := client.Database(cfg.DbName).Collection(cfg.WorkInformationCollection)
|
2023-04-10 14:52:05 +02:00
|
|
|
require.NoError(t, employeeWICollection.Drop(ctx), "employeeWICollection.Drop")
|
|
|
|
repo := employee_wi.NewRepo(employeeWICollection)
|
|
|
|
|
|
|
|
r := request.NewRequestService(cfg.AmsApi, cfg.AmsApiKey)
|
|
|
|
ewiLoader := xml_loader.NewEmployeeWILoader(r)
|
|
|
|
from, to := "2023-01-01", "2023-01-31"
|
|
|
|
etlLoader := etl.New(ewiLoader, repo)
|
|
|
|
|
|
|
|
require.NoError(t, etlLoader.FanOut2(ctx, cfg.EmployeeIdList, from, to))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestETLMain(t *testing.T) {
|
|
|
|
cr := crono.New()
|
|
|
|
if traceFlag {
|
|
|
|
trace.Start(os.Stdout)
|
|
|
|
} else {
|
|
|
|
defer cr.Table()
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if traceFlag {
|
|
|
|
trace.Stop()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
cfg := config.NewConfig(".env")
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
dbOpts := options.Client()
|
|
|
|
dbOpts.ApplyURI(cfg.DbAddress)
|
|
|
|
|
|
|
|
client, err := mongo.NewClient(dbOpts)
|
|
|
|
require.NoError(t, err, "mongo.NewClient")
|
|
|
|
|
|
|
|
require.NoError(t, client.Connect(ctx), "client.Connect")
|
|
|
|
|
2023-04-24 12:03:15 +02:00
|
|
|
employeeWICollection := client.Database(cfg.DbName).Collection(cfg.WorkInformationCollection)
|
2023-04-10 14:52:05 +02:00
|
|
|
require.NoError(t, employeeWICollection.Drop(ctx), "employeeWICollection.Drop")
|
|
|
|
repo := employee_wi.NewRepo(employeeWICollection)
|
|
|
|
|
|
|
|
r := request.NewRequestService(cfg.AmsApi, cfg.AmsApiKey)
|
|
|
|
|
|
|
|
ewiLoader := xml_loader.NewEmployeeWILoader(r)
|
|
|
|
from, to := "2023-01-01", "2023-01-31"
|
|
|
|
etlLoader := etl.New(ewiLoader, repo)
|
|
|
|
require.NoError(t, etlLoader.Main(ctx, cr, cfg.EmployeeIdList, from, to))
|
2023-04-10 11:43:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLoad(t *testing.T) {
|
|
|
|
cfg := config.NewConfig(".env")
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
dbOpts := options.Client()
|
|
|
|
dbOpts.ApplyURI(cfg.DbAddress)
|
|
|
|
|
|
|
|
client, err := mongo.NewClient(dbOpts)
|
|
|
|
require.NoError(t, err, "mongo.NewClient")
|
|
|
|
|
|
|
|
require.NoError(t, client.Connect(ctx), "client.Connect")
|
|
|
|
|
2023-04-24 12:03:15 +02:00
|
|
|
employeeWICollection := client.Database(cfg.DbName).Collection(cfg.WorkInformationCollection)
|
2023-04-10 11:43:13 +02:00
|
|
|
if err = employeeWICollection.Drop(ctx); err != nil {
|
|
|
|
log.Fatalln("employeeWICollection.Drop", err)
|
|
|
|
}
|
|
|
|
repo := employee_wi.NewRepo(employeeWICollection)
|
|
|
|
|
|
|
|
r := request.NewRequestService(cfg.AmsApi, cfg.AmsApiKey)
|
|
|
|
|
|
|
|
ewiLoader := xml_loader.NewEmployeeWILoader(r)
|
|
|
|
from, to := "2023-01-01", "2023-01-31"
|
2023-04-10 14:52:05 +02:00
|
|
|
e := etl.New(ewiLoader, repo)
|
2023-04-10 11:43:13 +02:00
|
|
|
|
|
|
|
require.NoError(t, e.FanOut(ctx, cfg.EmployeeIdList, from, to))
|
|
|
|
}
|