Skip to content

Commit 202062b

Browse files
authored
test fixes and documentation for new existing row semantics
Updated tests and method documentation for new existing row semantics.
1 parent 2699756 commit 202062b

File tree

6 files changed

+200
-99
lines changed

6 files changed

+200
-99
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/).
55

6+
## Unreleased
7+
8+
### Changed
9+
- Internal: updated tests for upcoming new "return existing row" semantics
10+
611
## 1.4.6 - 2024-08-12
712

813
### Fixed

nosqldb/client.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ type Client struct {
102102
// InTest is used for internal SDK testing. It controls logic that may be
103103
// specific to testing only.
104104
InTest bool
105+
106+
// Internal: used by tests. This is _not_ the wire protocol version.
107+
serverSerialVersion int
105108
}
106109

107110
var (
@@ -1524,6 +1527,7 @@ func (c *Client) processResponse(httpResp *http.Response, req Request, serialVer
15241527

15251528
if httpResp.StatusCode == http.StatusOK {
15261529
c.setSessionCookie(httpResp.Header)
1530+
c.setServerSerialVersion(httpResp.Header)
15271531
return c.processOKResponse(data, req, serialVerUsed, queryVerUsed)
15281532
}
15291533

@@ -1599,6 +1603,39 @@ func (c *Client) setSessionCookie(header http.Header) {
15991603
})
16001604
}
16011605

1606+
// setServerSerialVersion sets the server serial version (not the protocol version)
1607+
// in the client, if not already set.
1608+
// Note that if the client is connected to multiple proxies via a load balancer, this
1609+
// may set an inconsistent value. But this value is only used internally for testing,
1610+
// in which case only a single proxy is used.
1611+
func (c *Client) setServerSerialVersion(header http.Header) {
1612+
if header == nil || c.serverSerialVersion > 0 {
1613+
return
1614+
}
1615+
v := header.Get("x-nosql-serial-version")
1616+
if v == "" {
1617+
return
1618+
}
1619+
c.lockMux.Lock()
1620+
defer c.lockMux.Unlock()
1621+
i, err := strconv.Atoi(v)
1622+
if err == nil {
1623+
c.serverSerialVersion = i
1624+
c.logger.LogWithFn(logger.Fine, func() string {
1625+
return fmt.Sprintf("Set server serial version to %d", c.serverSerialVersion)
1626+
})
1627+
} else {
1628+
c.logger.LogWithFn(logger.Fine, func() string {
1629+
return fmt.Sprintf("Set server serial version failed: %v", err)
1630+
})
1631+
}
1632+
}
1633+
1634+
// GetServerSerialVersion is used by tests to determine feature capabilities.
1635+
func (c *Client) GetServerSerialVersion() int {
1636+
return c.serverSerialVersion
1637+
}
1638+
16021639
// processNotOKResponse processes the http response whose status code is not 200.
16031640
func (c *Client) processNotOKResponse(data []byte, statusCode int) error {
16041641
if statusCode == http.StatusBadRequest && len(data) > 0 {

0 commit comments

Comments
 (0)