20
20
import static com .datastax .oss .driver .Assertions .assertThat ;
21
21
import static com .datastax .oss .driver .Assertions .assertThatStage ;
22
22
import static org .awaitility .Awaitility .await ;
23
+ import static org .mockito .ArgumentMatchers .anyBoolean ;
23
24
import static org .mockito .Mockito .mock ;
24
25
import static org .mockito .Mockito .timeout ;
25
26
import static org .mockito .Mockito .verify ;
33
34
import com .datastax .oss .driver .internal .core .context .EventBus ;
34
35
import com .datastax .oss .driver .internal .core .context .InternalDriverContext ;
35
36
import com .datastax .oss .driver .internal .core .context .NettyOptions ;
37
+ import com .datastax .oss .driver .internal .core .control .ControlConnection ;
36
38
import com .datastax .oss .driver .internal .core .metadata .schema .parsing .SchemaParserFactory ;
37
39
import com .datastax .oss .driver .internal .core .metadata .schema .queries .SchemaQueriesFactory ;
38
40
import com .datastax .oss .driver .internal .core .metrics .MetricsFactory ;
@@ -64,6 +66,7 @@ public class MetadataManagerTest {
64
66
65
67
@ Mock private InternalDriverContext context ;
66
68
@ Mock private NettyOptions nettyOptions ;
69
+ @ Mock private ControlConnection controlConnection ;
67
70
@ Mock private TopologyMonitor topologyMonitor ;
68
71
@ Mock private DriverConfig config ;
69
72
@ Mock private DriverExecutionProfile defaultProfile ;
@@ -85,6 +88,7 @@ public void setup() {
85
88
when (context .getNettyOptions ()).thenReturn (nettyOptions );
86
89
87
90
when (context .getTopologyMonitor ()).thenReturn (topologyMonitor );
91
+ when (context .getControlConnection ()).thenReturn (controlConnection );
88
92
89
93
when (defaultProfile .getDuration (DefaultDriverOption .METADATA_SCHEMA_WINDOW ))
90
94
.thenReturn (Duration .ZERO );
@@ -286,6 +290,25 @@ public void should_remove_node() {
286
290
assertThat (refresh .broadcastRpcAddressToRemove ).isEqualTo (broadcastRpcAddress2 );
287
291
}
288
292
293
+ @ Test
294
+ public void refreshSchema_should_work () {
295
+ // Given
296
+ IllegalStateException expectedException = new IllegalStateException ("Error we're testing" );
297
+ when (schemaQueriesFactory .newInstance ()).thenThrow (expectedException );
298
+ when (topologyMonitor .refreshNodeList ()).thenReturn (CompletableFuture .completedFuture (ImmutableList .of (mock (NodeInfo .class ))));
299
+ when (topologyMonitor .checkSchemaAgreement ()).thenReturn (CompletableFuture .completedFuture (Boolean .TRUE ));
300
+ when (controlConnection .init (anyBoolean (), anyBoolean (), anyBoolean ())).thenReturn (CompletableFuture .completedFuture (null ));
301
+ metadataManager .refreshNodes (); // required internal state setup for this
302
+ waitForPendingAdminTasks (() -> metadataManager .refreshes .size () == 1 ); // sanity check
303
+
304
+ // When
305
+ CompletionStage <MetadataManager .RefreshSchemaResult > result = metadataManager .refreshSchema ("foo" , true , true );
306
+
307
+ // Then
308
+ waitForPendingAdminTasks (() -> result .toCompletableFuture ().isDone ());
309
+ assertThatStage (result ).isFailed (t -> assertThat (t ).isEqualTo (expectedException ));
310
+ }
311
+
289
312
private static class TestMetadataManager extends MetadataManager {
290
313
291
314
private List <MetadataRefresh > refreshes = new CopyOnWriteArrayList <>();
0 commit comments