2 using System.Collections.Generic;
14 [Trait(
"Category",
"Integration")]
17 private const string ConnectionUrl =
"http://localhost:9191";
18 private const string Username =
"admin";
19 private const string Password =
"secret";
20 private const string TestDirName =
"kifs_test_dir";
24 private readonly
string _tempDir;
34 _tempDir = Path.Combine(Path.GetTempPath(), $
"kifs_test_{Guid.NewGuid():N}");
35 Directory.CreateDirectory(_tempDir);
41 try { _fileHandler.DeleteDirectory(TestDirName,
true,
true); }
catch { }
44 if (Directory.Exists(_tempDir))
46 try { Directory.Delete(_tempDir,
true); }
catch { }
50 #region Directory Tests 56 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
59 _fileHandler.CreateDirectory(TestDirName);
62 Assert.True(_fileHandler.KifsDirectoryExists(TestDirName));
69 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
70 _fileHandler.CreateDirectory(TestDirName);
73 _fileHandler.CreateDirectory(TestDirName, noErrorIfExists:
true);
74 Assert.True(_fileHandler.KifsDirectoryExists(TestDirName));
81 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
82 _fileHandler.CreateDirectory(TestDirName);
83 Assert.True(_fileHandler.KifsDirectoryExists(TestDirName));
86 _fileHandler.DeleteDirectory(TestDirName);
89 Assert.False(_fileHandler.KifsDirectoryExists(TestDirName));
96 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
97 _fileHandler.CreateDirectory(TestDirName);
100 var directories = _fileHandler.ShowAllDirectories();
103 Assert.NotNull(directories);
104 Assert.Contains(directories, d => d.KifsPath == TestDirName);
111 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
112 _fileHandler.CreateDirectory(TestDirName);
115 var directories = _fileHandler.ShowDirectory(TestDirName);
118 Assert.NotNull(directories);
119 Assert.Single(directories);
120 Assert.Equal(TestDirName, directories[0].KifsPath);
121 Assert.NotEmpty(directories[0].CreatedBy);
128 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
129 _fileHandler.CreateDirectory(TestDirName);
132 Assert.True(_fileHandler.KifsDirectoryExists(TestDirName));
139 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
142 Assert.False(_fileHandler.KifsDirectoryExists(
"non_existing_dir_" + Guid.NewGuid().ToString(
"N")));
153 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
154 _fileHandler.CreateDirectory(TestDirName);
156 var testFileName =
"test_upload.txt";
157 var testFilePath = Path.Combine(_tempDir, testFileName);
158 File.WriteAllText(testFilePath,
"Hello, KiFS!");
161 _fileHandler.Upload(testFilePath, TestDirName);
164 var remoteFilePath = $
"{TestDirName}/{testFileName}";
165 Assert.True(_fileHandler.KifsFileExists(remoteFilePath));
172 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
173 _fileHandler.CreateDirectory(TestDirName);
175 var testFiles =
new List<string>();
176 for (
int i = 1; i <= 3; i++)
178 var fileName = $
"test_upload_{i}.txt";
179 var filePath = Path.Combine(_tempDir, fileName);
180 File.WriteAllText(filePath, $
"Content for file {i}");
181 testFiles.Add(filePath);
185 _fileHandler.Upload(testFiles, TestDirName);
188 foreach (var filePath
in testFiles)
190 var fileName = Path.GetFileName(filePath);
191 var remoteFilePath = $
"{TestDirName}/{fileName}";
192 Assert.True(_fileHandler.KifsFileExists(remoteFilePath));
200 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
201 _fileHandler.CreateDirectory(TestDirName);
203 var testFileName =
"test_callback.txt";
204 var testFilePath = Path.Combine(_tempDir, testFileName);
205 File.WriteAllText(testFilePath,
"Hello, Callback!");
207 var callback =
new TestUploadListener();
213 Assert.True(callback.FullFileUploadCalled);
220 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
221 _fileHandler.CreateDirectory(TestDirName);
225 _fileHandler.Upload(
"/non/existent/file.txt", TestDirName));
232 var testFilePath = Path.Combine(_tempDir,
"test.txt");
233 File.WriteAllText(testFilePath,
"Test");
237 _fileHandler.Upload(testFilePath,
"non_existent_dir_" + Guid.NewGuid().ToString(
"N")));
242 #region Download Tests 248 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
249 _fileHandler.CreateDirectory(TestDirName);
251 var testFileName =
"test_download.txt";
252 var uploadPath = Path.Combine(_tempDir, testFileName);
253 var expectedContent =
"Hello, Download!";
254 File.WriteAllText(uploadPath, expectedContent);
255 _fileHandler.Upload(uploadPath, TestDirName);
257 var downloadDir = Path.Combine(_tempDir,
"downloads");
258 Directory.CreateDirectory(downloadDir);
261 var remoteFilePath = $
"{TestDirName}/{testFileName}";
262 _fileHandler.Download(remoteFilePath, downloadDir);
265 var downloadedPath = Path.Combine(downloadDir, testFileName);
266 Assert.True(File.Exists(downloadedPath));
267 Assert.Equal(expectedContent, File.ReadAllText(downloadedPath));
274 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
275 _fileHandler.CreateDirectory(TestDirName);
277 var testFiles =
new List<string>();
278 for (
int i = 1; i <= 3; i++)
280 var fileName = $
"test_download_{i}.txt";
281 var filePath = Path.Combine(_tempDir, fileName);
282 File.WriteAllText(filePath, $
"Content for file {i}");
283 _fileHandler.Upload(filePath, TestDirName);
284 testFiles.Add($
"{TestDirName}/{fileName}");
287 var downloadDir = Path.Combine(_tempDir,
"downloads_multi");
288 Directory.CreateDirectory(downloadDir);
291 _fileHandler.Download(testFiles, downloadDir);
294 foreach (var remoteFile
in testFiles)
296 var fileName = Path.GetFileName(remoteFile);
297 var downloadedPath = Path.Combine(downloadDir, fileName);
298 Assert.True(File.Exists(downloadedPath));
306 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
307 _fileHandler.CreateDirectory(TestDirName);
309 var testFileName =
"test_overwrite.txt";
310 var uploadPath = Path.Combine(_tempDir, testFileName);
311 File.WriteAllText(uploadPath,
"Original content");
312 _fileHandler.Upload(uploadPath, TestDirName);
314 var downloadDir = Path.Combine(_tempDir,
"downloads_overwrite");
315 Directory.CreateDirectory(downloadDir);
316 var existingFile = Path.Combine(downloadDir, testFileName);
317 File.WriteAllText(existingFile,
"Existing content");
320 var remoteFilePath = $
"{TestDirName}/{testFileName}";
324 _fileHandler.Download(remoteFilePath, downloadDir, options,
null));
329 #region File Operations Tests 335 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
336 _fileHandler.CreateDirectory(TestDirName);
338 var testFileName =
"test_show.txt";
339 var testContent =
"Show files test content";
340 var uploadPath = Path.Combine(_tempDir, testFileName);
341 File.WriteAllText(uploadPath, testContent);
342 _fileHandler.Upload(uploadPath, TestDirName);
345 var files = _fileHandler.ShowFiles(
new List<string> { TestDirName });
348 Assert.NotNull(files);
349 Assert.NotEmpty(files);
350 Assert.Contains(files, f => f.FileName.EndsWith(testFileName));
352 var testFile = files[0];
353 Assert.True(testFile.FileSize > 0);
354 Assert.NotEmpty(testFile.CreatedBy);
361 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
362 _fileHandler.CreateDirectory(TestDirName);
364 var testFileName =
"test_delete.txt";
365 var uploadPath = Path.Combine(_tempDir, testFileName);
366 File.WriteAllText(uploadPath,
"Delete test");
367 _fileHandler.Upload(uploadPath, TestDirName);
369 var remoteFilePath = $
"{TestDirName}/{testFileName}";
370 Assert.True(_fileHandler.KifsFileExists(remoteFilePath));
373 _fileHandler.DeleteFiles(
new List<string> { remoteFilePath });
376 Assert.False(_fileHandler.KifsFileExists(remoteFilePath));
383 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
384 _fileHandler.CreateDirectory(TestDirName);
386 for (
int i = 1; i <= 3; i++)
388 var fileName = $
"test_delete_all_{i}.txt";
389 var filePath = Path.Combine(_tempDir, fileName);
390 File.WriteAllText(filePath, $
"Content {i}");
391 _fileHandler.Upload(filePath, TestDirName);
394 var files = _fileHandler.ShowFiles(
new List<string> { TestDirName });
395 Assert.Equal(3, files.Count);
398 _fileHandler.DeleteFilesInDirectory(TestDirName);
401 files = _fileHandler.ShowFiles(
new List<string> { TestDirName });
409 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
410 _fileHandler.CreateDirectory(TestDirName);
412 var testFileName =
"test_exists.txt";
413 var uploadPath = Path.Combine(_tempDir, testFileName);
414 File.WriteAllText(uploadPath,
"Exists test");
415 _fileHandler.Upload(uploadPath, TestDirName);
418 var remoteFilePath = $
"{TestDirName}/{testFileName}";
419 Assert.True(_fileHandler.KifsFileExists(remoteFilePath));
426 try { _fileHandler.DeleteDirectory(TestDirName); }
catch { }
427 _fileHandler.CreateDirectory(TestDirName);
430 Assert.False(_fileHandler.KifsFileExists($
"{TestDirName}/non_existing_file.txt"));
435 #region Options Tests 446 Assert.Equal(100, options.MaxFilesPerBatch);
456 Assert.True(options.Recursive);
457 Assert.Equal(-1, options.Ttl);
458 Assert.False(options.DeleteIfExists);
468 Assert.True(options.OverwriteExisting);
473 #region Helper Classes 477 public bool MultiPartUploadCompleteCalled {
get;
private set; }
478 public bool PartUploadCalled {
get;
private set; }
479 public bool FullFileUploadCalled {
get;
private set; }
480 public List<FileOperationResult> Results {
get; } =
new List<FileOperationResult>();
482 public void OnMultiPartUploadComplete(IList<FileOperationResult> results)
484 MultiPartUploadCompleteCalled =
true;
485 Results.AddRange(results);
490 PartUploadCalled =
true;
496 FullFileUploadCalled =
true;
void Download_OverwriteExistingFalse_ThrowsException()
void KifsFileExists_NonExistingFile_ReturnsFalse()
const long DefaultFileSizeToSplit
Default file size threshold for multi-part uploads (60 MB).
static DownloadOptions Default
Returns the default download options.
Interface for receiving callbacks during file upload operations.
void CreateDirectory_ExistsNoError_NoException()
void KifsFileExists_ExistingFile_ReturnsTrue()
Main class for handling file operations with Kinetica's KiFS (Kinetica File System).
void DeleteDirectory_ValidName_DeletesSuccessfully()
void CreateDirectory_ValidName_CreatesSuccessfully()
void Download_MultipleFiles_DownloadsSuccessfully()
const int DefaultThreadPoolSize
Default thread pool size for file operations.
void ShowDirectory_ValidName_ReturnsInfo()
Options for uploading files to KiFS.
void DownloadOptions_DefaultValues_AreCorrect()
void Upload_WithCallback_CallsCallback()
void Upload_MultipleFiles_UploadsSuccessfully()
void ShowFiles_ValidDirectory_ReturnsFileInfo()
void ShowAllDirectories_ReturnsDirectories()
void Options_DefaultValues_AreCorrect()
void Upload_SingleFile_UploadsSuccessfully()
void KifsDirectoryExists_ExistingDirectory_ReturnsTrue()
Integration tests for KiFS (Kinetica File System) operations.
Options for configuring the KineticaFileHandler behavior.
void UploadOptions_DefaultValues_AreCorrect()
void Download_SingleFile_DownloadsSuccessfully()
Options for downloading files from KiFS.
void DeleteFiles_ValidFile_DeletesSuccessfully()
static UploadOptions Default
Returns the default upload options.
void KifsDirectoryExists_NonExistingDirectory_ReturnsFalse()
void Upload_NonExistentDirectory_ThrowsException()
void DeleteFilesInDirectory_ValidDirectory_DeletesAllFiles()
void Upload_NonExistentFile_ThrowsException()
Contains the result of a file upload or download operation.
API to talk to Kinetica Database