public void returns_all_existing_files_with_correct_pattern() { File.Create(Path.Combine(PathName, "foo")).Close(); File.Create(Path.Combine(PathName, "bla")).Close(); File.Create(Path.Combine(PathName, "chunk-000001.000000")).Close(); File.Create(Path.Combine(PathName, "chunk-000002.000000")).Close(); File.Create(Path.Combine(PathName, "chunk-000003.000000")).Close(); File.Create(Path.Combine(PathName, "chunk-000005.000000")).Close(); File.Create(Path.Combine(PathName, "chunk-000005.000007")).Close(); File.Create(Path.Combine(PathName, "chunk-000005.000002")).Close(); File.Create(Path.Combine(PathName, "chunk-000005.000005")).Close(); var strategy = new VersionedPatternFileNamingStrategy(PathName, "chunk-"); var versions = strategy.GetAllPresentFiles(); Array.Sort(versions, StringComparer.CurrentCultureIgnoreCase); Assert.AreEqual(7, versions.Length); Assert.AreEqual(Path.Combine(PathName, "chunk-000001.000000"), versions[0]); Assert.AreEqual(Path.Combine(PathName, "chunk-000002.000000"), versions[1]); Assert.AreEqual(Path.Combine(PathName, "chunk-000003.000000"), versions[2]); Assert.AreEqual(Path.Combine(PathName, "chunk-000005.000000"), versions[3]); Assert.AreEqual(Path.Combine(PathName, "chunk-000005.000002"), versions[4]); Assert.AreEqual(Path.Combine(PathName, "chunk-000005.000005"), versions[5]); Assert.AreEqual(Path.Combine(PathName, "chunk-000005.000007"), versions[6]); }
public void returns_all_temp_files_in_directory() { File.Create(GetFilePathFor("bla")).Close(); File.Create(GetFilePathFor("bla.tmp")).Close(); File.Create(GetFilePathFor("bla.temp")).Close(); File.Create(GetFilePathFor("chunk-000005.000007.tmp")).Close(); File.Create(GetFilePathFor("foo.tmp")).Close(); var strategy = new VersionedPatternFileNamingStrategy(PathName, "chunk-"); var tempFiles = strategy.GetAllTempFiles(); Assert.AreEqual(3, tempFiles.Length); Assert.AreEqual(GetFilePathFor("bla.tmp"), tempFiles[0]); Assert.AreEqual(GetFilePathFor("chunk-000005.000007.tmp"), tempFiles[1]); Assert.AreEqual(GetFilePathFor("foo.tmp"), tempFiles[2]); }
public void returns_temp_filenames_detectable_by_getalltempfiles_method() { var strategy = new VersionedPatternFileNamingStrategy(PathName, "chunk-"); Assert.AreEqual(0, strategy.GetAllTempFiles().Length); var tmp1 = strategy.GetTempFilename(); var tmp2 = strategy.GetTempFilename(); File.Create(tmp1).Close(); File.Create(tmp2).Close(); var tmp = new[] { tmp1, tmp2 }; Array.Sort(tmp); var tempFiles = strategy.GetAllTempFiles(); Array.Sort(tempFiles); Assert.AreEqual(2, tempFiles.Length); Assert.AreEqual(tmp[0], tempFiles[0]); Assert.AreEqual(tmp[1], tempFiles[1]); }
public void iterates_chunks_with_correct_callback_order() { File.Create(GetFilePathFor("foo")).Close(); // should be ignored File.Create(GetFilePathFor("bla")).Close(); // should be ignored File.Create(GetFilePathFor("chunk-000001.000000.tmp")).Close(); // should be ignored File.Create(GetFilePathFor("chunk-001.000")).Close(); // should be ignored // chunk 0 is missing File.Create(GetFilePathFor("chunk-000001.000000")).Close(); // chunks 1 - 1 (latest) File.Create(GetFilePathFor("chunk-000002.000001")).Close(); // chunks 2 - 2 (latest) // chunks 3 & 4 are missing File.Create(GetFilePathFor("chunk-000005.000000")).Close(); // chunks 5 - 5 (old) File.Create(GetFilePathFor("chunk-000005.000001")).Close(); // chunks 5 - 6 (old) File.Create(GetFilePathFor("chunk-000005.000002")).Close(); // chunks 5 - 7 (latest) File.Create(GetFilePathFor("chunk-000006.000000")).Close(); // chunks 6 - 6 (old) // chunk 7 is not missing - it's merged with chunk 5 File.Create(GetFilePathFor("chunk-000008.000007")).Close(); // chunks 8 - 8 (latest) // chunk 9 is missing File.Create(GetFilePathFor("chunk-000010.000005")).Close(); // chunks 10 - 14 (latest) // chunks 15 & 16 are missing var strategy = new VersionedPatternFileNamingStrategy(PathName, "chunk-"); var chunkEnumerator = new TFChunkEnumerator(strategy); var result = new List <string>(); int GetNextFileNumber((string chunk, int chunkNumber, int chunkVersion) t) { return(Path.GetFileName(t.chunk) switch { "chunk-000001.000000" => 2, "chunk-000002.000001" => 3, "chunk-000005.000000" => 6, "chunk-000005.000001" => 7, "chunk-000005.000002" => 8, "chunk-000006.000000" => 7, "chunk-000008.000007" => 9, "chunk-000010.000005" => 15, _ => throw new Exception($"Unexpected file: {t.chunk}") });
public void returns_all_existing_versions_of_the_same_chunk_in_descending_order_of_versions() { File.Create(Path.Combine(PathName, "foo")).Close(); File.Create(Path.Combine(PathName, "bla")).Close(); File.Create(Path.Combine(PathName, "chunk-000001.000000")).Close(); File.Create(Path.Combine(PathName, "chunk-000002.000000")).Close(); File.Create(Path.Combine(PathName, "chunk-000003.000000")).Close(); File.Create(Path.Combine(PathName, "chunk-000005.000000")).Close(); File.Create(Path.Combine(PathName, "chunk-000005.000007")).Close(); File.Create(Path.Combine(PathName, "chunk-000005.000002")).Close(); File.Create(Path.Combine(PathName, "chunk-000005.000005")).Close(); var strategy = new VersionedPatternFileNamingStrategy(PathName, "chunk-"); var versions = strategy.GetAllVersionsFor(5); Assert.AreEqual(4, versions.Length); Assert.AreEqual(Path.Combine(PathName, "chunk-000005.000007"), versions[0]); Assert.AreEqual(Path.Combine(PathName, "chunk-000005.000005"), versions[1]); Assert.AreEqual(Path.Combine(PathName, "chunk-000005.000002"), versions[2]); Assert.AreEqual(Path.Combine(PathName, "chunk-000005.000000"), versions[3]); }
public void when_getting_file_for_negative_version_throws_argumentoutofrangeexception() { var strategy = new VersionedPatternFileNamingStrategy("Path", "prefix"); Assert.Throws <ArgumentOutOfRangeException>(() => strategy.GetFilenameFor(0, -1)); }
public void when_getting_file_for_nonnegative_index_and_version_appends_value_and_provided_version() { var strategy = new VersionedPatternFileNamingStrategy("path", "prefix-"); Assert.AreEqual("path" + Path.DirectorySeparatorChar + "prefix-000001.000007", strategy.GetFilenameFor(1, 7)); }
public void when_getting_file_for_positive_index_and_no_version_appends_index_to_name_with_zero_version() { var strategy = new VersionedPatternFileNamingStrategy("path", "prefix-"); Assert.AreEqual("path" + Path.DirectorySeparatorChar + "prefix-000001.000000", strategy.GetFilenameFor(1)); }
public void when_getting_file_for_negative_version_throws_argumentoutofrangeexception() { var strategy = new VersionedPatternFileNamingStrategy("Path", "prefix"); Assert.Throws<ArgumentOutOfRangeException>(() => strategy.GetFilenameFor(0, -1)); }
public void returns_all_temp_files_in_directory() { File.Create(Path.Combine(PathName, "bla")).Close(); File.Create(Path.Combine(PathName, "bla.tmp")).Close(); File.Create(Path.Combine(PathName, "bla.temp")).Close(); File.Create(Path.Combine(PathName, "foo.tmp")).Close(); var strategy = new VersionedPatternFileNamingStrategy(PathName, "chunk-"); var tempFiles = strategy.GetAllTempFiles(); Assert.AreEqual(2, tempFiles.Length); Assert.AreEqual(Path.Combine(PathName, "bla.tmp"), tempFiles[0]); Assert.AreEqual(Path.Combine(PathName, "foo.tmp"), tempFiles[1]); }