Skip to content

Commit

Permalink
Call Features() getter
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Whitehead <[email protected]>
  • Loading branch information
matthew1001 authored and EnriqueL8 committed Nov 14, 2024
1 parent a7fcea7 commit 88c253e
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 41 deletions.
2 changes: 1 addition & 1 deletion internal/database/sqlcommon/blob_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s *SQLCommon) InsertBlobs(ctx context.Context, blobs []*core.Blob) (err er
}
defer s.RollbackTx(ctx, tx, autoCommit)

if s.features.MultiRowInsert {
if s.Features().MultiRowInsert {
query := sq.Insert(blobsTable).Columns(blobColumns...)
for _, blob := range blobs {
query = s.setBlobInsertValues(query, blob)
Expand Down
12 changes: 7 additions & 5 deletions internal/database/sqlcommon/blob_sql_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021 Kaleido, Inc.
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -124,9 +124,10 @@ func TestInsertBlobsBeginFail(t *testing.T) {
}

func TestInsertBlobsMultiRowOK(t *testing.T) {
s, mock := newMockProvider().init()
s.features.MultiRowInsert = true
s := newMockProvider()
s.multiRowInsert = true
s.fakePSQLInsert = true
s, mock := s.init()

blob1 := &core.Blob{Hash: fftypes.NewRandB32(), PayloadRef: "pay1"}
blob2 := &core.Blob{Hash: fftypes.NewRandB32(), PayloadRef: "pay2"}
Expand All @@ -144,9 +145,10 @@ func TestInsertBlobsMultiRowOK(t *testing.T) {
}

func TestInsertBlobsMultiRowFail(t *testing.T) {
s, mock := newMockProvider().init()
s.features.MultiRowInsert = true
s := newMockProvider()
s.multiRowInsert = true
s.fakePSQLInsert = true
s, mock := s.init()
blob1 := &core.Blob{Hash: fftypes.NewRandB32(), PayloadRef: "pay1"}
mock.ExpectBegin()
mock.ExpectQuery("INSERT.*").WillReturnError(fmt.Errorf("pop"))
Expand Down
2 changes: 1 addition & 1 deletion internal/database/sqlcommon/data_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (s *SQLCommon) InsertDataArray(ctx context.Context, dataArray core.DataArra
}
defer s.RollbackTx(ctx, tx, autoCommit)

if s.features.MultiRowInsert {
if s.Features().MultiRowInsert {
query := sq.Insert(dataTable).Columns(dataColumnsWithValue...)
for _, data := range dataArray {
query = s.setDataInsertValues(query, data)
Expand Down
12 changes: 7 additions & 5 deletions internal/database/sqlcommon/data_sql_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021 Kaleido, Inc.
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -240,9 +240,10 @@ func TestInsertDataArrayBeginFail(t *testing.T) {
}

func TestInsertDataArrayMultiRowOK(t *testing.T) {
s, mock := newMockProvider().init()
s.features.MultiRowInsert = true
s := newMockProvider()
s.multiRowInsert = true
s.fakePSQLInsert = true
s, mock := s.init()

data1 := &core.Data{ID: fftypes.NewUUID(), Namespace: "ns1"}
data2 := &core.Data{ID: fftypes.NewUUID(), Namespace: "ns1"}
Expand All @@ -262,9 +263,10 @@ func TestInsertDataArrayMultiRowOK(t *testing.T) {
}

func TestInsertDataArrayMultiRowFail(t *testing.T) {
s, mock := newMockProvider().init()
s.features.MultiRowInsert = true
s := newMockProvider()
s.multiRowInsert = true
s.fakePSQLInsert = true
s, mock := s.init()
data1 := &core.Data{ID: fftypes.NewUUID(), Namespace: "ns1"}
mock.ExpectBegin()
mock.ExpectQuery("INSERT.*").WillReturnError(fmt.Errorf("pop"))
Expand Down
4 changes: 2 additions & 2 deletions internal/database/sqlcommon/event_sql.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Kaleido, Inc.
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -118,7 +118,7 @@ func (p *eventsPCA) PreCommit(ctx context.Context, tx *dbsql.TXWrapper) (err err
}
}

if p.s.features.MultiRowInsert {
if p.s.Features().MultiRowInsert {
query := sq.Insert(eventsTable).Columns(eventColumns...)
for _, event := range p.events {
query = p.s.setEventInsertValues(query, event)
Expand Down
12 changes: 7 additions & 5 deletions internal/database/sqlcommon/event_sql_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021 Kaleido, Inc.
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -133,9 +133,10 @@ func TestInsertEventFailCommit(t *testing.T) {
}

func TestInsertEventsPreCommitMultiRowOK(t *testing.T) {
s, mock := newMockProvider().init()
s.features.MultiRowInsert = true
s := newMockProvider()
s.multiRowInsert = true
s.fakePSQLInsert = true
s, mock := s.init()

ev1 := &core.Event{ID: fftypes.NewUUID(), Namespace: "ns1"}
ev2 := &core.Event{ID: fftypes.NewUUID(), Namespace: "ns1"}
Expand All @@ -162,9 +163,10 @@ func TestInsertEventsPreCommitMultiRowOK(t *testing.T) {
}

func TestInsertEventsPreCommitMultiRowFail(t *testing.T) {
s, mock := newMockProvider().init()
s.features.MultiRowInsert = true
s := newMockProvider()
s.multiRowInsert = true
s.fakePSQLInsert = true
s, mock := s.init()
ev1 := &core.Event{ID: fftypes.NewUUID(), Namespace: "ns1"}
mock.ExpectBegin()
mock.ExpectExec("<acquire lock ns1>").WillReturnResult(driver.ResultNoRows)
Expand Down
5 changes: 2 additions & 3 deletions internal/database/sqlcommon/message_sql.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Kaleido, Inc.
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -210,8 +210,7 @@ func (s *SQLCommon) InsertMessages(ctx context.Context, messages []*core.Message
return err
}
defer s.RollbackTx(ctx, tx, autoCommit)

if s.features.MultiRowInsert {
if s.Features().MultiRowInsert {
msgQuery := sq.Insert(messagesTable).Columns(msgColumns...)
dataRefQuery := sq.Insert(messagesDataJoinTable).Columns(
"namespace",
Expand Down
17 changes: 10 additions & 7 deletions internal/database/sqlcommon/message_sql_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021 Kaleido, Inc.
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -310,9 +310,10 @@ func TestInsertMessagesBeginFail(t *testing.T) {
}

func TestInsertMessagesMultiRowOK(t *testing.T) {
s, mock := newMockProvider().init()
s.features.MultiRowInsert = true
s := newMockProvider()
s.multiRowInsert = true
s.fakePSQLInsert = true
s, mock := s.init()

msg1 := &core.Message{Header: core.MessageHeader{ID: fftypes.NewUUID(), Namespace: "ns1"}, LocalNamespace: "ns1", Data: core.DataRefs{{ID: fftypes.NewUUID()}}}
msg2 := &core.Message{Header: core.MessageHeader{ID: fftypes.NewUUID(), Namespace: "ns1"}, LocalNamespace: "ns1", Data: core.DataRefs{{ID: fftypes.NewUUID()}}}
Expand Down Expand Up @@ -340,9 +341,10 @@ func TestInsertMessagesMultiRowOK(t *testing.T) {
}

func TestInsertMessagesMultiRowDataRefsFail(t *testing.T) {
s, mock := newMockProvider().init()
s.features.MultiRowInsert = true
s := newMockProvider()
s.multiRowInsert = true
s.fakePSQLInsert = true
s, mock := s.init()

msg1 := &core.Message{Header: core.MessageHeader{ID: fftypes.NewUUID(), Namespace: "ns1"}, Data: core.DataRefs{{ID: fftypes.NewUUID()}}}

Expand All @@ -356,9 +358,10 @@ func TestInsertMessagesMultiRowDataRefsFail(t *testing.T) {
}

func TestInsertMessagesMultiRowFail(t *testing.T) {
s, mock := newMockProvider().init()
s.features.MultiRowInsert = true
s := newMockProvider()
s.multiRowInsert = true
s.fakePSQLInsert = true
s, mock := s.init()
msg1 := &core.Message{Header: core.MessageHeader{ID: fftypes.NewUUID(), Namespace: "ns1"}}
mock.ExpectBegin()
mock.ExpectQuery("INSERT.*").WillReturnError(fmt.Errorf("pop"))
Expand Down
4 changes: 2 additions & 2 deletions internal/database/sqlcommon/pin_sql.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Kaleido, Inc.
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -124,7 +124,7 @@ func (s *SQLCommon) InsertPins(ctx context.Context, pins []*core.Pin) error {
}
defer s.RollbackTx(ctx, tx, autoCommit)

if s.features.MultiRowInsert {
if s.Features().MultiRowInsert {
query := sq.Insert(pinsTable).Columns(pinColumns...)
for _, pin := range pins {
query = s.setPinInsertValues(query, pin)
Expand Down
12 changes: 7 additions & 5 deletions internal/database/sqlcommon/pin_sql_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021 Kaleido, Inc.
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -146,9 +146,10 @@ func TestInsertPinsBeginFail(t *testing.T) {
}

func TestInsertPinsMultiRowOK(t *testing.T) {
s, mock := newMockProvider().init()
s.features.MultiRowInsert = true
s := newMockProvider()
s.multiRowInsert = true
s.fakePSQLInsert = true
s, mock := s.init()

pin1 := &core.Pin{Namespace: "ns1", Hash: fftypes.NewRandB32()}
pin2 := &core.Pin{Namespace: "ns1", Hash: fftypes.NewRandB32()}
Expand All @@ -168,9 +169,10 @@ func TestInsertPinsMultiRowOK(t *testing.T) {
}

func TestInsertPinsMultiRowFail(t *testing.T) {
s, mock := newMockProvider().init()
s.features.MultiRowInsert = true
s := newMockProvider()
s.multiRowInsert = true
s.fakePSQLInsert = true
s, mock := s.init()
pin1 := &core.Pin{Hash: fftypes.NewRandB32()}
mock.ExpectBegin()
mock.ExpectQuery("INSERT.*").WillReturnError(fmt.Errorf("pop"))
Expand Down
5 changes: 4 additions & 1 deletion internal/database/sqlcommon/provider_mock_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021 Kaleido, Inc.
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -45,6 +45,7 @@ type mockProvider struct {
openError error
getMigrationDriverError error
individualSort bool
multiRowInsert bool
}

func newMockProvider() *mockProvider {
Expand All @@ -59,6 +60,7 @@ func newMockProvider() *mockProvider {
mp.SQLCommon.InitConfig(mp, mp.config)
mp.config.Set(SQLConfMaxConnections, 10)
mp.mockDB, mp.mdb, _ = sqlmock.New()
mp.multiRowInsert = false
return mp
}

Expand All @@ -84,6 +86,7 @@ func (mp *mockProvider) MigrationsDir() string {
func (psql *mockProvider) Features() dbsql.SQLFeatures {
features := dbsql.DefaultSQLProviderFeatures()
features.UseILIKE = true
features.MultiRowInsert = psql.multiRowInsert
features.AcquireLock = func(lockName string) string {
return fmt.Sprintf(`<acquire lock %s>`, lockName)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/database/sqlcommon/sqlcommon.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Kaleido, Inc.
// Copyright © 2023 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -33,7 +33,6 @@ type SQLCommon struct {
dbsql.Database
capabilities *database.Capabilities
callbacks callbacks
features dbsql.SQLFeatures
}

type callbacks struct {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/multiparty/ethereum_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package multiparty
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
"os/exec"
"testing"
Expand Down Expand Up @@ -316,7 +316,7 @@ func readContractJSON(t *testing.T, contract string) fftypes.JSONObject {
jsonFile, err := os.Open(path)
assert.NoError(t, err)
defer jsonFile.Close()
byteValue, err := ioutil.ReadAll(jsonFile)
byteValue, err := io.ReadAll(jsonFile)
assert.NoError(t, err)
var jsonValue fftypes.JSONObject
err = json.Unmarshal(byteValue, &jsonValue)
Expand Down

0 comments on commit 88c253e

Please sign in to comment.