Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/d-ylee/dbs2go into fileDa…
Browse files Browse the repository at this point in the history
…tasetsValidFix
  • Loading branch information
d-ylee committed Apr 13, 2022
2 parents 9f800c9 + d94d584 commit 1628bc0
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,19 @@ test-integration:
echo "\"sqlite3 /tmp/dbs-test.db sqlite\"" > ./dbfile && LD_LIBRARY_PATH=${odir} DYLD_LIBRARY_PATH=${odir} DBS_READER_LEXICON_FILE=../static/lexicon_reader.json \
DBS_WRITER_LEXICON_FILE=../static/lexicon_writer.json DBS_DB_FILE=./dbfile INTEGRATION_DATA_FILE=./data/integration/integration_data.json \
go test -v -run Integration
test-migration:
cd test && rm -f /tmp/dbs-one.db && \
sqlite3 /tmp/dbs-one.db < ../static/schema/sqlite-schema.sql && \
echo "\"sqlite3 /tmp/dbs-one.db sqlite\"" > ./dbfile_1 && \
rm -f /tmp/dbs-two.db && \
sqlite3 /tmp/dbs-two.db < ../static/schema/sqlite-schema.sql && \
echo "\"sqlite3 /tmp/dbs-two.db sqlite\"" > ./dbfile_2 && \
LD_LIBRARY_PATH=${odir} DYLD_LIBRARY_PATH=${odir} \
DBS_READER_LEXICON_FILE=../static/lexicon_reader.json \
DBS_WRITER_LEXICON_FILE=../static/lexicon_writer.json \
DBS_DB_FILE_1=./dbfile_1 \
DBS_DB_FILE_2=./dbfile_2 \
INTEGRATION_DATA_FILE=./data/integration/integration_data.json \
go test -v -run Migration
bench:
cd test && rm -f /tmp/dbs-test.db && sqlite3 /tmp/dbs-test.db < ../static/schema/sqlite-schema.sql && LD_LIBRARY_PATH=${odir} DYLD_LIBRARY_PATH=${odir} DBS_LEXICON_FILE=../static/lexicon_writer.json go test -run Benchmark -bench=.
1 change: 1 addition & 0 deletions dbs/bulkblocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ func (a *API) InsertBulkBlocks() error {
PROCESSING_ERA_ID: processingEraID,
PHYSICS_GROUP_ID: physicsGroupID,
XTCROSSSECTION: rec.Dataset.Xtcrosssection,
PREP_ID: rec.Dataset.PrepID,
CREATION_DATE: rec.Dataset.CreationDate,
CREATE_BY: rec.Dataset.CreateBy,
LAST_MODIFICATION_DATE: creationDate,
Expand Down
3 changes: 3 additions & 0 deletions dbs/bulkblocks2.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ func getDatasetID(
processingEraID int64,
physicsGroupID int64,
xtcrosssection float64,
prepId string,
creationDate int64,
createBy string,
lastModificationDate int64,
Expand All @@ -410,6 +411,7 @@ func getDatasetID(
PROCESSING_ERA_ID: processingEraID,
PHYSICS_GROUP_ID: physicsGroupID,
XTCROSSSECTION: xtcrosssection,
PREP_ID: prepId,
CREATION_DATE: creationDate,
CREATE_BY: createBy,
LAST_MODIFICATION_DATE: lastModificationDate,
Expand Down Expand Up @@ -578,6 +580,7 @@ func (a *API) InsertBulkBlocksConcurrently() error {
processingEraID,
physicsGroupID,
rec.Dataset.Xtcrosssection,
rec.Dataset.PrepID,
rec.Dataset.CreationDate,
rec.Dataset.CreateBy,
creationDate,
Expand Down
1 change: 1 addition & 0 deletions test/bulkblocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"last_modified_by": "Yuyi", "creation_date": 1279912078,
"processed_ds_name": "Summer2011-pstr-v10",
"xtcrosssection": 123.0, "last_modification_date": 1279912078,
"prep_id": "test-prepID",
"dataset":
"/unittest_web_primary_ds_name_14144/Summer2011-pstr-v10/GEN-SIM-RAW"},

Expand Down
3 changes: 2 additions & 1 deletion test/bulkblocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"testing"
"time"

_ "github.com/mattn/go-sqlite3"
"github.com/dmwm/dbs2go/dbs"
"github.com/dmwm/dbs2go/utils"
_ "github.com/mattn/go-sqlite3"
)

// TestBulkBlocks API
Expand Down Expand Up @@ -96,6 +96,7 @@ func TestBulkBlocks(t *testing.T) {
ACQUISITION_ERA_ID: 1,
PROCESSING_ERA_ID: 1,
PHYSICS_GROUP_ID: 1,
PREP_ID: "test-prep_id",
CREATION_DATE: ts,
CREATE_BY: createBy,
LAST_MODIFICATION_DATE: ts,
Expand Down
1 change: 1 addition & 0 deletions test/data/bulkblocks0.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@
"creation_date": 1279912078,
"processed_ds_name": "Summer2011-pstr-v10",
"xtcrosssection": 123,
"prep_id": "test-prepID",
"last_modification_date": 1279912078,
"dataset": "/unittest_web_primary_ds_name_14144/Summer2011-pstr-v10/GEN-SIM-RAW"
},
Expand Down
134 changes: 134 additions & 0 deletions test/migration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package main

// Migration Tests
// This file contains code necessary to run DBS migration workflows
// 1. DBSReader server from which we will read the data for migration process
// 2. DBSWriter server associated with DBSReader which we will use to write the data
// 3. DBSReader server from which we will verify the data from migration process
// 4. DBSWriter server which we will use to write the data from migration process
// 5. DBSMigrate server which we will use to post migration requests
// 6. DBSMigration server which will process our migration requests
// In addition, we have two databases
// 1. DBS_DB_FILE_1 represents DBS db which we will use for migration process
// the DBSReader (1)/DBSWriter (2) will be associated with it
// 2. DBS_DB_FILE_2 represents DBS db where data will be migrated
// the DBSReader (3)/DBSWriter (4) will be associated with it

import (
"fmt"
"log"
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/dmwm/dbs2go/dbs"
"github.com/dmwm/dbs2go/utils"
"github.com/dmwm/dbs2go/web"
_ "github.com/mattn/go-sqlite3"
)

// helper funtion to return DBS server with basic parameters
func dbsServer(t *testing.T, base, dbFile, serverType string) *httptest.Server {
dbfile := os.Getenv(dbFile)
if dbfile == "" {
log.Fatal(fmt.Sprintf("no %s env variable, please define", dbFile))
}

var lexiconFile string

if serverType == "DBSReader" {
lexiconFile = os.Getenv("DBS_READER_LEXICON_FILE")
if lexiconFile == "" {
log.Fatal("no DBS_READER_LEXICON_FILE env variable, please define")
}
} else {
lexiconFile = os.Getenv("DBS_WRITER_LEXICON_FILE")
if lexiconFile == "" {
log.Fatal("no DBS_WRITER_LEXICON_FILE env variable, please define")
}
}

web.Config.Base = base
web.Config.DBFile = dbfile
web.Config.LexiconFile = lexiconFile
web.Config.ServerCrt = ""
web.Config.ServerKey = ""
web.Config.ServerType = serverType
web.Config.LogFile = fmt.Sprintf("/tmp/dbs2go-%s.log", base)
web.Config.Verbose = 0
utils.VERBOSE = 0
utils.BASE = base
lexPatterns, err := dbs.LoadPatterns(lexiconFile)
if err != nil {
t.Fatal(err)
}
dbs.LexiconPatterns = lexPatterns

initTestLimiter(t, "100-S")

ts := httptest.NewServer(web.Handlers())

return ts
}

// TestMigration tests DBS Migration process
func TestMigration(t *testing.T) {
db := initDB(false)
defer db.Close()

// start DBSReader server from which we will read the data for migration process
base := "dbs-one-reader"
srv1 := dbsServer(t, base, "DBS_DB_FILE_1", "DBSReader")
checkServer(t, srv1.URL, base)

// start DBSWriter server to which we will write the data
base = "dbs-one-writer"
srv2 := dbsServer(t, base, "DBS_DB_FILE_1", "DBSWriter")
checkServer(t, srv2.URL, base)

// start DBSReader server from which we will read the data after migration process
base = "dbs-two-reader"
srv3 := dbsServer(t, base, "DBS_DB_FILE_2", "DBSReader")
checkServer(t, srv3.URL, base)

// start DBSWriter server to which we will write the data durign migration process
base = "dbs-two-writer"
srv4 := dbsServer(t, base, "DBS_DB_FILE_2", "DBSWriter")
checkServer(t, srv4.URL, base)

// start DBSMigrate server to which we will post migration requests
base = "dbs-migrate"
srv5 := dbsServer(t, base, "DBS_DB_FILE_2", "DBSMigrate")
checkServer(t, srv5.URL, base)

// start DBSMigration server which will process migration requests
base = "dbs-migration"
srv6 := dbsServer(t, base, "DBS_DB_FILE_2", "DBSMigration")
checkServer(t, srv6.URL, base)
}

// helper function to check given server by accessing its apis end-point
func checkServer(t *testing.T, hostname, base string) {
endpoint := fmt.Sprintf("%s/apis", base)
headers := http.Header{
"Accept": []string{"application/json"},
"Content-Type": []string{"application/json"},
}
r, err := http.DefaultClient.Do(newreq(t, "GET", hostname, endpoint, nil, nil, headers))
if err != nil {
t.Fatal(err)
}
defer r.Body.Close()

if r.StatusCode != 200 {
t.Fatalf("Different HTTP Status: Expected 200, Received %v", r.StatusCode)
}
/*
data, err := io.ReadAll(r.Body)
if err != nil {
t.Fatal(err)
}
log.Printf("server %s APIs: %+v", hostname, string(data))
*/
}

0 comments on commit 1628bc0

Please sign in to comment.