fix flaky test and improve error handling

just ignore invalid entries
This commit is contained in:
2017-03-18 10:14:41 +01:00
parent a221259417
commit a01c8b3907
10 changed files with 74 additions and 50 deletions

View File

@@ -93,6 +93,7 @@ public class TcpIngestor implements AutoCloseable {
}
if (entry.isPresent()) {
LOGGER.trace("adding entry to queue: {}", entry);
queue.put(entry.get());
}
@@ -169,7 +170,7 @@ public class TcpIngestor implements AutoCloseable {
db.put(new BlockingQueueIterator<>(queue, Entry.POISON));
finished = true;
} catch (final Exception e) {
e.printStackTrace();
LOGGER.warn("Write to database failed. Will retry with the next element.", e);
}
}
return null;

View File

@@ -8,6 +8,7 @@ import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
@@ -15,6 +16,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.lucares.pdb.api.Entry;
import org.lucares.performance.db.FileUtils;
@@ -104,6 +106,13 @@ public class TcpIngestorTest {
final ByteBuffer src = ByteBuffer.wrap(streamData.toString().getBytes(StandardCharsets.UTF_8));
channel.write(src);
try {
// ugly workaround: the channel was close too early and not all data
// was received
TimeUnit.MILLISECONDS.sleep(10);
} catch (final InterruptedException e) {
throw new IllegalStateException(e);
}
channel.close();
LOGGER.trace("closed sender connection");
}
@@ -126,8 +135,9 @@ public class TcpIngestorTest {
return result;
}
@Test
public void testIngestionThreadDoesNotDieOnErrors() throws Exception {
final OffsetDateTime invalidDate = OffsetDateTime.of(1969, 12, 31, 23, 59, 59, 999, ZoneOffset.UTC);
final OffsetDateTime invalidDate = OffsetDateTime.ofInstant(Instant.ofEpochMilli(-1), ZoneOffset.UTC);
final OffsetDateTime dateB = OffsetDateTime.now();
final String host = "someHost";