@@ -25,6 +25,7 @@ import (
25
25
"math/rand"
26
26
"os"
27
27
"strconv"
28
+ "sync"
28
29
"testing"
29
30
"time"
30
31
@@ -65,7 +66,7 @@ func TestSmokeNearCachePopulation(t *testing.T) {
65
66
ctx := context .Background ()
66
67
ncc := nearcache.Config {Name : mapName }
67
68
ncc .SetInvalidateOnChange (true )
68
- cfg := cls .DefaultConfig ()
69
+ cfg := cls .DefaultConfigWithNoSSL ()
69
70
cfg .AddNearCache (ncc )
70
71
client := it .MustClient (hz .StartNewClientWithConfig (nil , cfg ))
71
72
defer client .Shutdown (ctx )
@@ -368,24 +369,36 @@ func TestNearCacheGet(t *testing.T) {
368
369
369
370
func TestNearCacheInvalidateOnChange (t * testing.T ) {
370
371
// port of: com.hazelcast.client.map.impl.nearcache.ClientMapNearCacheTest#testNearCacheInvalidateOnChange
371
- tcx := newNearCacheMapTestContextWithExpiration (t , nearcache .InMemoryFormatObject , true )
372
- tcx .Tester (func (tcx it.MapTestContext ) {
373
- m := tcx .M
374
- t := tcx .T
375
- ctx := context .Background ()
376
- const size = 118
377
- populateServerMapWithString (ctx , tcx , size )
378
- // populate Near Cache
379
- populateNearCacheWithString (tcx , size )
380
- oec := m .LocalMapStats ().NearCacheStats .OwnedEntryCount
381
- require .Equal (t , int64 (size ), oec )
382
- // invalidate Near Cache from server side
383
- populateServerMapWithString (ctx , tcx , size )
384
- it .Eventually (t , func () bool {
385
- oec := m .LocalMapStats ().NearCacheStats .OwnedEntryCount
386
- t .Logf ("OEC: %d" , oec )
387
- return oec == 0
388
- })
372
+ tcx := it.MapTestContext {T : t }
373
+ const port = 54001
374
+ clusterName := t .Name ()
375
+ clsCfg := invalidationXMLConfig (clusterName , "non-existent" , port )
376
+ tcx .Cluster = it .StartNewClusterWithConfig (1 , clsCfg , port )
377
+ defer tcx .Cluster .Shutdown ()
378
+ ctx := context .Background ()
379
+ const size = 118
380
+ tcx .MapName = it .NewUniqueObjectName ("map" )
381
+ populateServerMapWithString (ctx , tcx , size )
382
+ ncc := nearcache.Config {
383
+ Name : tcx .MapName ,
384
+ }
385
+ ncc .SetInvalidateOnChange (true )
386
+ cfg := tcx .Cluster .DefaultConfigWithNoSSL ()
387
+ cfg .AddNearCache (ncc )
388
+ tcx .Config = & cfg
389
+ tcx .Client = it .MustClient (hz .StartNewClientWithConfig (ctx , * tcx .Config ))
390
+ defer tcx .Client .Shutdown (ctx )
391
+ tcx .M = it .MustValue (tcx .Client .GetMap (ctx , tcx .MapName )).(* hz.Map )
392
+ // populate Near Cache
393
+ populateNearCacheWithString (tcx , size )
394
+ oec := tcx .M .LocalMapStats ().NearCacheStats .OwnedEntryCount
395
+ require .Equal (t , int64 (size ), oec )
396
+ // invalidate Near Cache from server side
397
+ populateServerMapWithString (ctx , tcx , size )
398
+ it .Eventually (t , func () bool {
399
+ oec := tcx .M .LocalMapStats ().NearCacheStats .OwnedEntryCount
400
+ t .Logf ("OEC: %d" , oec )
401
+ return oec == 0
389
402
})
390
403
}
391
404
@@ -925,7 +938,7 @@ func TestMemberLoadAllInvalidatesClientNearCache(t *testing.T) {
925
938
map.loadAll(true);
926
939
` , tcx .MapName )
927
940
}
928
- memberInvalidatesClientNearCache (t , f )
941
+ memberInvalidatesClientNearCache (t , 51001 , f )
929
942
}
930
943
931
944
func TestMemberPutAllInvalidatesClientNearCache (t * testing.T ) {
@@ -940,11 +953,12 @@ func TestMemberPutAllInvalidatesClientNearCache(t *testing.T) {
940
953
map.putAll(items);
941
954
` , size , tcx .MapName )
942
955
}
943
- memberInvalidatesClientNearCache (t , f )
956
+ memberInvalidatesClientNearCache (t , 51011 , f )
944
957
}
945
958
946
959
func TestMemberSetAllInvalidatesClientNearCache (t * testing.T ) {
947
960
// see: com.hazelcast.client.map.impl.nearcache.ClientMapNearCacheTest#testMemberSetAll_invalidates_clientNearCache
961
+ it .SkipIf (t , "hz > 4, hz < 4.1" )
948
962
f := func (tcx it.MapTestContext , size int32 ) string {
949
963
return fmt .Sprintf (`
950
964
var items = new java.util.HashMap(%[1]d);
@@ -955,10 +969,117 @@ func TestMemberSetAllInvalidatesClientNearCache(t *testing.T) {
955
969
map.setAll(items);
956
970
` , size , tcx .MapName )
957
971
}
958
- memberInvalidatesClientNearCache (t , f )
972
+ memberInvalidatesClientNearCache (t , 51021 , f )
959
973
}
960
974
961
- func memberInvalidatesClientNearCache (t * testing.T , makeScript func (tcx it.MapTestContext , size int32 ) string ) {
975
+ func TestForceRepairingTaskRun (t * testing.T ) {
976
+ // TODO: mark this test slow.
977
+ // this is a test for covering async init of RepairingTask.
978
+ clusterName := t .Name ()
979
+ mapName := it .NewUniqueObjectName ("map" )
980
+ const port = 53001
981
+ clsCfg := invalidationXMLConfig (clusterName , "non-existent" , port )
982
+ cls := it .StartNewClusterWithConfig (1 , clsCfg , port )
983
+ const mapSize = 1000
984
+ // populate server side map
985
+ for i := 0 ; i < mapSize ; i ++ {
986
+ v := strconv .Itoa (i )
987
+ it .MapSetOnServer (cls .ClusterID , mapName , v , v )
988
+ }
989
+ // add client with Near Cache
990
+ ctx := context .Background ()
991
+ cfg := cls .DefaultConfigWithNoSSL ()
992
+ cfg .NearCacheInvalidation .SetReconciliationIntervalSeconds (30 )
993
+ cfg .NearCacheInvalidation .SetMaxToleratedMissCount (1 )
994
+ ncc := nearcache.Config {
995
+ Name : mapName ,
996
+ }
997
+ ncc .SetInvalidateOnChange (true )
998
+ cfg .AddNearCache (ncc )
999
+ client := it .MustClient (hz .StartNewClientWithConfig (nil , cfg ))
1000
+ defer client .Shutdown (ctx )
1001
+ ic := hz .NewClientInternal (client )
1002
+ mgr := ic .NewNearCacheManager (1 , 1 )
1003
+ defer mgr .Stop ()
1004
+ m := it .MustValue (client .GetMap (ctx , mapName )).(* hz.Map )
1005
+ nca := hz .MakeNearCacheAdapterFromMap (m ).(it.NearCacheAdapter )
1006
+ for i := int32 (0 ); i < mapSize ; i ++ {
1007
+ if _ , err := m .Get (ctx , i ); err != nil {
1008
+ t .Fatal (err )
1009
+ }
1010
+ }
1011
+ cls .Shutdown ()
1012
+ wg := & sync.WaitGroup {}
1013
+ wg .Add (1 )
1014
+ go func () {
1015
+ time .Sleep (2 * time .Second )
1016
+ cls = it .StartNewClusterWithConfig (1 , clsCfg , port )
1017
+ t .Logf ("starting the new cluster: %p" , & cls )
1018
+ wg .Done ()
1019
+ }()
1020
+ defer func () {
1021
+ t .Logf ("stopping the new cluster: %p" , & cls )
1022
+ cls .Shutdown ()
1023
+ }()
1024
+ _ , err := mgr .RepairingTask ().RegisterAndGetHandler (ctx , mapName , nca .NearCache ())
1025
+ if err != nil {
1026
+ panic (err )
1027
+ }
1028
+ time .Sleep (2 * time .Second )
1029
+ wg .Wait ()
1030
+ // populate server side map
1031
+ for i := 0 ; i < mapSize ; i ++ {
1032
+ v := strconv .Itoa (i )
1033
+ it .MapSetOnServer (cls .ClusterID , mapName , v , v )
1034
+ }
1035
+ for i := int32 (0 ); i < mapSize ; i ++ {
1036
+ if _ , err := m .Get (ctx , i ); err != nil {
1037
+ t .Fatal (err )
1038
+ }
1039
+ }
1040
+ t .Logf ("waiting for the repair task do its job" )
1041
+ time .Sleep (35 * time .Second )
1042
+ if err := m .Destroy (ctx ); err != nil {
1043
+ t .Fatal (err )
1044
+ }
1045
+ }
1046
+
1047
+ func TestRepairingTaskRun (t * testing.T ) {
1048
+ // this is a test for covering sync init of RepairingTask.
1049
+ clusterName := t .Name ()
1050
+ mapName := it .NewUniqueObjectName ("map" )
1051
+ const port = 53011
1052
+ clsCfg := invalidationXMLConfig (clusterName , "non-existent" , port )
1053
+ cls := it .StartNewClusterWithConfig (1 , clsCfg , port )
1054
+ defer cls .Shutdown ()
1055
+ const mapSize = 1000
1056
+ // populate server side map
1057
+ for i := 0 ; i < mapSize ; i ++ {
1058
+ v := strconv .Itoa (i )
1059
+ it .MapSetOnServer (cls .ClusterID , mapName , v , v )
1060
+ }
1061
+ // add client with Near Cache
1062
+ ctx := context .Background ()
1063
+ cfg := cls .DefaultConfigWithNoSSL ()
1064
+ ncc := nearcache.Config {
1065
+ Name : mapName ,
1066
+ }
1067
+ cfg .AddNearCache (ncc )
1068
+ client := it .MustClient (hz .StartNewClientWithConfig (nil , cfg ))
1069
+ defer client .Shutdown (ctx )
1070
+ ic := hz .NewClientInternal (client )
1071
+ mgr := ic .NewNearCacheManager (1 , 1 )
1072
+ defer mgr .Stop ()
1073
+ m := it .MustValue (client .GetMap (ctx , mapName )).(* hz.Map )
1074
+ for i := int32 (0 ); i < mapSize ; i ++ {
1075
+ if _ , err := m .Get (ctx , i ); err != nil {
1076
+ t .Fatal (err )
1077
+ }
1078
+ }
1079
+ time .Sleep (2 * time .Second )
1080
+ }
1081
+
1082
+ func memberInvalidatesClientNearCache (t * testing.T , port int , makeScript func (tcx it.MapTestContext , size int32 ) string ) {
962
1083
// ported from: com.hazelcast.client.map.impl.nearcache.ClientMapNearCacheTest#testMemberLoadAll_invalidates_clientNearCache
963
1084
tcx := it.MapTestContext {
964
1085
T : t ,
@@ -967,7 +1088,6 @@ func memberInvalidatesClientNearCache(t *testing.T, makeScript func(tcx it.MapTe
967
1088
}
968
1089
clusterName := t .Name ()
969
1090
tcx .MapName = it .NewUniqueObjectName ("map" )
970
- const port = 51001
971
1091
clsCfg := invalidationXMLConfig (clusterName , tcx .MapName , port )
972
1092
cls := it .StartNewClusterWithConfig (1 , clsCfg , port )
973
1093
defer cls .Shutdown ()
@@ -978,10 +1098,11 @@ func memberInvalidatesClientNearCache(t *testing.T, makeScript func(tcx it.MapTe
978
1098
InMemoryFormat : nearcache .InMemoryFormatBinary ,
979
1099
}
980
1100
ncc .SetInvalidateOnChange (true )
981
- cfg := cls .DefaultConfig ()
1101
+ cfg := cls .DefaultConfigWithNoSSL ()
982
1102
cfg .AddNearCache (ncc )
983
1103
tcx .Config = & cfg
984
1104
client := it .MustClient (hz .StartNewClientWithConfig (nil , cfg ))
1105
+ defer client .Shutdown (ctx )
985
1106
tcx .Client = client
986
1107
m := it .MustValue (tcx .Client .GetMap (ctx , tcx .MapName )).(* hz.Map )
987
1108
tcx .M = m
0 commit comments