@@ -60,15 +60,17 @@ public void before() {
60
60
when (defaultProfile .isDefined (DseDriverOption .CONTINUOUS_PAGING_PAGE_SIZE )).thenReturn (true );
61
61
}
62
62
63
- private void buildContext (UUID clientId , String applicationName , String applicationVersion ) {
64
- this .driverContext =
65
- new DefaultDriverContext (
66
- configLoader ,
67
- ProgrammaticArguments .builder ()
68
- .withStartupClientId (clientId )
69
- .withStartupApplicationName (applicationName )
70
- .withStartupApplicationVersion (applicationVersion )
71
- .build ());
63
+ private void buildContext (
64
+ UUID clientId , String applicationName , String applicationVersion , String localDc ) {
65
+ ProgrammaticArguments .Builder builder =
66
+ ProgrammaticArguments .builder ()
67
+ .withStartupClientId (clientId )
68
+ .withStartupApplicationName (applicationName )
69
+ .withStartupApplicationVersion (applicationVersion );
70
+ if (localDc != null ) {
71
+ builder .withLocalDatacenter (DriverExecutionProfile .DEFAULT_NAME , localDc );
72
+ }
73
+ this .driverContext = new DefaultDriverContext (configLoader , builder .build ());
72
74
}
73
75
74
76
private void assertDefaultStartupOptions (Startup startup ) {
@@ -86,7 +88,7 @@ private void assertDefaultStartupOptions(Startup startup) {
86
88
public void should_build_startup_options_with_no_compression_if_undefined () {
87
89
when (defaultProfile .getString (DefaultDriverOption .PROTOCOL_COMPRESSION , "none" ))
88
90
.thenReturn ("none" );
89
- buildContext (null , null , null );
91
+ buildContext (null , null , null , null );
90
92
Startup startup = new Startup (driverContext .getStartupOptions ());
91
93
assertThat (startup .options ).doesNotContainKey (Startup .COMPRESSION_KEY );
92
94
assertDefaultStartupOptions (startup );
@@ -97,7 +99,7 @@ public void should_build_startup_options_with_no_compression_if_undefined() {
97
99
public void should_build_startup_options_with_compression (String compression ) {
98
100
when (defaultProfile .getString (DefaultDriverOption .PROTOCOL_COMPRESSION , "none" ))
99
101
.thenReturn (compression );
100
- buildContext (null , null , null );
102
+ buildContext (null , null , null , null );
101
103
Startup startup = new Startup (driverContext .getStartupOptions ());
102
104
// assert the compression option is present
103
105
assertThat (startup .options ).containsEntry (Startup .COMPRESSION_KEY , compression );
@@ -110,7 +112,7 @@ public void should_build_startup_options_with_compression(String compression) {
110
112
public void should_fail_to_build_startup_options_with_invalid_compression () {
111
113
when (defaultProfile .getString (DefaultDriverOption .PROTOCOL_COMPRESSION , "none" ))
112
114
.thenReturn ("foobar" );
113
- buildContext (null , null , null );
115
+ buildContext (null , null , null , null );
114
116
assertThatIllegalArgumentException ()
115
117
.isThrownBy (() -> new Startup (driverContext .getStartupOptions ()));
116
118
}
@@ -120,7 +122,7 @@ public void should_build_startup_options_with_client_id() {
120
122
when (defaultProfile .getString (DefaultDriverOption .PROTOCOL_COMPRESSION , "none" ))
121
123
.thenReturn ("none" );
122
124
UUID customClientId = Uuids .random ();
123
- buildContext (customClientId , null , null );
125
+ buildContext (customClientId , null , null , null );
124
126
Startup startup = new Startup (driverContext .getStartupOptions ());
125
127
// assert the client id is present
126
128
assertThat (startup .options )
@@ -135,7 +137,7 @@ public void should_build_startup_options_with_client_id() {
135
137
public void should_build_startup_options_with_application_version_and_name () {
136
138
when (defaultProfile .getString (DefaultDriverOption .PROTOCOL_COMPRESSION , "none" ))
137
139
.thenReturn ("none" );
138
- buildContext (null , "Custom_App_Name" , "Custom_App_Version" );
140
+ buildContext (null , "Custom_App_Name" , "Custom_App_Version" , null );
139
141
Startup startup = new Startup (driverContext .getStartupOptions ());
140
142
// assert the app name and version are present
141
143
assertThat (startup .options )
@@ -151,15 +153,17 @@ public void should_build_startup_options_with_all_options() {
151
153
// mock config to specify "snappy" compression
152
154
when (defaultProfile .getString (DefaultDriverOption .PROTOCOL_COMPRESSION , "none" ))
153
155
.thenReturn ("snappy" );
156
+ when (defaultProfile .getName ()).thenReturn (DriverExecutionProfile .DEFAULT_NAME );
154
157
155
158
UUID customClientId = Uuids .random ();
156
159
157
- buildContext (customClientId , "Custom_App_Name" , "Custom_App_Version" );
160
+ buildContext (customClientId , "Custom_App_Name" , "Custom_App_Version" , "dc6" );
158
161
Startup startup = new Startup (driverContext .getStartupOptions ());
159
162
assertThat (startup .options )
160
163
.containsEntry (StartupOptionsBuilder .CLIENT_ID_KEY , customClientId .toString ())
161
164
.containsEntry (StartupOptionsBuilder .APPLICATION_NAME_KEY , "Custom_App_Name" )
162
- .containsEntry (StartupOptionsBuilder .APPLICATION_VERSION_KEY , "Custom_App_Version" );
165
+ .containsEntry (StartupOptionsBuilder .APPLICATION_VERSION_KEY , "Custom_App_Version" )
166
+ .containsEntry (StartupOptionsBuilder .DRIVER_LOCAL_DC , "dc6" );
163
167
assertThat (startup .options ).containsEntry (Startup .COMPRESSION_KEY , "snappy" );
164
168
assertDefaultStartupOptions (startup );
165
169
}
@@ -172,25 +176,33 @@ public void should_use_configuration_when_no_programmatic_values_provided() {
172
176
.thenReturn ("Config_App_Version" );
173
177
when (defaultProfile .getString (DefaultDriverOption .PROTOCOL_COMPRESSION , "none" ))
174
178
.thenReturn ("none" );
179
+ when (defaultProfile .getString (DefaultDriverOption .LOAD_BALANCING_LOCAL_DATACENTER ))
180
+ .thenReturn ("Config_DC_1" );
181
+ when (defaultProfile .isDefined (DefaultDriverOption .LOAD_BALANCING_LOCAL_DATACENTER ))
182
+ .thenReturn (true );
183
+ when (defaultProfile .getName ()).thenReturn (DriverExecutionProfile .DEFAULT_NAME );
175
184
176
- buildContext (null , null , null );
185
+ buildContext (null , null , null , null );
177
186
Startup startup = new Startup (driverContext .getStartupOptions ());
178
187
179
188
assertThat (startup .options )
180
189
.containsEntry (StartupOptionsBuilder .APPLICATION_NAME_KEY , "Config_App_Name" )
181
- .containsEntry (StartupOptionsBuilder .APPLICATION_VERSION_KEY , "Config_App_Version" );
190
+ .containsEntry (StartupOptionsBuilder .APPLICATION_VERSION_KEY , "Config_App_Version" )
191
+ .containsEntry (StartupOptionsBuilder .DRIVER_LOCAL_DC , "Config_DC_1" );
182
192
}
183
193
184
194
@ Test
185
195
public void should_ignore_configuration_when_programmatic_values_provided () {
186
196
when (defaultProfile .getString (DefaultDriverOption .PROTOCOL_COMPRESSION , "none" ))
187
197
.thenReturn ("none" );
198
+ when (defaultProfile .getName ()).thenReturn (DriverExecutionProfile .DEFAULT_NAME );
188
199
189
- buildContext (null , "Custom_App_Name" , "Custom_App_Version" );
200
+ buildContext (null , "Custom_App_Name" , "Custom_App_Version" , "us-west-2" );
190
201
Startup startup = new Startup (driverContext .getStartupOptions ());
191
202
192
203
assertThat (startup .options )
193
204
.containsEntry (StartupOptionsBuilder .APPLICATION_NAME_KEY , "Custom_App_Name" )
194
- .containsEntry (StartupOptionsBuilder .APPLICATION_VERSION_KEY , "Custom_App_Version" );
205
+ .containsEntry (StartupOptionsBuilder .APPLICATION_VERSION_KEY , "Custom_App_Version" )
206
+ .containsEntry (StartupOptionsBuilder .DRIVER_LOCAL_DC , "us-west-2" );
195
207
}
196
208
}
0 commit comments