11
11
import static org .hamcrest .Matchers .sameInstance ;
12
12
import static org .hamcrest .junit .MatcherAssert .assertThat ;
13
13
14
+ import com .google .code .tempusfugit .concurrency .IntermittentTestRunner ;
15
+ import com .google .code .tempusfugit .concurrency .annotations .Intermittent ;
14
16
import com .meterware .simplestub .Memento ;
15
17
import com .meterware .simplestub .StaticStubSupport ;
16
18
import io .kubernetes .client .models .V1ObjectMeta ;
27
29
import org .junit .Test ;
28
30
import org .junit .rules .TestWatcher ;
29
31
import org .junit .runner .Description ;
32
+ import org .junit .runner .RunWith ;
30
33
34
+ @ RunWith (IntermittentTestRunner .class )
31
35
public class ServerKubernetesObjectsLookupTest {
32
36
33
37
private List <Memento > mementos = new ArrayList <>();
34
38
39
+ private String retryLegalName ;
40
+ private ServerKubernetesObjects retryInstance ;
41
+
35
42
@ Rule
36
43
public TestWatcher watcher =
37
44
new TestWatcher () {
38
45
@ Override
39
46
protected void failed (Throwable e , Description description ) {
40
47
super .failed (e , description );
41
48
System .out .println ("Tell Russell\n " + DomainPresenceMonitor .getExplanation ());
42
- try {
43
- Memento serverMap =
44
- StaticStubSupport .preserve (ServerKubernetesObjectsManager .class , "serverMap" );
45
- Map <String , ServerKubernetesObjects > map = serverMap .getOriginalValue ();
46
- System .out .println (" internal: " + map );
47
- System .out .println (
48
- " returned: " + ServerKubernetesObjectsManager .getServerKubernetesObjects ());
49
- } catch (NoSuchFieldException ignored ) {
50
- }
49
+ Map <String , ServerKubernetesObjects > returnedMap =
50
+ ServerKubernetesObjectsManager .getServerKubernetesObjects ();
51
+
52
+ System .out .printf (
53
+ "\n Object in map with key %s is %s, which compares %b" ,
54
+ retryLegalName ,
55
+ returnedMap .get (retryLegalName ),
56
+ retryInstance == returnedMap .get (retryLegalName ));
51
57
}
52
58
};
53
59
@@ -81,6 +87,7 @@ public void whenNoPreexistingDomains_createEmptyServerKubernetesObjectsMap() {
81
87
}
82
88
83
89
@ Test
90
+ @ Intermittent (repetition = 10 )
84
91
public void whenK8sHasDomainWithOneServer_canLookupFromServerKubernetesObjectsFactory () {
85
92
Domain domain = createDomain ("UID1" , "ns1" );
86
93
DomainPresenceInfo info = DomainPresenceInfoManager .getOrCreate (domain );
@@ -89,6 +96,8 @@ public void whenK8sHasDomainWithOneServer_canLookupFromServerKubernetesObjectsFa
89
96
90
97
assertThat (info .getServers (), hasEntry (equalTo ("admin" ), sameInstance (sko )));
91
98
99
+ retryLegalName = LegalNames .toServerName ("UID1" , "admin" );
100
+ retryInstance = sko ;
92
101
assertThat (
93
102
ServerKubernetesObjectsManager .getServerKubernetesObjects (),
94
103
hasEntry (equalTo (LegalNames .toServerName ("UID1" , "admin" )), sameInstance (sko )));
0 commit comments