Skip to content

Commit 6003f0f

Browse files
authored
Fixes map PutIfAbsentXXX methods (#829)
1 parent 89fbb4e commit 6003f0f

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

map_it_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008-2021, Hazelcast, Inc. All Rights Reserved.
2+
* Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License")
55
* you may not use this file except in compliance with the License.
@@ -93,23 +93,29 @@ func TestMap_PutWithTTLAndMaxIdle(t *testing.T) {
9393
func TestMap_PutIfAbsent(t *testing.T) {
9494
it.MapTester(t, func(t *testing.T, m *hz.Map) {
9595
targetValue := "value"
96-
if _, err := m.PutIfAbsent(context.Background(), "key", targetValue); err != nil {
96+
v, err := m.PutIfAbsent(context.Background(), "key", targetValue)
97+
if err != nil {
9798
t.Fatal(err)
9899
}
100+
it.AssertEquals(t, nil, v)
99101
it.AssertEquals(t, targetValue, it.MustValue(m.Get(context.Background(), "key")))
100-
if _, err := m.PutIfAbsent(context.Background(), "key", "another-value"); err != nil {
102+
v, err = m.PutIfAbsent(context.Background(), "key", "another-value")
103+
if err != nil {
101104
t.Fatal(err)
102105
}
106+
it.AssertEquals(t, "value", v)
103107
it.AssertEquals(t, targetValue, it.MustValue(m.Get(context.Background(), "key")))
104108
})
105109
}
106110

107111
func TestMap_PutIfAbsentWithTTL(t *testing.T) {
108112
it.MapTester(t, func(t *testing.T, m *hz.Map) {
109113
targetValue := "value"
110-
if _, err := m.PutIfAbsentWithTTL(context.Background(), "key", targetValue, 1*time.Second); err != nil {
114+
v, err := m.PutIfAbsentWithTTL(context.Background(), "key", targetValue, 1*time.Second)
115+
if err != nil {
111116
t.Fatal(err)
112117
}
118+
assert.Equal(t, nil, v)
113119
assert.Equal(t, targetValue, it.MustValue(m.Get(context.Background(), "key")))
114120
it.Eventually(t, func() bool {
115121
return it.MustValue(m.Get(context.Background(), "key")) == nil
@@ -120,9 +126,11 @@ func TestMap_PutIfAbsentWithTTL(t *testing.T) {
120126
func TestMap_PutIfAbsentWithTTLAndMaxIdle(t *testing.T) {
121127
it.MapTester(t, func(t *testing.T, m *hz.Map) {
122128
targetValue := "value"
123-
if _, err := m.PutIfAbsentWithTTLAndMaxIdle(context.Background(), "key", targetValue, 1*time.Second, 1*time.Second); err != nil {
129+
v, err := m.PutIfAbsentWithTTLAndMaxIdle(context.Background(), "key", targetValue, 1*time.Second, 1*time.Second)
130+
if err != nil {
124131
t.Fatal(err)
125132
}
133+
assert.Equal(t, nil, v)
126134
assert.Equal(t, targetValue, it.MustValue(m.Get(context.Background(), "key")))
127135
it.Eventually(t, func() bool {
128136
return it.MustValue(m.Get(context.Background(), "key")) == nil

proxy_map.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008-2021, Hazelcast, Inc. All Rights Reserved.
2+
* Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License")
55
* you may not use this file except in compliance with the License.
@@ -688,7 +688,7 @@ func (m *Map) PutIfAbsentWithTTLAndMaxIdle(ctx context.Context, key interface{},
688688
if response, err := m.invokeOnKey(ctx, request, keyData); err != nil {
689689
return nil, err
690690
} else {
691-
return codec.DecodeMapPutIfAbsentWithMaxIdleResponse(response), nil
691+
return m.convertToObject(codec.DecodeMapPutIfAbsentWithMaxIdleResponse(response))
692692
}
693693
}
694694
}
@@ -1053,7 +1053,7 @@ func (m *Map) putIfAbsent(ctx context.Context, key interface{}, value interface{
10531053
if response, err := m.invokeOnKey(ctx, request, keyData); err != nil {
10541054
return nil, err
10551055
} else {
1056-
return codec.DecodeMapPutIfAbsentResponse(response), nil
1056+
return m.convertToObject(codec.DecodeMapPutIfAbsentResponse(response))
10571057
}
10581058
}
10591059
}

0 commit comments

Comments
 (0)