Skip to content

Commit bd4729b

Browse files
authored
chore: remove unused code (#764)
1 parent 666615c commit bd4729b

13 files changed

Lines changed: 81 additions & 88 deletions

.github/workflows/unit-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ jobs:
6666
fi
6767
6868
- name: staticcheck .
69-
run: staticcheck -checks "inherit,-U1000" ./...
69+
run: staticcheck ./...
7070

7171
- name: staticcheck ./examples
7272
working-directory: ./examples
73-
run: staticcheck -checks "inherit,-U1000" ./...
73+
run: staticcheck ./...
7474

7575
- name: staticcheck ./benchmarks
7676
working-directory: ./benchmarks
77-
run: staticcheck -checks "inherit,-U1000" ./...
77+
run: staticcheck ./...

conn.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,10 +1468,6 @@ func (c *conn) setReadOnlyTransactionOptions(options *ReadOnlyTransactionOptions
14681468
}
14691469
}
14701470

1471-
func (c *conn) getReadOnlyTransactionOptions() ReadOnlyTransactionOptions {
1472-
return ReadOnlyTransactionOptions{TimestampBound: c.ReadOnlyStaleness(), BeginTransactionOption: c.convertDefaultBeginTransactionOption(propertyBeginTransactionOption.GetValueOrDefault(c.state))}
1473-
}
1474-
14751471
func (c *conn) setBatchReadOnlyTransactionOptions(options *BatchReadOnlyTransactionOptions) {
14761472
if options == nil {
14771473
return
@@ -1481,10 +1477,6 @@ func (c *conn) setBatchReadOnlyTransactionOptions(options *BatchReadOnlyTransact
14811477
}
14821478
}
14831479

1484-
func (c *conn) getBatchReadOnlyTransactionOptions() BatchReadOnlyTransactionOptions {
1485-
return BatchReadOnlyTransactionOptions{TimestampBound: c.ReadOnlyStaleness()}
1486-
}
1487-
14881480
// BeginReadOnlyTransaction is not part of the public API of the database/sql driver.
14891481
// It is exported for internal reasons, and may receive breaking changes without prior notice.
14901482
//

conn_with_mockserver_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,7 @@ func TestGenericConnectionState_GoogleSQL(t *testing.T) {
14181418
verifyConnectionPropertyValue(t, conn, "max_commit_delay", "100ms")
14191419
// Verify that other connection variables have a default value.
14201420
verifyConnectionPropertyValue(t, conn, "auto_batch_dml", false)
1421+
verifyConnectionPropertyValue(t, conn, propertyTransactionDeferrable.Key(), false)
14211422

14221423
// Verify that changing a connection variable value outside a transaction works.
14231424
setConnectionPropertyValue(t, conn, "max_commit_delay", "50ms")

driver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ func createConnector(d *Driver, connectorConfig ConnectorConfig) (*connector, er
688688
assignPropertyValueIfExists(state, propertyDisableNativeMetrics, &config.DisableNativeMetrics)
689689
assignPropertyValueIfExists(state, propertyDecodeToNativeArrays, &connectorConfig.DecodeToNativeArrays)
690690
assignPropertyValueIfExists(state, propertyAutoConfigEmulator, &connectorConfig.AutoConfigEmulator)
691+
assignPropertyValueIfExists(state, propertyConnectionStateType, &connectorConfig.ConnectionStateType)
691692
assignPropertyValueIfExists(state, propertyIsolationLevel, &connectorConfig.IsolationLevel)
692693
assignPropertyValueIfExists(state, propertyBeginTransactionOption, &connectorConfig.BeginTransactionOption)
693694
assignPropertyValueIfExists(state, propertyStatementCacheSize, &connectorConfig.StatementCacheSize)

driver_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,23 @@ func TestExtractDnsParts(t *testing.T) {
278278
input: "project/p/instances/i/databases/d",
279279
wantErr: true,
280280
},
281+
{
282+
input: "projects/p/instances/i/databases/d?connection_state_type=TRANSACTIONAL",
283+
wantConnectorConfig: ConnectorConfig{
284+
Project: "p",
285+
Instance: "i",
286+
Database: "d",
287+
Params: map[string]string{
288+
"connection_state_type": "TRANSACTIONAL",
289+
},
290+
ConnectionStateType: connectionstate.TypeTransactional,
291+
},
292+
wantSpannerConfig: spanner.ClientConfig{
293+
//lint:ignore SA1019 Needs a change that is backwards compatible
294+
SessionPoolConfig: spanner.DefaultSessionPoolConfig,
295+
UserAgent: userAgent,
296+
},
297+
},
281298
}
282299
for _, tc := range tests {
283300
t.Run(tc.input, func(t *testing.T) {
@@ -1053,3 +1070,20 @@ type ValuerNil struct {
10531070
func (v ValuerNil) Value() (driver.Value, error) {
10541071
return v.Name, nil
10551072
}
1073+
1074+
func TestConnectionStateTypeInitialization(t *testing.T) {
1075+
dsn := "projects/p/instances/i/databases/d?connection_state_type=TRANSACTIONAL"
1076+
config, err := ExtractConnectorConfig(dsn)
1077+
if err != nil {
1078+
t.Fatalf("ExtractConnectorConfig failed: %v", err)
1079+
}
1080+
1081+
c, err := createConnector(&Driver{}, config)
1082+
if err != nil {
1083+
t.Fatalf("createConnector failed: %v", err)
1084+
}
1085+
1086+
if c.connectorConfig.ConnectionStateType != connectionstate.TypeTransactional {
1087+
t.Errorf("ConnectionStateType mismatch. Got: %v, Want: %v", c.connectorConfig.ConnectionStateType, connectionstate.TypeTransactional)
1088+
}
1089+
}

driver_with_mockserver_test.go

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/google/go-cmp/cmp"
3939
"github.com/google/go-cmp/cmp/cmpopts"
4040
"github.com/google/uuid"
41+
"github.com/googleapis/go-sql-spanner/connectionstate"
4142
"github.com/googleapis/go-sql-spanner/parser"
4243
"github.com/googleapis/go-sql-spanner/testutil"
4344
"google.golang.org/api/option"
@@ -3698,6 +3699,47 @@ func TestMaxSessions(t *testing.T) {
36983699
}
36993700
}
37003701

3702+
func TestConnectionStateType(t *testing.T) {
3703+
t.Parallel()
3704+
3705+
ctx := context.Background()
3706+
db, _, teardown := setupTestDBConnectionWithParams(t, "connection_state_type=TRANSACTIONAL")
3707+
defer teardown()
3708+
3709+
c, err := db.Conn(ctx)
3710+
if err != nil {
3711+
t.Fatalf("failed to get a connection: %v", err)
3712+
}
3713+
3714+
verifyConnectionPropertyValue(t, c, "connection_state_type", connectionstate.TypeTransactional)
3715+
// Check that the behavior is actually transactional.
3716+
verifyConnectionPropertyValue(t, c, "data_boost_enabled", false)
3717+
tx, err := c.BeginTx(ctx, nil)
3718+
if err != nil {
3719+
t.Fatalf("failed to begin transaction: %v", err)
3720+
}
3721+
if _, err := tx.ExecContext(ctx, "set data_boost_enabled = true"); err != nil {
3722+
t.Fatalf("failed to set data_boost_enabled: %v", err)
3723+
}
3724+
if err := tx.Commit(); err != nil {
3725+
t.Fatalf("failed to commit transaction: %v", err)
3726+
}
3727+
verifyConnectionPropertyValue(t, c, "data_boost_enabled", true)
3728+
3729+
tx, err = c.BeginTx(ctx, nil)
3730+
if err != nil {
3731+
t.Fatalf("failed to begin transaction: %v", err)
3732+
}
3733+
if _, err := tx.ExecContext(ctx, "set data_boost_enabled = false"); err != nil {
3734+
t.Fatalf("failed to set data_boost_enabled: %v", err)
3735+
}
3736+
// Rolling back the transaction should also roll back the change to data_boost_enabled.
3737+
if err := tx.Rollback(); err != nil {
3738+
t.Fatalf("failed to rollback transaction: %v", err)
3739+
}
3740+
verifyConnectionPropertyValue(t, c, "data_boost_enabled", true)
3741+
}
3742+
37013743
func TestClientReuse(t *testing.T) {
37023744
// This test is intentionally not parallel, as the internal caching of clients could
37033745
// be impacted by other parallel tests.
@@ -5821,13 +5863,6 @@ func date(v string) civil.Date {
58215863
return res
58225864
}
58235865

5824-
func nullDate(valid bool, v string) spanner.NullDate {
5825-
if !valid {
5826-
return spanner.NullDate{}
5827-
}
5828-
return spanner.NullDate{Valid: true, Date: date(v)}
5829-
}
5830-
58315866
func nullJson(valid bool, v string) spanner.NullJSON {
58325867
if !valid {
58335868
return spanner.NullJSON{}
@@ -5969,28 +6004,3 @@ func filterBeginReadOnlyRequests(requests []interface{}) []*sppb.BeginTransactio
59696004
}
59706005
return res
59716006
}
5972-
5973-
func waitFor(t *testing.T, assert func() error) {
5974-
t.Helper()
5975-
timeout := 5 * time.Second
5976-
ta := time.After(timeout)
5977-
5978-
for {
5979-
select {
5980-
case <-ta:
5981-
if err := assert(); err != nil {
5982-
t.Fatalf("after %v waiting, got %v", timeout, err)
5983-
}
5984-
return
5985-
default:
5986-
}
5987-
5988-
if err := assert(); err != nil {
5989-
// Fail. Let's pause and retry.
5990-
time.Sleep(time.Millisecond)
5991-
continue
5992-
}
5993-
5994-
return
5995-
}
5996-
}

integration_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,6 @@ func skipIfShort(t *testing.T) {
315315
}
316316
}
317317

318-
func skipIfEmulator(t *testing.T, msg string) {
319-
if runsOnEmulator() {
320-
t.Skip(msg)
321-
}
322-
}
323-
324318
func TestAutoConfigEmulator(t *testing.T) {
325319
skipIfShort(t)
326320
if !runsOnEmulator() {

merged_row_iterator.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ func (m *mergedRowIterator) produceRowsFromPartition(ctx context.Context, index
168168
}
169169
}
170170

171-
func (m *mergedRowIterator) isStopped() bool {
172-
m.mu.Lock()
173-
defer m.mu.Unlock()
174-
return m.err != nil
175-
}
176-
177171
func (m *mergedRowIterator) hasErr() bool {
178172
m.mu.Lock()
179173
defer m.mu.Unlock()

parser/simple_parser.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,6 @@ func (p *simpleParser) isValidIdentifierChar() bool {
180180
return p.sql[p.pos] == '_' || p.sql[p.pos] == '$' || isLatinLetter(p.sql[p.pos]) || isLatinDigit(p.sql[p.pos])
181181
}
182182

183-
func (p *simpleParser) isValidDollarTagIdentifierChar() bool {
184-
return p.isValidIdentifierChar() && !p.isDollar()
185-
}
186-
187183
func (p *simpleParser) isDollar() bool {
188184
return !p.isMultibyte() && p.sql[p.pos] == '$'
189185
}

parser/statement_parser.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -717,26 +717,10 @@ func isDDLKeyword(keyword string) bool {
717717
return isStatementKeyword(keyword, ddlStatements)
718718
}
719719

720-
// isDml returns true if the given sql string is a Dml statement.
721-
// This function assumes that any comments and hints at the start
722-
// of the sql string have been removed.
723-
func (p *StatementParser) isDml(query string) bool {
724-
info := p.DetectStatementType(query)
725-
return info.StatementType == StatementTypeDml
726-
}
727-
728720
func isDmlKeyword(keyword string) bool {
729721
return isStatementKeyword(keyword, dmlStatements)
730722
}
731723

732-
// isQuery returns true if the given sql string is a SELECT statement.
733-
// This function assumes that any comments and hints at the start
734-
// of the sql string have been removed.
735-
func (p *StatementParser) isQuery(query string) bool {
736-
info := p.DetectStatementType(query)
737-
return info.StatementType == StatementTypeQuery
738-
}
739-
740724
func isQueryKeyword(keyword string) bool {
741725
return isStatementKeyword(keyword, selectStatements)
742726
}

0 commit comments

Comments
 (0)