Close input channel in LevelDbLogReader (#594)

* Close input channel in LevelDbLogReader

Input channel should be closed when all data has been read.
This commit is contained in:
Weimin Yu 2020-05-20 12:54:13 -04:00 committed by GitHub
parent 3947ac6ef7
commit ca2edb6a17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View file

@ -18,6 +18,9 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.tools.LevelDbUtil.MAX_RECORD;
import static google.registry.tools.LevelDbUtil.addRecord;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Bytes;
@ -93,7 +96,7 @@ public final class LevelDbLogReaderTest {
}
@Test
void read_noData() {
void read_noData() throws IOException {
assertThat(readIncrementally(new byte[0])).isEmpty();
}
@ -119,10 +122,11 @@ public final class LevelDbLogReaderTest {
}
@SafeVarargs
private static ImmutableList<byte[]> readIncrementally(byte[]... blocks) {
LevelDbLogReader recordReader =
LevelDbLogReader.from(new ByteArrayInputStream(Bytes.concat(blocks)));
return ImmutableList.copyOf(recordReader);
private static ImmutableList<byte[]> readIncrementally(byte[]... blocks) throws IOException {
ByteArrayInputStream source = spy(new ByteArrayInputStream(Bytes.concat(blocks)));
ImmutableList<byte[]> records = ImmutableList.copyOf(LevelDbLogReader.from(source));
verify(source, times(1)).close();
return records;
}
/** Aggregates the bytes of a test block with the record count. */