Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Sortedset inconsistencies #239

Merged
merged 7 commits into from
Mar 7, 2023
Merged
Prev Previous commit
Next Next commit
feat!: SortedSetGetRank takes Value, SortedSetGetScores takes Values.
There's nothing different about values in sorted sets from any other value.
schwern committed Mar 7, 2023

Unverified

No user is associated with the committer email.
commit 11e518f4d28a4baa0b36043aba1c35a307e14f9a
8 changes: 4 additions & 4 deletions momento/sorted_set_get_rank.go
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@ import (
)

type SortedSetGetRankRequest struct {
CacheName string
SetName string
ElementValue Value
CacheName string
SetName string
Value Value

grpcRequest *pb.XSortedSetGetRankRequest
grpcResponse *pb.XSortedSetGetRankResponse
@@ -30,7 +30,7 @@ func (r *SortedSetGetRankRequest) initGrpcRequest(scsDataClient) error {
}

var value []byte
if value, err = prepareElementValue(r.ElementValue); err != nil {
if value, err = prepareElementValue(r.Value); err != nil {
return err
}

8 changes: 4 additions & 4 deletions momento/sorted_set_get_scores.go
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@ import (
)

type SortedSetGetScoresRequest struct {
CacheName string
SetName string
ElementValues []Value
CacheName string
SetName string
Values []Value

grpcRequest *pb.XSortedSetGetScoreRequest
grpcResponse *pb.XSortedSetGetScoreResponse
@@ -29,7 +29,7 @@ func (r *SortedSetGetScoresRequest) initGrpcRequest(scsDataClient) error {
return err
}

values, err := momentoValuesToPrimitiveByteList(r.ElementValues)
values, err := momentoValuesToPrimitiveByteList(r.Values)
if err != nil {
return err
}
12 changes: 6 additions & 6 deletions momento/sorted_set_increment_score.go
Original file line number Diff line number Diff line change
@@ -14,11 +14,11 @@ import (
)

type SortedSetIncrementScoreRequest struct {
CacheName string
SetName string
ElementValue Value
Amount float64
Ttl *utils.CollectionTtl
CacheName string
SetName string
Value Value
Amount float64
Ttl *utils.CollectionTtl

grpcRequest *pb.XSortedSetIncrementRequest
grpcResponse *pb.XSortedSetIncrementResponse
@@ -47,7 +47,7 @@ func (r *SortedSetIncrementScoreRequest) initGrpcRequest(client scsDataClient) e
}

var value []byte
if value, err = prepareElementValue(r.ElementValue); err != nil {
if value, err = prepareElementValue(r.Value); err != nil {
return err
}

106 changes: 53 additions & 53 deletions momento/sorted_set_test.go
Original file line number Diff line number Diff line change
@@ -62,20 +62,20 @@ var _ = Describe("SortedSet", func() {

Expect(
client.SortedSetGetRank(ctx, &SortedSetGetRankRequest{
CacheName: cacheName, SetName: collectionName, ElementValue: element,
CacheName: cacheName, SetName: collectionName, Value: element,
}),
).Error().To(HaveMomentoErrorCode(expectedError))

elements := []Value{element}
Expect(
client.SortedSetGetScores(ctx, &SortedSetGetScoresRequest{
CacheName: cacheName, SetName: collectionName, ElementValues: elements,
CacheName: cacheName, SetName: collectionName, Values: elements,
}),
).Error().To(HaveMomentoErrorCode(expectedError))

Expect(
client.SortedSetIncrementScore(ctx, &SortedSetIncrementScoreRequest{
CacheName: cacheName, SetName: collectionName, ElementValue: element, Amount: 1,
CacheName: cacheName, SetName: collectionName, Value: element, Amount: 1,
}),
).Error().To(HaveMomentoErrorCode(expectedError))

@@ -168,10 +168,10 @@ var _ = Describe("SortedSet", func() {
`SortedSetIncrementScore`,
func(element SortedSetPutElement, ttl *utils.CollectionTtl) {
request := &SortedSetIncrementScoreRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValue: element.Value,
Amount: element.Score,
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: element.Value,
Amount: element.Score,
}
if ttl != nil {
request.Ttl = ttl
@@ -288,9 +288,9 @@ var _ = Describe("SortedSet", func() {
sharedContext.Client.SortedSetGetRank(
sharedContext.Ctx,
&SortedSetGetRankRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValue: String("foo"),
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("foo"),
},
),
).To(BeAssignableToTypeOf(&SortedSetGetRankMiss{}))
@@ -308,16 +308,16 @@ var _ = Describe("SortedSet", func() {
resp, err := sharedContext.Client.SortedSetGetRank(
sharedContext.Ctx,
&SortedSetGetRankRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValue: String("first"),
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("first"),
},
)
Expect(err).To(BeNil())
Expect(resp).To(Equal(SortedSetGetRankHit(2)))
switch r := resp.(type) {
case SortedSetGetRankHit:
Expect(r.Rank()).To(Equal(2))
Expect(r.Rank()).To(Equal(uint64(2)))
default:
Fail(fmt.Sprintf("Wrong type: %T", r))
}
@@ -326,9 +326,9 @@ var _ = Describe("SortedSet", func() {
sharedContext.Client.SortedSetGetRank(
sharedContext.Ctx,
&SortedSetGetRankRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValue: String("last"),
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("last"),
},
),
).To(Equal(SortedSetGetRankHit(0)))
@@ -339,9 +339,9 @@ var _ = Describe("SortedSet", func() {
sharedContext.Client.SortedSetGetRank(
sharedContext.Ctx,
&SortedSetGetRankRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValue: nil,
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: nil,
},
),
).Error().To(HaveMomentoErrorCode(InvalidArgumentError))
@@ -354,9 +354,9 @@ var _ = Describe("SortedSet", func() {
sharedContext.Client.SortedSetGetScores(
sharedContext.Ctx,
&SortedSetGetScoresRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValues: []Value{String("foo")},
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Values: []Value{String("foo")},
},
),
).To(BeAssignableToTypeOf(&SortedSetGetScoresMiss{}))
@@ -377,7 +377,7 @@ var _ = Describe("SortedSet", func() {
&SortedSetGetScoresRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValues: []Value{
Values: []Value{
String("first"), String("last"), String("dne"),
},
},
@@ -398,9 +398,9 @@ var _ = Describe("SortedSet", func() {
sharedContext.Client.SortedSetGetScores(
sharedContext.Ctx,
&SortedSetGetScoresRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValues: nil,
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Values: nil,
},
),
).Error().To(HaveMomentoErrorCode(InvalidArgumentError))
@@ -409,9 +409,9 @@ var _ = Describe("SortedSet", func() {
sharedContext.Client.SortedSetGetScores(
sharedContext.Ctx,
&SortedSetGetScoresRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValues: []Value{nil, String("aValue"), nil},
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Values: []Value{nil, String("aValue"), nil},
},
),
).Error().To(HaveMomentoErrorCode(InvalidArgumentError))
@@ -424,10 +424,10 @@ var _ = Describe("SortedSet", func() {
sharedContext.Client.SortedSetIncrementScore(
sharedContext.Ctx,
&SortedSetIncrementScoreRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValue: String("dne"),
Amount: 99,
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("dne"),
Amount: 99,
},
),
).To(BeAssignableToTypeOf(&SortedSetIncrementScoreSuccess{Value: 99}))
@@ -438,10 +438,10 @@ var _ = Describe("SortedSet", func() {
sharedContext.Client.SortedSetIncrementScore(
sharedContext.Ctx,
&SortedSetIncrementScoreRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValue: String("dne"),
Amount: 0,
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("dne"),
Amount: 0,
},
),
).Error().To(HaveMomentoErrorCode(InvalidArgumentError))
@@ -452,9 +452,9 @@ var _ = Describe("SortedSet", func() {
sharedContext.Client.SortedSetIncrementScore(
sharedContext.Ctx,
&SortedSetIncrementScoreRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValue: String("dne"),
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("dne"),
},
),
).Error().To(HaveMomentoErrorCode(InvalidArgumentError))
@@ -473,10 +473,10 @@ var _ = Describe("SortedSet", func() {
sharedContext.Client.SortedSetIncrementScore(
sharedContext.Ctx,
&SortedSetIncrementScoreRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValue: String("middle"),
Amount: 42,
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("middle"),
Amount: 42,
},
),
).To(BeAssignableToTypeOf(&SortedSetIncrementScoreSuccess{Value: 92}))
@@ -485,10 +485,10 @@ var _ = Describe("SortedSet", func() {
sharedContext.Client.SortedSetIncrementScore(
sharedContext.Ctx,
&SortedSetIncrementScoreRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValue: String("middle"),
Amount: -42,
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: String("middle"),
Amount: -42,
},
),
).To(BeAssignableToTypeOf(&SortedSetIncrementScoreSuccess{Value: 50}))
@@ -499,10 +499,10 @@ var _ = Describe("SortedSet", func() {
sharedContext.Client.SortedSetIncrementScore(
sharedContext.Ctx,
&SortedSetIncrementScoreRequest{
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
ElementValue: nil,
Amount: 42,
CacheName: sharedContext.CacheName,
SetName: sharedContext.CollectionName,
Value: nil,
Amount: 42,
},
),
).Error().To(HaveMomentoErrorCode(InvalidArgumentError))