diff --git a/src/main/java/org/breedinginsight/services/geno/impl/GigwaGenotypeServiceImpl.java b/src/main/java/org/breedinginsight/services/geno/impl/GigwaGenotypeServiceImpl.java index 7c2ba98b0..0790d10b3 100644 --- a/src/main/java/org/breedinginsight/services/geno/impl/GigwaGenotypeServiceImpl.java +++ b/src/main/java/org/breedinginsight/services/geno/impl/GigwaGenotypeServiceImpl.java @@ -22,6 +22,8 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import htsjdk.samtools.util.CloseableIterator; +import htsjdk.samtools.util.RuntimeIOException; +import htsjdk.samtools.util.SortingCollection; import htsjdk.tribble.TribbleException; import htsjdk.variant.variantcontext.VariantContext; import htsjdk.variant.vcf.VCFFileReader; @@ -83,10 +85,13 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.nio.file.Path; import java.time.LocalDateTime; import java.time.OffsetDateTime; @@ -249,23 +254,42 @@ public ImportResponse submitGenotypeData(UUID userId, UUID programId, UUID submi throw e; } + Path stagedFile = null; + boolean scheduled = false; try { - byte[] fileContents = uploadedFile.getBytes(); - if (validateSamples(program, submissionId, fileContents, upload) - && validateVariantRecords(fileContents, uploadedFile.getFilename(), upload)) { + stagedFile = Files.createTempFile("bi-genotype-", ".vcf"); + try (InputStream input = uploadedFile.getInputStream()) { + Files.copy(input, stagedFile, StandardCopyOption.REPLACE_EXISTING); + } + if (validateSamples(program, submissionId, stagedFile, upload) + && validateVariantRecords(stagedFile, fileName, upload)) { + // Only the application-owned file crosses the request lifetime boundary. + Path importFile = stagedFile; executor.execute(() -> { try { - processSubmission(gigwaAuthToken, program, submissionId, fileContents, uploadedFile.getFilename(), upload, progress); + processSubmission(gigwaAuthToken, program, submissionId, importFile, fileName, upload, progress); } catch (Exception e) { log.error(e.getMessage(), e); + } finally { + deleteStagedFile(importFile); } }); + scheduled = true; } } catch (IOException e) { progress.setStatuscode((short) HttpStatus.INTERNAL_SERVER_ERROR.getCode()); progress.setMessage("An error occurred while trying to validate sample information"); importDAO.updateProgress(progress); throw new RuntimeException(e); + } catch (java.util.concurrent.RejectedExecutionException e) { + progress.setStatuscode((short) HttpStatus.INTERNAL_SERVER_ERROR.getCode()); + progress.setMessage("An error occurred uploading the genotypic data"); + importDAO.updateProgress(progress); + throw e; + } finally { + if (!scheduled) { + deleteStagedFile(stagedFile); + } } ImportResponse response = new ImportResponse(); @@ -372,7 +396,7 @@ private Optional findStoredGenotypeImportKey(UUID programId, UUID submis .findFirst(); } - private boolean validateSamples(Program program, UUID submissionId, byte[] fileContents, ImportUpload upload) throws DoesNotExistException, ApiException { + private boolean validateSamples(Program program, UUID submissionId, Path file, ImportUpload upload) throws DoesNotExistException, ApiException, IOException { log.debug("Validating samples in submitted VCF file for submission: " + submissionId); Set submissionSampleNames = fetchSubmissionSamples(program, submissionId).stream() @@ -382,14 +406,15 @@ private boolean validateSamples(Program program, UUID submissionId, byte[] fileC log.debug("searching for the VCF header row"); String[] headerParts = null; - Scanner sc = new Scanner(new ByteArrayInputStream(fileContents), "UTF-8"); boolean foundHeader = false; - while (sc.hasNextLine() && !foundHeader) { - String line = sc.nextLine(); - if(line.startsWith("#CHROM")) { - log.debug("Header row found! -> " + line); - foundHeader = true; - headerParts = line.split("\t"); + try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { + String line; + while ((line = reader.readLine()) != null) { + if (line.startsWith("#CHROM")) { + foundHeader = true; + headerParts = line.split("\t"); + break; + } } } @@ -407,7 +432,7 @@ private boolean validateSamples(Program program, UUID submissionId, byte[] fileC if(validHeader) { int sampleStart = 8; - if(headerParts[8].equals("FORMAT")) { + if(headerParts.length > 8 && headerParts[8].equals("FORMAT")) { sampleStart++; } @@ -442,15 +467,14 @@ private boolean validateSamples(Program program, UUID submissionId, byte[] fileC return true; } - private boolean validateVariantRecords(byte[] fileContents, String filename, ImportUpload upload) { - Set positionalKeys = new HashSet<>(); - Path tempVcfFile = null; + private boolean validateVariantRecords(Path tempVcfFile, String filename, ImportUpload upload) { + // Spill positional keys to disk instead of retaining one entry per variant in heap. + SortingCollection positionalKeys = SortingCollection.newInstance( + String.class, new VcfPositionCodec(), Comparator.naturalOrder(), 100_000, + tempVcfFile.getParent()); int parsedVariantCount = 0; try { - tempVcfFile = Files.createTempFile("bi-vcf-validation-", ".vcf"); - Files.write(tempVcfFile, fileContents); - try (VCFFileReader reader = new VCFFileReader(tempVcfFile.toFile(), false); CloseableIterator variants = reader.iterator()) { @@ -463,15 +487,22 @@ private boolean validateVariantRecords(byte[] fileContents, String filename, Imp variant.getContig() + ":" + variant.getStart(); - if (!positionalKeys.add(positionalKey)) { - log.error("Duplicate Gigwa positional key detected during VCF validation for file '{}'. Parsed records: {}. Key: {}", - filename, parsedVariantCount, positionalKey); - + positionalKeys.add(positionalKey); + } + } + positionalKeys.doneAdding(); + try (CloseableIterator keys = positionalKeys.iterator()) { + String previous = null; + while (keys.hasNext()) { + String key = keys.next(); + if (key.equals(previous)) { + log.error("Duplicate Gigwa positional key detected during VCF validation for file '{}': {}", filename, key); upload.getProgress().setStatuscode((short) HttpStatus.BAD_REQUEST.getCode()); upload.getProgress().setMessage(DUPLICATE_POSITIONAL_KEY_MESSAGE); importDAO.updateProgress(upload.getProgress()); return false; } + previous = key; } } @@ -485,22 +516,14 @@ private boolean validateVariantRecords(byte[] fileContents, String filename, Imp upload.getProgress().setMessage(INVALID_REF_ALT_MESSAGE); importDAO.updateProgress(upload.getProgress()); return false; - } catch (IOException e) { - log.error("I/O failure during VCF validation setup for file '{}'. Parsed {} variant record(s) before failure. Error: {}", - filename, parsedVariantCount, e.getMessage(), e); - + } catch (RuntimeIOException e) { + log.error("I/O failure during VCF validation for file '{}'", filename, e); upload.getProgress().setStatuscode((short) HttpStatus.INTERNAL_SERVER_ERROR.getCode()); upload.getProgress().setMessage("An error occurred while trying to validate VCF variant information"); importDAO.updateProgress(upload.getProgress()); return false; } finally { - if (tempVcfFile != null) { - try { - Files.deleteIfExists(tempVcfFile); - } catch (IOException e) { - log.warn("Unable to delete temporary VCF validation file {}", tempVcfFile, e); - } - } + positionalKeys.cleanup(); } return true; @@ -633,12 +656,12 @@ private List fetchVariants(BrAPIClient genoBrAPIClient, List uploadedFileResult; try { progress.setMessage("Uploading file"); importDAO.updateProgress(progress); - uploadedFileResult = uploadGenotypeData(program.getId(), submissionId, upload.getId(), fileContents, filename); + uploadedFileResult = uploadGenotypeData(program.getId(), submissionId, upload.getId(), file, filename); log.debug("file saved to: " + uploadedFileResult.getLeft()); } catch (Exception e) { progress.setStatuscode((short) HttpStatus.INTERNAL_SERVER_ERROR.getCode()); @@ -766,7 +789,7 @@ private String submitRequestToGigwa(OkHttpClient client, Program program, UUID s } } - private Pair uploadGenotypeData(UUID programId, UUID submissionId, UUID uploadId, byte[] fileContents, String filename) throws IOException, MimeTypeException { + private Pair uploadGenotypeData(UUID programId, UUID submissionId, UUID uploadId, Path file, String filename) throws IOException, MimeTypeException { log.debug("saving genotype data to S3"); if(!storageService.listBucketNames().contains(storageService.getDefaultBucketName())) { @@ -774,50 +797,57 @@ private Pair uploadGenotypeData(UUID programId, UUID submissionId, storageService.createBucket(); } - var mimeType = mimeTypeParser.getMimeType(fileContents, filename); + var mimeType = mimeTypeParser.getMimeType(file, filename); var key = programId.toString() + "/" + submissionId.toString() + "/" + uploadId + mimeType.getExtension(); - var path = storeMultipartFile(key, fileContents, Map.of("originalFileName", filename)); + var path = storeMultipartFile(key, file, Map.of("originalFileName", filename)); - Long fileSize = Long.valueOf(fileContents.length); + Long fileSize = Files.size(file); return Pair.of(path, fileSize); } - private String storeMultipartFile(String key, byte[] fileContents, Map metadata) throws IOException { + String storeMultipartFile(String key, Path file, Map metadata) throws IOException { String bucketName = storageService.getDefaultBucketName(); + String uploadId = s3Client.createMultipartUpload(CreateMultipartUploadRequest.builder() + .bucket(bucketName).key(key).metadata(metadata).build()).uploadId(); + try (InputStream input = Files.newInputStream(file)) { + List parts = new ArrayList<>(); + // S3 requires at least 5 MiB for every part except the final one. + byte[] buffer = new byte[8 * 1024 * 1024]; + int length; + while ((length = input.readNBytes(buffer, 0, buffer.length)) > 0) { + int partNumber = parts.size() + 1; + String etag = s3Client.uploadPart(UploadPartRequest.builder() + .bucket(bucketName).key(key).uploadId(uploadId) + .partNumber(partNumber).build(), + software.amazon.awssdk.core.sync.RequestBody.fromInputStream( + new ByteArrayInputStream(buffer, 0, length), length)).eTag(); + parts.add(CompletedPart.builder().partNumber(partNumber).eTag(etag).build()); + } + return s3Client.completeMultipartUpload(CompleteMultipartUploadRequest.builder() + .bucket(bucketName).key(key).uploadId(uploadId) + .multipartUpload(CompletedMultipartUpload.builder().parts(parts).build()) + .build()).location(); + } catch (Exception e) { + try { + s3Client.abortMultipartUpload(AbortMultipartUploadRequest.builder() + .bucket(bucketName).key(key).uploadId(uploadId).build()); + } catch (Exception abortError) { + e.addSuppressed(abortError); + } + throw e; + } + } - CreateMultipartUploadResponse response = s3Client.createMultipartUpload(CreateMultipartUploadRequest.builder() - .bucket(bucketName) - .key(key) - .metadata(metadata) - .build()); - String uploadId = response.uploadId(); - - List parts = new ArrayList<>(); - int partNumber = 1; - String etag = s3Client.uploadPart(UploadPartRequest.builder() - .bucket(bucketName) - .key(key) - .uploadId(uploadId) - .partNumber(partNumber) - .build(), - software.amazon.awssdk.core.sync.RequestBody.fromBytes(fileContents)) - .eTag(); - - parts.add(CompletedPart.builder().partNumber(partNumber).eTag(etag).build()); - - log.debug("all parts have been uploaded, completing the upload"); - CompleteMultipartUploadResponse completeMultipartUploadResponse = s3Client.completeMultipartUpload(CompleteMultipartUploadRequest.builder() - .bucket(bucketName) - .key(key) - .uploadId(uploadId) - .multipartUpload(CompletedMultipartUpload.builder() - .parts(parts) - .build()) - .build()); - log.debug("upload complete"); - return completeMultipartUploadResponse.location(); + private static void deleteStagedFile(Path file) { + if (file != null) { + try { + Files.deleteIfExists(file); + } catch (IOException e) { + log.warn("Unable to delete temporary genotype file {}", file, e); + } + } } private boolean getBooleanValue(JsonObject progress, String key, boolean defaultVal) { diff --git a/src/main/java/org/breedinginsight/services/geno/impl/VcfPositionCodec.java b/src/main/java/org/breedinginsight/services/geno/impl/VcfPositionCodec.java new file mode 100644 index 000000000..a3245356d --- /dev/null +++ b/src/main/java/org/breedinginsight/services/geno/impl/VcfPositionCodec.java @@ -0,0 +1,56 @@ +package org.breedinginsight.services.geno.impl; + +import htsjdk.samtools.util.RuntimeIOException; +import htsjdk.samtools.util.SortingCollection; + +import java.io.*; +import java.nio.charset.StandardCharsets; + +/** Length-prefixed positional keys for HTSJDK's disk-backed sort. */ +final class VcfPositionCodec implements SortingCollection.Codec { + private DataInputStream input; + private DataOutputStream output; + + @Override + public void setInputStream(InputStream stream) { + input = new DataInputStream(stream); + } + + @Override + public void setOutputStream(OutputStream stream) { + output = new DataOutputStream(stream); + } + + @Override + public void encode(String key) { + try { + byte[] bytes = key.getBytes(StandardCharsets.UTF_8); + output.writeInt(bytes.length); + output.write(bytes); + } catch (IOException e) { + throw new RuntimeIOException(e); + } + } + + @Override + public String decode() { + try { + int first = input.read(); + if (first == -1) { + return null; + } + int length = (first << 24) | (input.readUnsignedByte() << 16) + | (input.readUnsignedByte() << 8) | input.readUnsignedByte(); + byte[] bytes = new byte[length]; + input.readFully(bytes); + return new String(bytes, StandardCharsets.UTF_8); + } catch (IOException e) { + throw new RuntimeIOException(e); + } + } + + @Override + public VcfPositionCodec clone() { + return new VcfPositionCodec(); + } +} diff --git a/src/main/java/org/breedinginsight/services/parsers/MimeTypeParser.java b/src/main/java/org/breedinginsight/services/parsers/MimeTypeParser.java index 797fce59f..3f57d1c66 100644 --- a/src/main/java/org/breedinginsight/services/parsers/MimeTypeParser.java +++ b/src/main/java/org/breedinginsight/services/parsers/MimeTypeParser.java @@ -30,6 +30,7 @@ import javax.inject.Singleton; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.nio.file.Path; @Singleton public class MimeTypeParser { @@ -68,4 +69,12 @@ public MimeType getMimeType(byte[] fileContents, String filename) throws IOExcep .getRegisteredMimeType(mediaType.toString()); } + public MimeType getMimeType(Path file, String filename) throws IOException, MimeTypeException { + Metadata metadata = new Metadata(); + metadata.add(TikaCoreProperties.RESOURCE_NAME_KEY, filename); + try (TikaInputStream stream = TikaInputStream.get(file)) { + return config.getMimeRepository().getRegisteredMimeType(detector.detect(stream, metadata).toString()); + } + } + } diff --git a/src/test/java/org/breedinginsight/services/geno/impl/GenotypeMultipartUploadTest.java b/src/test/java/org/breedinginsight/services/geno/impl/GenotypeMultipartUploadTest.java new file mode 100644 index 000000000..259de790e --- /dev/null +++ b/src/test/java/org/breedinginsight/services/geno/impl/GenotypeMultipartUploadTest.java @@ -0,0 +1,55 @@ +package org.breedinginsight.services.geno.impl; + +import com.agorapulse.micronaut.amazon.awssdk.s3.SimpleStorageService; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import software.amazon.awssdk.core.sync.RequestBody; +import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.model.*; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +class GenotypeMultipartUploadTest { + @TempDir + Path directory; + + @Test + void failedPartOrCompletionAbortsUploadAndPreservesOriginalError() throws Exception { + for (boolean failPart : new boolean[]{true, false}) { + S3Client s3 = mock(S3Client.class); + SimpleStorageService storage = mock(SimpleStorageService.class); + when(storage.getDefaultBucketName()).thenReturn("genotype"); + when(s3.createMultipartUpload(any(CreateMultipartUploadRequest.class))) + .thenReturn(CreateMultipartUploadResponse.builder().uploadId("upload-id").build()); + RuntimeException failure = new RuntimeException("Storage failed"); + if (failPart) { + when(s3.uploadPart(any(UploadPartRequest.class), any(RequestBody.class))).thenThrow(failure); + } else { + when(s3.uploadPart(any(UploadPartRequest.class), any(RequestBody.class))) + .thenReturn(UploadPartResponse.builder().eTag("etag").build()); + when(s3.completeMultipartUpload(any(CompleteMultipartUploadRequest.class))).thenThrow(failure); + } + RuntimeException abortFailure = new RuntimeException("Abort failed"); + when(s3.abortMultipartUpload(any(AbortMultipartUploadRequest.class))).thenThrow(abortFailure); + GigwaGenotypeServiceImpl service = new GigwaGenotypeServiceImpl( + "http://localhost/", "", "", "", null, null, null, null, null, null, null, + storage, s3, null, null, null, null, null); + Path file = Files.writeString(directory.resolve("sample.vcf"), "sample VCF"); + assertSame(failure, assertThrows(RuntimeException.class, + () -> service.storeMultipartFile("key", file, Collections.emptyMap()))); + assertArrayEquals(new Throwable[]{abortFailure}, failure.getSuppressed()); + verify(s3).abortMultipartUpload(argThat((AbortMultipartUploadRequest request) -> + request.bucket().equals("genotype") && request.key().equals("key") + && request.uploadId().equals("upload-id"))); + if (failPart) { + verify(s3, never()).completeMultipartUpload(any(CompleteMultipartUploadRequest.class)); + } + } + } +} diff --git a/src/test/java/org/breedinginsight/services/geno/impl/GigwaGenotypeServiceImplIntegrationTest.java b/src/test/java/org/breedinginsight/services/geno/impl/GigwaGenotypeServiceImplIntegrationTest.java index 20d1ea6fd..c9266cf43 100644 --- a/src/test/java/org/breedinginsight/services/geno/impl/GigwaGenotypeServiceImplIntegrationTest.java +++ b/src/test/java/org/breedinginsight/services/geno/impl/GigwaGenotypeServiceImplIntegrationTest.java @@ -372,6 +372,60 @@ public void testUpload() throws ApiException, AuthorizationException { } } + @Test + public void testMultipartUploadStreamsAllPartsAndAbortsOnReadFailure() throws Exception { + java.nio.file.Path file = java.nio.file.Files.createTempFile("vcf-multipart-test-", ".vcf"); + String key = "stream-test/" + UUID.randomUUID() + ".vcf"; + String failedKey = key + "-failed"; + if (!storageService.listBucketNames().contains(storageService.getDefaultBucketName())) { + storageService.createBucket(); + } + try { + byte[] chunk = new byte[1024 * 1024]; + new Random(2970).nextBytes(chunk); + try (java.io.OutputStream output = java.nio.file.Files.newOutputStream(file)) { + for (int i = 0; i < 9; i++) { + output.write(chunk); + } + output.write(42); + } + String location = gigwaGenoStorageService.storeMultipartFile(key, file, Map.of("originalFileName", "large.vcf")); + assertNotNull(location); + assertTrue(location.contains(key)); + try (java.io.InputStream stored = s3Client.getObject( + software.amazon.awssdk.services.s3.model.GetObjectRequest.builder() + .bucket(storageService.getDefaultBucketName()).key(key).build())) { + for (int i = 0; i < 9; i++) { + assertArrayEquals(chunk, stored.readNBytes(chunk.length)); + } + assertEquals(42, stored.read()); + assertEquals(-1, stored.read()); + } + java.nio.file.Files.delete(file); + assertThrows(IOException.class, () -> + gigwaGenoStorageService.storeMultipartFile(failedKey, file, Collections.emptyMap())); + assertTrue(s3Client.listMultipartUploads( + software.amazon.awssdk.services.s3.model.ListMultipartUploadsRequest.builder() + .bucket(storageService.getDefaultBucketName()).prefix(failedKey).build()) + .uploads().isEmpty(), "Failed upload must be aborted"); + } finally { + java.nio.file.Files.deleteIfExists(file); + s3Client.deleteObject(software.amazon.awssdk.services.s3.model.DeleteObjectRequest.builder() + .bucket(storageService.getDefaultBucketName()).key(key).build()); + } + } + + @Test + public void testSubmitMissingHeader() throws Exception { + UUID programId = UUID.randomUUID(); + UUID submissionId = UUID.randomUUID(); + setupMocksForSubmitGenoData(programId, submissionId, Collections.emptyList()); + ImportResponse response = submitGenoData(programId, "MISSINGHEADER", submissionId, "sample_missing_header.vcf"); + assertEquals((short) HttpStatus.BAD_REQUEST.getCode(), response.getProgress().getStatuscode()); + assertEquals("Could not find header row in file", response.getProgress().getMessage()); + verify(genotypeImportDAO, never()).createGenotypeImportLink(eq(submissionId), any(), any()); + } + @Test public void testFetchGermplasmGenotype() throws AuthorizationException, ApiException, DoesNotExistException { UUID programId = UUID.fromString("8b667063-480b-4b0a-862c-7eaa651dda28"); @@ -785,7 +839,7 @@ private void uploadGenoData(UUID programId, String programKey, UUID submissionId System.out.println("====================== program ID: " + program.getId() + " ==============="); System.out.println("=================== submission ID: " + submissionId + " ==============="); - gigwaGenoStorageService.processSubmission(gigwaGenoStorageService.getAuthToken(), program, submissionId, new TestFileUpload("src/test/resources/files/geno/sample.vcf", MediaType.of("application/vcard")).getBytes(), "sample.vcf", importUpload, progress); + gigwaGenoStorageService.processSubmission(gigwaGenoStorageService.getAuthToken(), program, submissionId, java.nio.file.Path.of("src/test/resources/files/geno/sample.vcf"), "sample.vcf", importUpload, progress); } private ImportResponse submitGenoData(UUID programId, String programKey, UUID submissionId, String file) @@ -827,7 +881,12 @@ private ImportResponse submitGenoData(UUID programId, String programKey, UUID su user.getId(), programId, submissionId, - new TestFileUpload("src/test/resources/files/geno/" + file, MediaType.of("application/vcard")) + new TestFileUpload("src/test/resources/files/geno/" + file, MediaType.of("application/vcard")) { + @Override + public byte[] getBytes() { + throw new AssertionError("Genotype imports must stream the upload"); + } + } ); } diff --git a/src/test/java/org/breedinginsight/services/geno/impl/VcfPositionCodecTest.java b/src/test/java/org/breedinginsight/services/geno/impl/VcfPositionCodecTest.java new file mode 100644 index 000000000..6b79e9f2a --- /dev/null +++ b/src/test/java/org/breedinginsight/services/geno/impl/VcfPositionCodecTest.java @@ -0,0 +1,42 @@ +package org.breedinginsight.services.geno.impl; + +import htsjdk.samtools.util.CloseableIterator; +import htsjdk.samtools.util.SortingCollection; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Comparator; + +import static org.junit.jupiter.api.Assertions.*; + +class VcfPositionCodecTest { + @TempDir + Path directory; + + @Test + void duplicateKeysSurviveDiskSpillAndFilesAreCleanedUp() throws Exception { + SortingCollection keys = SortingCollection.newInstance( + String.class, new VcfPositionCodec(), Comparator.naturalOrder(), 2, directory); + try { + keys.add("SNP:chr2:1"); + keys.add("SNP:chr1:1"); + keys.add("INDEL:chr1:1"); + keys.add("SNP:chr1:1"); + keys.doneAdding(); + try (CloseableIterator sorted = keys.iterator()) { + assertEquals("INDEL:chr1:1", sorted.next()); + assertEquals("SNP:chr1:1", sorted.next()); + assertEquals("SNP:chr1:1", sorted.next()); + assertEquals("SNP:chr2:1", sorted.next()); + assertFalse(sorted.hasNext()); + } + } finally { + keys.cleanup(); + } + try (java.util.stream.Stream files = Files.list(directory)) { + assertEquals(0, files.count()); + } + } +} diff --git a/src/test/resources/files/geno/sample_missing_header.vcf b/src/test/resources/files/geno/sample_missing_header.vcf new file mode 100644 index 000000000..a27df70b2 --- /dev/null +++ b/src/test/resources/files/geno/sample_missing_header.vcf @@ -0,0 +1,2 @@ +##fileformat=VCFv4.2 +##source=BI-2970-regression