17
17
package io .grpc .internal ;
18
18
19
19
import static com .google .common .truth .Truth .assertThat ;
20
- import static org .junit .Assert .fail ;
21
20
import static org .mockito .ArgumentMatchers .isA ;
22
21
import static org .mockito .Mockito .mock ;
23
22
import static org .mockito .Mockito .verify ;
28
27
import io .grpc .NameResolver .ResolutionResult ;
29
28
import io .grpc .Status ;
30
29
import io .grpc .SynchronizationContext ;
31
- import io .grpc .internal .RetryingNameResolver .ResolutionResultListener ;
32
30
import java .lang .Thread .UncaughtExceptionHandler ;
33
31
import org .junit .Before ;
34
32
import org .junit .Rule ;
@@ -58,8 +56,6 @@ public class RetryingNameResolverTest {
58
56
private RetryScheduler mockRetryScheduler ;
59
57
@ Captor
60
58
private ArgumentCaptor <Listener2 > listenerCaptor ;
61
- @ Captor
62
- private ArgumentCaptor <ResolutionResult > onResultCaptor ;
63
59
private final SynchronizationContext syncContext = new SynchronizationContext (
64
60
mock (UncaughtExceptionHandler .class ));
65
61
@@ -77,21 +73,14 @@ public void startAndShutdown() {
77
73
retryingNameResolver .shutdown ();
78
74
}
79
75
80
- // Make sure the ResolutionResultListener callback is added to the ResolutionResult attributes,
81
- // and the retry scheduler is reset since the name resolution was successful.
82
76
@ Test
83
77
public void onResult_success () {
78
+ when (mockListener .onResult2 (isA (ResolutionResult .class ))).thenReturn (Status .OK );
84
79
retryingNameResolver .start (mockListener );
85
80
verify (mockNameResolver ).start (listenerCaptor .capture ());
86
81
87
82
listenerCaptor .getValue ().onResult (ResolutionResult .newBuilder ().build ());
88
- verify (mockListener ).onResult (onResultCaptor .capture ());
89
- ResolutionResultListener resolutionResultListener = onResultCaptor .getValue ()
90
- .getAttributes ()
91
- .get (RetryingNameResolver .RESOLUTION_RESULT_LISTENER_KEY );
92
- assertThat (resolutionResultListener ).isNotNull ();
93
83
94
- resolutionResultListener .resolutionAttempted (Status .OK );
95
84
verify (mockRetryScheduler ).reset ();
96
85
}
97
86
@@ -107,21 +96,15 @@ public void onResult2_sucesss() {
107
96
verify (mockRetryScheduler ).reset ();
108
97
}
109
98
110
- // Make sure the ResolutionResultListener callback is added to the ResolutionResult attributes,
111
- // and that a retry gets scheduled when the resolution results are rejected.
99
+ // Make sure that a retry gets scheduled when the resolution results are rejected.
112
100
@ Test
113
101
public void onResult_failure () {
102
+ when (mockListener .onResult2 (isA (ResolutionResult .class ))).thenReturn (Status .UNAVAILABLE );
114
103
retryingNameResolver .start (mockListener );
115
104
verify (mockNameResolver ).start (listenerCaptor .capture ());
116
105
117
106
listenerCaptor .getValue ().onResult (ResolutionResult .newBuilder ().build ());
118
- verify (mockListener ).onResult (onResultCaptor .capture ());
119
- ResolutionResultListener resolutionResultListener = onResultCaptor .getValue ()
120
- .getAttributes ()
121
- .get (RetryingNameResolver .RESOLUTION_RESULT_LISTENER_KEY );
122
- assertThat (resolutionResultListener ).isNotNull ();
123
107
124
- resolutionResultListener .resolutionAttempted (Status .UNAVAILABLE );
125
108
verify (mockRetryScheduler ).schedule (isA (Runnable .class ));
126
109
}
127
110
@@ -138,24 +121,6 @@ public void onResult2_failure() {
138
121
verify (mockRetryScheduler ).schedule (isA (Runnable .class ));
139
122
}
140
123
141
- // Wrapping a NameResolver more than once is a misconfiguration.
142
- @ Test
143
- public void onResult_failure_doubleWrapped () {
144
- NameResolver doubleWrappedResolver = new RetryingNameResolver (retryingNameResolver ,
145
- mockRetryScheduler , syncContext );
146
-
147
- doubleWrappedResolver .start (mockListener );
148
- verify (mockNameResolver ).start (listenerCaptor .capture ());
149
-
150
- try {
151
- listenerCaptor .getValue ().onResult (ResolutionResult .newBuilder ().build ());
152
- } catch (IllegalStateException e ) {
153
- assertThat (e ).hasMessageThat ().contains ("can only be used once" );
154
- return ;
155
- }
156
- fail ("An exception should have been thrown for a double wrapped NAmeResolver" );
157
- }
158
-
159
124
// A retry should get scheduled when name resolution fails.
160
125
@ Test
161
126
public void onError () {
@@ -165,4 +130,4 @@ public void onError() {
165
130
verify (mockListener ).onError (Status .DEADLINE_EXCEEDED );
166
131
verify (mockRetryScheduler ).schedule (isA (Runnable .class ));
167
132
}
168
- }
133
+ }
0 commit comments