-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
442 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package e2e_bigquery | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/jackc/pgx/v5" | ||
|
||
connpostgres "github.com/PeerDB-io/peer-flow/connectors/postgres" | ||
"github.com/PeerDB-io/peer-flow/e2e" | ||
"github.com/PeerDB-io/peer-flow/generated/protos" | ||
"github.com/PeerDB-io/peer-flow/model" | ||
"github.com/PeerDB-io/peer-flow/shared" | ||
) | ||
|
||
type PeerFlowE2ETestSuiteBQ struct { | ||
t *testing.T | ||
|
||
bqSuffix string | ||
conn *connpostgres.PostgresConnector | ||
bqHelper *BigQueryTestHelper | ||
} | ||
|
||
func (s PeerFlowE2ETestSuiteBQ) T() *testing.T { | ||
return s.t | ||
} | ||
|
||
func (s PeerFlowE2ETestSuiteBQ) Conn() *pgx.Conn { | ||
return s.conn.Conn() | ||
} | ||
|
||
func (s PeerFlowE2ETestSuiteBQ) Connector() *connpostgres.PostgresConnector { | ||
return s.conn | ||
} | ||
|
||
func (s PeerFlowE2ETestSuiteBQ) Suffix() string { | ||
return s.bqSuffix | ||
} | ||
|
||
func (s PeerFlowE2ETestSuiteBQ) Peer() *protos.Peer { | ||
return s.bqHelper.Peer | ||
} | ||
|
||
func (s PeerFlowE2ETestSuiteBQ) GetRows(tableName string, colsString string) (*model.QRecordBatch, error) { | ||
s.t.Helper() | ||
qualifiedTableName := fmt.Sprintf("`%s.%s`", s.bqHelper.Config.DatasetId, tableName) | ||
bqSelQuery := fmt.Sprintf("SELECT %s FROM %s ORDER BY id", colsString, qualifiedTableName) | ||
s.t.Logf("running query on bigquery: %s", bqSelQuery) | ||
return s.bqHelper.ExecuteAndProcessQuery(bqSelQuery) | ||
} | ||
|
||
func (s PeerFlowE2ETestSuiteBQ) GetRowsWhere(tableName string, colsString string, where string) (*model.QRecordBatch, error) { | ||
s.t.Helper() | ||
qualifiedTableName := fmt.Sprintf("`%s.%s`", s.bqHelper.Config.DatasetId, tableName) | ||
bqSelQuery := fmt.Sprintf("SELECT %s FROM %s WHERE %s ORDER BY id", colsString, qualifiedTableName, where) | ||
s.t.Logf("running query on bigquery: %s", bqSelQuery) | ||
return s.bqHelper.ExecuteAndProcessQuery(bqSelQuery) | ||
} | ||
|
||
func (s PeerFlowE2ETestSuiteBQ) Teardown() { | ||
e2e.TearDownPostgres(s) | ||
|
||
err := s.bqHelper.DropDataset(s.bqHelper.Config.DatasetId) | ||
if err != nil { | ||
s.t.Fatalf("failed to tear down bigquery: %v", err) | ||
} | ||
} | ||
|
||
func SetupSuite(t *testing.T) PeerFlowE2ETestSuiteBQ { | ||
t.Helper() | ||
|
||
suffix := shared.RandomString(8) | ||
tsSuffix := time.Now().Format("20060102150405") | ||
bqSuffix := fmt.Sprintf("bq_%s_%s", strings.ToLower(suffix), tsSuffix) | ||
conn, err := e2e.SetupPostgres(t, bqSuffix) | ||
if err != nil || conn == nil { | ||
t.Fatalf("failed to setup postgres: %v", err) | ||
} | ||
|
||
bqHelper, err := NewBigQueryTestHelper() | ||
if err != nil { | ||
t.Fatalf("Failed to create helper: %v", err) | ||
} | ||
|
||
err = bqHelper.RecreateDataset() | ||
if err != nil { | ||
t.Fatalf("Failed to recreate dataset: %v", err) | ||
} | ||
|
||
return PeerFlowE2ETestSuiteBQ{ | ||
t: t, | ||
bqSuffix: bqSuffix, | ||
conn: conn, | ||
bqHelper: bqHelper, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package e2e_generic | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/PeerDB-io/peer-flow/e2e" | ||
"github.com/PeerDB-io/peer-flow/e2e/bigquery" | ||
"github.com/PeerDB-io/peer-flow/e2e/postgres" | ||
"github.com/PeerDB-io/peer-flow/e2e/snowflake" | ||
"github.com/PeerDB-io/peer-flow/e2eshared" | ||
"github.com/PeerDB-io/peer-flow/generated/protos" | ||
peerflow "github.com/PeerDB-io/peer-flow/workflows" | ||
) | ||
|
||
type GenericSuite interface { | ||
e2e.RowSource | ||
Peer() *protos.Peer | ||
} | ||
|
||
func TestGenericPG(t *testing.T) { | ||
e2eshared.RunSuite(t, SetupGenericSuite(e2e_postgres.SetupSuite)) | ||
} | ||
|
||
func TestGenericSF(t *testing.T) { | ||
e2eshared.RunSuite(t, SetupGenericSuite(e2e_snowflake.SetupSuite)) | ||
} | ||
|
||
func TestGenericBQ(t *testing.T) { | ||
e2eshared.RunSuite(t, SetupGenericSuite(e2e_bigquery.SetupSuite)) | ||
} | ||
|
||
type GenericWrapper struct { | ||
GenericSuite | ||
} | ||
|
||
func SetupGenericSuite[T GenericSuite](f func(t *testing.T) T) func(t *testing.T) GenericWrapper { | ||
return func(t *testing.T) GenericWrapper { | ||
t.Helper() | ||
return GenericWrapper{f(t)} | ||
} | ||
} | ||
|
||
func (s GenericWrapper) Test_Simple_Flow() { | ||
t := s.T() | ||
srcTableName := e2e.AttachSchema(s, "test_simple_flow") | ||
dstTableName := e2e.AttachSchema(s, "test_simple_flow_dst") | ||
|
||
_, err := s.Connector().Conn().Exec(context.Background(), fmt.Sprintf(` | ||
CREATE TABLE IF NOT EXISTS %s ( | ||
id SERIAL PRIMARY KEY, | ||
key TEXT NOT NULL, | ||
value TEXT NOT NULL, | ||
myh HSTORE NOT NULL | ||
); | ||
`, srcTableName)) | ||
require.NoError(t, err) | ||
|
||
connectionGen := e2e.FlowConnectionGenerationConfig{ | ||
FlowJobName: e2e.AddSuffix(s, "test_simple_flow"), | ||
TableNameMapping: map[string]string{srcTableName: dstTableName}, | ||
Destination: s.Peer(), | ||
} | ||
|
||
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs() | ||
flowConnConfig.MaxBatchSize = 100 | ||
|
||
tc := e2e.NewTemporalClient(t) | ||
env := e2e.ExecutePeerflow(tc, peerflow.CDCFlowWorkflow, flowConnConfig, nil) | ||
|
||
e2e.SetupCDCFlowStatusQuery(t, env, connectionGen) | ||
// insert 10 rows into the source table | ||
for i := range 10 { | ||
testKey := fmt.Sprintf("test_key_%d", i) | ||
testValue := fmt.Sprintf("test_value_%d", i) | ||
_, err = s.Connector().Conn().Exec(context.Background(), fmt.Sprintf(` | ||
INSERT INTO %s(key, value, myh) VALUES ($1, $2, '"a"=>"b"') | ||
`, srcTableName), testKey, testValue) | ||
e2e.EnvNoError(t, env, err) | ||
} | ||
t.Log("Inserted 10 rows into the source table") | ||
|
||
e2e.EnvWaitForEqualTables(env, s, "normalizing 10 rows", "id,key,value,myh", `id,key,value,myh`) | ||
env.Cancel() | ||
e2e.RequireEnvCanceled(t, env) | ||
} |
Oops, something went wrong.