@@ -13,7 +13,9 @@ import (
1313 "github.com/oracle/coherence-go-client/v2/coherence/filters"
1414 "github.com/oracle/coherence-go-client/v2/coherence/processors"
1515 "github.com/oracle/coherence-go-client/v2/test/utils"
16+ "log"
1617 "math"
18+ "strconv"
1719 "testing"
1820 "time"
1921)
@@ -583,6 +585,63 @@ func TestNearCachePruneFactor(t *testing.T) {
583585 g .Expect (coherence.GetNearCachePruneFactor [int , string ](namedCache )).To (gomega .Equal (float32 (0.8 )))
584586}
585587
588+ // TestNearCacheComparison runs tests to compare near and normal cache and outputs size and memory usage.
589+ func TestNearCacheComparison (t * testing.T ) {
590+ g := gomega .NewWithT (t )
591+ session , err := utils .GetSession ()
592+ g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
593+ defer session .Close ()
594+
595+ const maxValues = 2_000
596+
597+ nearCacheOptions := & coherence.NearCacheOptions {HighUnits : maxValues * 2 }
598+ namedCache , err := coherence .GetNamedCache [string , string ](session , "no-near-cache" )
599+ g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
600+
601+ namedCacheNear , err := coherence .GetNamedCache [string , string ](session , "near-cache" , coherence .WithNearCache (nearCacheOptions ))
602+ g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
603+
604+ g .Expect (namedCache .Clear (ctx )).ShouldNot (gomega .HaveOccurred ())
605+ g .Expect (namedCacheNear .Clear (ctx )).ShouldNot (gomega .HaveOccurred ())
606+
607+ values := make (map [string ]string , 0 )
608+
609+ // populate the map
610+ for i := 1 ; i <= maxValues ; i ++ {
611+ kv := strconv .Itoa (i )
612+ values [kv ] = kv
613+ }
614+
615+ log .Printf ("Insert %v entries into caches" , maxValues )
616+
617+ g .Expect (namedCache .PutAll (ctx , values )).ShouldNot (gomega .HaveOccurred ())
618+ g .Expect (namedCacheNear .PutAll (ctx , values )).ShouldNot (gomega .HaveOccurred ())
619+
620+ log .Println ("Start" , maxValues , "gets on normal cache" )
621+ start := time .Now ()
622+ for i := 1 ; i <= maxValues ; i ++ {
623+ kv := strconv .Itoa (i )
624+ _ , err = namedCache .Get (ctx , kv )
625+ g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
626+ }
627+
628+ log .Printf ("Time to get %v from normal cache is %v" , maxValues , time .Since (start ))
629+
630+ for j := 1 ; j <= 2 ; j ++ {
631+ log .Printf ("Run %v of get %v gets on near cache" , j , maxValues )
632+ start = time .Now ()
633+ for i := 1 ; i <= maxValues ; i ++ {
634+ kv := strconv .Itoa (i )
635+ _ , err = namedCacheNear .Get (ctx , kv )
636+ g .Expect (err ).ShouldNot (gomega .HaveOccurred ())
637+ }
638+
639+ log .Printf ("Run: %v time to get %v from near cache is %v" , j , maxValues , time .Since (start ))
640+ }
641+
642+ log .Println (namedCacheNear .GetNearCacheStats ())
643+ }
644+
586645// TestInvalidNearCacheOptions runs tests to ensure that we can't create a named cache/map with invalid options.
587646func TestInvalidNearCacheOptions (t * testing.T ) {
588647 var (
0 commit comments