From 615b5bd65707d45ca084425e9f7144b988f2b9a3 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Mon, 25 Sep 2023 22:27:52 +0300 Subject: [PATCH 1/2] Fixed Map LoadAll --- map_it_test.go | 33 ++++++++++++++++++--------------- proxy_map.go | 11 ++++++----- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/map_it_test.go b/map_it_test.go index 6fab7d474..ae3b26ae2 100644 --- a/map_it_test.go +++ b/map_it_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved. + * Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License") * you may not use this file except in compliance with the License. @@ -674,20 +674,23 @@ func mapLoadAllReplacing(t *testing.T) { return "test-map" } it.MapTesterWithConfigAndName(t, makeMapName, nil, func(t *testing.T, m *hz.Map) { - keys := putSampleKeyValues(m, 10) - it.Must(m.EvictAll(context.Background())) - it.Must(m.LoadAllReplacing(context.Background())) - entrySet := it.MustValue(m.GetAll(context.Background(), keys...)).([]types.Entry) - if len(keys) != len(entrySet) { - t.Fatalf("target len: %d != %d", len(keys), len(entrySet)) - } - it.Must(m.EvictAll(context.Background())) - keys = keys[:5] - it.Must(m.LoadAllReplacing(context.Background(), keys...)) - entrySet = it.MustValue(m.GetAll(context.Background(), keys...)).([]types.Entry) - if len(keys) != len(entrySet) { - t.Fatalf("target len: %d != %d", len(keys), len(entrySet)) - } + ctx := context.Background() + keys := putSampleKeyValues(m, 2) + // load all keys + it.Must(m.EvictAll(ctx)) + size := it.MustValue(m.Size(ctx)) + assert.Equal(t, 0, size) + it.Must(m.LoadAllReplacing(ctx)) + size = it.MustValue(m.Size(ctx)) + assert.Equal(t, 2, size) + // load some keys + it.Must(m.EvictAll(ctx)) + size = it.MustValue(m.Size(ctx)) + assert.Equal(t, 0, size) + keys = keys[:1] + it.Must(m.LoadAllReplacing(ctx, keys...)) + size = it.MustValue(m.Size(ctx)) + assert.Equal(t, 1, size) }) } diff --git a/proxy_map.go b/proxy_map.go index ce1f51a71..14a7041b2 100644 --- a/proxy_map.go +++ b/proxy_map.go @@ -1392,12 +1392,13 @@ func (m *Map) addEntryListener(ctx context.Context, flags int32, includeValue bo return subscriptionID, err } -func (m *Map) loadAll(ctx context.Context, replaceExisting bool, keys ...interface{}) error { - if len(keys) == 0 { - return nil - } +func (m *Map) loadAll(ctx context.Context, replaceExisting bool, keys ...interface{}) (err error) { if m.hasNearCache { - return m.ncm.LoadAll(ctx, m, replaceExisting, keys) + defer func() { + if err == nil { + err = m.ncm.Clear(ctx, m) + } + }() } return m.loadAllFromRemote(ctx, replaceExisting, keys) } From 2caa3261c60eb0da16dfbf02985566db9c49ea60 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Mon, 25 Sep 2023 23:09:15 +0300 Subject: [PATCH 2/2] Updates --- map_it_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/map_it_test.go b/map_it_test.go index ae3b26ae2..a11f7d6d4 100644 --- a/map_it_test.go +++ b/map_it_test.go @@ -651,6 +651,7 @@ func mapLoadAllWithoutReplacing(t *testing.T) { return "test-map" } it.MapTesterWithConfigAndName(t, makeMapName, nil, func(t *testing.T, m *hz.Map) { + it.Must(m.Destroy(context.Background())) putSampleKeyValues(m, 2) it.Must(m.EvictAll(context.Background())) it.Must(m.PutTransient(context.Background(), "k0", "new-v0")) @@ -675,6 +676,7 @@ func mapLoadAllReplacing(t *testing.T) { } it.MapTesterWithConfigAndName(t, makeMapName, nil, func(t *testing.T, m *hz.Map) { ctx := context.Background() + it.Must(m.Destroy(ctx)) keys := putSampleKeyValues(m, 2) // load all keys it.Must(m.EvictAll(ctx))