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.NotNil(t, expirationTime)
|
||||||
assert.True(t, expirationTime.Valid, "Expiration Time should have a value after set with TTL value")
|
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)
|
deleteItem(t, ods, key, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,6 +524,9 @@ func setNoTTLUpdatesExpiry(t *testing.T, ods state.Store) {
|
||||||
// expirationTime should not be set.
|
// expirationTime should not be set.
|
||||||
db := getDB(ods)
|
db := getDB(ods)
|
||||||
_, _, expirationTime := getTimesForRow(t, db, key)
|
_, _, 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")
|
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)
|
deleteItem(t, ods, key, nil)
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
|
@ -218,8 +219,9 @@ func (o *oracleDatabaseAccess) Get(ctx context.Context, req *state.GetRequest) (
|
||||||
value string
|
value string
|
||||||
binaryYN string
|
binaryYN string
|
||||||
etag 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 err != nil {
|
||||||
// If no rows exist, return an empty response, otherwise return the error.
|
// If no rows exist, return an empty response, otherwise return the error.
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
|
@ -227,6 +229,13 @@ func (o *oracleDatabaseAccess) Get(ctx context.Context, req *state.GetRequest) (
|
||||||
}
|
}
|
||||||
return nil, err
|
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" {
|
if binaryYN == "Y" {
|
||||||
var (
|
var (
|
||||||
s string
|
s string
|
||||||
|
@ -241,13 +250,13 @@ func (o *oracleDatabaseAccess) Get(ctx context.Context, req *state.GetRequest) (
|
||||||
return &state.GetResponse{
|
return &state.GetResponse{
|
||||||
Data: data,
|
Data: data,
|
||||||
ETag: &etag,
|
ETag: &etag,
|
||||||
Metadata: req.Metadata,
|
Metadata: metadata,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
return &state.GetResponse{
|
return &state.GetResponse{
|
||||||
Data: []byte(value),
|
Data: []byte(value),
|
||||||
ETag: &etag,
|
ETag: &etag,
|
||||||
Metadata: req.Metadata,
|
Metadata: metadata,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue