oracale: return ttlExpiryTime in GetResponse (#2897)
Signed-off-by: joshvanl <me@joshvanl.dev>
This commit is contained in:
parent
fa90710794
commit
f125940490
|
@ -491,6 +491,13 @@ func setTTLUpdatesExpiry(t *testing.T, ods state.Store) {
|
|||
|
||||
assert.NotNil(t, expirationTime)
|
||||
assert.True(t, expirationTime.Valid, "Expiration Time should have a value after set with TTL value")
|
||||
|
||||
resp, err := ods.Get(context.Background(), &state.GetRequest{Key: key})
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, resp.Metadata, "ttlExpireTime")
|
||||
expireTime, err := time.Parse(time.RFC3339, resp.Metadata["ttlExpireTime"])
|
||||
_ = assert.NoError(t, err) && assert.InDelta(t, time.Now().Add(time.Second*1000).Unix(), expireTime.Unix(), 10)
|
||||
|
||||
deleteItem(t, ods, key, nil)
|
||||
}
|
||||
|
||||
|
@ -517,6 +524,9 @@ func setNoTTLUpdatesExpiry(t *testing.T, ods state.Store) {
|
|||
// expirationTime should not be set.
|
||||
db := getDB(ods)
|
||||
_, _, expirationTime := getTimesForRow(t, db, key)
|
||||
resp, err := ods.Get(context.Background(), &state.GetRequest{Key: key})
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, resp.Metadata, "ttlExpireTime")
|
||||
|
||||
assert.True(t, !expirationTime.Valid, "Expiration Time should not have a value after first being set with TTL value and then being set without TTL value")
|
||||
deleteItem(t, ods, key, nil)
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
|
@ -215,11 +216,12 @@ func (o *oracleDatabaseAccess) Get(ctx context.Context, req *state.GetRequest) (
|
|||
return nil, errors.New("missing key in get operation")
|
||||
}
|
||||
var (
|
||||
value string
|
||||
binaryYN string
|
||||
etag string
|
||||
value string
|
||||
binaryYN string
|
||||
etag string
|
||||
expireTime sql.NullTime
|
||||
)
|
||||
err := o.db.QueryRowContext(ctx, "SELECT value, binary_yn, etag FROM "+o.metadata.TableName+" WHERE key = :key AND (expiration_time IS NULL OR expiration_time > systimestamp)", req.Key).Scan(&value, &binaryYN, &etag)
|
||||
err := o.db.QueryRowContext(ctx, "SELECT value, binary_yn, etag, expiration_time FROM "+o.metadata.TableName+" WHERE key = :key AND (expiration_time IS NULL OR expiration_time > systimestamp)", req.Key).Scan(&value, &binaryYN, &etag, &expireTime)
|
||||
if err != nil {
|
||||
// If no rows exist, return an empty response, otherwise return the error.
|
||||
if err == sql.ErrNoRows {
|
||||
|
@ -227,6 +229,13 @@ func (o *oracleDatabaseAccess) Get(ctx context.Context, req *state.GetRequest) (
|
|||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var metadata map[string]string
|
||||
if expireTime.Valid {
|
||||
metadata = map[string]string{
|
||||
state.GetRespMetaKeyTTLExpireTime: expireTime.Time.UTC().Format(time.RFC3339),
|
||||
}
|
||||
}
|
||||
if binaryYN == "Y" {
|
||||
var (
|
||||
s string
|
||||
|
@ -241,13 +250,13 @@ func (o *oracleDatabaseAccess) Get(ctx context.Context, req *state.GetRequest) (
|
|||
return &state.GetResponse{
|
||||
Data: data,
|
||||
ETag: &etag,
|
||||
Metadata: req.Metadata,
|
||||
Metadata: metadata,
|
||||
}, nil
|
||||
}
|
||||
return &state.GetResponse{
|
||||
Data: []byte(value),
|
||||
ETag: &etag,
|
||||
Metadata: req.Metadata,
|
||||
Metadata: metadata,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue