Fixes a couple of test related issues for debezium-core
* fixes a java.sql.Date conversion test to take into account zone offsets * makes sure the ZK DB is closed during testing, otherwise file handles may leak and cause test failures
This commit is contained in:
parent
a8efb99b7d
commit
a6dddaed92
@ -5,10 +5,12 @@
|
|||||||
*/
|
*/
|
||||||
package io.debezium.jdbc;
|
package io.debezium.jdbc;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.time.Month;
|
import java.time.Month;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.temporal.ChronoField;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -38,12 +40,13 @@ public void beforeEach() {
|
|||||||
public void shouldAdaptSqlDate() {
|
public void shouldAdaptSqlDate() {
|
||||||
// '2014-09-08', '17:51:04.777', '2014-09-08 17:51:04.777', '2014-09-08 17:51:04.777'
|
// '2014-09-08', '17:51:04.777', '2014-09-08 17:51:04.777', '2014-09-08 17:51:04.777'
|
||||||
java.sql.Date sqlDate = createSqlDate(2014, Month.SEPTEMBER, 8);
|
java.sql.Date sqlDate = createSqlDate(2014, Month.SEPTEMBER, 8);
|
||||||
|
ZonedDateTime expectedDateInTargetTZ = ZonedDateTime.ofInstant(Instant.ofEpochMilli(sqlDate.getTime()), adapter.targetZoneId());
|
||||||
ZonedDateTime zdt = adapter.toZonedDateTime(sqlDate);
|
ZonedDateTime zdt = adapter.toZonedDateTime(sqlDate);
|
||||||
// The date should match ...
|
// The date should match ...
|
||||||
LocalDate date = zdt.toLocalDate();
|
LocalDate date = zdt.toLocalDate();
|
||||||
assertThat(date.getYear()).isEqualTo(2014);
|
assertThat(date.getYear()).isEqualTo(2014);
|
||||||
assertThat(date.getMonth()).isEqualTo(Month.SEPTEMBER);
|
assertThat(date.getMonth()).isEqualTo(Month.SEPTEMBER);
|
||||||
assertThat(date.getDayOfMonth()).isEqualTo(8);
|
assertThat(date.getDayOfMonth()).isEqualTo(expectedDateInTargetTZ.get(ChronoField.DAY_OF_MONTH));
|
||||||
// There should be no time component ...
|
// There should be no time component ...
|
||||||
LocalTime time = zdt.toLocalTime();
|
LocalTime time = zdt.toLocalTime();
|
||||||
assertThat(time.getHour()).isEqualTo(0);
|
assertThat(time.getHour()).isEqualTo(0);
|
||||||
|
@ -41,6 +41,7 @@ public class ZookeeperServer {
|
|||||||
private volatile File dataDir;
|
private volatile File dataDir;
|
||||||
private volatile File snapshotDir;
|
private volatile File snapshotDir;
|
||||||
private volatile File logDir;
|
private volatile File logDir;
|
||||||
|
private volatile ZooKeeperServer server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new server instance.
|
* Create a new server instance.
|
||||||
@ -75,7 +76,8 @@ public synchronized ZookeeperServer startup() throws IOException {
|
|||||||
this.logDir.mkdirs();
|
this.logDir.mkdirs();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
factory.startup(new ZooKeeperServer(snapshotDir, logDir, tickTime));
|
server = new ZooKeeperServer(snapshotDir, logDir, tickTime);
|
||||||
|
factory.startup(server);
|
||||||
return this;
|
return this;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
factory = null;
|
factory = null;
|
||||||
@ -100,6 +102,12 @@ public synchronized void shutdown(boolean deleteData) {
|
|||||||
if (factory != null) {
|
if (factory != null) {
|
||||||
try {
|
try {
|
||||||
factory.shutdown();
|
factory.shutdown();
|
||||||
|
try {
|
||||||
|
// Zookeeper 3.4.6 does not close the ZK DB during shutdown, so we must do this here to avoid file locks and open handles...
|
||||||
|
server.getZKDatabase().close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("Unable to close zookeeper DB", e);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
factory = null;
|
factory = null;
|
||||||
if (deleteData) {
|
if (deleteData) {
|
||||||
|
Loading…
Reference in New Issue
Block a user