Repository: oom-ai/oomstore
Pull request #815 (2021-12-24 07:26:22)

test: use oomplay in dynamodb tests


Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 1dc8c9b0..cad527ca 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -48,7 +48,7 @@ jobs:
   test:
     runs-on: ubuntu-latest
     env:
-      oomplay-version: '0.3.0'
+      oomplay-version: '0.3.1'
     steps:
     - uses: actions/checkout@v2
     - uses: actions/setup-go@v2
diff --git a/internal/database/metadata/mysql/feature.go b/internal/database/metadata/mysql/feature.go
index a9d2d213..0eaf691e 100644
--- a/internal/database/metadata/mysql/feature.go
+++ b/internal/database/metadata/mysql/feature.go
@@ -12,8 +12,8 @@ func createFeature(ctx context.Context, sqlxCtx metadata.SqlxContext, opt metada
 	if err := opt.ValueType.Validate(); err != nil {
 		return 0, err
 	}
-	query := "INSERT INTO feature(name, full_name, group_id, value_type, description) VALUES (?, ?, ?, ?, ?)"
-	res, err := sqlxCtx.ExecContext(ctx, sqlxCtx.Rebind(query), opt.FeatureName, opt.FullName, opt.GroupID, opt.ValueType, opt.Description)
+	query := "INSERT INTO feature(name, group_id, value_type, description) VALUES (?, ?, ?, ?)"
+	res, err := sqlxCtx.ExecContext(ctx, sqlxCtx.Rebind(query), opt.FeatureName, opt.GroupID, opt.ValueType, opt.Description)
 	if err != nil {
 		if er, ok := err.(*mysql.MySQLError); ok {
 			if er.Number == ER_DUP_ENTRY {
diff --git a/internal/database/metadata/mysql/schema.go b/internal/database/metadata/mysql/schema.go
index fbd654e3..28d2c59e 100644
--- a/internal/database/metadata/mysql/schema.go
+++ b/internal/database/metadata/mysql/schema.go
@@ -5,7 +5,6 @@ var META_TABLE_SCHEMAS = map[string]string{
 		CREATE TABLE feature (
 			id				INT 			NOT NULL AUTO_INCREMENT PRIMARY KEY,
 			name          	VARCHAR(32) 	NOT	NULL,
-			full_name   	VARCHAR(65)		NOT NULL COMMENT "<group_name>:<feature_name>",
 			group_id      	INT         	NOT	NULL,
 			value_type    	INT         	NOT	NULL COMMENT "data type of feature value",
 			description   	VARCHAR(128)	DEFAULT '',
diff --git a/internal/database/metadata/postgres/feature.go b/internal/database/metadata/postgres/feature.go
index dfc45ef0..2cce8175 100644
--- a/internal/database/metadata/postgres/feature.go
+++ b/internal/database/metadata/postgres/feature.go
@@ -14,8 +14,8 @@ func createFeature(ctx context.Context, sqlxCtx metadata.SqlxContext, opt metada
 		return 0, err
 	}
 	var featureID int
-	query := "INSERT INTO feature(name, full_name, group_id, value_type, description) VALUES ($1, $2, $3, $4, $5) RETURNING id"
-	err := sqlxCtx.GetContext(ctx, &featureID, query, opt.FeatureName, opt.FullName, opt.GroupID, opt.ValueType, opt.Description)
+	query := "INSERT INTO feature(name, group_id, value_type, description) VALUES ($1, $2, $3, $4) RETURNING id"
+	err := sqlxCtx.GetContext(ctx, &featureID, query, opt.FeatureName, opt.GroupID, opt.ValueType, opt.Description)
 	if err != nil {
 		if e2, ok := err.(*pq.Error); ok {
 			if e2.Code == pgerrcode.UniqueViolation {
diff --git a/internal/database/metadata/postgres/schema.go b/internal/database/metadata/postgres/schema.go
index 036a0cfb..8801258f 100644
--- a/internal/database/metadata/postgres/schema.go
+++ b/internal/database/metadata/postgres/schema.go
@@ -22,17 +22,15 @@ var META_TABLE_SCHEMAS = map[string]string{
 	"feature": `
 		CREATE TABLE feature (
 			id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
-			name        	VARCHAR(32)  	NOT NULL,
-			full_name   	VARCHAR(65)		NOT NULL,
-			group_id    	INT          	NOT NULL,
-			value_type  	INT  		   	NOT NULL,
-			description 	VARCHAR(128) 	DEFAULT '',
-			create_time   	TIMESTAMP    	NOT NULL DEFAULT CURRENT_TIMESTAMP,
-			modify_time   	TIMESTAMP    	NOT NULL DEFAULT CURRENT_TIMESTAMP,
+			name          VARCHAR(32)  NOT     NULL,
+			group_id      INT          NOT     NULL,
+			value_type    INT  		   NOT     NULL,
+			description   VARCHAR(128) DEFAULT '',
+			create_time   TIMESTAMP    NOT     NULL DEFAULT CURRENT_TIMESTAMP,
+			modify_time   TIMESTAMP    NOT     NULL DEFAULT CURRENT_TIMESTAMP,
 			UNIQUE (name)
 		);
 		COMMENT ON COLUMN feature.value_type    IS 'data type of feature value';
-		COMMENT ON COLUMN feature.full_name		IS '<group_name>:<feature_name>';
 		`,
 	"feature_group": `
 		CREATE TABLE feature_group (
diff --git a/internal/database/metadata/sqlite/feature.go b/internal/database/metadata/sqlite/feature.go
index 17b7264b..11ea2381 100644
--- a/internal/database/metadata/sqlite/feature.go
+++ b/internal/database/metadata/sqlite/feature.go
@@ -13,8 +13,8 @@ func createFeature(ctx context.Context, sqlxCtx metadata.SqlxContext, opt metada
 	if err := opt.ValueType.Validate(); err != nil {
 		return 0, err
 	}
-	query := "INSERT INTO feature(name, full_name, group_id, value_type, description) VALUES (?, ?, ?, ?, ?)"
-	res, err := sqlxCtx.ExecContext(ctx, sqlxCtx.Rebind(query), opt.FeatureName, opt.FullName, opt.GroupID, opt.ValueType, opt.Description)
+	query := "INSERT INTO feature(name, group_id, value_type, description) VALUES (?, ?, ?, ?)"
+	res, err := sqlxCtx.ExecContext(ctx, sqlxCtx.Rebind(query), opt.FeatureName, opt.GroupID, opt.ValueType, opt.Description)
 	if err != nil {
 		if sqliteErr, ok := err.(sqlite3.Error); ok {
 			if sqliteErr.ExtendedCode == sqlite3.ErrConstraintUnique {
diff --git a/internal/database/metadata/sqlite/schema.go b/internal/database/metadata/sqlite/schema.go
index 7a45d341..c9a6c883 100644
--- a/internal/database/metadata/sqlite/schema.go
+++ b/internal/database/metadata/sqlite/schema.go
@@ -13,7 +13,6 @@ var META_TABLE_SCHEMAS = map[string]string{
 		CREATE TABLE feature (
 			id				INTEGER 		NOT NULL PRIMARY KEY AUTOINCREMENT,
 			name          	VARCHAR(32) 	NOT	NULL,
-			full_name   	VARCHAR(65)		NOT NULL,
 			group_id      	INT         	NOT	NULL,
 			value_type    	INT          	NOT	NULL,
 			description   	VARCHAR(128)	DEFAULT '',
diff --git a/internal/database/metadata/types.go b/internal/database/metadata/types.go
index a33add34..6809e368 100644
--- a/internal/database/metadata/types.go
+++ b/internal/database/metadata/types.go
@@ -15,7 +15,6 @@ type CreateEntityOpt struct {
 
 type CreateFeatureOpt struct {
 	FeatureName string
-	FullName    string
 	GroupID     int
 	Description string
 	ValueType   types.ValueType
diff --git a/pkg/oomstore/feature.go b/pkg/oomstore/feature.go
index eb5c0ec7..7604c5e6 100644
--- a/pkg/oomstore/feature.go
+++ b/pkg/oomstore/feature.go
@@ -64,7 +64,6 @@ func (s *OomStore) CreateBatchFeature(ctx context.Context, opt types.CreateFeatu
 
 	return s.metadata.CreateFeature(ctx, metadata.CreateFeatureOpt{
 		FeatureName: opt.FeatureName,
-		FullName:    fmt.Sprintf("%s:%s", group.Name, opt.FeatureName),
 		GroupID:     group.ID,
 		ValueType:   opt.ValueType,
 		Description: opt.Description,
diff --git a/pkg/oomstore/types/feature.go b/pkg/oomstore/types/feature.go
index e22f44b0..33270caa 100644
--- a/pkg/oomstore/types/feature.go
+++ b/pkg/oomstore/types/feature.go
@@ -7,7 +7,6 @@ import (
 type Feature struct {
 	ID        int       `db:"id"`
 	Name      string    `db:"name"`
-	FullName  string    `db:"full_name"`
 	ValueType ValueType `db:"value_type"`
 
 	Description string    `db:"description"`


Test patch:
diff --git a/internal/database/online/dynamodb/store_test.go b/internal/database/online/dynamodb/store_test.go
index 1c98dfab..182c51b1 100644
--- a/internal/database/online/dynamodb/store_test.go
+++ b/internal/database/online/dynamodb/store_test.go
@@ -2,6 +2,7 @@ package dynamodb_test
 
 import (
 	"context"
+	"fmt"
 	"testing"
 
 	"github.com/aws/aws-sdk-go-v2/aws"
@@ -30,7 +31,7 @@ func destroyStore(t *testing.T) func() {
 			if _, err := db.Client.DeleteTable(ctx, &awsDynamodb.DeleteTableInput{
 				TableName: aws.String(tableName),
 			}); err != nil {
-				panic(err)
+				panic(fmt.Sprintf("failed deleting table '%s': %v", tableName, err))
 			}
 		}
 	}
diff --git a/internal/database/online/test_impl/util.go b/internal/database/online/test_impl/util.go
index 09413ebb..b741406e 100644
--- a/internal/database/online/test_impl/util.go
+++ b/internal/database/online/test_impl/util.go
@@ -90,7 +90,7 @@ func init() {
 		entity := &types.Entity{ID: 5, Name: "user", Length: 5}
 		var data []types.ExportRecord
 
-		for i := 0; i < 1000; i++ {
+		for i := 0; i < 100; i++ {
 			record := []interface{}{dbutil.RandString(entity.Length), rand.Float64()}
 			data = append(data, record)
 		}
diff --git a/internal/database/test/runtime_dynamodb/dynamodb.go b/internal/database/test/runtime_dynamodb/dynamodb.go
index 0b9130db..ce13184b 100644
--- a/internal/database/test/runtime_dynamodb/dynamodb.go
+++ b/internal/database/test/runtime_dynamodb/dynamodb.go
@@ -3,53 +3,37 @@ package runtime_dynamodb
 import (
 	"context"
 	"fmt"
-	"os"
-	"os/signal"
-	"syscall"
+	"os/exec"
 	"testing"
 
 	"github.com/oom-ai/oomstore/internal/database/online/dynamodb"
 	"github.com/oom-ai/oomstore/pkg/oomstore/types"
-	"github.com/orlangure/gnomock"
-	"github.com/orlangure/gnomock/preset/localstack"
 )
 
-var DynamoDBDbOpt types.DynamoDBOpt
-
 func init() {
-	dynamodbContainer, err := gnomock.Start(
-		localstack.Preset(
-			localstack.WithServices(localstack.DynamoDB),
-		),
-		gnomock.WithUseLocalImagesFirst(),
-	)
-	if err != nil {
-		panic(err)
-	}
-
-	DynamoDBDbOpt = types.DynamoDBOpt{
-		Region:          "us-east-1",
-		EndpointURL:     fmt.Sprintf("http://%s/", dynamodbContainer.Address(localstack.APIPort)),
-		AccessKeyID:     "test",
-		SecretAccessKey: "test",
-		SessionToken:    "test",
-		Source:          "test",
+	if out, err := exec.Command(
+		"oomplay", "init", "dynamodb",
+		"--port", "4566",
+	).CombinedOutput(); err != nil {
+		panic(fmt.Sprintf("oomplay failed with error: %v, output: %s", err, out))
 	}
-
-	go func() {
-		c := make(chan os.Signal, 1)
-		signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT)
-		<-c
-
-		_ = gnomock.Stop(dynamodbContainer)
-	}()
 }
 
 func PrepareDB(t *testing.T) (context.Context, *dynamodb.DB) {
-	db, err := dynamodb.Open(&DynamoDBDbOpt)
+	db, err := dynamodb.Open(GetOpt())
 	if err != nil {
 		t.Fatal(err)
 	}
 	return context.Background(), db
+}
 
+func GetOpt() *types.DynamoDBOpt {
+	return &types.DynamoDBOpt{
+		Region:          ".",
+		EndpointURL:     "http://localhost:4566",
+		AccessKeyID:     ".",
+		SecretAccessKey: ".",
+		SessionToken:    ".",
+		Source:          ".",
+	}
 }
diff --git a/pkg/oomstore/feature_test.go b/pkg/oomstore/feature_test.go
index 422e6a44..ee647836 100644
--- a/pkg/oomstore/feature_test.go
+++ b/pkg/oomstore/feature_test.go
@@ -71,7 +71,6 @@ func TestCreateBatchFeature(t *testing.T) {
 			if tc.group.Category == types.BatchFeatureCategory {
 				metadataOpt := metadata.CreateFeatureOpt{
 					FeatureName: tc.opt.FeatureName,
-					FullName:    fmt.Sprintf("%s:%s", tc.opt.GroupName, tc.opt.FeatureName),
 					GroupID:     tc.group.ID,
 					ValueType:   tc.valueType,
 					Description: tc.opt.Description,