|
52 | 52 | import java.sql.SQLException; |
53 | 53 | import java.sql.SQLSyntaxErrorException; |
54 | 54 | import java.sql.Statement; |
| 55 | +import java.util.AbstractMap; |
55 | 56 | import java.util.BitSet; |
56 | 57 | import java.util.Calendar; |
57 | 58 | import java.util.List; |
|
61 | 62 | import java.util.concurrent.CountDownLatch; |
62 | 63 | import java.util.concurrent.TimeUnit; |
63 | 64 | import java.util.concurrent.TimeoutException; |
| 65 | +import java.util.concurrent.atomic.AtomicReference; |
64 | 66 | import java.util.logging.Level; |
65 | 67 | import java.util.logging.Logger; |
66 | 68 |
|
@@ -333,6 +335,53 @@ public void execute(Statement statement) throws SQLException { |
333 | 335 | return result; |
334 | 336 | } |
335 | 337 |
|
| 338 | + @Test |
| 339 | + public void testBinlogPositionPointsToTableMapEventUntilTheEndOfLogicalGroup() throws Exception { |
| 340 | + final AtomicReference<Map.Entry<String, Long>> markHolder = new AtomicReference<Map.Entry<String, Long>>(); |
| 341 | + BinaryLogClient.EventListener markEventListener = new BinaryLogClient.EventListener() { |
| 342 | + |
| 343 | + private int counter; |
| 344 | + |
| 345 | + @Override |
| 346 | + public void onEvent(Event event) { |
| 347 | + if (EventType.isRowMutation(event.getHeader().getEventType()) && counter++ == 1) { |
| 348 | + // coordinates of second insert |
| 349 | + markHolder.set(new AbstractMap.SimpleEntry<String, Long>(client.getBinlogFilename(), |
| 350 | + client.getBinlogPosition())); |
| 351 | + } |
| 352 | + } |
| 353 | + }; |
| 354 | + client.registerEventListener(markEventListener); |
| 355 | + try { |
| 356 | + master.execute(new Callback<Statement>() { |
| 357 | + @Override |
| 358 | + public void execute(Statement statement) throws SQLException { |
| 359 | + statement.execute("insert into bikini_bottom values('SpongeBob')"); |
| 360 | + statement.execute("insert into bikini_bottom values('Patrick')"); |
| 361 | + statement.execute("insert into bikini_bottom values('Squidward')"); |
| 362 | + } |
| 363 | + }); |
| 364 | + eventListener.waitFor(WriteRowsEventData.class, 3, DEFAULT_TIMEOUT); |
| 365 | + final BinaryLogClient anotherClient = new BinaryLogClient(slave.hostname, slave.port, |
| 366 | + slave.username, slave.password); |
| 367 | + anotherClient.registerLifecycleListener(new TraceLifecycleListener()); |
| 368 | + CountDownEventListener anotherClientEventListener = new CountDownEventListener(); |
| 369 | + anotherClient.registerEventListener(anotherClientEventListener); |
| 370 | + Map.Entry<String, Long> mark = markHolder.get(); |
| 371 | + anotherClient.setBinlogFilename(mark.getKey()); |
| 372 | + anotherClient.setBinlogPosition(mark.getValue()); |
| 373 | + anotherClient.connect(DEFAULT_TIMEOUT); |
| 374 | + try { |
| 375 | + // expecting Patrick & Squidward |
| 376 | + anotherClientEventListener.waitFor(WriteRowsEventData.class, 2, DEFAULT_TIMEOUT); |
| 377 | + } finally { |
| 378 | + anotherClient.disconnect(); |
| 379 | + } |
| 380 | + } finally { |
| 381 | + client.unregisterEventListener(markEventListener); |
| 382 | + } |
| 383 | + } |
| 384 | + |
336 | 385 | @Test(enabled = false) |
337 | 386 | public void testUnsupportedColumnTypeDoesNotCauseClientToFail() throws Exception { |
338 | 387 | BinaryLogClient.LifecycleListener lifecycleListenerMock = mock(BinaryLogClient.LifecycleListener.class); |
|
0 commit comments