77import io .ebean .config .ServerConfig ;
88import org .junit .Test ;
99
10+ import static org .assertj .core .api .Assertions .assertThat ;
11+
1012public class ClusterTest {
1113
1214
@@ -23,31 +25,70 @@ private EbeanServer createOther() {
2325 }
2426
2527 @ Test
26- public void test () {
28+ public void test () throws InterruptedException {
2729
2830 EbeanServer server = Ebean .getDefaultServer ();
2931
3032 EbeanServer other = createOther ();
3133
3234 for (int i = 0 ; i < 10 ; i ++) {
33- EFoo foo = new EFoo ("name " + i );
35+ EFoo foo = new EFoo ("name " + i );
3436 foo .save ();
3537 }
3638
3739
3840 other .getServerCacheManager ().clearAll ();
3941
42+ DuelCache dualCache = (DuelCache ) other .getServerCacheManager ().getBeanCache (EFoo .class );
43+
4044 EFoo foo0 = other .find (EFoo .class , 1 );
41- EFoo foo1 = other .find (EFoo .class , 1 );
42- EFoo foo2 = other .find (EFoo .class , 1 );
45+ assertCounts (dualCache , 0 , 1 , 0 , 1 );
4346
44- other .getServerCacheManager ().clearAll ();
47+ other .find (EFoo .class , 1 );
48+ assertCounts (dualCache , 1 , 1 , 0 , 1 );
49+
50+ other .find (EFoo .class , 1 );
51+ assertCounts (dualCache , 2 , 1 , 0 , 1 );
52+
53+ other .find (EFoo .class , 1 );
54+ assertCounts (dualCache , 3 , 1 , 0 , 1 );
55+
56+ other .find (EFoo .class , 2 );
57+ assertCounts (dualCache , 3 , 2 , 0 , 2 );
58+
59+
60+ //other.getServerCacheManager().clearAll();
4561
46- System .out .println ("done" );
62+
63+ foo0 .setName ("name2" );
64+ foo0 .save ();
65+ allowAsyncMessaging ();
4766
4867 EFoo foo3 = other .find (EFoo .class , 1 );
68+ assertThat (foo3 .getName ()).isEqualTo ("name2" );
69+ assertCounts (dualCache , 3 , 3 , 1 , 2 );
70+
71+
72+ foo0 .setName ("name3" );
73+ foo0 .save ();
74+ allowAsyncMessaging ();
75+
76+ foo3 = other .find (EFoo .class , 1 );
77+ assertThat (foo3 .getName ()).isEqualTo ("name3" );
78+ assertCounts (dualCache , 3 , 4 , 2 , 2 );
4979
5080 System .out .println ("done" );
81+ }
82+
83+ private void assertCounts (DuelCache dualCache , int nearHits , int nearMiss , int remoteHit , int remoteMiss ) {
84+
85+ assertThat (dualCache .getNearHitCount ()).isEqualTo (nearHits );
86+ assertThat (dualCache .getNearMissCount ()).isEqualTo (nearMiss );
87+ assertThat (dualCache .getRemoteHitCount ()).isEqualTo (remoteHit );
88+ assertThat (dualCache .getRemoteMissCount ()).isEqualTo (remoteMiss );
89+ }
5190
91+ private void allowAsyncMessaging () throws InterruptedException {
92+ Thread .sleep (200 );
5293 }
5394}
0 commit comments