PostgreSQLPositionManager extends BasePositionManager<WalPosition> { @Override public WalPosition getPosition() { WalPosition position = super.getPosition(); if (null != position) { return position; } initPosition(); return super.getPosition(); } PostgreSQLPositionManager(final DataSource dataSource);  PostgreSQLPositionManager(final String position); @Override WalPosition getPosition(); static final String SLOT_NAME; static final String DECODE_PLUGIN; static final String DUPLICATE_OBJECT_ERROR_CODE; }
@Test public void assertInitPositionByJson() { PostgreSQLPositionManager postgreSQLPositionManager = new PostgreSQLPositionManager("100"); WalPosition actual = postgreSQLPositionManager.getPosition(); assertThat(actual.getLogSequenceNumber().asLong(), is(LogSequenceNumber.valueOf(100L).asLong())); }
@Test public void assertGetCurrentPositionOnPostgreSQL96() throws SQLException { PostgreSQLPositionManager postgreSQLPositionManager = new PostgreSQLPositionManager(dataSource); when(databaseMetaData.getDatabaseMajorVersion()).thenReturn(9); when(databaseMetaData.getDatabaseMinorVersion()).thenReturn(6); WalPosition actual = postgreSQLPositionManager.getPosition(); assertThat(actual.getLogSequenceNumber(), is(LogSequenceNumber.valueOf(POSTGRESQL_96_LSN))); }
@Test public void assertGetCurrentPositionOnPostgreSQL10() throws SQLException { PostgreSQLPositionManager postgreSQLPositionManager = new PostgreSQLPositionManager(dataSource); when(databaseMetaData.getDatabaseMajorVersion()).thenReturn(10); WalPosition actual = postgreSQLPositionManager.getPosition(); assertThat(actual.getLogSequenceNumber(), is(LogSequenceNumber.valueOf(POSTGRESQL_10_LSN))); }
@Test(expected = RuntimeException.class) public void assertGetCurrentPositionThrowException() throws SQLException { PostgreSQLPositionManager postgreSQLPositionManager = new PostgreSQLPositionManager(dataSource); when(databaseMetaData.getDatabaseMajorVersion()).thenReturn(9); when(databaseMetaData.getDatabaseMinorVersion()).thenReturn(4); postgreSQLPositionManager.getPosition(); }
@Test public void assertUpdateCurrentPosition() { PostgreSQLPositionManager postgreSQLPositionManager = new PostgreSQLPositionManager(dataSource); WalPosition expected = new WalPosition(LogSequenceNumber.valueOf(POSTGRESQL_96_LSN)); postgreSQLPositionManager.setPosition(expected); assertThat(postgreSQLPositionManager.getPosition(), is(expected)); }