@@ -155,30 +155,6 @@ public void test_Connect_tryReconnectNums_Filed_enableHighAvailability_false_ena
155
155
assertEquals ("java.lang.RuntimeException: Connect to " +HOST +":" +port +" failed after " +trynums +" reconnect attemps." ,R );
156
156
}
157
157
@ Test
158
- public void test_Connect_tryReconnectNums_Success_enableHighAvailability_false_enableLoadBalance_false () throws IOException {
159
- class LogCapture {
160
- private final ByteArrayOutputStream baos = new ByteArrayOutputStream ();
161
- private final PrintStream originalErr = System .err ;
162
- public void start () {
163
- System .setErr (new PrintStream (baos ));
164
- }
165
- public void stop () {
166
- System .setErr (originalErr );
167
- }
168
- public String getLogMessages () {
169
- return baos .toString ();
170
- }
171
- }
172
- int trynums =3 ;
173
- LogCapture logCapture = new LogCapture ();
174
- logCapture .start ();
175
- DBConnection conn =new DBConnection ();
176
- conn .connect (HOST ,PORT ,0 ,true ,trynums );
177
- logCapture .stop ();
178
- String s =logCapture .getLogMessages ();
179
- assertTrue (s .contains ("Connect to " +HOST +":" +PORT +" successfully." ));
180
- }
181
- @ Test
182
158
public void test_Connect_tryReconnectNums_Filed_enableHighAvailability_true_enableLoadBalance_false () throws IOException {
183
159
class LogCapture {
184
160
private final ByteArrayOutputStream baos = new ByteArrayOutputStream ();
@@ -195,48 +171,15 @@ public String getLogMessages() {
195
171
}
196
172
int port =7102 ;
197
173
int trynums =3 ;
198
- String [] N ={};
174
+ String [] N ={"localhost:7300" };
199
175
DBConnection conn =new DBConnection ();
200
176
LogCapture logCapture = new LogCapture ();
201
177
logCapture .start ();
202
178
conn .connect (HOST ,port ,"admin" ,"123456" ,"" ,true ,N ,true ,false ,trynums );
203
179
logCapture .stop ();
204
180
String s =logCapture .getLogMessages ();
205
- String searchString = "拒绝连接" ;
206
- int actualCount = 0 ;
207
- int fromIndex = 0 ;
208
- while ((fromIndex = s .indexOf (searchString , fromIndex )) != -1 ) {
209
- actualCount ++;
210
- fromIndex ++;
211
- }
212
- assertEquals (trynums ,actualCount );
213
- }
214
- @ Test
215
- public void test_Connect_tryReconnectNums_Success_enableHighAvailability_true_enableLoadBalance_false () throws IOException {
216
- class LogCapture {
217
- private final ByteArrayOutputStream baos = new ByteArrayOutputStream ();
218
- private final PrintStream originalErr = System .err ;
219
- public void start () {
220
- System .setErr (new PrintStream (baos ));
221
- }
222
- public void stop () {
223
- System .setErr (originalErr );
224
- }
225
- public String getLogMessages () {
226
- return baos .toString ();
227
- }
228
- }
229
- int port =7102 ;
230
- int trynums =3 ;
231
- DBConnection conn =new DBConnection ();
232
- LogCapture logCapture = new LogCapture ();
233
- logCapture .start ();
234
- conn .connect (HOST ,port ,"admin" ,"123456" ,"" ,true ,ipports ,true ,false ,trynums );
235
- logCapture .stop ();
236
- String s =logCapture .getLogMessages ();
237
- assertTrue (s .contains ("successfully" ));
238
- assertFalse (s .contains ("Switch to node:" ));
239
-
181
+ int temp =trynums *(1 +N .length );
182
+ assertTrue (s .contains ("Connect failed after " +temp +" reconnect attemps for every node in high availability sites." ));
240
183
}
241
184
@ Test
242
185
public void test_Connect_tryReconnectNums_Filed_enableHighAvailability_true_enableLoadBalance_true () throws IOException {
@@ -255,50 +198,18 @@ public String getLogMessages() {
255
198
}
256
199
int port =7102 ;
257
200
int trynums =3 ;
258
- String [] N ={};
201
+ String [] N ={"localhost:7300" };
259
202
DBConnection conn =new DBConnection ();
260
203
LogCapture logCapture = new LogCapture ();
261
204
logCapture .start ();
262
205
conn .connect (HOST ,port ,"admin" ,"123456" ,"" ,true ,N ,true ,true ,trynums );
263
206
logCapture .stop ();
264
207
String s =logCapture .getLogMessages ();
265
- String searchString = "拒绝连接" ;
266
- int actualCount = 0 ;
267
- int fromIndex = 0 ;
268
- while ((fromIndex = s .indexOf (searchString , fromIndex )) != -1 ) {
269
- actualCount ++;
270
- fromIndex ++;
271
- }
272
- assertEquals (trynums ,actualCount );
273
- }
274
- @ Test
275
- public void test_Connect_tryReconnectNums_Success_enableHighAvailability_true_enableLoadBalance_true () throws IOException {
276
- class LogCapture {
277
- private final ByteArrayOutputStream baos = new ByteArrayOutputStream ();
278
- private final PrintStream originalErr = System .err ;
279
- public void start () {
280
- System .setErr (new PrintStream (baos ));
281
- }
282
- public void stop () {
283
- System .setErr (originalErr );
284
- }
285
- public String getLogMessages () {
286
- return baos .toString ();
287
- }
288
- }
289
- int trynums =3 ;
290
- int port =7102 ;
291
- DBConnection conn =new DBConnection ();
292
- LogCapture logCapture = new LogCapture ();
293
- logCapture .start ();
294
- conn .connect (HOST ,port ,"admin" ,"123456" ,"" ,true ,ipports ,true ,true ,trynums );
295
- logCapture .stop ();
296
- String s =logCapture .getLogMessages ();
208
+ int temp =trynums *(1 +N .length );
209
+ assertTrue (s .contains ("Connect failed after " +temp +" reconnect attemps for every node in high availability sites." ));
297
210
298
- assertTrue (s .contains ("Switch to node:" ));
299
211
300
212
}
301
-
302
213
@ Test
303
214
public void Test_Connect_initialScript () throws IOException {
304
215
DBConnection conn = new DBConnection ();
0 commit comments