|
13 | 13 | import org.junit.Before;
|
14 | 14 | import org.junit.Test;
|
15 | 15 |
|
| 16 | +import java.io.ByteArrayOutputStream; |
16 | 17 | import java.io.IOException;
|
| 18 | +import java.io.PrintStream; |
17 | 19 | import java.text.SimpleDateFormat;
|
18 | 20 | import java.time.*;
|
19 | 21 | import java.time.format.DateTimeFormatter;
|
@@ -170,6 +172,192 @@ public void test_MultithreadedTableWriter_pwd_wrong() throws Exception {
|
170 | 172 | conn.run("undef(`t1,SHARED)");
|
171 | 173 | }
|
172 | 174 |
|
| 175 | + @Test |
| 176 | + public void test_MultithreadedTableWriter_reconnect_false() throws IOException { |
| 177 | + int port=7102; |
| 178 | + String re = null; |
| 179 | + try { |
| 180 | + mutithreadTableWriter_ = new MultithreadedTableWriter(HOST, port, "admin", "123456", |
| 181 | + "", "tt", false, false, null, 10000, 1, |
| 182 | + 5, "date",null,false,false,0); |
| 183 | + }catch (Exception ex) { |
| 184 | + re = ex.getMessage(); |
| 185 | + } |
| 186 | + assertEquals(true,re.contains("Failed to connect to server ")); |
| 187 | + } |
| 188 | + |
| 189 | + @Test |
| 190 | + public void test_MultithreadedTableWriter_reconnect_false_tryReconnectNums_not_set() throws IOException { |
| 191 | + int port=7102; |
| 192 | + String re = null; |
| 193 | + try { |
| 194 | + mutithreadTableWriter_ = new MultithreadedTableWriter(HOST, port, "admin", "123456", |
| 195 | + "", "tt", false, false, null, 10000, 1, |
| 196 | + 5, "date",null,false,false); |
| 197 | + }catch (Exception ex) { |
| 198 | + re = ex.getMessage(); |
| 199 | + } |
| 200 | + assertEquals(true,re.contains("Failed to connect to server ")); |
| 201 | + } |
| 202 | + |
| 203 | + @Test |
| 204 | + public void test_MultithreadedTableWriter_reconnect_false_tryReconnectNums_1() throws Exception { |
| 205 | + int port=7102; |
| 206 | + String re = null; |
| 207 | + try { |
| 208 | + mutithreadTableWriter_ = new MultithreadedTableWriter(HOST, port, "admin", "123456", |
| 209 | + "", "tt", false, false, null, 10000, 1, |
| 210 | + 5, "date",null,false,false,1); |
| 211 | + }catch (Exception ex) { |
| 212 | + re = ex.getMessage(); |
| 213 | + } |
| 214 | + assertEquals(true,re.contains("Failed to connect to server ")); |
| 215 | + } |
| 216 | + |
| 217 | + @Test |
| 218 | + public void test_MultithreadedTableWriter_reconnect_true() throws IOException { |
| 219 | + int port=7102; |
| 220 | + int trynums=3; |
| 221 | + String re = null; |
| 222 | + try { |
| 223 | + mutithreadTableWriter_ = new MultithreadedTableWriter(HOST, port, "admin", "123456", |
| 224 | + "", "tt", false, false, null, 10000, 1, |
| 225 | + 5, "date",null,false,true,trynums); |
| 226 | + }catch (Exception ex) { |
| 227 | + re = ex.getMessage(); |
| 228 | + } |
| 229 | + assertEquals("Connect to "+HOST+":"+port+" failed after "+trynums+" reconnect attempts.",re); |
| 230 | + } |
| 231 | + |
| 232 | + //@Test 会一直重连 ,故回归注销 |
| 233 | + public void test_MultithreadedTableWriter_reconnect_true_tryReconnectNums_not_set() throws IOException { |
| 234 | + int port=7102; |
| 235 | + int trynums=3; |
| 236 | + String re = null; |
| 237 | + try { |
| 238 | + mutithreadTableWriter_ = new MultithreadedTableWriter(HOST, port, "admin", "123456", |
| 239 | + "", "tt", false, false, null, 10000, 1, |
| 240 | + 5, "date",null,false,true); |
| 241 | + }catch (Exception ex) { |
| 242 | + re = ex.getMessage(); |
| 243 | + } |
| 244 | + assertEquals("Connect to "+HOST+":"+port+" failed after "+trynums+" reconnect attempts.",re); |
| 245 | + } |
| 246 | + |
| 247 | + //@Test 会一直重连 ,故回归注销 |
| 248 | + public void test_MultithreadedTableWriter_tryReconnectNums_0_reconnect_true() throws Exception { |
| 249 | + int port=7102; |
| 250 | + int trynums=0; |
| 251 | + mutithreadTableWriter_ = new MultithreadedTableWriter(HOST, port, "admin", "123456", |
| 252 | + "", "tt", false, false, null, 10000, 1, |
| 253 | + 5, "date",null,false,true,trynums); |
| 254 | + } |
| 255 | + |
| 256 | + //@Test tryReconnectNums设置为-1时 会无限重连 |
| 257 | + public void test_MultithreadedTableWriter_tryReconnectNums_negetive_reconnect_true() throws Exception { |
| 258 | + int port=7102; |
| 259 | + int trynums=-1; |
| 260 | + mutithreadTableWriter_ = new MultithreadedTableWriter(HOST, port, "admin", "123456", |
| 261 | + "", "tt", false, true, null, 10000, 1, |
| 262 | + 5, "date",null,false,false,trynums); |
| 263 | + } |
| 264 | + |
| 265 | + @Test |
| 266 | + public void test_MultithreadedTableWriter_tryReconnectNums_enableHighAvailability_true_reconnect_false() throws Exception { |
| 267 | + class LogCapture { |
| 268 | + private final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 269 | + private final PrintStream originalErr = System.err; |
| 270 | + public void start() { |
| 271 | + System.setErr(new PrintStream(baos)); |
| 272 | + } |
| 273 | + public void stop() { |
| 274 | + System.setErr(originalErr); |
| 275 | + } |
| 276 | + public String getLogMessages() { |
| 277 | + return baos.toString(); |
| 278 | + } |
| 279 | + } |
| 280 | + int port=7102; |
| 281 | + int trynums=3; |
| 282 | + LogCapture logCapture = new LogCapture(); |
| 283 | + logCapture.start(); |
| 284 | + try{ |
| 285 | + mutithreadTableWriter_ = new MultithreadedTableWriter(HOST, port, "admin", "123456", |
| 286 | + "", "tt", false, true, new String[]{"192.168.0.69:7002"}, 10000, 1, |
| 287 | + 5, "date",null,true,false,trynums); |
| 288 | + }catch(Exception ex){ |
| 289 | + System.out.println(ex.getMessage()); |
| 290 | + } |
| 291 | + logCapture.stop(); |
| 292 | + String s=logCapture.getLogMessages(); |
| 293 | + assertTrue(s.contains("Connect failed after "+trynums+" reconnect attempts for every node in high availability sites.")); |
| 294 | + } |
| 295 | + |
| 296 | + @Test |
| 297 | + public void test_MultithreadedTableWriter_tryReconnectNums_enableHighAvailability_true_reconnect_false_1() throws Exception { |
| 298 | + class LogCapture { |
| 299 | + private final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 300 | + private final PrintStream originalErr = System.err; |
| 301 | + public void start() { |
| 302 | + System.setErr(new PrintStream(baos)); |
| 303 | + } |
| 304 | + public void stop() { |
| 305 | + System.setErr(originalErr); |
| 306 | + } |
| 307 | + public String getLogMessages() { |
| 308 | + return baos.toString(); |
| 309 | + } |
| 310 | + } |
| 311 | + int port=7102; |
| 312 | + int trynums=3; |
| 313 | + LogCapture logCapture = new LogCapture(); |
| 314 | + logCapture.start(); |
| 315 | + try{ |
| 316 | + mutithreadTableWriter_ = new MultithreadedTableWriter(HOST, port, "admin", "123456", |
| 317 | + "", "tt", false, true, new String[]{"192.168.0.69:7002","192.168.0.69:7222"}, 10000, 1, |
| 318 | + 5, "date",null,true,false,trynums); |
| 319 | + }catch(Exception ex){ |
| 320 | + System.out.println(ex.getMessage()); |
| 321 | + } |
| 322 | + logCapture.stop(); |
| 323 | + String s=logCapture.getLogMessages(); |
| 324 | + assertTrue(s.contains("Connect failed after "+trynums+" reconnect attempts for every node in high availability sites.")); |
| 325 | + } |
| 326 | + |
| 327 | + @Test |
| 328 | + public void test_MultithreadedTableWriter_tryReconnectNums_enableHighAvailability_true_reconnect_true() throws Exception { |
| 329 | + class LogCapture { |
| 330 | + private final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 331 | + private final PrintStream originalErr = System.err; |
| 332 | + public void start() { |
| 333 | + System.setErr(new PrintStream(baos)); |
| 334 | + } |
| 335 | + public void stop() { |
| 336 | + System.setErr(originalErr); |
| 337 | + } |
| 338 | + public String getLogMessages() { |
| 339 | + return baos.toString(); |
| 340 | + } |
| 341 | + } |
| 342 | + int port=7102; |
| 343 | + int trynums=3; |
| 344 | + String re = null; |
| 345 | + String[] N={"localhost:7300"}; |
| 346 | + DBConnection conn =new DBConnection(); |
| 347 | + LogCapture logCapture = new LogCapture(); |
| 348 | + logCapture.start(); |
| 349 | + try{ |
| 350 | + mutithreadTableWriter_ = new MultithreadedTableWriter(HOST, port, "admin", "123456", |
| 351 | + "", "tt", false, true, new String[]{"192.168.0.69:7002"}, 10000, 1, |
| 352 | + 5, "date",null,true,true,trynums); |
| 353 | + }catch(Exception ex){ |
| 354 | + System.out.println(ex.getMessage()); |
| 355 | + } |
| 356 | + logCapture.stop(); |
| 357 | + String s=logCapture.getLogMessages(); |
| 358 | + assertTrue(s.contains("Connect failed after "+trynums+" reconnect attempts for every node in high availability sites.")); |
| 359 | + } |
| 360 | + |
173 | 361 | @Test(timeout = 120000)
|
174 | 362 | public void test_MultithreadedTableWriter_memory_dbname_wrong() throws Exception {
|
175 | 363 | StringBuilder sb = new StringBuilder();
|
@@ -6712,14 +6900,14 @@ public void writeCompletion(Table callbackTable) {
|
6712 | 6900 | }
|
6713 | 6901 | }
|
6714 | 6902 | mtw.waitForThreadCompletion();
|
6715 |
| - conn1.run("sleep(5000)"); |
| 6903 | + conn1.run("sleep(10000)"); |
6716 | 6904 | try{conn1.run("startDataNode([\""+HOST+":"+PORT+"\"])");
|
6717 | 6905 |
|
6718 | 6906 | }
|
6719 | 6907 | catch(IOException ex) {
|
6720 | 6908 | System.out.println(ex.getMessage());
|
6721 | 6909 | }
|
6722 |
| - conn1.run("sleep(8000)"); |
| 6910 | + conn1.run("sleep(10000)"); |
6723 | 6911 | DBConnection conn2= new DBConnection(false, false, false, false);
|
6724 | 6912 | conn2.connect(HOST, PORT, "admin", "123456");
|
6725 | 6913 | conn1.run("sleep(2000)");
|
|
0 commit comments