From 264bc4f7e478eb37709169017e52931768a1287b Mon Sep 17 00:00:00 2001 From: Burak Sezer Date: Sat, 14 Aug 2021 11:44:24 +0300 Subject: [PATCH] feat: add Name() to expose DMap name --- dmap.go | 7 ++++++- dmap_test.go | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dmap.go b/dmap.go index 0f24ba17..233f3324 100644 --- a/dmap.go +++ b/dmap.go @@ -28,7 +28,7 @@ type dmap struct { storage *storage.Storage } -// dmap represents a distributed map instance. +// DMap represents a distributed map instance. type DMap struct { name string db *Olric @@ -51,6 +51,11 @@ func (db *Olric) NewDMap(name string) (*DMap, error) { }, nil } +// Name exposes DMap name. +func (dm *DMap) Name() string { + return dm.name +} + // createDMap creates and returns a new dmap, internal representation of a dmap. This function is not thread-safe. func (db *Olric) createDMap(part *partition, name string, str *storage.Storage) (*dmap, error) { // create a new map here. diff --git a/dmap_test.go b/dmap_test.go index 9f37a8c6..46f4c02a 100644 --- a/dmap_test.go +++ b/dmap_test.go @@ -265,6 +265,10 @@ func TestDMap_Standalone(t *testing.T) { t.Fatalf("Expected value %v. Got: %v", value, val) } + if d.Name() != d.name { + t.Fatalf("Expected DMap name: %s. Got: %s", d.name, d.Name()) + } + // Delete it and check again. err = d.Delete(key) if err != nil {